def ip_cidr_range_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/subnetworks/{name}/expandIpCidrRange" ]).format(**module.params), {u'ipCidrRange': module.params.get('ip_cidr_range')}, )
def size_gb_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/disks/{name}/resize" ]).format(**module.params), {u'sizeGb': module.params.get('size_gb')}, )
def tensorflow_version_update(module, request, response): auth = GcpSession(module, 'tpu') auth.post( ''.join([ "https://tpu.googleapis.com/v1/", "projects/{project}/locations/{zone}/nodes/{name}:reimage" ]).format(**module.params), {u'tensorflowVersion': module.params.get('tensorflow_version')}, )
def quic_override_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetHttpsProxies/{name}/setQuicOverride" ]).format(**module.params), {u'quicOverride': module.params.get('quic_override')}, )
def proxy_header_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetTcpProxies/{name}/setProxyHeader" ]).format(**module.params), {u'proxyHeader': module.params.get('proxy_header')}, )
def security_policy_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/global/backendServices/{name}/setSecurityPolicy" ]).format(**module.params), {u'securityPolicy': module.params.get('security_policy')}, )
def target_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/global/forwardingRules/{name}/setTarget" ]).format(**module.params), {u'target': module.params.get('target')}, )
def label_fingerprint_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/disks/{name}/setLabels" ]).format(**module.params), { u'labelFingerprint': response.get('labelFingerprint'), u'labels': module.params.get('labels') }, )
def private_ip_google_access_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/subnetworks/{name}/setPrivateIpGoogleAccess" ]).format(**module.params), { u'privateIpGoogleAccess': module.params.get('private_ip_google_access') }, )
def url_map_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/targetHttpsProxies/{name}/setUrlMap" ]).format(**module.params), { u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink') }, )
def ssl_certificates_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/targetHttpsProxies/{name}/setSslCertificates" ]).format(**module.params), { u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink') }, )
def node_template_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join([ "https://www.googleapis.com/compute/v1/", "projects/{project}/zones/{zone}/nodeGroups/{name}/setNodeTemplate" ]).format(**module.params), { u'nodeTemplate': replace_resource_dict(module.params.get(u'node_template', {}), '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') }, )
def create(module): auth = GcpSession(module, 'iam') json_content = return_if_object( module, auth.post(self_link(module), resource_to_request(module))) with open(module.params['path'], 'w') as f: private_key_contents = to_native( base64.b64decode(json_content['privateKeyData'])) f.write(private_key_contents)
def kms_encrypt(self, module): payload = {"plaintext": module.params['plaintext']} if module.params['additional_authenticated_data']: payload['additionalAuthenticatedData'] = module.params['additional_authenticated_data'] auth = GcpSession(module, 'cloudkms') url = "https://cloudkms.googleapis.com/v1/projects/{projects}/locations/{locations}/" \ "keyRings/{key_ring}/cryptoKeys/{crypto_key}:encrypt".format(**module.params) response = auth.post(url, body=payload) return response.json()['ciphertext']
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 list_instances(self): auth = GcpSession(self.module, 'compute') response = return_if_object( self.module, auth.post(self._list_instances_url(), {'instanceState': 'ALL'}), 'compute#instanceGroupsListInstances') # Transform instance list into a list of selfLinks for diffing with module parameters instances = [] for instance in response.get('items', []): instances.append(instance['instance']) return instances
def create(module, link, kind): auth = GcpSession(module, 'compute') return wait_for_operation(module, auth.post(link, resource_to_request(module)))
def create(module, link): auth = GcpSession(module, 'filestore') return wait_for_operation(module, auth.post(link, resource_to_request(module)))
def create(module, link, kind): auth = GcpSession(module, 'storage') return return_if_object(module, auth.post(link, resource_to_request(module)), kind)
def create(module, link): auth = GcpSession(module, 'iam') return return_if_object(module, auth.post(link, resource_to_request(module)))
def stop(self): auth = GcpSession(self.module, 'cloudtasks') return_if_object(self.module, auth.post(self._stop_url()))
def remove_instances(self, instances): auth = GcpSession(self.module, 'compute') wait_for_operation( self.module, auth.post(self._remove_instances_url(), self._build_request(instances)))
def target_update(module, request, response): auth = GcpSession(module, 'compute') auth.post( ''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/forwardingRules/{name}/setTarget"]).format(**module.params), {u'target': replace_resource_dict(module.params.get(u'target', {}), 'selfLink')}, )
def create(module, link): auth = GcpSession(module, 'spanner') return wait_for_operation(module, auth.post(link, resource_to_create(module)))
def create_change(original, updated, module): auth = GcpSession(module, 'dns') return return_if_change_object( module, auth.post(collection(module), resource_to_change_request(original, updated, module)))