Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
response = virtual_network.create_vcn(request)
vcn = response.data
get_vcn_response = virtual_network.get_vcn(vcn.id)
get_vcn_response.data.lifecycle_state = 'DUMMY' # This will force at least one service call
def fetch_func(response=None):
counters['wait'] = counters['wait'] + 1
return virtual_network.get_vcn(vcn.id)
response = oci.wait_until(virtual_network, get_vcn_response, 'lifecycle_state', 'AVAILABLE', fetch_func=fetch_func)
assert 'AVAILABLE' == response.data.lifecycle_state
assert counters['wait'] > 0
print('Deleting vcn')
response = virtual_network.delete_vcn(vcn.id)
result = oci.wait_until(virtual_network, get_vcn_response, 'lifecycle_state', 'TERMINATED', max_wait_seconds=180, succeed_on_not_found=True)
assert result == oci.waiter.WAIT_RESOURCE_NOT_FOUND
)
oci_utils.call_with_backoff(
instance_action_method, instance_pool_id=instance_pool_id
)
response = oci_utils.call_with_backoff(
compute_management_client.get_instance_pool,
instance_pool_id=instance_pool_id,
)
# for now the power actions on instances do not go through common utilities for wait.
if module.params.get("wait", None):
debug(
"waiting for lifecycle_state to reach {0}".format(
desired_lifecycle_states[desired_state]
)
)
oci.wait_until(
compute_management_client,
response,
"lifecycle_state",
desired_lifecycle_states[desired_state],
max_wait_seconds=module.params.get(
"wait_timeout", oci_utils.MAX_WAIT_TIMEOUT_IN_SECONDS
),
)
response = oci_utils.call_with_backoff(
compute_management_client.get_instance_pool,
instance_pool_id=instance_pool_id,
)
else:
debug(
"Not waiting for power action request {0} as 'wait' is false.".format(
desired_state
operation_result = None
try:
operation_result = self.client.delete_configuration_source_provider(configuration_source_provider_id, **operation_kwargs)
except oci.exceptions.ServiceError as e:
if e.status == 404:
return WAIT_RESOURCE_NOT_FOUND
else:
raise e
if not wait_for_states:
return operation_result
lowered_wait_for_states = [w.lower() for w in wait_for_states]
try:
waiter_result = oci.wait_until(
self.client,
initial_get_result,
evaluate_response=lambda r: getattr(r.data, 'lifecycle_state') and getattr(r.data, 'lifecycle_state').lower() in lowered_wait_for_states,
succeed_on_not_found=True,
**waiter_kwargs
)
result_to_return = waiter_result
return result_to_return
except Exception as e:
raise oci.exceptions.CompositeOperationError(partial_results=[operation_result], cause=e)
client = cli_util.build_client('resource_manager', ctx)
result = client.delete_stack(
stack_id=stack_id,
**kwargs
)
if wait_for_state:
if hasattr(client, 'get_stack') and callable(getattr(client, 'get_stack')):
try:
wait_period_kwargs = {}
if max_wait_seconds is not None:
wait_period_kwargs['max_wait_seconds'] = max_wait_seconds
if wait_interval_seconds is not None:
wait_period_kwargs['max_interval_seconds'] = wait_interval_seconds
click.echo('Action completed. Waiting until the resource has entered state: {}'.format(wait_for_state), file=sys.stderr)
oci.wait_until(client, client.get_stack(stack_id), 'lifecycle_state', wait_for_state, succeed_on_not_found=True, **wait_period_kwargs)
except oci.exceptions.ServiceError as e:
# We make an initial service call so we can pass the result to oci.wait_until(), however if we are waiting on the
# outcome of a delete operation it is possible that the resource is already gone and so the initial service call
# will result in an exception that reflects a HTTP 404. In this case, we can exit with success (rather than raising
# the exception) since this would have been the behaviour in the waiter anyway (as for delete we provide the argument
# succeed_on_not_found=True to the waiter).
#
# Any non-404 should still result in the exception being thrown.
if e.status == 404:
pass
else:
raise
except oci.exceptions.MaximumWaitTimeExceeded as e:
# If we fail, we should show an error, but we should still provide the information to the customer
click.echo('Failed to wait until the resource entered the specified state. Please retrieve the resource to find its current state', file=sys.stderr)
cli_util.render_response(result, ctx)
:param dict operation_kwargs:
A dictionary of keyword arguments to pass to :py:func:`~oci.resource_manager.ResourceManagerClient.update_configuration_source_provider`
:param dict waiter_kwargs:
A dictionary of keyword arguments to pass to the :py:func:`oci.wait_until` function. For example, you could pass ``max_interval_seconds`` or ``max_interval_seconds``
as dictionary keys to modify how long the waiter function will wait between retries and the maximum amount of time it will wait
"""
operation_result = self.client.update_configuration_source_provider(configuration_source_provider_id, update_configuration_source_provider_details, **operation_kwargs)
if not wait_for_states:
return operation_result
lowered_wait_for_states = [w.lower() for w in wait_for_states]
wait_for_resource_id = operation_result.data.id
try:
waiter_result = oci.wait_until(
self.client,
self.client.get_configuration_source_provider(wait_for_resource_id),
evaluate_response=lambda r: getattr(r.data, 'lifecycle_state') and getattr(r.data, 'lifecycle_state').lower() in lowered_wait_for_states,
**waiter_kwargs
)
result_to_return = waiter_result
return result_to_return
except Exception as e:
raise oci.exceptions.CompositeOperationError(partial_results=[operation_result], cause=e)
compute_client.get_volume_attachment,
volume_attachment_id=volume_attachment_id,
).data
if volume_attachment.lifecycle_state in ["DETACHING", "DETACHED"]:
result["changed"] = False
result["volume_attachment"] = to_dict(volume_attachment)
else:
oci_utils.call_with_backoff(
compute_client.detach_volume, volume_attachment_id=volume_attachment_id
)
response = oci_utils.call_with_backoff(
compute_client.get_volume_attachment,
volume_attachment_id=volume_attachment_id,
)
result["volume_attachment"] = to_dict(
oci.wait_until(
compute_client, response, "lifecycle_state", "DETACHED"
).data
)
result["changed"] = True
except MaximumWaitTimeExceeded as ex:
module.fail_json(msg=str(ex))
except ServiceError as ex:
module.fail_json(msg=ex.message)
return result
operation_result = None
try:
operation_result = self.client.delete_nat_gateway(nat_gateway_id, **operation_kwargs)
except oci.exceptions.ServiceError as e:
if e.status == 404:
return WAIT_RESOURCE_NOT_FOUND
else:
raise e
if not wait_for_states:
return operation_result
lowered_wait_for_states = [w.lower() for w in wait_for_states]
try:
waiter_result = oci.wait_until(
self.client,
initial_get_result,
evaluate_response=lambda r: getattr(r.data, 'lifecycle_state') and getattr(r.data, 'lifecycle_state').lower() in lowered_wait_for_states,
succeed_on_not_found=True,
**waiter_kwargs
)
result_to_return = waiter_result
return result_to_return
except Exception as e:
raise oci.exceptions.CompositeOperationError(partial_results=[operation_result], cause=e)
:param dict operation_kwargs:
A dictionary of keyword arguments to pass to :py:func:`~oci.oda.OdaClient.create_oda_instance`
:param dict waiter_kwargs:
A dictionary of keyword arguments to pass to the :py:func:`oci.wait_until` function. For example, you could pass ``max_interval_seconds`` or ``max_interval_seconds``
as dictionary keys to modify how long the waiter function will wait between retries and the maximum amount of time it will wait
"""
operation_result = self.client.create_oda_instance(create_oda_instance_details, **operation_kwargs)
if not wait_for_states:
return operation_result
lowered_wait_for_states = [w.lower() for w in wait_for_states]
wait_for_resource_id = operation_result.headers['opc-work-request-id']
try:
waiter_result = oci.wait_until(
self.client,
self.client.get_work_request(wait_for_resource_id),
evaluate_response=lambda r: getattr(r.data, 'status') and getattr(r.data, 'status').lower() in lowered_wait_for_states,
**waiter_kwargs
)
result_to_return = self.client.get_oda_instance(waiter_result.data.oda_instance_id)
return result_to_return
except Exception as e:
raise oci.exceptions.CompositeOperationError(partial_results=[operation_result], cause=e)
:param dict operation_kwargs:
A dictionary of keyword arguments to pass to :py:func:`~oci.core.VirtualNetworkClient.update_vcn`
:param dict waiter_kwargs:
A dictionary of keyword arguments to pass to the :py:func:`oci.wait_until` function. For example, you could pass ``max_interval_seconds`` or ``max_interval_seconds``
as dictionary keys to modify how long the waiter function will wait between retries and the maximum amount of time it will wait
"""
operation_result = self.client.update_vcn(vcn_id, update_vcn_details, **operation_kwargs)
if not wait_for_states:
return operation_result
lowered_wait_for_states = [w.lower() for w in wait_for_states]
wait_for_resource_id = operation_result.data.id
try:
waiter_result = oci.wait_until(
self.client,
self.client.get_vcn(wait_for_resource_id),
evaluate_response=lambda r: getattr(r.data, 'lifecycle_state') and getattr(r.data, 'lifecycle_state').lower() in lowered_wait_for_states,
**waiter_kwargs
)
result_to_return = waiter_result
return result_to_return
except Exception as e:
raise oci.exceptions.CompositeOperationError(partial_results=[operation_result], cause=e)
try:
operation_result = self.client.delete_path_route_set(load_balancer_id, path_route_set_name, **operation_kwargs)
except oci.exceptions.ServiceError as e:
if e.status == 404:
return WAIT_RESOURCE_NOT_FOUND
else:
raise e
if not wait_for_states:
return operation_result
lowered_wait_for_states = [w.lower() for w in wait_for_states]
wait_for_resource_id = operation_result.headers['opc-work-request-id']
try:
waiter_result = oci.wait_until(
self.client,
self.client.get_work_request(wait_for_resource_id),
evaluate_response=lambda r: getattr(r.data, 'lifecycle_state') and getattr(r.data, 'lifecycle_state').lower() in lowered_wait_for_states,
**waiter_kwargs
)
result_to_return = waiter_result
return result_to_return
except Exception as e:
raise oci.exceptions.CompositeOperationError(partial_results=[operation_result], cause=e)