def delete(config): module = config.module client = config.client(get_region(module), "vpc", "project") if module.params["port_id"]: module.params["port_id"] = "" update(config) send_delete_request(module, None, client) url = build_path(module, "publicips/{id}") def _refresh_status(): try: client.get(url) except HwcClientException404: return True, "Done" except Exception: return None, "" return True, "Pending" timeout = 60 * int(module.params['timeouts']['create'].rstrip('m')) try: wait_to_finish(["Done"], ["Pending"], _refresh_status, timeout) except Exception as ex: module.fail_json(msg="module(hwc_vpc_eip): error " "waiting for api(delete) to " "be done, error= %s" % str(ex))
def wait_for_completion(op_uri, timeout, allowed_states, complete_states, config): module = config.module client = config.client(get_region(module), "vpc", "project") def _refresh_status(): r = None try: r = fetch_resource(module, client, op_uri) except Exception: return None, "" status = "" try: status = navigate_value(r, ['vpc', 'status']) except Exception: return None, "" return r, status try: return wait_to_finish(complete_states, allowed_states, _refresh_status, timeout) except Exception as ex: module.fail_json(msg=str(ex))
def async_wait_update(config, result, client, timeout): module = config.module url = build_path(module, "publicips/{id}") def _query_status(): r = None try: r = client.get(url, timeout=timeout) except HwcClientException: return None, "" try: s = navigate_value(r, ["publicip", "status"]) return r, s except Exception: return None, "" try: return wait_to_finish( ["ACTIVE", "DOWN"], None, _query_status, timeout) except Exception as ex: module.fail_json(msg="module(hwc_vpc_eip): error " "waiting for api(update) to " "be done, error= %s" % str(ex))
def async_wait_create(config, result, client, timeout): module = config.module path_parameters = { "publicip_id": ["publicip", "id"], } data = dict((key, navigate_value(result, path)) for key, path in path_parameters.items()) url = build_path(module, "publicips/{publicip_id}", data) def _query_status(): r = None try: r = client.get(url, timeout=timeout) except HwcClientException: return None, "" try: s = navigate_value(r, ["publicip", "status"]) return r, s except Exception: return None, "" try: return wait_to_finish( ["ACTIVE", "DOWN"], None, _query_status, timeout) except Exception as ex: module.fail_json(msg="module(hwc_vpc_eip): error " "waiting for api(create) to " "be done, error= %s" % str(ex))
def async_wait(config, result, client, timeout): module = config.module path_parameters = { "job_id": ["job_id"], } data = dict((key, navigate_value(result, path)) for key, path in path_parameters.items()) url = build_path(module, "jobs/{job_id}", data) def _query_status(): r = None try: r = client.get(url, timeout=timeout) except HwcClientException: return None, "" try: s = navigate_value(r, ["status"]) return r, s except Exception: return None, "" try: return wait_to_finish(["SUCCESS"], ["RUNNING", "INIT"], _query_status, timeout) except Exception as ex: module.fail_json(msg="module(hwc_evs_disk): error " "waiting to be done, error= %s" % str(ex))
def wait_for_delete(module, client, link): def _refresh_status(): try: client.get(link) except HwcClientException404: return True, "Done" except Exception: return None, "" return True, "Pending" timeout = 60 * int(module.params['timeouts']['delete'].rstrip('m')) try: return wait_to_finish(["Done"], ["Pending"], _refresh_status, timeout) except Exception as ex: module.fail_json(msg=str(ex))