diff options
author | Martin Nečas <necas.marty@gmail.com> | 2020-08-07 20:00:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-07 13:00:42 -0500 |
commit | 90334b1dddcd5a18adb49b9f7cafbd1e6a71f9bc (patch) | |
tree | 8eec7c21d796718b63e812f1206fe53a8ac55b86 | |
parent | c632d74487e7425cd4ad78bfcf37475610deeeb8 (diff) | |
download | ansible-90334b1dddcd5a18adb49b9f7cafbd1e6a71f9bc.tar.gz |
Backport: ovirt_vm fix cd attachment (#70932)
* Backport: ovirt_vm fix cd attachment
* add changelog
* fix formats
* Update changelogs/fragments/70932-ovirt_vm-fix-cd_iso-search.yml
Co-authored-by: Rick Elrod <rick@elrod.me>
-rw-r--r-- | changelogs/fragments/70932-ovirt_vm-fix-cd_iso-search.yml | 2 | ||||
-rw-r--r-- | lib/ansible/modules/cloud/ovirt/ovirt_vm.py | 26 |
2 files changed, 22 insertions, 6 deletions
diff --git a/changelogs/fragments/70932-ovirt_vm-fix-cd_iso-search.yml b/changelogs/fragments/70932-ovirt_vm-fix-cd_iso-search.yml new file mode 100644 index 0000000000..b1d8c116d9 --- /dev/null +++ b/changelogs/fragments/70932-ovirt_vm-fix-cd_iso-search.yml @@ -0,0 +1,2 @@ +bugfixes: +- ovirt_vm - fix cd_iso search diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py index 2edc476aec..0c96ae26fa 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_vm.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_vm.py @@ -306,7 +306,7 @@ options: 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. @@ -1677,15 +1677,29 @@ class VmsModule(BaseModule): 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="{0}"'.format(self.param('cd_iso'))) + sds_service = self._connection.system_service().storage_domains_service() + sds = sds_service.list(search='name="{0}"'.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 "{0}".'.format(self.param('cd_iso'))) if len(disks) > 1: raise ValueError('Found mutiple disks with same name "{0}" 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): |