ovirt_vms: Wait for VM disks when adding VM (#31468)

Fixes: https://github.com/ansible/ansible/issues/30515
This commit is contained in:
Ondra Machacek 2017-10-12 14:56:13 +02:00 committed by ansibot
parent e5c0958dbb
commit f5c0e2895b

View file

@ -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(