Exemplo n.º 1
0
def delete(config):
    module = config.module
    client = config.client(get_region(module), "network", "project")

    send_delete_request(module, None, client)

    url = build_path(module, "v2.0/vpc/peerings/{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_peering_connect): error "
                         "waiting for api(delete) to "
                         "be done, error= %s" % str(ex))
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
def async_wait_create(config, result, client, timeout):
    module = config.module

    path_parameters = {
        "peering_id": ["peering", "id"],
    }
    data = {
        key: navigate_value(result, path)
        for key, path in path_parameters.items()
    }

    url = build_path(module, "v2.0/vpc/peerings/{peering_id}", data)

    def _query_status():
        r = None
        try:
            r = client.get(url, timeout=timeout)
        except HwcClientException:
            return None, ""

        try:
            s = navigate_value(r, ["peering", "status"])
            return r, s
        except Exception:
            return None, ""

    try:
        return wait_to_finish(["ACTIVE"], ["PENDING_ACCEPTANCE"],
                              _query_status, timeout)
    except Exception as ex:
        module.fail_json(msg="module(hwc_vpc_peering_connect): error "
                         "waiting for api(create) to "
                         "be done, error= %s" % str(ex))
Exemplo n.º 4
0
def async_wait_update(config, result, client, timeout):
    module = config.module

    path_parameters = {
        "subnet_id": ["subnet", "id"],
    }
    data = {
        key: navigate_value(result, path)
        for key, path in path_parameters.items()
    }

    url = build_path(module, "subnets/{subnet_id}", data)

    def _query_status():
        r = None
        try:
            r = client.get(url, timeout=timeout)
        except HwcClientException:
            return None, ""

        try:
            s = navigate_value(r, ["subnet", "status"])
            return r, s
        except Exception:
            return None, ""

    try:
        return wait_to_finish(["ACTIVE"], ["UNKNOWN"], _query_status, timeout)
    except Exception as ex:
        module.fail_json(msg="module(hwc_vpc_subnet): error "
                         "waiting for api(update) to "
                         "be done, error= %s" % str(ex))
def search_resource(config):
    module = config.module
    client = config.client(get_region(module), "autoscaling", "project")

    identity_obj = build_identity_object(module)
    path = build_path(module, "scaling_policy/{group_id}/list")
    query_link = build_query_link(module.params)
    link = path + query_link

    result = []
    p = {'start_number': 0}
    while True:
        url = link.format(**p)
        r = send_list_request(module, client, url)
        if not r:
            break

        for item in r:
            item = fill_read_resp_body(item)
            if not are_different_dicts(identity_obj, item):
                result.append(item)

        if len(result) > 1:
            break

        p['start_number'] += 10

    return result
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
def search_resource(config):
    module = config.module
    client = config.client(get_region(module), "vpc", "project")
    opts = user_input_parameters(module)
    identity_obj = _build_identity_object(module, opts)
    query_link = _build_query_link(opts)
    link = build_path(module, "subnets/{subnet_id}/privateips") + query_link

    result = []
    p = {'marker': ''}
    while True:
        url = link.format(**p)
        r = send_list_request(module, client, url)
        if not r:
            break

        for item in r:
            item = fill_list_resp_body(item)
            if not are_different_dicts(identity_obj, item):
                result.append(item)

        if len(result) > 1:
            break

        p['marker'] = r[-1].get('id')

    return result
Exemplo n.º 8
0
def get_resource(config, result):
    module = config.module
    client = config.client(get_region(module), "smn", "project")

    d = {'topic_urn': navigate_hash(result, ['topic_urn'])}
    url = build_path(module, 'notifications/topics/{topic_urn}', d)

    return fetch_resource(module, client, url)
