tools: split calling qubes.PostInstall service to a separate function
The code is long enough to warrant separate function (suggested by pylint).
This commit is contained in:
parent
627aebf2cd
commit
7c9699cd87
@ -31,8 +31,6 @@ import sys
|
|||||||
|
|
||||||
import grp
|
import grp
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
import qubesadmin
|
import qubesadmin
|
||||||
import qubesadmin.exc
|
import qubesadmin.exc
|
||||||
import qubesadmin.tools
|
import qubesadmin.tools
|
||||||
@ -142,39 +140,12 @@ def import_appmenus(vm, source_dir):
|
|||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
vm.log.warning('Failed to set default application list: %s', e)
|
vm.log.warning('Failed to set default application list: %s', e)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def post_install(args):
|
def call_postinstall_service(vm):
|
||||||
'''Handle post-installation tasks'''
|
'''Call qubes.PostInstall service
|
||||||
|
|
||||||
app = args.app
|
And adjust related settings (netvm, features).
|
||||||
try:
|
'''
|
||||||
# reinstall
|
|
||||||
vm = app.domains[args.name]
|
|
||||||
except KeyError:
|
|
||||||
if app.qubesd_connection_type == 'socket' and \
|
|
||||||
args.dir == '/var/lib/qubes/vm-templates/' + args.name:
|
|
||||||
# vm.create_on_disk() need to create the directory on its own,
|
|
||||||
# move it away for from its way
|
|
||||||
tmp_sourcedir = os.path.join('/var/lib/qubes/vm-templates',
|
|
||||||
'tmp-' + args.name)
|
|
||||||
shutil.move(args.dir, tmp_sourcedir)
|
|
||||||
args.dir = tmp_sourcedir
|
|
||||||
|
|
||||||
vm = app.add_new_vm('TemplateVM',
|
|
||||||
name=args.name,
|
|
||||||
label=qubesadmin.config.defaults['template_label'])
|
|
||||||
|
|
||||||
vm.log.info('Importing data')
|
|
||||||
try:
|
|
||||||
import_root_img(vm, args.dir)
|
|
||||||
except:
|
|
||||||
# if data import fails, remove half-created VM
|
|
||||||
del app.domains[vm.name]
|
|
||||||
raise
|
|
||||||
import_appmenus(vm, args.dir)
|
|
||||||
|
|
||||||
if not args.skip_start:
|
|
||||||
# just created, so no need to save previous value - we know what it was
|
# just created, so no need to save previous value - we know what it was
|
||||||
vm.netvm = None
|
vm.netvm = None
|
||||||
# temporarily enable qrexec feature - so vm.start() will wait for it;
|
# temporarily enable qrexec feature - so vm.start() will wait for it;
|
||||||
@ -209,6 +180,41 @@ def post_install(args):
|
|||||||
finally:
|
finally:
|
||||||
vm.netvm = qubesadmin.DEFAULT
|
vm.netvm = qubesadmin.DEFAULT
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def post_install(args):
|
||||||
|
'''Handle post-installation tasks'''
|
||||||
|
|
||||||
|
app = args.app
|
||||||
|
try:
|
||||||
|
# reinstall
|
||||||
|
vm = app.domains[args.name]
|
||||||
|
except KeyError:
|
||||||
|
if app.qubesd_connection_type == 'socket' and \
|
||||||
|
args.dir == '/var/lib/qubes/vm-templates/' + args.name:
|
||||||
|
# vm.create_on_disk() need to create the directory on its own,
|
||||||
|
# move it away for from its way
|
||||||
|
tmp_sourcedir = os.path.join('/var/lib/qubes/vm-templates',
|
||||||
|
'tmp-' + args.name)
|
||||||
|
shutil.move(args.dir, tmp_sourcedir)
|
||||||
|
args.dir = tmp_sourcedir
|
||||||
|
|
||||||
|
vm = app.add_new_vm('TemplateVM',
|
||||||
|
name=args.name,
|
||||||
|
label=qubesadmin.config.defaults['template_label'])
|
||||||
|
|
||||||
|
vm.log.info('Importing data')
|
||||||
|
try:
|
||||||
|
import_root_img(vm, args.dir)
|
||||||
|
except:
|
||||||
|
# if data import fails, remove half-created VM
|
||||||
|
del app.domains[vm.name]
|
||||||
|
raise
|
||||||
|
import_appmenus(vm, args.dir)
|
||||||
|
|
||||||
|
if not args.skip_start:
|
||||||
|
yield from call_postinstall_service(vm)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user