From f5c0e2895bb4028b657b4d853cd68fd180f34ae0 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Thu, 12 Oct 2017 14:56:13 +0200 Subject: [PATCH] ovirt_vms: Wait for VM disks when adding VM (#31468) Fixes: https://github.com/ansible/ansible/issues/30515 --- lib/ansible/modules/cloud/ovirt/ovirt_vms.py | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py index 8e4c6a53278..02da72407cc 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py @@ -843,6 +843,17 @@ class VmsModule(BaseModule): timeout=self.param('timeout'), ) + def _wait_for_vm_disks(self, vm_service): + disks_service = self._connection.system_service().disks_service() + for da in vm_service.disk_attachments_service().list(): + disk_service = disks_service.disk_service(da.disk.id) + wait( + service=disk_service, + condition=lambda disk: disk.status == otypes.DiskStatus.OK, + wait=self.param('wait'), + timeout=self.param('timeout'), + ) + def wait_for_down(self, vm): """ This function will first wait for the status DOWN of the VM. @@ -884,8 +895,14 @@ class VmsModule(BaseModule): return True def __attach_disks(self, entity): - disks_service = self._connection.system_service().disks_service() + if not self.param('disks'): + return + vm_service = self._service.service(entity.id) + disks_service = self._connection.system_service().disks_service() + disk_attachments_service = vm_service.disk_attachments_service() + + self._wait_for_vm_disks(vm_service) for disk in self.param('disks'): # If disk ID is not specified, find disk by name: disk_id = disk.get('id') @@ -900,8 +917,8 @@ class VmsModule(BaseModule): ) # Attach disk to VM: - disk_attachments_service = self._service.service(entity.id).disk_attachments_service() - if get_entity(disk_attachments_service.attachment_service(disk_id)) is None: + disk_attachment = disk_attachments_service.attachment_service(disk_id) + if get_entity(disk_attachment) is None: if not self._module.check_mode: disk_attachments_service.add( otypes.DiskAttachment(