summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndra Machacek <machacek.ondra@gmail.com>2017-01-18 16:00:23 +0100
committerRyan Brown <sb@ryansb.com>2017-01-18 10:00:23 -0500
commitd9d1194c8004091d783fac379e57859931a03230 (patch)
tree636bf76d8b4032029f48ee3ef6189e7bfe1e0c3f
parentb519ee9bb31b953c92da46692c57ac46624d980f (diff)
downloadansible-d9d1194c8004091d783fac379e57859931a03230.tar.gz
cloud: ovirt: Ignore 404 error when getting entity (#20386)
-rw-r--r--lib/ansible/module_utils/ovirt.py16
-rw-r--r--lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py3
-rw-r--r--lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py7
3 files changed, 21 insertions, 5 deletions
diff --git a/lib/ansible/module_utils/ovirt.py b/lib/ansible/module_utils/ovirt.py
index e044b878f2..c74aafb8ab 100644
--- a/lib/ansible/module_utils/ovirt.py
+++ b/lib/ansible/module_utils/ovirt.py
@@ -247,6 +247,20 @@ def search_by_name(service, name, **kwargs):
return res[0]
+def get_entity(service):
+ """
+ Ignore SDK Error in case of getting an entity from service.
+ """
+ entity = None
+ try:
+ entity = service.get()
+ except sdk.Error:
+ # We can get here 404, we should ignore it, in case
+ # of removing entity for example.
+ pass
+ return entity
+
+
def wait(
service,
condition,
@@ -270,7 +284,7 @@ def wait(
start = time.time()
while time.time() < start + timeout:
# Exit if the condition of entity is valid:
- entity = service.get()
+ entity = get_entity(service)
if condition(entity):
return
elif fail_condition(entity):
diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py b/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py
index bb0714a6bb..5bdb7d6938 100644
--- a/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py
+++ b/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py
@@ -33,6 +33,7 @@ from ansible.module_utils.ovirt import (
create_connection,
equal,
get_dict_of_struct,
+ get_entity,
get_link_name,
ovirt_full_argument_spec,
search_by_name,
@@ -192,7 +193,7 @@ class HostNetworksModule(BaseModule):
update = False
bond = self._module.params['bond']
networks = self._module.params['networks']
- nic = nic_service.get()
+ nic = get_entity(nic_service)
if nic is None:
return update
diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py b/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py
index bf4a3bb2fd..bb0fe20a5f 100644
--- a/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py
+++ b/lib/ansible/modules/cloud/ovirt/ovirt_storage_domains.py
@@ -34,6 +34,7 @@ from ansible.module_utils.ovirt import (
check_sdk,
create_connection,
equal,
+ get_entity,
ovirt_full_argument_spec,
search_by_name,
wait,
@@ -285,7 +286,7 @@ class StorageDomainModule(BaseModule):
return
attached_sd_service = attached_sds_service.storage_domain_service(storage_domain.id)
- attached_sd = attached_sd_service.get()
+ attached_sd = get_entity(attached_sd_service)
if attached_sd and attached_sd.status != sdstate.MAINTENANCE:
if not self._module.check_mode:
@@ -305,7 +306,7 @@ class StorageDomainModule(BaseModule):
return
attached_sd_service = attached_sds_service.storage_domain_service(storage_domain.id)
- attached_sd = attached_sd_service.get()
+ attached_sd = get_entity(attached_sd_service)
if attached_sd and attached_sd.status == sdstate.MAINTENANCE:
if not self._module.check_mode:
@@ -333,7 +334,7 @@ class StorageDomainModule(BaseModule):
# If storage domain isn't attached, attach it:
attached_sd_service = self._service.service(storage_domain.id)
- if attached_sd_service.get() is None:
+ if get_entity(attached_sd_service) is None:
self._service.add(
otypes.StorageDomain(
id=storage_domain.id,