From 81caa837a429c41675b675a8ff4146f0ed068c5f Mon Sep 17 00:00:00 2001 From: maorlipchuk Date: Tue, 29 Aug 2017 16:50:38 +0300 Subject: [PATCH] Use data center UUID/name in storage domains module (#28659) The ansible action ovirt_storage_domains obligates a data center name of the attached storage domain as part of its action's arguments, so it will get the attached_sd_service as part of the functionality of changing the storage domain status (to maintenance for example). On the other hand, ovirt_storage_domains_facts retrieves a storage domain entity with information about the data center which the storage domain is attached to as a UUID identifier (without name). So for the user to use that storage domain, fetched from the facts module, one will have to fetch the DC entity to get the name. We could use the search which is used today using: service.list(search=...) but that type of search does not support search by Guid. Therefor this patch provides the ability to use ovirt_storage_domains action with state change using also a DC UUID instead of a DC name. --- .../modules/cloud/ovirt/ovirt_storage_domains.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py b/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py index 5d03caf6e8f..59043ffee93 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py @@ -137,6 +137,15 @@ EXAMPLES = ''' address: 10.34.63.199 path: /path/data +# Add data NFS storage domain with id for data center +- ovirt_storage_domains: + name: data_nfs + host: myhost + data_center: 11111 + nfs: + address: 10.34.63.199 + path: /path/data + # Add data localfs storage domain - ovirt_storage_domains: name: data_localfs @@ -321,9 +330,13 @@ class StorageDomainModule(BaseModule): def _attached_sds_service(self): # Get data center object of the storage domain: dcs_service = self._connection.system_service().data_centers_service() + + # Serach the data_center name, if it does not exists, try to search by guid. dc = search_by_name(dcs_service, self._module.params['data_center']) if dc is None: - return + dc = dcs_service.service(self._module.params['data_center']).get() + if dc is None: + return dc_service = dcs_service.data_center_service(dc.id) return dc_service.storage_domains_service()