From f07333fb7238e79b32f480a8c82c61fc2fb26dee Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 10:27:45 +0530 Subject: [PATCH] feat: Add custom instance config operations (#810) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add custom instance config operations PiperOrigin-RevId: 474535825 Source-Link: https://github.com/googleapis/googleapis/commit/69c840ef92253dd2813c8d3d794b779ae08178cf Source-Link: https://github.com/googleapis/googleapis-gen/commit/33e360e7d4bf2479fa79eace85166453cd760b0d Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzNlMzYwZTdkNGJmMjQ3OWZhNzllYWNlODUxNjY0NTNjZDc2MGIwZCJ9 * 🦉 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 --- .../spanner_admin_instance_v1/__init__.py | 16 + .../gapic_metadata.json | 40 + .../services/instance_admin/async_client.py | 608 +++++++- .../services/instance_admin/client.py | 614 +++++++- .../services/instance_admin/pagers.py | 141 ++ .../instance_admin/transports/base.py | 59 + .../instance_admin/transports/grpc.py | 224 +++ .../instance_admin/transports/grpc_asyncio.py | 226 +++ .../types/__init__.py | 18 + .../spanner_admin_instance_v1/types/common.py | 60 + .../types/spanner_instance_admin.py | 437 ++++++ ...et_metadata_spanner admin instance_v1.json | 800 ++++++++++- ...ance_admin_create_instance_config_async.py | 57 + ...tance_admin_create_instance_config_sync.py | 57 + ...ance_admin_delete_instance_config_async.py | 50 + ...tance_admin_delete_instance_config_sync.py | 50 + ...n_list_instance_config_operations_async.py | 53 + ...in_list_instance_config_operations_sync.py | 53 + ...ance_admin_update_instance_config_async.py | 55 + ...tance_admin_update_instance_config_sync.py | 55 + ...ixup_spanner_admin_instance_v1_keywords.py | 4 + .../test_database_admin.py | 2 +- .../test_instance_admin.py | 1229 ++++++++++++++++- tests/unit/gapic/spanner_v1/test_spanner.py | 2 +- 24 files changed, 4834 insertions(+), 76 deletions(-) create mode 100644 google/cloud/spanner_admin_instance_v1/types/common.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py create mode 100644 samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py diff --git a/google/cloud/spanner_admin_instance_v1/__init__.py b/google/cloud/spanner_admin_instance_v1/__init__.py index c641cd061c..12ba0676c0 100644 --- a/google/cloud/spanner_admin_instance_v1/__init__.py +++ b/google/cloud/spanner_admin_instance_v1/__init__.py @@ -17,36 +17,52 @@ from .services.instance_admin import InstanceAdminClient from .services.instance_admin import InstanceAdminAsyncClient +from .types.common import OperationProgress +from .types.spanner_instance_admin import CreateInstanceConfigMetadata +from .types.spanner_instance_admin import CreateInstanceConfigRequest from .types.spanner_instance_admin import CreateInstanceMetadata from .types.spanner_instance_admin import CreateInstanceRequest +from .types.spanner_instance_admin import DeleteInstanceConfigRequest from .types.spanner_instance_admin import DeleteInstanceRequest from .types.spanner_instance_admin import GetInstanceConfigRequest from .types.spanner_instance_admin import GetInstanceRequest from .types.spanner_instance_admin import Instance from .types.spanner_instance_admin import InstanceConfig +from .types.spanner_instance_admin import ListInstanceConfigOperationsRequest +from .types.spanner_instance_admin import ListInstanceConfigOperationsResponse from .types.spanner_instance_admin import ListInstanceConfigsRequest from .types.spanner_instance_admin import ListInstanceConfigsResponse from .types.spanner_instance_admin import ListInstancesRequest from .types.spanner_instance_admin import ListInstancesResponse from .types.spanner_instance_admin import ReplicaInfo +from .types.spanner_instance_admin import UpdateInstanceConfigMetadata +from .types.spanner_instance_admin import UpdateInstanceConfigRequest from .types.spanner_instance_admin import UpdateInstanceMetadata from .types.spanner_instance_admin import UpdateInstanceRequest __all__ = ( "InstanceAdminAsyncClient", + "CreateInstanceConfigMetadata", + "CreateInstanceConfigRequest", "CreateInstanceMetadata", "CreateInstanceRequest", + "DeleteInstanceConfigRequest", "DeleteInstanceRequest", "GetInstanceConfigRequest", "GetInstanceRequest", "Instance", "InstanceAdminClient", "InstanceConfig", + "ListInstanceConfigOperationsRequest", + "ListInstanceConfigOperationsResponse", "ListInstanceConfigsRequest", "ListInstanceConfigsResponse", "ListInstancesRequest", "ListInstancesResponse", + "OperationProgress", "ReplicaInfo", + "UpdateInstanceConfigMetadata", + "UpdateInstanceConfigRequest", "UpdateInstanceMetadata", "UpdateInstanceRequest", ) diff --git a/google/cloud/spanner_admin_instance_v1/gapic_metadata.json b/google/cloud/spanner_admin_instance_v1/gapic_metadata.json index 6fee5bcd53..6b4bfffc92 100644 --- a/google/cloud/spanner_admin_instance_v1/gapic_metadata.json +++ b/google/cloud/spanner_admin_instance_v1/gapic_metadata.json @@ -15,11 +15,21 @@ "create_instance" ] }, + "CreateInstanceConfig": { + "methods": [ + "create_instance_config" + ] + }, "DeleteInstance": { "methods": [ "delete_instance" ] }, + "DeleteInstanceConfig": { + "methods": [ + "delete_instance_config" + ] + }, "GetIamPolicy": { "methods": [ "get_iam_policy" @@ -35,6 +45,11 @@ "get_instance_config" ] }, + "ListInstanceConfigOperations": { + "methods": [ + "list_instance_config_operations" + ] + }, "ListInstanceConfigs": { "methods": [ "list_instance_configs" @@ -59,6 +74,11 @@ "methods": [ "update_instance" ] + }, + "UpdateInstanceConfig": { + "methods": [ + "update_instance_config" + ] } } }, @@ -70,11 +90,21 @@ "create_instance" ] }, + "CreateInstanceConfig": { + "methods": [ + "create_instance_config" + ] + }, "DeleteInstance": { "methods": [ "delete_instance" ] }, + "DeleteInstanceConfig": { + "methods": [ + "delete_instance_config" + ] + }, "GetIamPolicy": { "methods": [ "get_iam_policy" @@ -90,6 +120,11 @@ "get_instance_config" ] }, + "ListInstanceConfigOperations": { + "methods": [ + "list_instance_config_operations" + ] + }, "ListInstanceConfigs": { "methods": [ "list_instance_configs" @@ -114,6 +149,11 @@ "methods": [ "update_instance" ] + }, + "UpdateInstanceConfig": { + "methods": [ + "update_instance_config" + ] } } } diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py index 28d1098417..e42a706845 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py @@ -37,6 +37,7 @@ from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import InstanceAdminTransport, DEFAULT_CLIENT_INFO @@ -293,7 +294,7 @@ async def sample_list_instance_configs(): Returns: google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsAsyncPager: The response for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. Iterating over this object will yield results and resolve additional pages automatically. @@ -476,6 +477,609 @@ async def sample_get_instance_config(): # Done; return the response. return response + async def create_instance_config( + self, + request: Union[spanner_instance_admin.CreateInstanceConfigRequest, dict] = None, + *, + parent: str = None, + instance_config: spanner_instance_admin.InstanceConfig = None, + instance_config_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + .. 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 spanner_admin_instance_v1 + + async def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest, dict]): + The request object. The request for + [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. + parent (:class:`str`): + Required. The name of the project in which to create the + instance config. Values are of the form + ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config (:class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig`): + Required. The InstanceConfig proto of the configuration + to create. instance_config.name must be + ``/instanceConfigs/``. + instance_config.base_config must be a Google managed + configuration name, e.g. /instanceConfigs/us-east1, + /instanceConfigs/nam3. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config_id (:class:`str`): + Required. The ID of the instance config to create. Valid + identifiers are of the form + ``custom-[-a-z0-9]*[a-z0-9]`` and must be between 2 and + 64 characters in length. The ``custom-`` prefix is + required to avoid name conflicts with Google managed + configurations. + + This corresponds to the ``instance_config_id`` 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.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # 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([parent, instance_config, instance_config_id]) + 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 = spanner_instance_admin.CreateInstanceConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if instance_config is not None: + request.instance_config = instance_config + if instance_config_id is not None: + request.instance_config_id = instance_config_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_instance_config, + 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((("parent", request.parent),)), + ) + + # 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, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.CreateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + async def update_instance_config( + self, + request: Union[spanner_instance_admin.UpdateInstanceConfigRequest, dict] = None, + *, + instance_config: spanner_instance_admin.InstanceConfig = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. 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 spanner_admin_instance_v1 + + async def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest, dict]): + The request object. The request for + [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. + instance_config (:class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig`): + Required. The user instance config to update, which must + always include the instance config name. Otherwise, only + fields mentioned in + [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] + need be included. To prevent conflicts of concurrent + updates, + [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + can be used. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. A mask specifying which fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + should be updated. The field mask must always be + specified; this prevents any future fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + from being erased accidentally by clients that do not + know about them. Only display_name and labels can be + updated. + + This corresponds to the ``update_mask`` 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.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # 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([instance_config, update_mask]) + 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 = spanner_instance_admin.UpdateInstanceConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if instance_config is not None: + request.instance_config = instance_config + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_instance_config, + 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( + (("instance_config.name", request.instance_config.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, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.UpdateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + async def delete_instance_config( + self, + request: Union[spanner_instance_admin.DeleteInstanceConfigRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. 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 spanner_admin_instance_v1 + + async def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + await client.delete_instance_config(request=request) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest, dict]): + The request object. The request for + [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. + name (:class:`str`): + Required. The name of the instance configuration to be + deleted. Values are of the form + ``projects//instanceConfigs/`` + + 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. + """ + # 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 = spanner_instance_admin.DeleteInstanceConfigRequest(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.delete_instance_config, + 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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_instance_config_operations( + self, + request: Union[ + spanner_instance_admin.ListInstanceConfigOperationsRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstanceConfigOperationsAsyncPager: + r"""Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + .. 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 spanner_admin_instance_v1 + + async def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest, dict]): + The request object. The request for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + parent (:class:`str`): + Required. The project of the instance config operations. + Values are of the form ``projects/``. + + This corresponds to the ``parent`` 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.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsAsyncPager: + The response for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # 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([parent]) + 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 = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_instance_config_operations, + 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((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListInstanceConfigOperationsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + async def list_instances( self, request: Union[spanner_instance_admin.ListInstancesRequest, dict] = None, @@ -535,7 +1139,7 @@ async def sample_list_instances(): Returns: google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesAsyncPager: The response for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. Iterating over this object will yield results and resolve additional pages automatically. diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py index 2f653b7216..9a1a7e38cd 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py @@ -40,6 +40,7 @@ from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import InstanceAdminTransport, DEFAULT_CLIENT_INFO @@ -527,7 +528,7 @@ def sample_list_instance_configs(): Returns: google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsPager: The response for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. Iterating over this object will yield results and resolve additional pages automatically. @@ -690,6 +691,615 @@ def sample_get_instance_config(): # Done; return the response. return response + def create_instance_config( + self, + request: Union[spanner_instance_admin.CreateInstanceConfigRequest, dict] = None, + *, + parent: str = None, + instance_config: spanner_instance_admin.InstanceConfig = None, + instance_config_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + .. 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 spanner_admin_instance_v1 + + def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest, dict]): + The request object. The request for + [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. + parent (str): + Required. The name of the project in which to create the + instance config. Values are of the form + ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The InstanceConfig proto of the configuration + to create. instance_config.name must be + ``/instanceConfigs/``. + instance_config.base_config must be a Google managed + configuration name, e.g. /instanceConfigs/us-east1, + /instanceConfigs/nam3. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config_id (str): + Required. The ID of the instance config to create. Valid + identifiers are of the form + ``custom-[-a-z0-9]*[a-z0-9]`` and must be between 2 and + 64 characters in length. The ``custom-`` prefix is + required to avoid name conflicts with Google managed + configurations. + + This corresponds to the ``instance_config_id`` 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.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # 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([parent, instance_config, instance_config_id]) + 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 spanner_instance_admin.CreateInstanceConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.CreateInstanceConfigRequest): + request = spanner_instance_admin.CreateInstanceConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if instance_config is not None: + request.instance_config = instance_config + if instance_config_id is not None: + request.instance_config_id = instance_config_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_instance_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # 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, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.CreateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + def update_instance_config( + self, + request: Union[spanner_instance_admin.UpdateInstanceConfigRequest, dict] = None, + *, + instance_config: spanner_instance_admin.InstanceConfig = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. 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 spanner_admin_instance_v1 + + def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest, dict]): + The request object. The request for + [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The user instance config to update, which must + always include the instance config name. Otherwise, only + fields mentioned in + [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] + need be included. To prevent conflicts of concurrent + updates, + [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + can be used. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + should be updated. The field mask must always be + specified; this prevents any future fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + from being erased accidentally by clients that do not + know about them. Only display_name and labels can be + updated. + + This corresponds to the ``update_mask`` 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.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # 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([instance_config, update_mask]) + 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 spanner_instance_admin.UpdateInstanceConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.UpdateInstanceConfigRequest): + request = spanner_instance_admin.UpdateInstanceConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if instance_config is not None: + request.instance_config = instance_config + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_instance_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("instance_config.name", request.instance_config.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, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.UpdateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + def delete_instance_config( + self, + request: Union[spanner_instance_admin.DeleteInstanceConfigRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. 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 spanner_admin_instance_v1 + + def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + client.delete_instance_config(request=request) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest, dict]): + The request object. The request for + [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. + name (str): + Required. The name of the instance configuration to be + deleted. Values are of the form + ``projects//instanceConfigs/`` + + 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. + """ + # 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 spanner_instance_admin.DeleteInstanceConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.DeleteInstanceConfigRequest): + request = spanner_instance_admin.DeleteInstanceConfigRequest(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.delete_instance_config] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_instance_config_operations( + self, + request: Union[ + spanner_instance_admin.ListInstanceConfigOperationsRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstanceConfigOperationsPager: + r"""Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + .. 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 spanner_admin_instance_v1 + + def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest, dict]): + The request object. The request for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + parent (str): + Required. The project of the instance config operations. + Values are of the form ``projects/``. + + This corresponds to the ``parent`` 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.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsPager: + The response for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # 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([parent]) + 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 spanner_instance_admin.ListInstanceConfigOperationsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, spanner_instance_admin.ListInstanceConfigOperationsRequest + ): + request = spanner_instance_admin.ListInstanceConfigOperationsRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.list_instance_config_operations + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListInstanceConfigOperationsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + def list_instances( self, request: Union[spanner_instance_admin.ListInstancesRequest, dict] = None, @@ -749,7 +1359,7 @@ def sample_list_instances(): Returns: google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesPager: The response for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. Iterating over this object will yield results and resolve additional pages automatically. diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py index aec3583c56..29ceb01830 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py @@ -25,6 +25,7 @@ ) from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.longrunning import operations_pb2 # type: ignore class ListInstanceConfigsPager: @@ -159,6 +160,146 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) +class ListInstanceConfigOperationsPager: + """A pager for iterating through ``list_instance_config_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListInstanceConfigOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., spanner_instance_admin.ListInstanceConfigOperationsResponse + ], + request: spanner_instance_admin.ListInstanceConfigOperationsRequest, + response: spanner_instance_admin.ListInstanceConfigOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstanceConfigOperationsRequest( + request + ) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages( + self, + ) -> Iterator[spanner_instance_admin.ListInstanceConfigOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[operations_pb2.Operation]: + for page in self.pages: + yield from page.operations + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListInstanceConfigOperationsAsyncPager: + """A pager for iterating through ``list_instance_config_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListInstanceConfigOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse] + ], + request: spanner_instance_admin.ListInstanceConfigOperationsRequest, + response: spanner_instance_admin.ListInstanceConfigOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstanceConfigOperationsRequest( + request + ) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[spanner_instance_admin.ListInstanceConfigOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[operations_pb2.Operation]: + async def async_generator(): + async for page in self.pages: + for response in page.operations: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + class ListInstancesPager: """A pager for iterating through ``list_instances`` requests. diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py index 365da90576..8c49c375d9 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py @@ -165,6 +165,26 @@ def _prep_wrapped_messages(self, client_info): default_timeout=3600.0, client_info=client_info, ), + self.create_instance_config: gapic_v1.method.wrap_method( + self.create_instance_config, + default_timeout=None, + client_info=client_info, + ), + self.update_instance_config: gapic_v1.method.wrap_method( + self.update_instance_config, + default_timeout=None, + client_info=client_info, + ), + self.delete_instance_config: gapic_v1.method.wrap_method( + self.delete_instance_config, + default_timeout=None, + client_info=client_info, + ), + self.list_instance_config_operations: gapic_v1.method.wrap_method( + self.list_instance_config_operations, + default_timeout=None, + client_info=client_info, + ), self.list_instances: gapic_v1.method.wrap_method( self.list_instances, default_retry=retries.Retry( @@ -285,6 +305,45 @@ def get_instance_config( ]: raise NotImplementedError() + @property + def create_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.CreateInstanceConfigRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def update_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.UpdateInstanceConfigRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.DeleteInstanceConfigRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + + @property + def list_instance_config_operations( + self, + ) -> Callable[ + [spanner_instance_admin.ListInstanceConfigOperationsRequest], + Union[ + spanner_instance_admin.ListInstanceConfigOperationsResponse, + Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse], + ], + ]: + raise NotImplementedError() + @property def list_instances( self, diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py index ccb9b7dd8f..5837dc6127 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py @@ -329,6 +329,230 @@ def get_instance_config( ) return self._stubs["get_instance_config"] + @property + def create_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.CreateInstanceConfigRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create instance config method over gRPC. + + Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + Returns: + Callable[[~.CreateInstanceConfigRequest], + ~.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 "create_instance_config" not in self._stubs: + self._stubs["create_instance_config"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstanceConfig", + request_serializer=spanner_instance_admin.CreateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_instance_config"] + + @property + def update_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.UpdateInstanceConfigRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update instance config method over gRPC. + + Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.UpdateInstanceConfigRequest], + ~.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 "update_instance_config" not in self._stubs: + self._stubs["update_instance_config"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstanceConfig", + request_serializer=spanner_instance_admin.UpdateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_instance_config"] + + @property + def delete_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.DeleteInstanceConfigRequest], empty_pb2.Empty + ]: + r"""Return a callable for the delete instance config method over gRPC. + + Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.DeleteInstanceConfigRequest], + ~.Empty]: + 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 "delete_instance_config" not in self._stubs: + self._stubs["delete_instance_config"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstanceConfig", + request_serializer=spanner_instance_admin.DeleteInstanceConfigRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_instance_config"] + + @property + def list_instance_config_operations( + self, + ) -> Callable[ + [spanner_instance_admin.ListInstanceConfigOperationsRequest], + spanner_instance_admin.ListInstanceConfigOperationsResponse, + ]: + r"""Return a callable for the list instance config + operations method over gRPC. + + Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + Returns: + Callable[[~.ListInstanceConfigOperationsRequest], + ~.ListInstanceConfigOperationsResponse]: + 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 "list_instance_config_operations" not in self._stubs: + self._stubs[ + "list_instance_config_operations" + ] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigOperations", + request_serializer=spanner_instance_admin.ListInstanceConfigOperationsRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstanceConfigOperationsResponse.deserialize, + ) + return self._stubs["list_instance_config_operations"] + @property def list_instances( self, diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py index b6958ac25d..c38ef38069 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py @@ -334,6 +334,232 @@ def get_instance_config( ) return self._stubs["get_instance_config"] + @property + def create_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.CreateInstanceConfigRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create instance config method over gRPC. + + Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + Returns: + Callable[[~.CreateInstanceConfigRequest], + 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 "create_instance_config" not in self._stubs: + self._stubs["create_instance_config"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstanceConfig", + request_serializer=spanner_instance_admin.CreateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_instance_config"] + + @property + def update_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.UpdateInstanceConfigRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update instance config method over gRPC. + + Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.UpdateInstanceConfigRequest], + 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 "update_instance_config" not in self._stubs: + self._stubs["update_instance_config"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstanceConfig", + request_serializer=spanner_instance_admin.UpdateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_instance_config"] + + @property + def delete_instance_config( + self, + ) -> Callable[ + [spanner_instance_admin.DeleteInstanceConfigRequest], Awaitable[empty_pb2.Empty] + ]: + r"""Return a callable for the delete instance config method over gRPC. + + Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.DeleteInstanceConfigRequest], + Awaitable[~.Empty]]: + 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 "delete_instance_config" not in self._stubs: + self._stubs["delete_instance_config"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstanceConfig", + request_serializer=spanner_instance_admin.DeleteInstanceConfigRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_instance_config"] + + @property + def list_instance_config_operations( + self, + ) -> Callable[ + [spanner_instance_admin.ListInstanceConfigOperationsRequest], + Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse], + ]: + r"""Return a callable for the list instance config + operations method over gRPC. + + Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + Returns: + Callable[[~.ListInstanceConfigOperationsRequest], + Awaitable[~.ListInstanceConfigOperationsResponse]]: + 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 "list_instance_config_operations" not in self._stubs: + self._stubs[ + "list_instance_config_operations" + ] = self.grpc_channel.unary_unary( + "/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigOperations", + request_serializer=spanner_instance_admin.ListInstanceConfigOperationsRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstanceConfigOperationsResponse.deserialize, + ) + return self._stubs["list_instance_config_operations"] + @property def list_instances( self, diff --git a/google/cloud/spanner_admin_instance_v1/types/__init__.py b/google/cloud/spanner_admin_instance_v1/types/__init__.py index e403b6f3b6..c64220e235 100644 --- a/google/cloud/spanner_admin_instance_v1/types/__init__.py +++ b/google/cloud/spanner_admin_instance_v1/types/__init__.py @@ -13,36 +13,54 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from .common import ( + OperationProgress, +) from .spanner_instance_admin import ( + CreateInstanceConfigMetadata, + CreateInstanceConfigRequest, CreateInstanceMetadata, CreateInstanceRequest, + DeleteInstanceConfigRequest, DeleteInstanceRequest, GetInstanceConfigRequest, GetInstanceRequest, Instance, InstanceConfig, + ListInstanceConfigOperationsRequest, + ListInstanceConfigOperationsResponse, ListInstanceConfigsRequest, ListInstanceConfigsResponse, ListInstancesRequest, ListInstancesResponse, ReplicaInfo, + UpdateInstanceConfigMetadata, + UpdateInstanceConfigRequest, UpdateInstanceMetadata, UpdateInstanceRequest, ) __all__ = ( + "OperationProgress", + "CreateInstanceConfigMetadata", + "CreateInstanceConfigRequest", "CreateInstanceMetadata", "CreateInstanceRequest", + "DeleteInstanceConfigRequest", "DeleteInstanceRequest", "GetInstanceConfigRequest", "GetInstanceRequest", "Instance", "InstanceConfig", + "ListInstanceConfigOperationsRequest", + "ListInstanceConfigOperationsResponse", "ListInstanceConfigsRequest", "ListInstanceConfigsResponse", "ListInstancesRequest", "ListInstancesResponse", "ReplicaInfo", + "UpdateInstanceConfigMetadata", + "UpdateInstanceConfigRequest", "UpdateInstanceMetadata", "UpdateInstanceRequest", ) diff --git a/google/cloud/spanner_admin_instance_v1/types/common.py b/google/cloud/spanner_admin_instance_v1/types/common.py new file mode 100644 index 0000000000..49c2de342b --- /dev/null +++ b/google/cloud/spanner_admin_instance_v1/types/common.py @@ -0,0 +1,60 @@ +# -*- 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. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.spanner.admin.instance.v1", + manifest={ + "OperationProgress", + }, +) + + +class OperationProgress(proto.Message): + r"""Encapsulates progress related information for a Cloud Spanner + long running instance operations. + + Attributes: + progress_percent (int): + Percent completion of the operation. + Values are between 0 and 100 inclusive. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Time the request was received. + end_time (google.protobuf.timestamp_pb2.Timestamp): + If set, the time at which this operation + failed or was completed successfully. + """ + + progress_percent = proto.Field( + proto.INT32, + number=1, + ) + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py b/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py index 6ace9819ed..cf11297f76 100644 --- a/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +++ b/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py @@ -15,6 +15,8 @@ # import proto # type: ignore +from google.cloud.spanner_admin_instance_v1.types import common +from google.longrunning import operations_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -28,6 +30,11 @@ "ListInstanceConfigsRequest", "ListInstanceConfigsResponse", "GetInstanceConfigRequest", + "CreateInstanceConfigRequest", + "UpdateInstanceConfigRequest", + "DeleteInstanceConfigRequest", + "ListInstanceConfigOperationsRequest", + "ListInstanceConfigOperationsResponse", "GetInstanceRequest", "CreateInstanceRequest", "ListInstancesRequest", @@ -36,6 +43,8 @@ "DeleteInstanceRequest", "CreateInstanceMetadata", "UpdateInstanceMetadata", + "CreateInstanceConfigMetadata", + "UpdateInstanceConfigMetadata", }, ) @@ -95,15 +104,95 @@ class InstanceConfig(proto.Message): display_name (str): The name of this instance configuration as it appears in UIs. + config_type (google.cloud.spanner_admin_instance_v1.types.InstanceConfig.Type): + Output only. Whether this instance config is + a Google or User Managed Configuration. replicas (Sequence[google.cloud.spanner_admin_instance_v1.types.ReplicaInfo]): The geographic placement of nodes in this instance configuration and their replication properties. + optional_replicas (Sequence[google.cloud.spanner_admin_instance_v1.types.ReplicaInfo]): + Output only. The available optional replicas + to choose from for user managed configurations. + Populated for Google managed configurations. + base_config (str): + Base configuration name, e.g. + projects//instanceConfigs/nam3, based on which + this configuration is created. Only set for user managed + configurations. ``base_config`` must refer to a + configuration of type GOOGLE_MANAGED in the same project as + this configuration. + labels (Mapping[str, str]): + Cloud Labels are a flexible and lightweight mechanism for + organizing cloud resources into groups that reflect a + customer's organizational needs and deployment strategies. + Cloud Labels can be used to filter collections of resources. + They can be used to control how resource metrics are + aggregated. And they can be used as arguments to policy + management rules (e.g. route, firewall, load balancing, + etc.). + + - Label keys must be between 1 and 63 characters long and + must conform to the following regular expression: + ``[a-z][a-z0-9_-]{0,62}``. + - Label values must be between 0 and 63 characters long and + must conform to the regular expression + ``[a-z0-9_-]{0,63}``. + - No more than 64 labels can be associated with a given + resource. + + See https://goo.gl/xmQnxf for more information on and + examples of labels. + + If you plan to use labels in your own code, please note that + additional characters may be allowed in the future. + Therefore, you are advised to use an internal label + representation, such as JSON, which doesn't rely upon + specific characters being disallowed. For example, + representing labels as the string: name + "*" + value would + prove problematic if we were to allow "*" in a future + release. + etag (str): + etag is used for optimistic concurrency + control as a way to help prevent simultaneous + updates of a instance config from overwriting + each other. It is strongly suggested that + systems make use of the etag in the + read-modify-write cycle to perform instance + config updates in order to avoid race + conditions: An etag is returned in the response + which contains instance configs, and systems are + expected to put that etag in the request to + update instance config to ensure that their + change will be applied to the same version of + the instance config. + If no etag is provided in the call to update + instance config, then the existing instance + config is overwritten blindly. leader_options (Sequence[str]): Allowed values of the "default_leader" schema option for databases in instances that use this instance configuration. + reconciling (bool): + Output only. If true, the instance config is + being created or updated. If false, there are no + ongoing operations for the instance config. + state (google.cloud.spanner_admin_instance_v1.types.InstanceConfig.State): + Output only. The current instance config + state. """ + class Type(proto.Enum): + r"""The type of this configuration.""" + TYPE_UNSPECIFIED = 0 + GOOGLE_MANAGED = 1 + USER_MANAGED = 2 + + class State(proto.Enum): + r"""Indicates the current state of the instance config.""" + STATE_UNSPECIFIED = 0 + CREATING = 1 + READY = 2 + name = proto.Field( proto.STRING, number=1, @@ -112,15 +201,47 @@ class InstanceConfig(proto.Message): proto.STRING, number=2, ) + config_type = proto.Field( + proto.ENUM, + number=5, + enum=Type, + ) replicas = proto.RepeatedField( proto.MESSAGE, number=3, message="ReplicaInfo", ) + optional_replicas = proto.RepeatedField( + proto.MESSAGE, + number=6, + message="ReplicaInfo", + ) + base_config = proto.Field( + proto.STRING, + number=7, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=8, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) leader_options = proto.RepeatedField( proto.STRING, number=4, ) + reconciling = proto.Field( + proto.BOOL, + number=10, + ) + state = proto.Field( + proto.ENUM, + number=11, + enum=State, + ) class Instance(proto.Message): @@ -343,6 +464,256 @@ class GetInstanceConfigRequest(proto.Message): ) +class CreateInstanceConfigRequest(proto.Message): + r"""The request for + [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. + + Attributes: + parent (str): + Required. The name of the project in which to create the + instance config. Values are of the form + ``projects/``. + instance_config_id (str): + Required. The ID of the instance config to create. Valid + identifiers are of the form ``custom-[-a-z0-9]*[a-z0-9]`` + and must be between 2 and 64 characters in length. The + ``custom-`` prefix is required to avoid name conflicts with + Google managed configurations. + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The InstanceConfig proto of the configuration to + create. instance_config.name must be + ``/instanceConfigs/``. + instance_config.base_config must be a Google managed + configuration name, e.g. /instanceConfigs/us-east1, + /instanceConfigs/nam3. + validate_only (bool): + An option to validate, but not actually + execute, a request, and provide the same + response. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + instance_config_id = proto.Field( + proto.STRING, + number=2, + ) + instance_config = proto.Field( + proto.MESSAGE, + number=3, + message="InstanceConfig", + ) + validate_only = proto.Field( + proto.BOOL, + number=4, + ) + + +class UpdateInstanceConfigRequest(proto.Message): + r"""The request for + [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. + + Attributes: + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The user instance config to update, which must + always include the instance config name. Otherwise, only + fields mentioned in + [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] + need be included. To prevent conflicts of concurrent + updates, + [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + can be used. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + should be updated. The field mask must always be specified; + this prevents any future fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + from being erased accidentally by clients that do not know + about them. Only display_name and labels can be updated. + validate_only (bool): + An option to validate, but not actually + execute, a request, and provide the same + response. + """ + + instance_config = proto.Field( + proto.MESSAGE, + number=1, + message="InstanceConfig", + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + validate_only = proto.Field( + proto.BOOL, + number=3, + ) + + +class DeleteInstanceConfigRequest(proto.Message): + r"""The request for + [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. + + Attributes: + name (str): + Required. The name of the instance configuration to be + deleted. Values are of the form + ``projects//instanceConfigs/`` + etag (str): + Used for optimistic concurrency control as a + way to help prevent simultaneous deletes of an + instance config from overwriting each other. If + not empty, the API + only deletes the instance config when the etag + provided matches the current status of the + requested instance config. Otherwise, deletes + the instance config without checking the current + status of the requested instance config. + validate_only (bool): + An option to validate, but not actually + execute, a request, and provide the same + response. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + etag = proto.Field( + proto.STRING, + number=2, + ) + validate_only = proto.Field( + proto.BOOL, + number=3, + ) + + +class ListInstanceConfigOperationsRequest(proto.Message): + r"""The request for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Attributes: + parent (str): + Required. The project of the instance config operations. + Values are of the form ``projects/``. + filter (str): + An expression that filters the list of returned operations. + + A filter expression consists of a field name, a comparison + operator, and a value for filtering. The value must be a + string, a number, or a boolean. The comparison operator must + be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or + ``:``. Colon ``:`` is the contains operator. Filter rules + are not case sensitive. + + The following fields in the + [Operation][google.longrunning.Operation] are eligible for + filtering: + + - ``name`` - The name of the long-running operation + - ``done`` - False if the operation is in progress, else + true. + - ``metadata.@type`` - the type of metadata. For example, + the type string for + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata] + is + ``type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata``. + - ``metadata.`` - any field in metadata.value. + ``metadata.@type`` must be specified first, if filtering + on metadata fields. + - ``error`` - Error associated with the long-running + operation. + - ``response.@type`` - the type of response. + - ``response.`` - any field in response.value. + + You can combine multiple expressions by enclosing each + expression in parentheses. By default, expressions are + combined with AND logic. However, you can specify AND, OR, + and NOT logic explicitly. + + Here are a few examples: + + - ``done:true`` - The operation is complete. + - ``(metadata.@type=`` + ``type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata) AND`` + ``(metadata.instance_config.name:custom-config) AND`` + ``(metadata.progress.start_time < \"2021-03-28T14:50:00Z\") AND`` + ``(error:*)`` - Return operations where: + + - The operation's metadata type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + - The instance config name contains "custom-config". + - The operation started before 2021-03-28T14:50:00Z. + - The operation resulted in an error. + page_size (int): + Number of operations to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.instance.v1.ListInstanceConfigOperationsResponse.next_page_token] + from a previous + [ListInstanceConfigOperationsResponse][google.spanner.admin.instance.v1.ListInstanceConfigOperationsResponse] + to the same ``parent`` and with the same ``filter``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + + +class ListInstanceConfigOperationsResponse(proto.Message): + r"""The response for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Attributes: + operations (Sequence[google.longrunning.operations_pb2.Operation]): + The list of matching instance config [long-running + operations][google.longrunning.Operation]. Each operation's + name will be prefixed by the instance config's name. The + operation's + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations] + call to fetch more of the matching metadata. + """ + + @property + def raw_page(self): + return self + + operations = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=operations_pb2.Operation, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + class GetInstanceRequest(proto.Message): r"""The request for [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. @@ -625,4 +996,70 @@ class UpdateInstanceMetadata(proto.Message): ) +class CreateInstanceConfigMetadata(proto.Message): + r"""Metadata type for the operation returned by + [CreateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig]. + + Attributes: + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + The target instance config end state. + progress (google.cloud.spanner_admin_instance_v1.types.OperationProgress): + The progress of the + [CreateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. + """ + + instance_config = proto.Field( + proto.MESSAGE, + number=1, + message="InstanceConfig", + ) + progress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) + cancel_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +class UpdateInstanceConfigMetadata(proto.Message): + r"""Metadata type for the operation returned by + [UpdateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig]. + + Attributes: + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + The desired instance config after updating. + progress (google.cloud.spanner_admin_instance_v1.types.OperationProgress): + The progress of the + [UpdateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. + """ + + instance_config = proto.Field( + proto.MESSAGE, + number=1, + message="InstanceConfig", + ) + progress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) + cancel_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/samples/generated_samples/snippet_metadata_spanner admin instance_v1.json b/samples/generated_samples/snippet_metadata_spanner admin instance_v1.json index 32abe2cce0..51f67db6dc 100644 --- a/samples/generated_samples/snippet_metadata_spanner admin instance_v1.json +++ b/samples/generated_samples/snippet_metadata_spanner admin instance_v1.json @@ -10,6 +10,183 @@ "name": "google-cloud-spanner-admin-instance" }, "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.create_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "instance_config_id", + "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": "create_instance_config" + }, + "description": "Sample for CreateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_create_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.create_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "instance_config_id", + "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": "create_instance_config" + }, + "description": "Sample for CreateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_create_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_config_sync.py" + }, { "canonical": true, "clientMethod": { @@ -187,6 +364,161 @@ ], "title": "spanner_v1_generated_instance_admin_create_instance_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.delete_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance_config" + }, + "description": "Sample for DeleteInstanceConfig", + "file": "spanner_v1_generated_instance_admin_delete_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.delete_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance_config" + }, + "description": "Sample for DeleteInstanceConfig", + "file": "spanner_v1_generated_instance_admin_delete_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_config_sync.py" + }, { "canonical": true, "clientMethod": { @@ -430,22 +762,183 @@ "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", "shortName": "InstanceAdminClient" }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_iam_policy", + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" + }, + { + "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.cloud.spanner_admin_instance_v1.types.InstanceConfig", + "shortName": "get_instance_config" + }, + "description": "Sample for GetInstanceConfig", + "file": "spanner_v1_generated_instance_admin_get_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance_config", "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", "service": { "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", "shortName": "InstanceAdmin" }, - "shortName": "GetIamPolicy" + "shortName": "GetInstanceConfig" }, "parameters": [ { "name": "request", - "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" }, { - "name": "resource", + "name": "name", "type": "str" }, { @@ -461,47 +954,47 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "get_iam_policy" + "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", + "shortName": "get_instance_config" }, - "description": "Sample for GetIamPolicy", - "file": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py", + "description": "Sample for GetInstanceConfig", + "file": "spanner_v1_generated_instance_admin_get_instance_config_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync", "segments": [ { - "end": 52, + "end": 51, "start": 27, "type": "FULL" }, { - "end": 52, + "end": 51, "start": 27, "type": "SHORT" }, { - "end": 41, - "start": 39, + "end": 40, + "start": 38, "type": "CLIENT_INITIALIZATION" }, { - "end": 46, - "start": 42, + "end": 45, + "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 49, - "start": 47, + "end": 48, + "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 53, - "start": 50, + "end": 52, + "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py" + "title": "spanner_v1_generated_instance_admin_get_instance_config_sync.py" }, { "canonical": true, @@ -511,19 +1004,19 @@ "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", "shortName": "InstanceAdminAsyncClient" }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance_config", + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance", "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", "service": { "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", "shortName": "InstanceAdmin" }, - "shortName": "GetInstanceConfig" + "shortName": "GetInstance" }, "parameters": [ { "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" }, { "name": "name", @@ -542,14 +1035,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", - "shortName": "get_instance_config" + "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", + "shortName": "get_instance" }, - "description": "Sample for GetInstanceConfig", - "file": "spanner_v1_generated_instance_admin_get_instance_config_async.py", + "description": "Sample for GetInstance", + "file": "spanner_v1_generated_instance_admin_get_instance_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_async", "segments": [ { "end": 51, @@ -582,7 +1075,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "spanner_v1_generated_instance_admin_get_instance_config_async.py" + "title": "spanner_v1_generated_instance_admin_get_instance_async.py" }, { "canonical": true, @@ -591,19 +1084,19 @@ "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", "shortName": "InstanceAdminClient" }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance_config", + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance", "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", "service": { "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", "shortName": "InstanceAdmin" }, - "shortName": "GetInstanceConfig" + "shortName": "GetInstance" }, "parameters": [ { "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" }, { "name": "name", @@ -622,14 +1115,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", - "shortName": "get_instance_config" + "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", + "shortName": "get_instance" }, - "description": "Sample for GetInstanceConfig", - "file": "spanner_v1_generated_instance_admin_get_instance_config_sync.py", + "description": "Sample for GetInstance", + "file": "spanner_v1_generated_instance_admin_get_instance_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_sync", "segments": [ { "end": 51, @@ -662,7 +1155,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "spanner_v1_generated_instance_admin_get_instance_config_sync.py" + "title": "spanner_v1_generated_instance_admin_get_instance_sync.py" }, { "canonical": true, @@ -672,22 +1165,22 @@ "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", "shortName": "InstanceAdminAsyncClient" }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance", + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instance_config_operations", "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations", "service": { "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", "shortName": "InstanceAdmin" }, - "shortName": "GetInstance" + "shortName": "ListInstanceConfigOperations" }, "parameters": [ { "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest" }, { - "name": "name", + "name": "parent", "type": "str" }, { @@ -703,22 +1196,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", - "shortName": "get_instance" + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsAsyncPager", + "shortName": "list_instance_config_operations" }, - "description": "Sample for GetInstance", - "file": "spanner_v1_generated_instance_admin_get_instance_async.py", + "description": "Sample for ListInstanceConfigOperations", + "file": "spanner_v1_generated_instance_admin_list_instance_config_operations_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_async", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, @@ -738,12 +1231,12 @@ "type": "REQUEST_EXECUTION" }, { - "end": 52, + "end": 53, "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "spanner_v1_generated_instance_admin_get_instance_async.py" + "title": "spanner_v1_generated_instance_admin_list_instance_config_operations_async.py" }, { "canonical": true, @@ -752,22 +1245,22 @@ "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", "shortName": "InstanceAdminClient" }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance", + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instance_config_operations", "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations", "service": { "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", "shortName": "InstanceAdmin" }, - "shortName": "GetInstance" + "shortName": "ListInstanceConfigOperations" }, "parameters": [ { "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest" }, { - "name": "name", + "name": "parent", "type": "str" }, { @@ -783,22 +1276,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", - "shortName": "get_instance" + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsPager", + "shortName": "list_instance_config_operations" }, - "description": "Sample for GetInstance", - "file": "spanner_v1_generated_instance_admin_get_instance_sync.py", + "description": "Sample for ListInstanceConfigOperations", + "file": "spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_sync", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, @@ -818,12 +1311,12 @@ "type": "REQUEST_EXECUTION" }, { - "end": 52, + "end": 53, "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "spanner_v1_generated_instance_admin_get_instance_sync.py" + "title": "spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py" }, { "canonical": true, @@ -1477,6 +1970,175 @@ ], "title": "spanner_v1_generated_instance_admin_test_iam_permissions_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.update_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "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": "update_instance_config" + }, + "description": "Sample for UpdateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_update_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.update_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "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": "update_instance_config" + }, + "description": "Sample for UpdateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_update_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_config_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py new file mode 100644 index 0000000000..432ea6a1af --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py @@ -0,0 +1,57 @@ +# -*- 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 CreateInstanceConfig +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_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 spanner_admin_instance_v1 + + +async def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py new file mode 100644 index 0000000000..fcd79a04ff --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py @@ -0,0 +1,57 @@ +# -*- 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 CreateInstanceConfig +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_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 spanner_admin_instance_v1 + + +def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py new file mode 100644 index 0000000000..0234dd31be --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py @@ -0,0 +1,50 @@ +# -*- 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 DeleteInstanceConfig +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_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 spanner_admin_instance_v1 + + +async def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + await client.delete_instance_config(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py new file mode 100644 index 0000000000..7e7ef31843 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py @@ -0,0 +1,50 @@ +# -*- 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 DeleteInstanceConfig +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_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 spanner_admin_instance_v1 + + +def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + client.delete_instance_config(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py new file mode 100644 index 0000000000..ba5baa65d4 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py @@ -0,0 +1,53 @@ +# -*- 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 ListInstanceConfigOperations +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_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 spanner_admin_instance_v1 + + +async def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py new file mode 100644 index 0000000000..b7e113488b --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py @@ -0,0 +1,53 @@ +# -*- 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 ListInstanceConfigOperations +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_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 spanner_admin_instance_v1 + + +def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py new file mode 100644 index 0000000000..6c4ffdadad --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py @@ -0,0 +1,55 @@ +# -*- 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 UpdateInstanceConfig +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_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 spanner_admin_instance_v1 + + +async def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py new file mode 100644 index 0000000000..bdcb9a8dbd --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py @@ -0,0 +1,55 @@ +# -*- 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 UpdateInstanceConfig +# 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-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_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 spanner_admin_instance_v1 + + +def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync] diff --git a/scripts/fixup_spanner_admin_instance_v1_keywords.py b/scripts/fixup_spanner_admin_instance_v1_keywords.py index 7b8b1c9895..c5d08e6b51 100644 --- a/scripts/fixup_spanner_admin_instance_v1_keywords.py +++ b/scripts/fixup_spanner_admin_instance_v1_keywords.py @@ -40,15 +40,19 @@ class spanner_admin_instanceCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { 'create_instance': ('parent', 'instance_id', 'instance', ), + 'create_instance_config': ('parent', 'instance_config_id', 'instance_config', 'validate_only', ), 'delete_instance': ('name', ), + 'delete_instance_config': ('name', 'etag', 'validate_only', ), 'get_iam_policy': ('resource', 'options', ), 'get_instance': ('name', 'field_mask', ), 'get_instance_config': ('name', ), + 'list_instance_config_operations': ('parent', 'filter', 'page_size', 'page_token', ), 'list_instance_configs': ('parent', 'page_size', 'page_token', ), 'list_instances': ('parent', 'page_size', 'page_token', 'filter', ), 'set_iam_policy': ('resource', 'policy', 'update_mask', ), 'test_iam_permissions': ('resource', 'permissions', ), 'update_instance': ('instance', 'field_mask', ), + 'update_instance_config': ('instance_config', 'update_mask', 'validate_only', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: diff --git a/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py b/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py index b49de8360c..116ec94771 100644 --- a/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py +++ b/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py @@ -27,7 +27,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions diff --git a/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py b/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py index 0d0134bac6..8cc99c7ac8 100644 --- a/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py +++ b/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py @@ -27,7 +27,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions @@ -54,6 +54,7 @@ from google.iam.v1 import options_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -1170,7 +1171,12 @@ def test_get_instance_config(request_type, transport: str = "grpc"): call.return_value = spanner_instance_admin.InstanceConfig( name="name_value", display_name="display_name_value", + config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, + base_config="base_config_value", + etag="etag_value", leader_options=["leader_options_value"], + reconciling=True, + state=spanner_instance_admin.InstanceConfig.State.CREATING, ) response = client.get_instance_config(request) @@ -1183,7 +1189,15 @@ def test_get_instance_config(request_type, transport: str = "grpc"): assert isinstance(response, spanner_instance_admin.InstanceConfig) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert ( + response.config_type + == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED + ) + assert response.base_config == "base_config_value" + assert response.etag == "etag_value" assert response.leader_options == ["leader_options_value"] + assert response.reconciling is True + assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING def test_get_instance_config_empty_call(): @@ -1227,7 +1241,12 @@ async def test_get_instance_config_async( spanner_instance_admin.InstanceConfig( name="name_value", display_name="display_name_value", + config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, + base_config="base_config_value", + etag="etag_value", leader_options=["leader_options_value"], + reconciling=True, + state=spanner_instance_admin.InstanceConfig.State.CREATING, ) ) response = await client.get_instance_config(request) @@ -1241,7 +1260,15 @@ async def test_get_instance_config_async( assert isinstance(response, spanner_instance_admin.InstanceConfig) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert ( + response.config_type + == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED + ) + assert response.base_config == "base_config_value" + assert response.etag == "etag_value" assert response.leader_options == ["leader_options_value"] + assert response.reconciling is True + assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING @pytest.mark.asyncio @@ -1400,6 +1427,1202 @@ async def test_get_instance_config_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + spanner_instance_admin.CreateInstanceConfigRequest, + dict, + ], +) +def test_create_instance_config(request_type, transport: str = "grpc"): + client = InstanceAdminClient( + 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.create_instance_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_instance_config_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 = InstanceAdminClient( + 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.create_instance_config), "__call__" + ) as call: + client.create_instance_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() + + +@pytest.mark.asyncio +async def test_create_instance_config_async( + transport: str = "grpc_asyncio", + request_type=spanner_instance_admin.CreateInstanceConfigRequest, +): + client = InstanceAdminAsyncClient( + 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.create_instance_config), "__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.create_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_instance_config_async_from_dict(): + await test_create_instance_config_async(request_type=dict) + + +def test_create_instance_config_field_headers(): + client = InstanceAdminClient( + 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 = spanner_instance_admin.CreateInstanceConfigRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_instance_config(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", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_instance_config_field_headers_async(): + client = InstanceAdminAsyncClient( + 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 = spanner_instance_admin.CreateInstanceConfigRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_instance_config(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", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_instance_config_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), "__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.create_instance_config( + parent="parent_value", + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + instance_config_id="instance_config_id_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].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name="name_value") + assert arg == mock_val + arg = args[0].instance_config_id + mock_val = "instance_config_id_value" + assert arg == mock_val + + +def test_create_instance_config_flattened_error(): + client = InstanceAdminClient( + 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.create_instance_config( + spanner_instance_admin.CreateInstanceConfigRequest(), + parent="parent_value", + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + instance_config_id="instance_config_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_instance_config_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), "__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.create_instance_config( + parent="parent_value", + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + instance_config_id="instance_config_id_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].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name="name_value") + assert arg == mock_val + arg = args[0].instance_config_id + mock_val = "instance_config_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_instance_config_flattened_error_async(): + client = InstanceAdminAsyncClient( + 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.create_instance_config( + spanner_instance_admin.CreateInstanceConfigRequest(), + parent="parent_value", + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + instance_config_id="instance_config_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + spanner_instance_admin.UpdateInstanceConfigRequest, + dict, + ], +) +def test_update_instance_config(request_type, transport: str = "grpc"): + client = InstanceAdminClient( + 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.update_instance_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_instance_config_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 = InstanceAdminClient( + 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.update_instance_config), "__call__" + ) as call: + client.update_instance_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() + + +@pytest.mark.asyncio +async def test_update_instance_config_async( + transport: str = "grpc_asyncio", + request_type=spanner_instance_admin.UpdateInstanceConfigRequest, +): + client = InstanceAdminAsyncClient( + 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.update_instance_config), "__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.update_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_instance_config_async_from_dict(): + await test_update_instance_config_async(request_type=dict) + + +def test_update_instance_config_field_headers(): + client = InstanceAdminClient( + 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 = spanner_instance_admin.UpdateInstanceConfigRequest() + + request.instance_config.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_instance_config(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", + "instance_config.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_instance_config_field_headers_async(): + client = InstanceAdminAsyncClient( + 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 = spanner_instance_admin.UpdateInstanceConfigRequest() + + request.instance_config.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_instance_config(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", + "instance_config.name=name_value", + ) in kw["metadata"] + + +def test_update_instance_config_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), "__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.update_instance_config( + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_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].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_instance_config_flattened_error(): + client = InstanceAdminClient( + 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.update_instance_config( + spanner_instance_admin.UpdateInstanceConfigRequest(), + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_instance_config_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), "__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.update_instance_config( + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_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].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_instance_config_flattened_error_async(): + client = InstanceAdminAsyncClient( + 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.update_instance_config( + spanner_instance_admin.UpdateInstanceConfigRequest(), + instance_config=spanner_instance_admin.InstanceConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + spanner_instance_admin.DeleteInstanceConfigRequest, + dict, + ], +) +def test_delete_instance_config(request_type, transport: str = "grpc"): + client = InstanceAdminClient( + 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.delete_instance_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_instance_config_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 = InstanceAdminClient( + 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.delete_instance_config), "__call__" + ) as call: + client.delete_instance_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() + + +@pytest.mark.asyncio +async def test_delete_instance_config_async( + transport: str = "grpc_asyncio", + request_type=spanner_instance_admin.DeleteInstanceConfigRequest, +): + client = InstanceAdminAsyncClient( + 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.delete_instance_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_instance_config_async_from_dict(): + await test_delete_instance_config_async(request_type=dict) + + +def test_delete_instance_config_field_headers(): + client = InstanceAdminClient( + 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 = spanner_instance_admin.DeleteInstanceConfigRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), "__call__" + ) as call: + call.return_value = None + client.delete_instance_config(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_delete_instance_config_field_headers_async(): + client = InstanceAdminAsyncClient( + 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 = spanner_instance_admin.DeleteInstanceConfigRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_instance_config(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_delete_instance_config_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_instance_config( + 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_delete_instance_config_flattened_error(): + client = InstanceAdminClient( + 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.delete_instance_config( + spanner_instance_admin.DeleteInstanceConfigRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_instance_config_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_instance_config( + 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_delete_instance_config_flattened_error_async(): + client = InstanceAdminAsyncClient( + 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.delete_instance_config( + spanner_instance_admin.DeleteInstanceConfigRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + spanner_instance_admin.ListInstanceConfigOperationsRequest, + dict, + ], +) +def test_list_instance_config_operations(request_type, transport: str = "grpc"): + client = InstanceAdminClient( + 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.list_instance_config_operations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_instance_config_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigOperationsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_instance_config_operations_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 = InstanceAdminClient( + 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.list_instance_config_operations), "__call__" + ) as call: + client.list_instance_config_operations() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async( + transport: str = "grpc_asyncio", + request_type=spanner_instance_admin.ListInstanceConfigOperationsRequest, +): + client = InstanceAdminAsyncClient( + 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.list_instance_config_operations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_instance_config_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigOperationsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async_from_dict(): + await test_list_instance_config_operations_async(request_type=dict) + + +def test_list_instance_config_operations_field_headers(): + client = InstanceAdminClient( + 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 = spanner_instance_admin.ListInstanceConfigOperationsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), "__call__" + ) as call: + call.return_value = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse() + ) + client.list_instance_config_operations(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", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_field_headers_async(): + client = InstanceAdminAsyncClient( + 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 = spanner_instance_admin.ListInstanceConfigOperationsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + spanner_instance_admin.ListInstanceConfigOperationsResponse() + ) + await client.list_instance_config_operations(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", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_instance_config_operations_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_instance_config_operations( + parent="parent_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].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_instance_config_operations_flattened_error(): + client = InstanceAdminClient( + 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.list_instance_config_operations( + spanner_instance_admin.ListInstanceConfigOperationsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + spanner_instance_admin.ListInstanceConfigOperationsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_instance_config_operations( + parent="parent_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].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_flattened_error_async(): + client = InstanceAdminAsyncClient( + 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.list_instance_config_operations( + spanner_instance_admin.ListInstanceConfigOperationsRequest(), + parent="parent_value", + ) + + +def test_list_instance_config_operations_pager(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token="abc", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token="def", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_instance_config_operations(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, operations_pb2.Operation) for i in results) + + +def test_list_instance_config_operations_pages(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token="abc", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token="def", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = list(client.list_instance_config_operations(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async_pager(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token="abc", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token="def", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_instance_config_operations( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, operations_pb2.Operation) for i in responses) + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async_pages(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token="abc", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token="def", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_instance_config_operations(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + @pytest.mark.parametrize( "request_type", [ @@ -3697,6 +4920,10 @@ def test_instance_admin_base_transport(): methods = ( "list_instance_configs", "get_instance_config", + "create_instance_config", + "update_instance_config", + "delete_instance_config", + "list_instance_config_operations", "list_instances", "get_instance", "create_instance", diff --git a/tests/unit/gapic/spanner_v1/test_spanner.py b/tests/unit/gapic/spanner_v1/test_spanner.py index 49cb9aebb0..d17741419e 100644 --- a/tests/unit/gapic/spanner_v1/test_spanner.py +++ b/tests/unit/gapic/spanner_v1/test_spanner.py @@ -27,7 +27,7 @@ import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule - +from proto.marshal.rules import wrappers from google.api_core import client_options from google.api_core import exceptions as core_exceptions