def response_to_hash(module, response):
    return {
        u'id':
        response.get(u'id'),
        u'creationTimestamp':
        response.get(u'creationTimestamp'),
        u'name':
        response.get(u'name'),
        u'description':
        module.params.get('description'),
        u'targetVpnGateway':
        replace_resource_dict(module.params.get(u'target_vpn_gateway', {}),
                              'selfLink'),
        u'router':
        replace_resource_dict(module.params.get(u'router', {}), 'selfLink'),
        u'peerIp':
        response.get(u'peerIp'),
        u'sharedSecret':
        response.get(u'sharedSecret'),
        u'sharedSecretHash':
        response.get(u'sharedSecretHash'),
        u'ikeVersion':
        response.get(u'ikeVersion'),
        u'localTrafficSelector':
        response.get(u'localTrafficSelector'),
        u'remoteTrafficSelector':
        response.get(u'remoteTrafficSelector'),
    }
def resource_to_request(module):
    request = {
        u'kind':
        'compute#instanceGroupManager',
        u'baseInstanceName':
        module.params.get('base_instance_name'),
        u'description':
        module.params.get('description'),
        u'instanceTemplate':
        replace_resource_dict(module.params.get(u'instance_template', {}),
                              'selfLink'),
        u'name':
        module.params.get('name'),
        u'namedPorts':
        InstanceGroupManagerNamedportsArray(
            module.params.get('named_ports', []), module).to_request(),
        u'targetPools':
        replace_resource_dict(module.params.get('target_pools', []),
                              'selfLink'),
        u'targetSize':
        module.params.get('target_size'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def resource_to_request(module):
    request = {
        u'kind':
        'compute#vpnTunnel',
        u'name':
        module.params.get('name'),
        u'description':
        module.params.get('description'),
        u'targetVpnGateway':
        replace_resource_dict(module.params.get(u'target_vpn_gateway', {}),
                              'selfLink'),
        u'router':
        replace_resource_dict(module.params.get(u'router', {}), 'selfLink'),
        u'peerIp':
        module.params.get('peer_ip'),
        u'sharedSecret':
        module.params.get('shared_secret'),
        u'ikeVersion':
        module.params.get('ike_version'),
        u'localTrafficSelector':
        module.params.get('local_traffic_selector'),
        u'remoteTrafficSelector':
        module.params.get('remote_traffic_selector'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
Ejemplo n.º 4
0
def resource_to_request(module):
    request = {
        u'kind':
        'compute#targetHttpsProxy',
        u'description':
        module.params.get('description'),
        u'name':
        module.params.get('name'),
        u'quicOverride':
        module.params.get('quic_override'),
        u'sslCertificates':
        replace_resource_dict(module.params.get('ssl_certificates', []),
                              'selfLink'),
        u'sslPolicy':
        replace_resource_dict(module.params.get(u'ssl_policy', {}),
                              'selfLink'),
        u'urlMap':
        replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def resource_to_request(module):
    request = {
        u'kind':
        'compute#instanceGroup',
        u'description':
        module.params.get('description'),
        u'name':
        module.params.get('name'),
        u'namedPorts':
        InstanceGroupNamedportsArray(module.params.get('named_ports', []),
                                     module).to_request(),
        u'network':
        replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
        u'region':
        region_selflink(module.params.get('region'), module.params),
        u'subnetwork':
        replace_resource_dict(module.params.get(u'subnetwork', {}),
                              'selfLink'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def resource_to_request(module):
    request = {
        u'kind':
        'compute#targetPool',
        u'backupPool':
        replace_resource_dict(module.params.get(u'backup_pool', {}),
                              'selfLink'),
        u'description':
        module.params.get('description'),
        u'failoverRatio':
        module.params.get('failover_ratio'),
        u'healthCheck':
        replace_resource_dict(module.params.get(u'health_check', {}),
                              'selfLink'),
        u'instances':
        replace_resource_dict(module.params.get('instances', []), 'selfLink'),
        u'name':
        module.params.get('name'),
        u'sessionAffinity':
        module.params.get('session_affinity'),
    }
    request = encode_request(request, module)
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
Ejemplo n.º 7
0
def prefetch_soa_resource(module):

    resource = SOAForwardable(
        {
            'type':
            'SOA',
            'managed_zone':
            module.params['managed_zone'],
            'name':
            replace_resource_dict(module.params['managed_zone'], 'dnsName'),
            'project':
            module.params['project'],
            'scopes':
            module.params['scopes'],
            'service_account_file':
            module.params.get('service_account_file'),
            'auth_kind':
            module.params['auth_kind'],
            'service_account_email':
            module.params.get('service_account_email'),
            'service_account_contents':
            module.params.get('service_account_contents'),
        },
        module,
    )

    result = fetch_wrapped_resource(resource, 'dns#resourceRecordSet',
                                    'dns#resourceRecordSetsListResponse',
                                    'rrsets')
    if not result:
        raise ValueError(
            "Google DNS Managed Zone %s not found" %
            replace_resource_dict(module.params['managed_zone'], 'name'))
    return result
def response_to_hash(module, response):
    return {
        u'destRange':
        response.get(u'destRange'),
        u'description':
        response.get(u'description'),
        u'name':
        response.get(u'name'),
        u'network':
        replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
        u'priority':
        module.params.get('priority'),
        u'tags':
        module.params.get('tags'),
        u'nextHopGateway':
        module.params.get('next_hop_gateway'),
        u'nextHopInstance':
        replace_resource_dict(module.params.get(u'next_hop_instance', {}),
                              'selfLink'),
        u'nextHopIp':
        module.params.get('next_hop_ip'),
        u'nextHopVpnTunnel':
        replace_resource_dict(module.params.get(u'next_hop_vpn_tunnel', {}),
                              'selfLink'),
        u'nextHopNetwork':
        response.get(u'nextHopNetwork'),
        u'nextHopIlb':
        replace_resource_dict(module.params.get(u'next_hop_ilb', {}),
                              'selfLink'),
    }
def collection(module):
    res = {
        'project': module.params['project'],
        'instance': replace_resource_dict(module.params['instance'], 'name')
    }
    return "https://spanner.googleapis.com/v1/projects/{project}/instances/{instance}/databases".format(
        **res)
Ejemplo n.º 10
0
def resource_to_request(module):
    request = {
        u'kind':
        'compute#interconnectAttachment',
        u'adminEnabled':
        module.params.get('admin_enabled'),
        u'interconnect':
        module.params.get('interconnect'),
        u'description':
        module.params.get('description'),
        u'bandwidth':
        module.params.get('bandwidth'),
        u'edgeAvailabilityDomain':
        module.params.get('edge_availability_domain'),
        u'type':
        module.params.get('type'),
        u'router':
        replace_resource_dict(module.params.get(u'router', {}), 'selfLink'),
        u'name':
        module.params.get('name'),
        u'candidateSubnets':
        module.params.get('candidate_subnets'),
        u'vlanTag8021q':
        module.params.get('vlan_tag8021q'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def resource_to_request(module):
    request = {
        u'kind': 'compute#firewall',
        u'allowed': FirewallAllowedArray(module.params.get('allowed', []), module).to_request(),
        u'denied': FirewallDeniedArray(module.params.get('denied', []), module).to_request(),
        u'description': module.params.get('description'),
        u'destinationRanges': module.params.get('destination_ranges'),
        u'direction': module.params.get('direction'),
        u'disabled': module.params.get('disabled'),
        u'logConfig': FirewallLogconfig(module.params.get('log_config', {}), module).to_request(),
        u'name': module.params.get('name'),
        u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
        u'priority': module.params.get('priority'),
        u'sourceRanges': module.params.get('source_ranges'),
        u'sourceServiceAccounts': module.params.get('source_service_accounts'),
        u'sourceTags': module.params.get('source_tags'),
        u'targetServiceAccounts': module.params.get('target_service_accounts'),
        u'targetTags': module.params.get('target_tags'),
    }
    request = encode_request(request, module)
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def resource_to_request(module):
    request = {
        u'kind': 'compute#targetSslProxy',
        u'description': module.params.get('description'),
        u'name': module.params.get('name'),
        u'proxyHeader': module.params.get('proxy_header'),
        u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink'),
        u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink'),
        u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
Ejemplo n.º 13
0
def resource_to_request(module):
    request = {
        u'kind':
        'compute#subnetwork',
        u'description':
        module.params.get('description'),
        u'ipCidrRange':
        module.params.get('ip_cidr_range'),
        u'name':
        module.params.get('name'),
        u'network':
        replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
        u'secondaryIpRanges':
        SubnetworkSecondaryiprangesArray(
            module.params.get('secondary_ip_ranges', []), module).to_request(),
        u'privateIpGoogleAccess':
        module.params.get('private_ip_google_access'),
        u'region':
        module.params.get('region'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def resource_to_request(module):
    request = {
        u'kind':
        'compute#address',
        u'address':
        module.params.get('address'),
        u'description':
        module.params.get('description'),
        u'name':
        module.params.get('name'),
        u'ipVersion':
        module.params.get('ip_version'),
        u'prefixLength':
        module.params.get('prefix_length'),
        u'addressType':
        module.params.get('address_type'),
        u'purpose':
        module.params.get('purpose'),
        u'network':
        replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def collection(module):
    res = {
        'project': module.params['project'],
        'model': replace_resource_dict(module.params['model'], 'name')
    }
    return "https://ml.googleapis.com/v1/projects/{project}/models/{model}/versions".format(
        **res)
def resource_to_request(module):
    request = {
        u'name':
        name_pattern(module.params.get('name'), module),
        u'topic':
        topic_pattern(
            replace_resource_dict(module.params.get(u'topic', {}), 'name'),
            module),
        u'labels':
        module.params.get('labels'),
        u'pushConfig':
        SubscriptionPushconfig(module.params.get('push_config', {}),
                               module).to_request(),
        u'ackDeadlineSeconds':
        module.params.get('ack_deadline_seconds'),
        u'messageRetentionDuration':
        module.params.get('message_retention_duration'),
        u'retainAckedMessages':
        module.params.get('retain_acked_messages'),
        u'expirationPolicy':
        SubscriptionExpirationpolicy(
            module.params.get('expiration_policy', {}), module).to_request(),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def resource_to_request(module):
    request = {
        u'kind':
        'compute#forwardingRule',
        u'description':
        module.params.get('description'),
        u'IPAddress':
        module.params.get('ip_address'),
        u'IPProtocol':
        module.params.get('ip_protocol'),
        u'ipVersion':
        module.params.get('ip_version'),
        u'loadBalancingScheme':
        module.params.get('load_balancing_scheme'),
        u'metadataFilters':
        GlobalForwardingRuleMetadatafiltersArray(
            module.params.get('metadata_filters', []), module).to_request(),
        u'name':
        module.params.get('name'),
        u'network':
        replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
        u'portRange':
        module.params.get('port_range'),
        u'target':
        module.params.get('target'),
    }
    return_vals = {}
    for k, v in request.items():
        if v or v is False:
            return_vals[k] = v

    return return_vals
def self_link(module):
    res = {
        'bucket': replace_resource_dict(module.params['bucket'], 'name'),
        'entity': module.params['entity']
    }
    return "https://www.googleapis.com/storage/v1/b/{bucket}/acl/{entity}".format(
        **res)
def collection(module):
    res = {
        'project': module.params['project'],
        'instance': replace_resource_dict(module.params['instance'], 'name')
    }
    return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/users".format(
        **res)
Ejemplo n.º 20
0
def response_to_hash(module, response):
    return {
        u'name': response.get(u'name'),
        u'creationTimestamp': response.get(u'creationTimestamp'),
        u'description': response.get(u'description'),
        u'instance': replace_resource_dict(module.params.get(u'instance', {}), 'selfLink'),
        u'natPolicy': module.params.get('nat_policy'),
    }
def self_link(module):
    res = {
        'project': module.params['project'],
        'instance': replace_resource_dict(module.params['instance'], 'name'),
        'name': module.params['name'],
        'host': module.params['host'],
    }
    return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/users?name={name}&host={host}".format(**res)
def collection(module):
    res = {
        'project': module.params['project'],
        'location': module.params['location'],
        'cluster': replace_resource_dict(module.params['cluster'], 'name')
    }
    return "https://container.googleapis.com/v1/projects/{project}/locations/{location}/clusters/{cluster}/nodePools".format(
        **res)
def self_link(module):
    res = {
        'project': module.params['project'],
        'model': replace_resource_dict(module.params['model'], 'name'),
        'name': module.params['name']
    }
    return "https://ml.googleapis.com/v1/projects/{project}/models/{model}/versions/{name}".format(
        **res)
Ejemplo n.º 24
0
def collection(module):
    res = {
        'project':
        module.params['project'],
        'managed_zone':
        replace_resource_dict(module.params['managed_zone'], 'name')
    }
    return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(
        **res)
Ejemplo n.º 25
0
 def _request_for_item(self, item):
     return remove_nones_from_dict(
         {
             u'bucket': replace_resource_dict(item.get(u'bucket', {}), 'name'),
             u'entity': item.get('entity'),
             u'object': item.get('object'),
             u'role': item.get('role'),
         }
     )
Ejemplo n.º 26
0
def self_link(module):
    results = {
        'project':
        module.params['project'],
        'service_account':
        replace_resource_dict(module.params['service_account'], 'name')
    }
    return "https://iam.googleapis.com/v1/projects/{project}/serviceAccounts/{service_account}/keys".format(
        **results)
Ejemplo n.º 27
0
 def _request_for_item(self, item):
     return remove_nones_from_dict(
         {
             u'bucket': replace_resource_dict(item.get(u'bucket', {}), 'name'),
             u'entity': item.get('entity'),
             u'entityId': item.get('entity_id'),
             u'projectTeam': BucketProjectteam(item.get('project_team', {}), self.module).to_request(),
             u'role': item.get('role'),
         }
     )
def set_default(module):
    res = {
        'project': module.params['project'],
        'model': replace_resource_dict(module.params['model'], 'name'),
        'name': module.params['name']
    }
    link = "https://ml.googleapis.com/v1/projects/{project}/models/{model}/versions/{name}:setDefault".format(
        **res)

    auth = GcpSession(module, 'mlengine')
    return_if_object(module, auth.post(link))
    def __init__(self, module):
        self.module = module
        self.current_instances = self.list_instances()
        self.module_instances = []

        # Transform module list of instances (dicts of instance responses) into a list of selfLinks.
        instances = self.module.params.get('instances')
        if instances:
            for instance in instances:
                self.module_instances.append(
                    replace_resource_dict(instance, 'selfLink'))
def service_update(module, request, response):
    auth = GcpSession(module, 'compute')
    auth.post(
        ''.join([
            "https://www.googleapis.com/compute/v1/",
            "projects/{project}/global/targetTcpProxies/{name}/setBackendService"
        ]).format(**module.params),
        {
            u'service':
            replace_resource_dict(module.params.get(u'service', {}),
                                  'selfLink')
        },
    )