mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-04 04:12:48 +00:00
cloud: ovirt: Ignore 404 error when getting entity (#20386)
This commit is contained in:
committed by
Ryan Brown
parent
b519ee9bb3
commit
d9d1194c80
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user