From 4c7bb32c1fe5a32d2975bde82472707d59214d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ne=C4=8Das?= Date: Fri, 5 Oct 2018 09:09:45 +0200 Subject: [PATCH] Ovirt add kernel persist (#45555) * ovirt add kernel persist * Add description to kernel_params_persist * update kernel_params_persist control logic * correct pep8 syntax * add condition for kernel_params * put kernel persist check to function * kernel persist check update tabs --- lib/ansible/modules/cloud/ovirt/ovirt_vm.py | 31 ++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py index a9f0fb7de7..05f8392d64 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py @@ -363,6 +363,12 @@ options: type: bool version_added: "2.5" aliases: [ 'sysprep_persist' ] + kernel_params_persist: + description: + - "If I(true) C(kernel_params), C(initrd_path) and C(kernel_path) will persist in virtual machine configuration, + if I(False) it will be used for run once." + type: bool + version_added: "2.8" kernel_path: description: - Path to a kernel image used to boot the virtual machine. @@ -1081,8 +1087,11 @@ class VmsModule(BaseModule): otypes.BootDevice(dev) for dev in self.param('boot_devices') ], ) if self.param('boot_devices') else None, + cmdline=self.param('kernel_params') if self.param('kernel_params_persist') else None, + initrd=self.param('initrd_path') if self.param('kernel_params_persist') else None, + kernel=self.param('kernel_path') if self.param('kernel_params_persist') else None, ) if ( - self.param('operating_system') or self.param('boot_devices') + self.param('operating_system') or self.param('boot_devices') or self.param('kernel_params_persist') ) else None, type=otypes.VmType( self.param('type') @@ -1181,6 +1190,7 @@ class VmsModule(BaseModule): check_custom_properties() and check_host() and not self.param('cloud_init_persist') and + not self.param('kernel_params_persist') and equal(self.param('cluster'), get_link_name(self._connection, entity.cluster)) and equal(convert_to_bytes(self.param('memory')), entity.memory) and equal(convert_to_bytes(self.param('memory_guaranteed')), entity.memory_policy.guaranteed) and equal(convert_to_bytes(self.param('memory_max')), entity.memory_policy.max) and @@ -1947,6 +1957,7 @@ def main(): cloud_init=dict(type='dict'), cloud_init_nics=dict(type='list', default=[]), cloud_init_persist=dict(type='bool', default=False, aliases=['sysprep_persist']), + kernel_params_persist=dict(type='bool', default=False), sysprep=dict(type='dict'), host=dict(type='str'), clone=dict(type='bool', default=False), @@ -2021,6 +2032,11 @@ def main(): vms_module.post_present(ret['id']) # Run the VM if it was just created, else don't run it: if state == 'running': + def kernel_persist_check(): + return (module.params.get('kernel_params') or + module.params.get('initrd_path') or + module.params.get('kernel_path') + and not module.params.get('cloud_init_persist')) initialization = vms_module.get_initialization() ret = vms_module.action( action='start', @@ -2048,17 +2064,12 @@ def main(): cmdline=module.params.get('kernel_params'), initrd=module.params.get('initrd_path'), kernel=module.params.get('kernel_path'), - ) if ( - module.params.get('kernel_params') or - module.params.get('initrd_path') or - module.params.get('kernel_path') - ) else None, + ) if (kernel_persist_check()) else None, ) if ( - module.params.get('kernel_params') or - module.params.get('initrd_path') or - module.params.get('kernel_path') or + kernel_persist_check() or module.params.get('host') or - initialization is not None and not module.params.get('cloud_init_persist') + initialization is not None + and not module.params.get('cloud_init_persist') ) else None, )