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#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
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#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
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['service_account_file'], 'auth_kind': module.params['auth_kind'], 'service_account_email': module.params['service_account_email'], }, 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'), }
def response_to_hash(module, response): return { 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#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 response_to_hash(module, response): return { u'creationTimestamp': response.get(u'creationTimestamp'), u'description': response.get(u'description'), u'gatewayAddress': response.get(u'gatewayAddress'), u'id': response.get(u'id'), u'ipCidrRange': response.get(u'ipCidrRange'), u'name': response.get(u'name'), u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'), u'enableFlowLogs': response.get(u'enableFlowLogs'), u'fingerprint': response.get(u'fingerprint'), u'secondaryIpRanges': SubnetworkSecondaryiprangesArray( response.get(u'secondaryIpRanges', []), module).from_response(), u'privateIpGoogleAccess': response.get(u'privateIpGoogleAccess'), u'region': module.params.get('region'), }
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'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'enableFlowLogs': module.params.get('enable_flow_logs'), 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#urlMap', u'defaultService': replace_resource_dict(module.params.get(u'default_service', {}), 'selfLink'), u'description': module.params.get('description'), u'hostRules': UrlMapHostrulesArray(module.params.get('host_rules', []), module).to_request(), u'name': module.params.get('name'), u'pathMatchers': UrlMapPathmatchersArray(module.params.get('path_matchers', []), module).to_request(), u'tests': UrlMapTestsArray(module.params.get('tests', []), 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 _request_for_item(self, item): return remove_nones_from_dict({ u'paths': item.get('paths'), u'service': replace_resource_dict(item.get(u'service', {}), 'selfLink') })
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#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#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 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'], '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 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)
def response_to_hash(module, response): return { u'id': response.get(u'id'), u'creationTimestamp': response.get(u'creationTimestamp'), u'name': module.params.get('name'), u'description': response.get(u'description'), u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'), u'bgp': RouterBgp(response.get(u'bgp', {}), module).from_response(), }
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)
def create_link(module): res = { 'project': module.params['project'], 'zone': module.params['zone'], 'source_disk': replace_resource_dict(module.params['source_disk'], 'name') } return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/disks/{source_disk}/createSnapshot".format( **res)
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)
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'backendService': replace_resource_dict(module.params.get(u'backend_service', {}), 'selfLink'), u'ipVersion': module.params.get('ip_version'), u'loadBalancingScheme': module.params.get('load_balancing_scheme'), 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'ports': module.params.get('ports'), u'subnetwork': replace_resource_dict(module.params.get(u'subnetwork', {}), 'selfLink'), u'target': replace_resource_dict(module.params.get(u'target', {}), 'selfLink'), u'allPorts': module.params.get('all_ports'), u'networkTier': module.params.get('network_tier'), u'serviceLabel': module.params.get('service_label'), } 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
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 _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'), })
def _request_for_item(self, item): return remove_nones_from_dict({ u'description': item.get('description'), u'host': item.get('host'), u'path': item.get('path'), u'service': replace_resource_dict(item.get(u'service', {}), 'selfLink'), })
def resource_to_request(module): request = { u'kind': 'compute#route', u'destRange': module.params.get('dest_range'), u'description': module.params.get('description'), u'name': module.params.get('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'), } return_vals = {} for k, v in request.items(): if v or v is False: return_vals[k] = v return return_vals
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))