def test_from_http_response_text_content(): response = make_response(b"message") exception = exceptions.from_http_response(response) assert isinstance(exception, exceptions.NotFound) assert exception.code == http_client.NOT_FOUND assert exception.message == "POST https://example.com/: message"
def test_from_http_response_bad_json_content(): response = make_response(json.dumps({"meep": "moop"}).encode("utf-8")) exception = exceptions.from_http_response(response) assert isinstance(exception, exceptions.NotFound) assert exception.code == http_client.NOT_FOUND assert exception.message == "POST https://example.com/: unknown error"
def test_from_http_response_no_content(): response = make_response(None) exception = exceptions.from_http_response(response) assert isinstance(exception, exceptions.NotFound) assert exception.code == http_client.NOT_FOUND assert exception.message == "POST https://example.com/: unknown error" assert exception.response == response
def test_from_http_response_json_unicode_content(): response = make_response( json.dumps( {"error": {"message": u"\u2019 message", "errors": ["1", "2"]}} ).encode("utf-8") ) exception = exceptions.from_http_response(response) assert isinstance(exception, exceptions.NotFound) assert exception.code == http_client.NOT_FOUND assert exception.message == u"POST https://example.com/: \u2019 message" assert exception.errors == ["1", "2"]
def delete( self, request: compute.DeleteGlobalPublicDelegatedPrefixeRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Operation: r"""Call the delete method over HTTP. Args: request (~.compute.DeleteGlobalPublicDelegatedPrefixeRequest): The request object. A request message for GlobalPublicDelegatedPrefixes.Delete. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Operation: Represents an Operation resource. Google Compute Engine has three Operation resources: - `Global </compute/docs/reference/rest/{$api_version}/globalOperations>`__ \* `Regional </compute/docs/reference/rest/{$api_version}/regionOperations>`__ \* `Zonal </compute/docs/reference/rest/{$api_version}/zoneOperations>`__ You can use an operation resource to manage asynchronous API requests. For more information, read Handling API responses. Operations can be global, regional or zonal. - For global operations, use the ``globalOperations`` resource. - For regional operations, use the ``regionOperations`` resource. - For zonal operations, use the ``zonalOperations`` resource. For more information, read Global, Regional, and Zonal Resources. (== resource_for {$api_version}.globalOperations ==) (== resource_for {$api_version}.regionOperations ==) (== resource_for {$api_version}.zoneOperations ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/publicDelegatedPrefixes/{public_delegated_prefix}".format( host=self._host, project=request.project, public_delegated_prefix=request.public_delegated_prefix, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} if compute.DeleteGlobalPublicDelegatedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.delete( url, headers=headers, params=query_params, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Operation.from_json(response.content, ignore_unknown_fields=True)
def list( self, request: compute.ListGlobalPublicDelegatedPrefixesRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.PublicDelegatedPrefixList: r"""Call the list method over HTTP. Args: request (~.compute.ListGlobalPublicDelegatedPrefixesRequest): The request object. A request message for GlobalPublicDelegatedPrefixes.List. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.PublicDelegatedPrefixList: """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/publicDelegatedPrefixes".format( host=self._host, project=request.project, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} if compute.ListGlobalPublicDelegatedPrefixesRequest.filter in request: query_params["filter"] = request.filter if compute.ListGlobalPublicDelegatedPrefixesRequest.max_results in request: query_params["maxResults"] = request.max_results if compute.ListGlobalPublicDelegatedPrefixesRequest.order_by in request: query_params["orderBy"] = request.order_by if compute.ListGlobalPublicDelegatedPrefixesRequest.page_token in request: query_params["pageToken"] = request.page_token if (compute.ListGlobalPublicDelegatedPrefixesRequest. return_partial_success in request): query_params[ "returnPartialSuccess"] = request.return_partial_success # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, params=query_params, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.PublicDelegatedPrefixList.from_json( response.content, ignore_unknown_fields=True)
def list_available_features( self, request: compute.ListAvailableFeaturesSslPoliciesRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.SslPoliciesListAvailableFeaturesResponse: r"""Call the list available features method over HTTP. Args: request (~.compute.ListAvailableFeaturesSslPoliciesRequest): The request object. A request message for SslPolicies.ListAvailableFeatures. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.SslPoliciesListAvailableFeaturesResponse: """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/sslPolicies/listAvailableFeatures".format( host=self._host, project=request.project, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} if compute.ListAvailableFeaturesSslPoliciesRequest.filter in request: query_params["filter"] = request.filter if compute.ListAvailableFeaturesSslPoliciesRequest.max_results in request: query_params["maxResults"] = request.max_results if compute.ListAvailableFeaturesSslPoliciesRequest.order_by in request: query_params["orderBy"] = request.order_by if compute.ListAvailableFeaturesSslPoliciesRequest.page_token in request: query_params["pageToken"] = request.page_token if (compute.ListAvailableFeaturesSslPoliciesRequest. return_partial_success in request): query_params[ "returnPartialSuccess"] = request.return_partial_success # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.SslPoliciesListAvailableFeaturesResponse.from_json( response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetSslPolicyRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.SslPolicy: r"""Call the get method over HTTP. Args: request (~.compute.GetSslPolicyRequest): The request object. A request message for SslPolicies.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.SslPolicy: Represents an SSL Policy resource. Use SSL policies to control the SSL features, such as versions and cipher suites, offered by an HTTPS or SSL Proxy load balancer. For more information, read SSL Policy Concepts. (== resource_for {$api_version}.sslPolicies ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/sslPolicies/{ssl_policy}".format( host=self._host, project=request.project, ssl_policy=request.ssl_policy, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.SslPolicy.from_json(response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetVpnGatewayRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.VpnGateway: r"""Call the get method over HTTP. Args: request (~.compute.GetVpnGatewayRequest): The request object. A request message for VpnGateways.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.VpnGateway: Represents a HA VPN gateway. HA VPN is a high-availability (HA) Cloud VPN solution that lets you securely connect your on-premises network to your Google Cloud Virtual Private Cloud network through an IPsec VPN connection in a single region. For more information about Cloud HA VPN solutions, see Cloud VPN topologies . (== resource_for {$api_version}.vpnGateways ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/vpnGateways/{vpn_gateway}".format( host=self._host, project=request.project, region=request.region, vpn_gateway=request.vpn_gateway, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get(url, headers=headers,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.VpnGateway.from_json( response.content, ignore_unknown_fields=True )
def list_instances( self, request: compute.ListInstancesRegionInstanceGroupsRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.RegionInstanceGroupsListInstances: r"""Call the list instances method over HTTP. Args: request (~.compute.ListInstancesRegionInstanceGroupsRequest): The request object. A request message for RegionInstanceGroups.ListInstances. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.RegionInstanceGroupsListInstances: """ # Jsonify the request body body = compute.RegionInstanceGroupsListInstancesRequest.to_json( request.region_instance_groups_list_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, ) # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/instanceGroups/{instance_group}/listInstances".format( host=self._host, project=request.project, region=request.region, instance_group=request.instance_group, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} if compute.ListInstancesRegionInstanceGroupsRequest.filter in request: query_params["filter"] = request.filter if compute.ListInstancesRegionInstanceGroupsRequest.max_results in request: query_params["maxResults"] = request.max_results if compute.ListInstancesRegionInstanceGroupsRequest.order_by in request: query_params["orderBy"] = request.order_by if compute.ListInstancesRegionInstanceGroupsRequest.page_token in request: query_params["pageToken"] = request.page_token if (compute.ListInstancesRegionInstanceGroupsRequest. return_partial_success in request): query_params[ "returnPartialSuccess"] = request.return_partial_success # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.post( url, headers=headers, params=query_params, data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.RegionInstanceGroupsListInstances.from_json( response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetInterconnectAttachmentRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.InterconnectAttachment: r"""Call the get method over HTTP. Args: request (~.compute.GetInterconnectAttachmentRequest): The request object. A request message for InterconnectAttachments.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.InterconnectAttachment: Represents an Interconnect Attachment (VLAN) resource. You can use Interconnect attachments (VLANS) to connect your Virtual Private Cloud networks to your on-premises networks through an Interconnect. For more information, read Creating VLAN Attachments. (== resource_for {$api_version}.interconnectAttachments ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/interconnectAttachments/{interconnect_attachment}".format( host=self._host, project=request.project, region=request.region, interconnect_attachment=request.interconnect_attachment, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.InterconnectAttachment.from_json( response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetGlobalNetworkEndpointGroupRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.NetworkEndpointGroup: r"""Call the get method over HTTP. Args: request (~.compute.GetGlobalNetworkEndpointGroupRequest): The request object. A request message for GlobalNetworkEndpointGroups.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.NetworkEndpointGroup: Represents a collection of network endpoints. A network endpoint group (NEG) defines how a set of endpoints should be reached, whether they are reachable, and where they are located. For more information about using NEGs, see Setting up external HTTP(S) Load Balancing with internet NEGs, Setting up zonal NEGs, or Setting up external HTTP(S) Load Balancing with serverless NEGs. (== resource_for {$api_version}.networkEndpointGroups ==) (== resource_for {$api_version}.globalNetworkEndpointGroups ==) (== resource_for {$api_version}.regionNetworkEndpointGroups ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/networkEndpointGroups/{network_endpoint_group}".format( host=self._host, project=request.project, network_endpoint_group=request.network_endpoint_group, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, params=query_params, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.NetworkEndpointGroup.from_json( response.content, ignore_unknown_fields=True)
def set_iam_policy( self, request: compute.SetIamPolicyLicenseRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Policy: r"""Call the set iam policy method over HTTP. Args: request (~.compute.SetIamPolicyLicenseRequest): The request object. A request message for Licenses.SetIamPolicy. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Policy: An Identity and Access Management (IAM) policy, which specifies access controls for Google Cloud resources. A ``Policy`` is a collection of ``bindings``. A ``binding`` binds one or more ``members`` to a single ``role``. Members can be user accounts, service accounts, Google groups, and domains (such as G Suite). A ``role`` is a named list of permissions; each ``role`` can be an IAM predefined role or a user-created custom role. For some types of Google Cloud resources, a ``binding`` can also specify a ``condition``, which is a logical expression that allows access to a resource only if the expression evaluates to ``true``. A condition can add constraints based on attributes of the request, the resource, or both. To learn which resources support conditions in their IAM policies, see the `IAM documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__. **JSON example:** { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:[email protected]", "group:[email protected]", "domain:google.com", "serviceAccount:[email protected]" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:[email protected]" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 } **YAML example:** bindings: - members: - user:[email protected] - group:[email protected] - domain:google.com - serviceAccount:[email protected] role: roles/resourcemanager.organizationAdmin - members: - user:[email protected] role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - etag: BwWWja0YfJA= - version: 3 For a description of IAM and its features, see the `IAM documentation <https://cloud.google.com/iam/docs/>`__. """ # Jsonify the request body body = compute.GlobalSetPolicyRequest.to_json( request.global_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, ) # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/licenses/{resource}/setIamPolicy".format( host=self._host, project=request.project, resource=request.resource, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.post( url, headers=headers, params=query_params, data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Policy.from_json(response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetFirewallRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Firewall: r"""Call the get method over HTTP. Args: request (~.compute.GetFirewallRequest): The request object. A request message for Firewalls.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Firewall: Represents a Firewall Rule resource. Firewall rules allow or deny ingress traffic to, and egress traffic from your instances. For more information, read Firewall rules. """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/firewalls/{firewall}".format( host=self._host, project=request.project, firewall=request.firewall, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Firewall.from_json(response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetRegionDiskRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Disk: r"""Call the get method over HTTP. Args: request (~.compute.GetRegionDiskRequest): The request object. A request message for RegionDisks.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Disk: Represents a Persistent Disk resource. Google Compute Engine has two Disk resources: - `Zonal </compute/docs/reference/rest/{$api_version}/disks>`__ \* `Regional </compute/docs/reference/rest/{$api_version}/regionDisks>`__ Persistent disks are required for running your VM instances. Create both boot and non-boot (data) persistent disks. For more information, read Persistent Disks. For more storage options, read Storage options. The disks resource represents a zonal persistent disk. For more information, read Zonal persistent disks. The regionDisks resource represents a regional persistent disk. For more information, read Regional resources. (== resource_for {$api_version}.disks ==) (== resource_for {$api_version}.regionDisks ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/disks/{disk}".format( host=self._host, project=request.project, region=request.region, disk=request.disk, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Disk.from_json(response.content, ignore_unknown_fields=True)
def test_iam_permissions( self, request: compute.TestIamPermissionsRegionDiskRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.TestPermissionsResponse: r"""Call the test iam permissions method over HTTP. Args: request (~.compute.TestIamPermissionsRegionDiskRequest): The request object. A request message for RegionDisks.TestIamPermissions. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.TestPermissionsResponse: """ # Jsonify the request body body = compute.TestPermissionsRequest.to_json( request.test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, ) # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/disks/{resource}/testIamPermissions".format( host=self._host, project=request.project, region=request.region, resource=request.resource, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.post( url, headers=headers, data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.TestPermissionsResponse.from_json( response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetAddressRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Address: r"""Call the get method over HTTP. Args: request (~.compute.GetAddressRequest): The request object. A request message for Addresses.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Address: Use global external addresses for GFE-based external HTTP(S) load balancers in Premium Tier. Use global internal addresses for reserved peering network range. Use regional external addresses for the following resources: - External IP addresses for VM instances - Regional external forwarding rules - Cloud NAT external IP addresses - GFE based LBs in Standard Tier - Network LBs in Premium or Standard Tier - Cloud VPN gateways (both Classic and HA) Use regional internal IP addresses for subnet IP ranges (primary and secondary). This includes: - Internal IP addresses for VM instances - Alias IP ranges of VM instances (/32 only) - Regional internal forwarding rules - Internal TCP/UDP load balancer addresses - Internal HTTP(S) load balancer addresses - Cloud DNS inbound forwarding IP addresses For more information, read reserved IP address. (== resource_for {$api_version}.addresses ==) (== resource_for {$api_version}.globalAddresses ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/addresses/{address}".format( host=self._host, project=request.project, region=request.region, address=request.address, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Address.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.ListRegionAutoscalersRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.RegionAutoscalerList: r"""Call the list method over HTTP. Args: request (~.compute.ListRegionAutoscalersRequest): The request object. A request message for RegionAutoscalers.List. See the method description for details. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.RegionAutoscalerList: Contains a list of autoscalers. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/autoscalers", }, ] request_kwargs = compute.ListRegionAutoscalersRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.ListRegionAutoscalersRequest.to_json( compute.ListRegionAutoscalersRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.RegionAutoscalerList.from_json( response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.UpdateRegionAutoscalerRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Operation: r"""Call the update method over HTTP. Args: request (~.compute.UpdateRegionAutoscalerRequest): The request object. A request message for RegionAutoscalers.Update. See the method description for details. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Operation: Represents an Operation resource. Google Compute Engine has three Operation resources: \* `Global </compute/docs/reference/rest/v1/globalOperations>`__ \* `Regional </compute/docs/reference/rest/v1/regionOperations>`__ \* `Zonal </compute/docs/reference/rest/v1/zoneOperations>`__ You can use an operation resource to manage asynchronous API requests. For more information, read Handling API responses. Operations can be global, regional or zonal. - For global operations, use the ``globalOperations`` resource. - For regional operations, use the ``regionOperations`` resource. - For zonal operations, use the ``zonalOperations`` resource. For more information, read Global, Regional, and Zonal Resources. """ http_options = [ { "method": "put", "uri": "/compute/v1/projects/{project}/regions/{region}/autoscalers", "body": "autoscaler_resource", }, ] request_kwargs = compute.UpdateRegionAutoscalerRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) # Jsonify the request body body = compute.Autoscaler.to_json( compute.Autoscaler(transcoded_request["body"]), including_default_value_fields=False, use_integers_for_enums=False, ) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.UpdateRegionAutoscalerRequest.to_json( compute.UpdateRegionAutoscalerRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Operation.from_json(response.content, ignore_unknown_fields=True)
def attach_network_endpoints( self, request: compute. AttachNetworkEndpointsGlobalNetworkEndpointGroupRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Operation: r"""Call the attach network endpoints method over HTTP. Args: request (~.compute.AttachNetworkEndpointsGlobalNetworkEndpointGroupRequest): The request object. A request message for GlobalNetworkEndpointGroups.AttachNetworkEndpoints. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Operation: Represents an Operation resource. Google Compute Engine has three Operation resources: - `Global </compute/docs/reference/rest/{$api_version}/globalOperations>`__ \* `Regional </compute/docs/reference/rest/{$api_version}/regionOperations>`__ \* `Zonal </compute/docs/reference/rest/{$api_version}/zoneOperations>`__ You can use an operation resource to manage asynchronous API requests. For more information, read Handling API responses. Operations can be global, regional or zonal. - For global operations, use the ``globalOperations`` resource. - For regional operations, use the ``regionOperations`` resource. - For zonal operations, use the ``zonalOperations`` resource. For more information, read Global, Regional, and Zonal Resources. (== resource_for {$api_version}.globalOperations ==) (== resource_for {$api_version}.regionOperations ==) (== resource_for {$api_version}.zoneOperations ==) """ # Jsonify the request body body = compute.GlobalNetworkEndpointGroupsAttachEndpointsRequest.to_json( request. global_network_endpoint_groups_attach_endpoints_request_resource, including_default_value_fields=False, use_integers_for_enums=False, ) # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/networkEndpointGroups/{network_endpoint_group}/attachNetworkEndpoints".format( host=self._host, project=request.project, network_endpoint_group=request.network_endpoint_group, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} if (compute.AttachNetworkEndpointsGlobalNetworkEndpointGroupRequest. request_id in request): query_params["requestId"] = request.request_id # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.post( url, headers=headers, params=query_params, data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Operation.from_json(response.content, ignore_unknown_fields=True)
def insert( self, request: compute.InsertInterconnectAttachmentRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Operation: r"""Call the insert method over HTTP. Args: request (~.compute.InsertInterconnectAttachmentRequest): The request object. A request message for InterconnectAttachments.Insert. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Operation: Represents an Operation resource. Google Compute Engine has three Operation resources: - `Global </compute/docs/reference/rest/{$api_version}/globalOperations>`__ \* `Regional </compute/docs/reference/rest/{$api_version}/regionOperations>`__ \* `Zonal </compute/docs/reference/rest/{$api_version}/zoneOperations>`__ You can use an operation resource to manage asynchronous API requests. For more information, read Handling API responses. Operations can be global, regional or zonal. - For global operations, use the ``globalOperations`` resource. - For regional operations, use the ``regionOperations`` resource. - For zonal operations, use the ``zonalOperations`` resource. For more information, read Global, Regional, and Zonal Resources. (== resource_for {$api_version}.globalOperations ==) (== resource_for {$api_version}.regionOperations ==) (== resource_for {$api_version}.zoneOperations ==) """ # Jsonify the request body body = compute.InterconnectAttachment.to_json( request.interconnect_attachment_resource, including_default_value_fields=False, use_integers_for_enums=False, ) # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/interconnectAttachments".format( host=self._host, project=request.project, region=request.region, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} if compute.InsertInterconnectAttachmentRequest.request_id in request: query_params["requestId"] = request.request_id if compute.InsertInterconnectAttachmentRequest.validate_only in request: query_params["validateOnly"] = request.validate_only # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.post( url, headers=headers, data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Operation.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetRegionNetworkEndpointGroupRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.NetworkEndpointGroup: r"""Call the get method over HTTP. Args: request (~.compute.GetRegionNetworkEndpointGroupRequest): The request object. A request message for RegionNetworkEndpointGroups.Get. See the method description for details. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.NetworkEndpointGroup: Represents a collection of network endpoints. A network endpoint group (NEG) defines how a set of endpoints should be reached, whether they are reachable, and where they are located. For more information about using NEGs, see Setting up external HTTP(S) Load Balancing with internet NEGs, Setting up zonal NEGs, or Setting up external HTTP(S) Load Balancing with serverless NEGs. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/networkEndpointGroups/{network_endpoint_group}", }, ] request_kwargs = compute.GetRegionNetworkEndpointGroupRequest.to_dict( request ) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetRegionNetworkEndpointGroupRequest.to_json( compute.GetRegionNetworkEndpointGroupRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.NetworkEndpointGroup.from_json( response.content, ignore_unknown_fields=True )
def __call__( self, request: compute.SetIamPolicyNodeTemplateRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Policy: r"""Call the set iam policy method over HTTP. Args: request (~.compute.SetIamPolicyNodeTemplateRequest): The request object. A request message for NodeTemplates.SetIamPolicy. See the method description for details. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.Policy: An Identity and Access Management (IAM) policy, which specifies access controls for Google Cloud resources. A ``Policy`` is a collection of ``bindings``. A ``binding`` binds one or more ``members`` to a single ``role``. Members can be user accounts, service accounts, Google groups, and domains (such as G Suite). A ``role`` is a named list of permissions; each ``role`` can be an IAM predefined role or a user-created custom role. For some types of Google Cloud resources, a ``binding`` can also specify a ``condition``, which is a logical expression that allows access to a resource only if the expression evaluates to ``true``. A condition can add constraints based on attributes of the request, the resource, or both. To learn which resources support conditions in their IAM policies, see the `IAM documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__. **JSON example:** { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:[email protected]", "group:[email protected]", "domain:google.com", "serviceAccount:[email protected]" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:[email protected]" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 } **YAML example:** bindings: - members: - user:[email protected] - group:[email protected] - domain:google.com - serviceAccount:[email protected] role: roles/resourcemanager.organizationAdmin - members: - user:[email protected] role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3 For a description of IAM and its features, see the `IAM documentation <https://cloud.google.com/iam/docs/>`__. """ http_options = [ { "method": "post", "uri": "/compute/v1/projects/{project}/regions/{region}/nodeTemplates/{resource}/setIamPolicy", "body": "region_set_policy_request_resource", }, ] request_kwargs = compute.SetIamPolicyNodeTemplateRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) # Jsonify the request body body = compute.RegionSetPolicyRequest.to_json( compute.RegionSetPolicyRequest(transcoded_request["body"]), including_default_value_fields=False, use_integers_for_enums=False, ) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.SetIamPolicyNodeTemplateRequest.to_json( compute.SetIamPolicyNodeTemplateRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Policy.from_json(response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetRegionInstanceGroupRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.InstanceGroup: r"""Call the get method over HTTP. Args: request (~.compute.GetRegionInstanceGroupRequest): The request object. A request message for RegionInstanceGroups.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.InstanceGroup: Represents an Instance Group resource. Instance Groups can be used to configure a target for load balancing. Instance groups can either be managed or unmanaged. To create managed instance groups, use the instanceGroupManager or regionInstanceGroupManager resource instead. Use zonal unmanaged instance groups if you need to apply load balancing to groups of heterogeneous instances or if you need to manage the instances yourself. You cannot create regional unmanaged instance groups. For more information, read Instance groups. (== resource_for {$api_version}.instanceGroups ==) (== resource_for {$api_version}.regionInstanceGroups ==) """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/regions/{region}/instanceGroups/{instance_group}".format( host=self._host, project=request.project, region=request.region, instance_group=request.instance_group, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, params=query_params, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.InstanceGroup.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetInstanceGroupRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.InstanceGroup: r"""Call the get method over HTTP. Args: request (~.compute.GetInstanceGroupRequest): The request object. A request message for InstanceGroups.Get. See the method description for details. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.InstanceGroup: Represents an Instance Group resource. Instance Groups can be used to configure a target for load balancing. Instance groups can either be managed or unmanaged. To create managed instance groups, use the instanceGroupManager or regionInstanceGroupManager resource instead. Use zonal unmanaged instance groups if you need to apply load balancing to groups of heterogeneous instances or if you need to manage the instances yourself. You cannot create regional unmanaged instance groups. For more information, read Instance groups. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/zones/{zone}/instanceGroups/{instance_group}", }, ] request_kwargs = compute.GetInstanceGroupRequest.to_dict(request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetInstanceGroupRequest.to_json( compute.GetInstanceGroupRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.InstanceGroup.from_json(response.content, ignore_unknown_fields=True)
def get( self, request: compute.GetHealthCheckRequest, *, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.HealthCheck: r"""Call the get method over HTTP. Args: request (~.compute.GetHealthCheckRequest): The request object. A request message for HealthChecks.Get. See the method description for details. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.compute.HealthCheck: Represents a Health Check resource. Google Compute Engine has two Health Check resources: - `Global </compute/docs/reference/rest/{$api_version}/healthChecks>`__ \* `Regional </compute/docs/reference/rest/{$api_version}/regionHealthChecks>`__ Internal HTTP(S) load balancers must use regional health checks (``compute.v1.regionHealthChecks``). Traffic Director must use global health checks (``compute.v1.HealthChecks``). Internal TCP/UDP load balancers can use either regional or global health checks (``compute.v1.regionHealthChecks`` or ``compute.v1.HealthChecks``). External HTTP(S), TCP proxy, and SSL proxy load balancers as well as managed instance group auto-healing must use global health checks (``compute.v1.HealthChecks``). Network load balancers must use legacy HTTP health checks (httpHealthChecks). For more information, see Health checks overview. """ # TODO(yon-mg): need to handle grpc transcoding and parse url correctly # current impl assumes basic case of grpc transcoding url = "https://{host}/compute/v1/projects/{project}/global/healthChecks/{health_check}".format( host=self._host, project=request.project, health_check=request.health_check, ) # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings query_params = [ "{k}={v}".format(k=k, v=v) for k, v in query_params.items() ] url += "?{}".format("&".join(query_params)).replace(" ", "+") # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = self._session.get( url, headers=headers, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.HealthCheck.from_json(response.content, ignore_unknown_fields=True)