cloud: ovirt: Ignore 404 error when getting entity (#20386)

pull/20410/head
Ondra Machacek 8 years ago committed by Ryan Brown
parent b519ee9bb3
commit d9d1194c80

@ -247,6 +247,20 @@ def search_by_name(service, name, **kwargs):
return res[0] 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( def wait(
service, service,
condition, condition,
@ -270,7 +284,7 @@ def wait(
start = time.time() start = time.time()
while time.time() < start + timeout: while time.time() < start + timeout:
# Exit if the condition of entity is valid: # Exit if the condition of entity is valid:
entity = service.get() entity = get_entity(service)
if condition(entity): if condition(entity):
return return
elif fail_condition(entity): elif fail_condition(entity):

@ -33,6 +33,7 @@ from ansible.module_utils.ovirt import (
create_connection, create_connection,
equal, equal,
get_dict_of_struct, get_dict_of_struct,
get_entity,
get_link_name, get_link_name,
ovirt_full_argument_spec, ovirt_full_argument_spec,
search_by_name, search_by_name,
@ -192,7 +193,7 @@ class HostNetworksModule(BaseModule):
update = False update = False
bond = self._module.params['bond'] bond = self._module.params['bond']
networks = self._module.params['networks'] networks = self._module.params['networks']
nic = nic_service.get() nic = get_entity(nic_service)
if nic is None: if nic is None:
return update return update

@ -34,6 +34,7 @@ from ansible.module_utils.ovirt import (
check_sdk, check_sdk,
create_connection, create_connection,
equal, equal,
get_entity,
ovirt_full_argument_spec, ovirt_full_argument_spec,
search_by_name, search_by_name,
wait, wait,
@ -285,7 +286,7 @@ class StorageDomainModule(BaseModule):
return return
attached_sd_service = attached_sds_service.storage_domain_service(storage_domain.id) 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 attached_sd and attached_sd.status != sdstate.MAINTENANCE:
if not self._module.check_mode: if not self._module.check_mode:
@ -305,7 +306,7 @@ class StorageDomainModule(BaseModule):
return return
attached_sd_service = attached_sds_service.storage_domain_service(storage_domain.id) 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 attached_sd and attached_sd.status == sdstate.MAINTENANCE:
if not self._module.check_mode: if not self._module.check_mode:
@ -333,7 +334,7 @@ class StorageDomainModule(BaseModule):
# If storage domain isn't attached, attach it: # If storage domain isn't attached, attach it:
attached_sd_service = self._service.service(storage_domain.id) 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( self._service.add(
otypes.StorageDomain( otypes.StorageDomain(
id=storage_domain.id, id=storage_domain.id,

Loading…
Cancel
Save