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 time
|
||||
|
||||
import qubesadmin
|
||||
import qubesadmin.exc
|
||||
import qubesadmin.tools
|
||||
@ -142,39 +140,12 @@ def import_appmenus(vm, source_dir):
|
||||
except subprocess.CalledProcessError as e:
|
||||
vm.log.warning('Failed to set default application list: %s', e)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def post_install(args):
|
||||
'''Handle post-installation tasks'''
|
||||
def call_postinstall_service(vm):
|
||||
'''Call qubes.PostInstall service
|
||||
|
||||
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:
|
||||
And adjust related settings (netvm, features).
|
||||
'''
|
||||
# just created, so no need to save previous value - we know what it was
|
||||
vm.netvm = None
|
||||
# temporarily enable qrexec feature - so vm.start() will wait for it;
|
||||
@ -209,6 +180,41 @@ def post_install(args):
|
||||
finally:
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user