コード例 #1
0
def create_target_http_proxy(client, params, project_id):
    """
    Create a new Target_Proxy.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param params: Dictionary of arguments from AnsibleModule.
    :type params:  ``dict``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    gcp_dict = _build_target_proxy_dict(params, project_id)
    try:
        req = client.targetHttpProxies().insert(project=project_id,
                                                body=gcp_dict)
        return_data = GCPUtils.execute_api_client_req(req, client, raw=False)
        if not return_data:
            return_data = get_target_http_proxy(
                client,
                name=params['target_proxy_name'],
                project_id=project_id)
        return (True, return_data)
    except Exception:
        raise
コード例 #2
0
def create_healthcheck(client, params, project_id, resource_type='HTTP'):
    """
    Create a new Healthcheck.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param params: Dictionary of arguments from AnsibleModule.
    :type params:  ``dict``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    gcp_dict = _build_healthcheck_dict(params)
    try:
        resource, _ = _get_req_resource(client, resource_type)
        args = {'project': project_id, 'body': gcp_dict}
        req = resource.insert(**args)
        return_data = GCPUtils.execute_api_client_req(req, client, raw=False)
        if not return_data:
            return_data = get_healthcheck(client,
                                          name=params['healthcheck_name'],
                                          project_id=project_id)
        return (True, return_data)
    except Exception:
        raise
コード例 #3
0
def update_healthcheck(client,
                       healthcheck,
                       params,
                       name,
                       project_id,
                       resource_type='HTTP'):
    """
    Update a Healthcheck.

    If the healthcheck has not changed, the update will not occur.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param healthcheck: Name of the Url Map.
    :type healthcheck:  ``dict``

    :param params: Dictionary of arguments from AnsibleModule.
    :type params:  ``dict``

    :param name: Name of the Url Map.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    gcp_dict = _build_healthcheck_dict(params)
    ans = GCPUtils.are_params_equal(healthcheck, gcp_dict)
    if ans:
        return (False, 'no update necessary')

    try:
        resource, entity_name = _get_req_resource(client, resource_type)
        args = {'project': project_id, entity_name: name, 'body': gcp_dict}
        req = resource.update(**args)
        return_data = GCPUtils.execute_api_client_req(req,
                                                      client=client,
                                                      raw=False)
        return (True, return_data)
    except Exception:
        raise
コード例 #4
0
def get_target_http_proxy(client, name, project_id=None):
    """
    Get a Target HTTP Proxy from GCP.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param name: Name of the Target Proxy.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: A dict resp from the respective GCP 'get' request.
    :rtype: ``dict``
    """
    req = client.targetHttpProxies().get(project=project_id,
                                         targetHttpProxy=name)
    return GCPUtils.execute_api_client_req(req, raise_404=False)
コード例 #5
0
def update_url_map(client, url_map, params, name, project_id):
    """
    Update a Url_Map.

    If the url_map has not changed, the update will not occur.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param url_map: Name of the Url Map.
    :type url_map:  ``dict``

    :param params: Dictionary of arguments from AnsibleModule.
    :type params:  ``dict``

    :param name: Name of the Url Map.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    gcp_dict = _build_url_map_dict(params, project_id)

    ans = GCPUtils.are_params_equal(url_map, gcp_dict)
    if ans:
        return (False, 'no update necessary')

    gcp_dict['fingerprint'] = url_map['fingerprint']
    try:
        req = client.urlMaps().update(project=project_id,
                                      urlMap=name,
                                      body=gcp_dict)
        return_data = GCPUtils.execute_api_client_req(req,
                                                      client=client,
                                                      raw=False)
        return (True, return_data)
    except Exception:
        raise
