qvm-template-postprocess: extract config handling into separate function

Keep post_install() short.
This commit is contained in:
Marek Marczykowski-Górecki 2021-02-19 14:12:53 +01:00
parent bcf59579f1
commit c4efdf41c5
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -309,6 +309,38 @@ def post_install(args):
conf_path = os.path.join(args.dir, 'template.conf')
if os.path.exists(conf_path):
import_template_config(args, conf_path, vm)
if not args.skip_start:
yield from call_postinstall_service(vm)
if not args.keep_source:
if local_reinstall:
# remove only imported root img
root_path = os.path.join(args.dir, 'root.img')
for root_part in glob.glob(root_path + '.part.*'):
os.unlink(root_part)
else:
shutil.rmtree(args.dir)
# if running as root, tell underlying storage layer about just freed
# data blocks
if os.getuid() == 0:
subprocess.call(['sync', '-f', os.path.dirname(args.dir)])
subprocess.call(['fstrim', os.path.dirname(args.dir)])
return 0
def import_template_config(args, conf_path, vm):
"""
Parse template.conf and apply its content to the just installed TemplateVM
:param args: arguments for qvm-template-postprocess (used for --allow-pv
option and possibly some other in the future)
:param conf_path: path to the template.conf
:param vm: Template to operate on
:return:
"""
conf = parse_template_config(conf_path)
# Import qvm-feature tags
for key in (
@ -352,25 +384,6 @@ def post_install(args):
vm.log.warning(
'Currently only supports setting kernel to (none)')
if not args.skip_start:
yield from call_postinstall_service(vm)
if not args.keep_source:
if local_reinstall:
# remove only imported root img
root_path = os.path.join(args.dir, 'root.img')
for root_part in glob.glob(root_path + '.part.*'):
os.unlink(root_part)
else:
shutil.rmtree(args.dir)
# if running as root, tell underlying storage layer about just freed
# data blocks
if os.getuid() == 0:
subprocess.call(['sync', '-f', os.path.dirname(args.dir)])
subprocess.call(['fstrim', os.path.dirname(args.dir)])
return 0
def pre_remove(args):
'''Handle pre-removal tasks'''