From 43af09fc8fe7df6b691a46f620d7209412fd9f8f Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Thu, 31 May 2018 12:40:19 +0200 Subject: [PATCH] ovirt_vms: Fix change cd (#40939) * ovirt_vms: Fix attaching of CD * ovirt_vms: Fix idemptency --- lib/ansible/modules/cloud/ovirt/ovirt_vms.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py index 5be363d8cd..4d069dd541 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py @@ -1186,8 +1186,9 @@ class VmsModule(BaseModule): def post_present(self, entity_id): # After creation of the VM, attach disks and NICs: entity = self._service.service(entity_id).get() - self.changed = self.__attach_disks(entity) - self.changed = self.__attach_nics(entity) + self.__attach_disks(entity) + self.__attach_nics(entity) + self._attach_cd(entity) self.changed = self.__attach_numa_nodes(entity) self.changed = self.__attach_watchdog(entity) self.changed = self.__attach_graphical_console(entity) @@ -1239,7 +1240,7 @@ class VmsModule(BaseModule): cd_iso = self.param('cd_iso') if cd_iso is not None: vm_service = self._service.service(entity.id) - current = vm_service.get().status == otypes.VmStatus.UP + current = vm_service.get().status == otypes.VmStatus.UP and self.param('state') == 'running' cdroms_service = vm_service.cdroms_service() cdrom_device = cdroms_service.list()[0] cdrom_service = cdroms_service.cdrom_service(cdrom_device.id) @@ -1339,7 +1340,7 @@ class VmsModule(BaseModule): def __attach_graphical_console(self, entity): graphical_console = self.param('graphical_console') if not graphical_console: - return + return False vm_service = self._service.service(entity.id) gcs_service = vm_service.graphics_consoles_service() @@ -1450,6 +1451,7 @@ class VmsModule(BaseModule): ) def __attach_numa_nodes(self, entity): + updated = False numa_nodes_service = self._service.service(entity.id).numa_nodes_service() if len(self.param('numa_nodes')) > 0: @@ -1458,10 +1460,11 @@ class VmsModule(BaseModule): existed_numa_nodes.sort(reverse=len(existed_numa_nodes) > 1 and existed_numa_nodes[1].index > existed_numa_nodes[0].index) for current_numa_node in existed_numa_nodes: numa_nodes_service.node_service(current_numa_node.id).remove() + updated = True for numa_node in self.param('numa_nodes'): if numa_node is None or numa_node.get('index') is None or numa_node.get('cores') is None or numa_node.get('memory') is None: - return False + continue numa_nodes_service.add( otypes.VirtualNumaNode( @@ -1481,8 +1484,9 @@ class VmsModule(BaseModule): ] if numa_node.get('numa_node_pins') is not None else None, ) ) + updated = True - return True + return updated def __attach_watchdog(self, entity): watchdogs_service = self._service.service(entity.id).watchdogs_service() @@ -2002,11 +2006,9 @@ def main(): clone=module.params['clone'], clone_permissions=module.params['clone_permissions'], ) - vms_module.post_present(ret['id']) if module.params['force']: ret = vms_module.action( action='stop', - post_action=vms_module._attach_cd, action_condition=lambda vm: vm.status != otypes.VmStatus.DOWN, wait_condition=vms_module.wait_for_down, ) @@ -2014,10 +2016,10 @@ def main(): ret = vms_module.action( action='shutdown', pre_action=vms_module._pre_shutdown_action, - post_action=vms_module._attach_cd, action_condition=lambda vm: vm.status != otypes.VmStatus.DOWN, wait_condition=vms_module.wait_for_down, ) + vms_module.post_present(ret['id']) elif state == 'suspended': vms_module.create( entity=vm,