From 45b85f2e7692e7df11e763bc618137f100a52298 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 15 Apr 2023 10:10:55 -0400 Subject: [PATCH 1/2] feat: make reservation_name parameter generally visible in QueuedResource message (#224) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: make reservation_name parameter generally visible in QueuedResource message --- feat: add DeleteQueuedResource experiment --- docs(v2alpha1): minor formatting to the description for `queued_resource_id` PiperOrigin-RevId: 524336094 Source-Link: https://github.com/googleapis/googleapis/commit/cad90d2ae086097bf0f4924ff60100d75b3dd501 Source-Link: https://github.com/googleapis/googleapis-gen/commit/848f9c294076db6d1d1a78013040251b1c0ad7a9 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODQ4ZjljMjk0MDc2ZGI2ZDFkMWE3ODAxMzA0MDI1MWIxYzBhZDdhOSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- google/cloud/tpu_v2alpha1/__init__.py | 2 + google/cloud/tpu_v2alpha1/gapic_metadata.json | 10 + .../tpu_v2alpha1/services/tpu/async_client.py | 117 +++++++++ .../cloud/tpu_v2alpha1/services/tpu/client.py | 117 +++++++++ .../services/tpu/transports/base.py | 14 + .../services/tpu/transports/grpc.py | 26 ++ .../services/tpu/transports/grpc_asyncio.py | 28 ++ google/cloud/tpu_v2alpha1/types/__init__.py | 2 + google/cloud/tpu_v2alpha1/types/cloud_tpu.py | 24 ++ .../snippet_metadata_google.cloud.tpu.v1.json | 2 +- .../snippet_metadata_google.cloud.tpu.v2.json | 2 +- ...et_metadata_google.cloud.tpu.v2alpha1.json | 163 +++++++++++- ...nerated_tpu_reset_queued_resource_async.py | 56 ++++ ...enerated_tpu_reset_queued_resource_sync.py | 56 ++++ scripts/fixup_tpu_v2alpha1_keywords.py | 1 + tests/unit/gapic/tpu_v2alpha1/test_tpu.py | 245 ++++++++++++++++++ 16 files changed, 862 insertions(+), 3 deletions(-) create mode 100644 samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_async.py create mode 100644 samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_sync.py diff --git a/google/cloud/tpu_v2alpha1/__init__.py b/google/cloud/tpu_v2alpha1/__init__.py index 09b9383..9760f13 100644 --- a/google/cloud/tpu_v2alpha1/__init__.py +++ b/google/cloud/tpu_v2alpha1/__init__.py @@ -53,6 +53,7 @@ OperationMetadata, QueuedResource, QueuedResourceState, + ResetQueuedResourceRequest, RuntimeVersion, SchedulingConfig, ServiceAccount, @@ -100,6 +101,7 @@ "OperationMetadata", "QueuedResource", "QueuedResourceState", + "ResetQueuedResourceRequest", "RuntimeVersion", "SchedulingConfig", "ServiceAccount", diff --git a/google/cloud/tpu_v2alpha1/gapic_metadata.json b/google/cloud/tpu_v2alpha1/gapic_metadata.json index 4c5e3e7..cb51745 100644 --- a/google/cloud/tpu_v2alpha1/gapic_metadata.json +++ b/google/cloud/tpu_v2alpha1/gapic_metadata.json @@ -80,6 +80,11 @@ "list_runtime_versions" ] }, + "ResetQueuedResource": { + "methods": [ + "reset_queued_resource" + ] + }, "SimulateMaintenanceEvent": { "methods": [ "simulate_maintenance_event" @@ -175,6 +180,11 @@ "list_runtime_versions" ] }, + "ResetQueuedResource": { + "methods": [ + "reset_queued_resource" + ] + }, "SimulateMaintenanceEvent": { "methods": [ "simulate_maintenance_event" diff --git a/google/cloud/tpu_v2alpha1/services/tpu/async_client.py b/google/cloud/tpu_v2alpha1/services/tpu/async_client.py index 1a4649f..8796e28 100644 --- a/google/cloud/tpu_v2alpha1/services/tpu/async_client.py +++ b/google/cloud/tpu_v2alpha1/services/tpu/async_client.py @@ -1475,6 +1475,123 @@ async def sample_delete_queued_resource(): # Done; return the response. return response + async def reset_queued_resource( + self, + request: Optional[Union[cloud_tpu.ResetQueuedResourceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Resets a QueuedResource TPU instance + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import tpu_v2alpha1 + + async def sample_reset_queued_resource(): + # Create a client + client = tpu_v2alpha1.TpuAsyncClient() + + # Initialize request argument(s) + request = tpu_v2alpha1.ResetQueuedResourceRequest( + name="name_value", + ) + + # Make the request + operation = client.reset_queued_resource(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.tpu_v2alpha1.types.ResetQueuedResourceRequest, dict]]): + The request object. Request for + [ResetQueuedResource][google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource]. + name (:class:`str`): + Required. The name of the queued + resource. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.tpu_v2alpha1.types.QueuedResource` A QueuedResource represents a request for resources that will be placed + in a queue and fulfilled when the necessary resources + are available. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = cloud_tpu.ResetQueuedResourceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.reset_queued_resource, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + cloud_tpu.QueuedResource, + metadata_type=cloud_tpu.OperationMetadata, + ) + + # Done; return the response. + return response + async def generate_service_identity( self, request: Optional[Union[cloud_tpu.GenerateServiceIdentityRequest, dict]] = None, diff --git a/google/cloud/tpu_v2alpha1/services/tpu/client.py b/google/cloud/tpu_v2alpha1/services/tpu/client.py index 6e3a246..2677b64 100644 --- a/google/cloud/tpu_v2alpha1/services/tpu/client.py +++ b/google/cloud/tpu_v2alpha1/services/tpu/client.py @@ -1772,6 +1772,123 @@ def sample_delete_queued_resource(): # Done; return the response. return response + def reset_queued_resource( + self, + request: Optional[Union[cloud_tpu.ResetQueuedResourceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Resets a QueuedResource TPU instance + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import tpu_v2alpha1 + + def sample_reset_queued_resource(): + # Create a client + client = tpu_v2alpha1.TpuClient() + + # Initialize request argument(s) + request = tpu_v2alpha1.ResetQueuedResourceRequest( + name="name_value", + ) + + # Make the request + operation = client.reset_queued_resource(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.tpu_v2alpha1.types.ResetQueuedResourceRequest, dict]): + The request object. Request for + [ResetQueuedResource][google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource]. + name (str): + Required. The name of the queued + resource. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.tpu_v2alpha1.types.QueuedResource` A QueuedResource represents a request for resources that will be placed + in a queue and fulfilled when the necessary resources + are available. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a cloud_tpu.ResetQueuedResourceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_tpu.ResetQueuedResourceRequest): + request = cloud_tpu.ResetQueuedResourceRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.reset_queued_resource] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + cloud_tpu.QueuedResource, + metadata_type=cloud_tpu.OperationMetadata, + ) + + # Done; return the response. + return response + def generate_service_identity( self, request: Optional[Union[cloud_tpu.GenerateServiceIdentityRequest, dict]] = None, diff --git a/google/cloud/tpu_v2alpha1/services/tpu/transports/base.py b/google/cloud/tpu_v2alpha1/services/tpu/transports/base.py index 2950eb9..8561a9e 100644 --- a/google/cloud/tpu_v2alpha1/services/tpu/transports/base.py +++ b/google/cloud/tpu_v2alpha1/services/tpu/transports/base.py @@ -179,6 +179,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.reset_queued_resource: gapic_v1.method.wrap_method( + self.reset_queued_resource, + default_timeout=None, + client_info=client_info, + ), self.generate_service_identity: gapic_v1.method.wrap_method( self.generate_service_identity, default_timeout=None, @@ -331,6 +336,15 @@ def delete_queued_resource( ]: raise NotImplementedError() + @property + def reset_queued_resource( + self, + ) -> Callable[ + [cloud_tpu.ResetQueuedResourceRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def generate_service_identity( self, diff --git a/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc.py b/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc.py index 8df33ea..a1351ba 100644 --- a/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc.py +++ b/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc.py @@ -533,6 +533,32 @@ def delete_queued_resource( ) return self._stubs["delete_queued_resource"] + @property + def reset_queued_resource( + self, + ) -> Callable[[cloud_tpu.ResetQueuedResourceRequest], operations_pb2.Operation]: + r"""Return a callable for the reset queued resource method over gRPC. + + Resets a QueuedResource TPU instance + + Returns: + Callable[[~.ResetQueuedResourceRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "reset_queued_resource" not in self._stubs: + self._stubs["reset_queued_resource"] = self.grpc_channel.unary_unary( + "/google.cloud.tpu.v2alpha1.Tpu/ResetQueuedResource", + request_serializer=cloud_tpu.ResetQueuedResourceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["reset_queued_resource"] + @property def generate_service_identity( self, diff --git a/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc_asyncio.py b/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc_asyncio.py index c8e4d64..e881668 100644 --- a/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc_asyncio.py +++ b/google/cloud/tpu_v2alpha1/services/tpu/transports/grpc_asyncio.py @@ -547,6 +547,34 @@ def delete_queued_resource( ) return self._stubs["delete_queued_resource"] + @property + def reset_queued_resource( + self, + ) -> Callable[ + [cloud_tpu.ResetQueuedResourceRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the reset queued resource method over gRPC. + + Resets a QueuedResource TPU instance + + Returns: + Callable[[~.ResetQueuedResourceRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "reset_queued_resource" not in self._stubs: + self._stubs["reset_queued_resource"] = self.grpc_channel.unary_unary( + "/google.cloud.tpu.v2alpha1.Tpu/ResetQueuedResource", + request_serializer=cloud_tpu.ResetQueuedResourceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["reset_queued_resource"] + @property def generate_service_identity( self, diff --git a/google/cloud/tpu_v2alpha1/types/__init__.py b/google/cloud/tpu_v2alpha1/types/__init__.py index 4788987..a92b9cd 100644 --- a/google/cloud/tpu_v2alpha1/types/__init__.py +++ b/google/cloud/tpu_v2alpha1/types/__init__.py @@ -47,6 +47,7 @@ OperationMetadata, QueuedResource, QueuedResourceState, + ResetQueuedResourceRequest, RuntimeVersion, SchedulingConfig, ServiceAccount, @@ -93,6 +94,7 @@ "OperationMetadata", "QueuedResource", "QueuedResourceState", + "ResetQueuedResourceRequest", "RuntimeVersion", "SchedulingConfig", "ServiceAccount", diff --git a/google/cloud/tpu_v2alpha1/types/cloud_tpu.py b/google/cloud/tpu_v2alpha1/types/cloud_tpu.py index 204cc2a..797f7c1 100644 --- a/google/cloud/tpu_v2alpha1/types/cloud_tpu.py +++ b/google/cloud/tpu_v2alpha1/types/cloud_tpu.py @@ -52,6 +52,7 @@ "GetQueuedResourceRequest", "CreateQueuedResourceRequest", "DeleteQueuedResourceRequest", + "ResetQueuedResourceRequest", "ServiceIdentity", "GenerateServiceIdentityRequest", "GenerateServiceIdentityResponse", @@ -638,6 +639,10 @@ class QueuedResource(proto.Message): state (google.cloud.tpu_v2alpha1.types.QueuedResourceState): Output only. State of the QueuedResource request. + reservation_name (str): + Name of the reservation in which the resource + should be provisioned. Format: + projects/{project}/locations/{zone}/reservations/{reservation} """ class Tpu(proto.Message): @@ -819,6 +824,10 @@ class QueueingPolicy(proto.Message): number=6, message="QueuedResourceState", ) + reservation_name: str = proto.Field( + proto.STRING, + number=8, + ) class QueuedResourceState(proto.Message): @@ -1321,6 +1330,21 @@ class DeleteQueuedResourceRequest(proto.Message): ) +class ResetQueuedResourceRequest(proto.Message): + r"""Request for + [ResetQueuedResource][google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource]. + + Attributes: + name (str): + Required. The name of the queued resource. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + class ServiceIdentity(proto.Message): r"""The per-product per-project service identity for Cloud TPU service. diff --git a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json index 81380c3..0a659a0 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-tpu", - "version": "1.9.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json index fd1fc98..9f7e7c8 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-tpu", - "version": "1.9.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json index 16550f6..2ee3935 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-tpu", - "version": "1.9.0" + "version": "0.1.0" }, "snippets": [ { @@ -2281,6 +2281,167 @@ ], "title": "tpu_v2alpha1_generated_tpu_list_runtime_versions_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.tpu_v2alpha1.TpuAsyncClient", + "shortName": "TpuAsyncClient" + }, + "fullName": "google.cloud.tpu_v2alpha1.TpuAsyncClient.reset_queued_resource", + "method": { + "fullName": "google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource", + "service": { + "fullName": "google.cloud.tpu.v2alpha1.Tpu", + "shortName": "Tpu" + }, + "shortName": "ResetQueuedResource" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.tpu_v2alpha1.types.ResetQueuedResourceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "reset_queued_resource" + }, + "description": "Sample for ResetQueuedResource", + "file": "tpu_v2alpha1_generated_tpu_reset_queued_resource_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "tpu_v2alpha1_generated_tpu_reset_queued_resource_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.tpu_v2alpha1.TpuClient", + "shortName": "TpuClient" + }, + "fullName": "google.cloud.tpu_v2alpha1.TpuClient.reset_queued_resource", + "method": { + "fullName": "google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource", + "service": { + "fullName": "google.cloud.tpu.v2alpha1.Tpu", + "shortName": "Tpu" + }, + "shortName": "ResetQueuedResource" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.tpu_v2alpha1.types.ResetQueuedResourceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "reset_queued_resource" + }, + "description": "Sample for ResetQueuedResource", + "file": "tpu_v2alpha1_generated_tpu_reset_queued_resource_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "tpu_v2alpha1_generated_Tpu_ResetQueuedResource_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "tpu_v2alpha1_generated_tpu_reset_queued_resource_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_async.py b/samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_async.py new file mode 100644 index 0000000..6f9c423 --- /dev/null +++ b/samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_async.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResetQueuedResource +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-tpu + + +# [START tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import tpu_v2alpha1 + + +async def sample_reset_queued_resource(): + # Create a client + client = tpu_v2alpha1.TpuAsyncClient() + + # Initialize request argument(s) + request = tpu_v2alpha1.ResetQueuedResourceRequest( + name="name_value", + ) + + # Make the request + operation = client.reset_queued_resource(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async] diff --git a/samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_sync.py b/samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_sync.py new file mode 100644 index 0000000..b0a8edc --- /dev/null +++ b/samples/generated_samples/tpu_v2alpha1_generated_tpu_reset_queued_resource_sync.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResetQueuedResource +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-tpu + + +# [START tpu_v2alpha1_generated_Tpu_ResetQueuedResource_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import tpu_v2alpha1 + + +def sample_reset_queued_resource(): + # Create a client + client = tpu_v2alpha1.TpuClient() + + # Initialize request argument(s) + request = tpu_v2alpha1.ResetQueuedResourceRequest( + name="name_value", + ) + + # Make the request + operation = client.reset_queued_resource(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END tpu_v2alpha1_generated_Tpu_ResetQueuedResource_sync] diff --git a/scripts/fixup_tpu_v2alpha1_keywords.py b/scripts/fixup_tpu_v2alpha1_keywords.py index b2f15db..9e95df2 100644 --- a/scripts/fixup_tpu_v2alpha1_keywords.py +++ b/scripts/fixup_tpu_v2alpha1_keywords.py @@ -53,6 +53,7 @@ class tpuCallTransformer(cst.CSTTransformer): 'list_nodes': ('parent', 'page_size', 'page_token', ), 'list_queued_resources': ('parent', 'page_size', 'page_token', ), 'list_runtime_versions': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'reset_queued_resource': ('name', ), 'simulate_maintenance_event': ('name', 'worker_ids', ), 'start_node': ('name', ), 'stop_node': ('name', ), diff --git a/tests/unit/gapic/tpu_v2alpha1/test_tpu.py b/tests/unit/gapic/tpu_v2alpha1/test_tpu.py index 7deb964..62ebce1 100644 --- a/tests/unit/gapic/tpu_v2alpha1/test_tpu.py +++ b/tests/unit/gapic/tpu_v2alpha1/test_tpu.py @@ -2797,6 +2797,7 @@ def test_get_queued_resource(request_type, transport: str = "grpc"): # Designate an appropriate return value for the call. call.return_value = cloud_tpu.QueuedResource( name="name_value", + reservation_name="reservation_name_value", tpu=cloud_tpu.QueuedResource.Tpu( node_spec=[cloud_tpu.QueuedResource.Tpu.NodeSpec(parent="parent_value")] ), @@ -2812,6 +2813,7 @@ def test_get_queued_resource(request_type, transport: str = "grpc"): # Establish that the response is the type that we expect. assert isinstance(response, cloud_tpu.QueuedResource) assert response.name == "name_value" + assert response.reservation_name == "reservation_name_value" def test_get_queued_resource_empty_call(): @@ -2853,6 +2855,7 @@ async def test_get_queued_resource_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_tpu.QueuedResource( name="name_value", + reservation_name="reservation_name_value", ) ) response = await client.get_queued_resource(request) @@ -2865,6 +2868,7 @@ async def test_get_queued_resource_async( # Establish that the response is the type that we expect. assert isinstance(response, cloud_tpu.QueuedResource) assert response.name == "name_value" + assert response.reservation_name == "reservation_name_value" @pytest.mark.asyncio @@ -3523,6 +3527,246 @@ async def test_delete_queued_resource_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + cloud_tpu.ResetQueuedResourceRequest, + dict, + ], +) +def test_reset_queued_resource(request_type, transport: str = "grpc"): + client = TpuClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reset_queued_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.reset_queued_resource(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_tpu.ResetQueuedResourceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_reset_queued_resource_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TpuClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reset_queued_resource), "__call__" + ) as call: + client.reset_queued_resource() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_tpu.ResetQueuedResourceRequest() + + +@pytest.mark.asyncio +async def test_reset_queued_resource_async( + transport: str = "grpc_asyncio", request_type=cloud_tpu.ResetQueuedResourceRequest +): + client = TpuAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reset_queued_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.reset_queued_resource(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_tpu.ResetQueuedResourceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_reset_queued_resource_async_from_dict(): + await test_reset_queued_resource_async(request_type=dict) + + +def test_reset_queued_resource_field_headers(): + client = TpuClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_tpu.ResetQueuedResourceRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reset_queued_resource), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.reset_queued_resource(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_reset_queued_resource_field_headers_async(): + client = TpuAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_tpu.ResetQueuedResourceRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reset_queued_resource), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.reset_queued_resource(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_reset_queued_resource_flattened(): + client = TpuClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reset_queued_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.reset_queued_resource( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_reset_queued_resource_flattened_error(): + client = TpuClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.reset_queued_resource( + cloud_tpu.ResetQueuedResourceRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_reset_queued_resource_flattened_async(): + client = TpuAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reset_queued_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.reset_queued_resource( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_reset_queued_resource_flattened_error_async(): + client = TpuAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.reset_queued_resource( + cloud_tpu.ResetQueuedResourceRequest(), + name="name_value", + ) + + @pytest.mark.parametrize( "request_type", [ @@ -5527,6 +5771,7 @@ def test_tpu_base_transport(): "get_queued_resource", "create_queued_resource", "delete_queued_resource", + "reset_queued_resource", "generate_service_identity", "list_accelerator_types", "get_accelerator_type", From d98cdaef7f057e47220ef2cb34de2ccf8b316971 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 17 Apr 2023 06:40:55 -0400 Subject: [PATCH 2/2] chore(main): release 1.10.0 (#225) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ google/cloud/tpu/gapic_version.py | 2 +- google/cloud/tpu_v1/gapic_version.py | 2 +- google/cloud/tpu_v2/gapic_version.py | 2 +- google/cloud/tpu_v2alpha1/gapic_version.py | 2 +- .../snippet_metadata_google.cloud.tpu.v1.json | 2 +- .../snippet_metadata_google.cloud.tpu.v2.json | 2 +- .../snippet_metadata_google.cloud.tpu.v2alpha1.json | 2 +- 9 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4fcfdf7..d9246dd 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.9.0" + ".": "1.10.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 013c0d7..8b9cb7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.10.0](https://github.com/googleapis/python-tpu/compare/v1.9.0...v1.10.0) (2023-04-15) + + +### Features + +* **v2alpha1:** Add reset_queued_resource ([45b85f2](https://github.com/googleapis/python-tpu/commit/45b85f2e7692e7df11e763bc618137f100a52298)) +* **v2alpha1:** Make reservation_name parameter generally visible in QueuedResource message ([45b85f2](https://github.com/googleapis/python-tpu/commit/45b85f2e7692e7df11e763bc618137f100a52298)) + ## [1.9.0](https://github.com/googleapis/python-tpu/compare/v1.8.0...v1.9.0) (2023-03-24) diff --git a/google/cloud/tpu/gapic_version.py b/google/cloud/tpu/gapic_version.py index 163d151..7ce1917 100644 --- a/google/cloud/tpu/gapic_version.py +++ b/google/cloud/tpu/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.9.0" # {x-release-please-version} +__version__ = "1.10.0" # {x-release-please-version} diff --git a/google/cloud/tpu_v1/gapic_version.py b/google/cloud/tpu_v1/gapic_version.py index 163d151..7ce1917 100644 --- a/google/cloud/tpu_v1/gapic_version.py +++ b/google/cloud/tpu_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.9.0" # {x-release-please-version} +__version__ = "1.10.0" # {x-release-please-version} diff --git a/google/cloud/tpu_v2/gapic_version.py b/google/cloud/tpu_v2/gapic_version.py index 163d151..7ce1917 100644 --- a/google/cloud/tpu_v2/gapic_version.py +++ b/google/cloud/tpu_v2/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.9.0" # {x-release-please-version} +__version__ = "1.10.0" # {x-release-please-version} diff --git a/google/cloud/tpu_v2alpha1/gapic_version.py b/google/cloud/tpu_v2alpha1/gapic_version.py index 163d151..7ce1917 100644 --- a/google/cloud/tpu_v2alpha1/gapic_version.py +++ b/google/cloud/tpu_v2alpha1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.9.0" # {x-release-please-version} +__version__ = "1.10.0" # {x-release-please-version} diff --git a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json index 0a659a0..6c664f7 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-tpu", - "version": "0.1.0" + "version": "1.10.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json index 9f7e7c8..f2b69b5 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-tpu", - "version": "0.1.0" + "version": "1.10.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json index 2ee3935..79a2e84 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.tpu.v2alpha1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-tpu", - "version": "0.1.0" + "version": "1.10.0" }, "snippets": [ {