Exemplo n.º 9
0
def send_delete_request(module, params, client):
    url = build_path(module, "privateips/{id}")

    try:
        r = client.delete(url, params)
    except HwcClientException as ex:
        msg = ("module(hwc_vpc_private_ip): error running "
               "api(delete), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return r
Exemplo n.º 10
0
def send_update_request(module, params, client):
    url = build_path(module, "v2.0/vpc/peerings/{id}")

    try:
        r = client.put(url, params)
    except HwcClientException as ex:
        msg = ("module(hwc_vpc_peering_connect): error running "
               "api(update), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return r
Exemplo n.º 11
0
def send_extend_disk_request(module, params, client):
    url = build_path(module, "cloudvolumes/{id}/action")

    try:
        r = client.post(url, params)
    except HwcClientException as ex:
        msg = ("module(hwc_evs_disk): error running "
               "api(extend_disk), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return r
Exemplo n.º 12
0
def send_delete_request(module, params, client):
    url = build_path(module, "scaling_group/{id}")

    try:
        r = client.delete(url, params)
    except HwcClientException as ex:
        msg = ("module(hcs_as_group): error running "
               "api(delete), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return r
Exemplo n.º 13
0
def send_delete_request(module, params, client):
    url = build_path(module, "security-group-rules/{id}")

    try:
        r = client.delete(url, params)
    except HwcClientException as ex:
        msg = ("module(hwc_vpc_security_group_rule): error running "
               "api(delete), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return r
Exemplo n.º 14
0
def send_read_request(module, client):
    url = build_path(module, "privateips/{id}")

    r = None
    try:
        r = client.get(url)
    except HwcClientException as ex:
        msg = ("module(hwc_vpc_private_ip): error running "
               "api(read), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return navigate_value(r, ["privateip"], None)
Exemplo n.º 15
0
def send_update_request(module, params, client):
    # the endpoint: https://as-api.xxx.com/autoscaling-api/v1/{{project_id}}
    url = build_path(module, "scaling_group/{id}")

    try:
        r = client.put(url, params)
    except HwcClientException as ex:
        msg = ("module(hcs_as_group): error running api(update), "
               "url: %s%s, params:%s, error: %s" % (client.endpoint, url, params, str(ex)))
        module.fail_json(msg=msg)

    return r
Exemplo n.º 16
0
def send_read_request(module, client):
    url = build_path(module, "security-group-rules/{id}")

    r = None
    try:
        r = client.get(url)
    except HwcClientException as ex:
        msg = ("module(hwc_vpc_security_group_rule): error running "
               "api(read), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return navigate_value(r, ["security_group_rule"], None)
Exemplo n.º 17
0
def send_read_request(module, client):
    url = build_path(module, "scaling_configuration/{id}")

    r = None
    try:
        r = client.get(url)
    except HwcClientException as ex:
        msg = ("module(hcs_as_configuration): error running "
               "api(read), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return navigate_value(r, ["scaling_configuration"], None)
Exemplo n.º 18
0
def send_read_request(module, client):
    url = build_path(module, "scaling_group/{id}")

    r = None
    try:
        r = client.get(url)
    except HwcClientException as ex:
        msg = ("module(hcs_as_group): error running api(read), "
               "url: %s%s, error: %s" % (client.endpoint, url, str(ex)))
        module.fail_json(msg=msg)

    return navigate_value(r, ["scaling_group"], None)
Exemplo n.º 19
0
def send_read_request(module, client):
    url = build_path(module, "os-vendor-volumes/{id}")

    r = None
    try:
        r = client.get(url)
    except HwcClientException as ex:
        msg = ("module(hwc_evs_disk): error running "
               "api(read), error: %s" % str(ex))
        module.fail_json(msg=msg)

    return navigate_value(r, ["volume"], None)
Exemplo n.º 20
0
def get_resource(config, result):
    module = config.module
    client = config.client(get_region(module), "smn", "project")

    v = ""
    try:
        v = navigate_value(result, ['topic_urn'])
    except Exception as ex:
        module.fail_json(msg=str(ex))

    d = {'topic_urn': v}
    url = build_path(module, 'notifications/topics/{topic_urn}', d)

    return fetch_resource(module, client, url)
Exemplo n.º 21
0
def create(config, link):
    module = config.module
    client = config.client(get_region(module), "vpc", "project")

    r = None
    try:
        r = client.post(link, resource_to_create(module))
    except HwcClientException as ex:
        msg = ("module(hwc_network_vpc): error creating "
               "resource, error: %s" % str(ex))
        module.fail_json(msg=msg)

    wait_done = wait_for_operation(config, 'create', r)

    v = navigate_hash(wait_done, ['vpc', 'id'])
    url = build_path(module, 'vpcs/{op_id}', {'op_id': v})
    return fetch_resource(module, client, url)
Exemplo n.º 22
0
def wait_for_operation(config, op_type, op_result):
    module = config.module
    op_id = navigate_hash(op_result, ['vpc', 'id'])
    url = build_path(module, "vpcs/{op_id}", {'op_id': op_id})
    timeout = 60 * int(module.params['timeouts'][op_type].rstrip('m'))
    states = {
        'create': {
            'allowed': ['CREATING', 'DONW', 'OK'],
            'complete': ['OK'],
        },
        'update': {
            'allowed': ['PENDING_UPDATE', 'DONW', 'OK'],
            'complete': ['OK'],
        }
    }

    return wait_for_completion(url, timeout, states[op_type]['allowed'],
                               states[op_type]['complete'], config)
Exemplo n.º 23
0
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))
Exemplo n.º 24
0
def self_link(module):
    return build_path(module, "notifications/topics/{id}")
Exemplo n.º 25
0
def self_link(module):
    return build_path(module, "vpcs/{id}")