コード例 #6
0
def update_target_http_proxy(client, target_proxy, params, name, project_id):
    """
    Update a HTTP Target_Proxy. Currently only the Url Map can be updated.

    If the target_proxy has not changed, the update will not occur.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param target_proxy: Name of the Target Proxy.
    :type target_proxy:  ``dict``

    :param params: Dictionary of arguments from AnsibleModule.
    :type params:  ``dict``

    :param name: Name of the Target Proxy.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    gcp_dict = _build_target_proxy_dict(params, project_id)

    GCPUtils.are_params_equal(target_proxy, gcp_dict)
    if target_proxy['urlMap'] == gcp_dict['urlMap']:
        return (False, 'no update necessary')

    try:
        req = client.targetHttpProxies().setUrlMap(
            project=project_id,
            targetHttpProxy=name,
            body={"urlMap": gcp_dict['urlMap']})
        return_data = GCPUtils.execute_api_client_req(req,
                                                      client=client,
                                                      raw=False)
        return (True, return_data)
    except Exception:
        raise
コード例 #7
0
def get_url_map(client, name, project_id=None):
    """
    Get a Url_Map from GCP.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param name: Name of the Url Map.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: A dict resp from the respective GCP 'get' request.
    :rtype: ``dict``
    """
    try:
        req = client.urlMaps().get(project=project_id, urlMap=name)
        return GCPUtils.execute_api_client_req(req, raise_404=False)
    except Exception:
        raise
コード例 #8
0
def delete_url_map(client, name, project_id):
    """
    Delete a Url_Map.

    :param client: An initialized GCE Compute Discover resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param name: Name of the Url Map.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    try:
        req = client.urlMaps().delete(project=project_id, urlMap=name)
        return_data = GCPUtils.execute_api_client_req(req, client)
        return (True, return_data)
    except Exception:
        raise
コード例 #9
0
def update_global_forwarding_rule(client, forwarding_rule, params, name, project_id):
    """
    Update a Global Forwarding_Rule. Currently, only a target can be updated.

    If the forwarding_rule has not changed, the update will not occur.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param forwarding_rule: Name of the Target Proxy.
    :type forwarding_rule:  ``dict``

    :param params: Dictionary of arguments from AnsibleModule.
    :type params:  ``dict``

    :param name: Name of the Global Forwarding Rule.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    gcp_dict = _build_global_forwarding_rule_dict(params, project_id)

    GCPUtils.are_params_equal(forwarding_rule, gcp_dict)
    if forwarding_rule['target'] == gcp_dict['target']:
        return (False, 'no update necessary')

    try:
        req = client.globalForwardingRules().setTarget(project=project_id,
                                                       forwardingRule=name,
                                                       body={'target': gcp_dict['target']})
        return_data = GCPUtils.execute_api_client_req(
            req, client=client, raw=False)
        return (True, return_data)
    except Exception:
        raise
コード例 #10
0
def delete_global_forwarding_rule(client, name, project_id):
    """
    Delete a Global Forwarding Rule.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param name: Name of the Target Proxy.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    try:
        req = client.globalForwardingRules().delete(
            project=project_id, forwardingRule=name)
        return_data = GCPUtils.execute_api_client_req(req, client)
        return (True, return_data)
    except Exception:
        raise
コード例 #11
0
def get_healthcheck(client, name, project_id=None, resource_type='HTTP'):
    """
    Get a Healthcheck from GCP.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param name: Name of the Url Map.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: A dict resp from the respective GCP 'get' request.
    :rtype: ``dict``
    """
    try:
        resource, entity_name = _get_req_resource(client, resource_type)
        args = {'project': project_id, entity_name: name}
        req = resource.get(**args)
        return GCPUtils.execute_api_client_req(req, raise_404=False)
    except Exception:
        raise
コード例 #12
0
def delete_healthcheck(client, name, project_id, resource_type='HTTP'):
    """
    Delete a Healthcheck.

    :param client: An initialized GCE Compute Discovery resource.
    :type client:  :class: `googleapiclient.discovery.Resource`

    :param name: Name of the Url Map.
    :type name:  ``str``

    :param project_id: The GCP project ID.
    :type project_id:  ``str``

    :return: Tuple with changed status and response dict
    :rtype: ``tuple`` in the format of (bool, dict)
    """
    try:
        resource, entity_name = _get_req_resource(client, resource_type)
        args = {'project': project_id, entity_name: name}
        req = resource.delete(**args)
        return_data = GCPUtils.execute_api_client_req(req, client)
        return (True, return_data)
    except Exception:
        raise