qvm-template-postprocess: extract config handling into separate function
Keep post_install() short.
This commit is contained in:
parent
bcf59579f1
commit
c4efdf41c5
@ -309,6 +309,38 @@ def post_install(args):
|
|||||||
|
|
||||||
conf_path = os.path.join(args.dir, 'template.conf')
|
conf_path = os.path.join(args.dir, 'template.conf')
|
||||||
if os.path.exists(conf_path):
|
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)
|
conf = parse_template_config(conf_path)
|
||||||
# Import qvm-feature tags
|
# Import qvm-feature tags
|
||||||
for key in (
|
for key in (
|
||||||
@ -352,25 +384,6 @@ def post_install(args):
|
|||||||
vm.log.warning(
|
vm.log.warning(
|
||||||
'Currently only supports setting kernel to (none)')
|
'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):
|
def pre_remove(args):
|
||||||
'''Handle pre-removal tasks'''
|
'''Handle pre-removal tasks'''
|
||||||
|
Loading…
Reference in New Issue
Block a user