Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovirt_vm: fix cd_iso get all disks from storage domains #66

Merged
merged 8 commits into from
Jul 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions plugins/modules/ovirt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
cd_iso:
description:
- ISO file from ISO storage domain which should be attached to Virtual Machine.
- If you have multiple ISO disks with the same name use disk ID to specify which should be used.
- If you have multiple ISO disks with the same name use disk ID to specify which should be used or use C(storage_domain) to filter disks.
- If you pass empty string the CD will be ejected from VM.
- If used with C(state) I(running) or I(present) and VM is running the CD will be attached to VM.
- If used with C(state) I(running) or I(present) and VM is down the CD will be attached to VM persistently.
Expand Down Expand Up @@ -1660,15 +1660,29 @@ def _post_start_action(self, entity):
self._wait_for_UP(vm_service)
self._attach_cd(vm_service.get())

def __get_cds_from_sds(self, sds):
for sd in sds:
if sd.type == otypes.StorageDomainType.ISO:
disks = sd.files
elif sd.type == otypes.StorageDomainType.DATA:
disks = sd.disks
else:
continue
disks = list(filter(lambda x: (x.name == self.param('cd_iso') or x.id == self.param('cd_iso')) and
(sd.type == otypes.StorageDomainType.ISO or x.content_type == otypes.DiskContentType.ISO),
self._connection.follow_link(disks)))
if disks:
return disks

def __get_cd_id(self):
disks_service = self._connection.system_service().disks_service()
disks = disks_service.list(search='name="{}"'.format(self.param('cd_iso')))
sds_service = self._connection.system_service().storage_domains_service()
sds = sds_service.list(search='name="{}"'.format(self.param('storage_domain') if self.param('storage_domain') else "*"))
disks = self.__get_cds_from_sds(sds)
if not disks:
raise ValueError('Was not able to find disk with name or id "{}".'.format(self.param('cd_iso')))
if len(disks) > 1:
raise ValueError('Found mutiple disks with same name "{}" please use \
disk ID in "cd_iso" to specify which disk should be used.'.format(self.param('cd_iso')))
if not disks:
# The `cd_iso` is valid disk ID returning to _attach_cd
return disks_service.disk_service(self.param('cd_iso')).get().id
return disks[0].id

def _attach_cd(self, entity):
Expand Down