diff --git a/packages/google-cloud-filestore/google/cloud/filestore/__init__.py b/packages/google-cloud-filestore/google/cloud/filestore/__init__.py index 915e5e7561dc..aaceaa395593 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore/__init__.py +++ b/packages/google-cloud-filestore/google/cloud/filestore/__init__.py @@ -28,21 +28,28 @@ Backup, CreateBackupRequest, CreateInstanceRequest, + CreateSnapshotRequest, DeleteBackupRequest, DeleteInstanceRequest, + DeleteSnapshotRequest, FileShareConfig, GetBackupRequest, GetInstanceRequest, + GetSnapshotRequest, Instance, ListBackupsRequest, ListBackupsResponse, ListInstancesRequest, ListInstancesResponse, + ListSnapshotsRequest, + ListSnapshotsResponse, NetworkConfig, NfsExportOptions, RestoreInstanceRequest, + Snapshot, UpdateBackupRequest, UpdateInstanceRequest, + UpdateSnapshotRequest, ) __all__ = ( @@ -51,19 +58,26 @@ "Backup", "CreateBackupRequest", "CreateInstanceRequest", + "CreateSnapshotRequest", "DeleteBackupRequest", "DeleteInstanceRequest", + "DeleteSnapshotRequest", "FileShareConfig", "GetBackupRequest", "GetInstanceRequest", + "GetSnapshotRequest", "Instance", "ListBackupsRequest", "ListBackupsResponse", "ListInstancesRequest", "ListInstancesResponse", + "ListSnapshotsRequest", + "ListSnapshotsResponse", "NetworkConfig", "NfsExportOptions", "RestoreInstanceRequest", + "Snapshot", "UpdateBackupRequest", "UpdateInstanceRequest", + "UpdateSnapshotRequest", ) diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/__init__.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/__init__.py index 39ff5b8f040c..080b941ea9da 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/__init__.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/__init__.py @@ -26,21 +26,28 @@ Backup, CreateBackupRequest, CreateInstanceRequest, + CreateSnapshotRequest, DeleteBackupRequest, DeleteInstanceRequest, + DeleteSnapshotRequest, FileShareConfig, GetBackupRequest, GetInstanceRequest, + GetSnapshotRequest, Instance, ListBackupsRequest, ListBackupsResponse, ListInstancesRequest, ListInstancesResponse, + ListSnapshotsRequest, + ListSnapshotsResponse, NetworkConfig, NfsExportOptions, RestoreInstanceRequest, + Snapshot, UpdateBackupRequest, UpdateInstanceRequest, + UpdateSnapshotRequest, ) __all__ = ( @@ -49,19 +56,26 @@ "CloudFilestoreManagerClient", "CreateBackupRequest", "CreateInstanceRequest", + "CreateSnapshotRequest", "DeleteBackupRequest", "DeleteInstanceRequest", + "DeleteSnapshotRequest", "FileShareConfig", "GetBackupRequest", "GetInstanceRequest", + "GetSnapshotRequest", "Instance", "ListBackupsRequest", "ListBackupsResponse", "ListInstancesRequest", "ListInstancesResponse", + "ListSnapshotsRequest", + "ListSnapshotsResponse", "NetworkConfig", "NfsExportOptions", "RestoreInstanceRequest", + "Snapshot", "UpdateBackupRequest", "UpdateInstanceRequest", + "UpdateSnapshotRequest", ) diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_metadata.json b/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_metadata.json index ba2fb6291224..7f8973930ac9 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_metadata.json +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_metadata.json @@ -20,6 +20,11 @@ "create_instance" ] }, + "CreateSnapshot": { + "methods": [ + "create_snapshot" + ] + }, "DeleteBackup": { "methods": [ "delete_backup" @@ -30,6 +35,11 @@ "delete_instance" ] }, + "DeleteSnapshot": { + "methods": [ + "delete_snapshot" + ] + }, "GetBackup": { "methods": [ "get_backup" @@ -40,6 +50,11 @@ "get_instance" ] }, + "GetSnapshot": { + "methods": [ + "get_snapshot" + ] + }, "ListBackups": { "methods": [ "list_backups" @@ -50,6 +65,11 @@ "list_instances" ] }, + "ListSnapshots": { + "methods": [ + "list_snapshots" + ] + }, "RestoreInstance": { "methods": [ "restore_instance" @@ -64,6 +84,11 @@ "methods": [ "update_instance" ] + }, + "UpdateSnapshot": { + "methods": [ + "update_snapshot" + ] } } }, @@ -80,6 +105,11 @@ "create_instance" ] }, + "CreateSnapshot": { + "methods": [ + "create_snapshot" + ] + }, "DeleteBackup": { "methods": [ "delete_backup" @@ -90,6 +120,11 @@ "delete_instance" ] }, + "DeleteSnapshot": { + "methods": [ + "delete_snapshot" + ] + }, "GetBackup": { "methods": [ "get_backup" @@ -100,6 +135,11 @@ "get_instance" ] }, + "GetSnapshot": { + "methods": [ + "get_snapshot" + ] + }, "ListBackups": { "methods": [ "list_backups" @@ -110,6 +150,11 @@ "list_instances" ] }, + "ListSnapshots": { + "methods": [ + "list_snapshots" + ] + }, "RestoreInstance": { "methods": [ "restore_instance" @@ -124,6 +169,11 @@ "methods": [ "update_instance" ] + }, + "UpdateSnapshot": { + "methods": [ + "update_snapshot" + ] } } }, @@ -140,6 +190,11 @@ "create_instance" ] }, + "CreateSnapshot": { + "methods": [ + "create_snapshot" + ] + }, "DeleteBackup": { "methods": [ "delete_backup" @@ -150,6 +205,11 @@ "delete_instance" ] }, + "DeleteSnapshot": { + "methods": [ + "delete_snapshot" + ] + }, "GetBackup": { "methods": [ "get_backup" @@ -160,6 +220,11 @@ "get_instance" ] }, + "GetSnapshot": { + "methods": [ + "get_snapshot" + ] + }, "ListBackups": { "methods": [ "list_backups" @@ -170,6 +235,11 @@ "list_instances" ] }, + "ListSnapshots": { + "methods": [ + "list_snapshots" + ] + }, "RestoreInstance": { "methods": [ "restore_instance" @@ -184,6 +254,11 @@ "methods": [ "update_instance" ] + }, + "UpdateSnapshot": { + "methods": [ + "update_snapshot" + ] } } } diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py index af39ce9676cd..8a7914b44803 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py @@ -61,12 +61,12 @@ class CloudFilestoreManagerAsyncClient: - """Configures and manages Cloud Filestore resources. + """Configures and manages Filestore resources. - Cloud Filestore Manager v1. + Filestore Manager v1. - The ``file.googleapis.com`` service implements the Cloud Filestore - API and defines the following resource model for managing instances: + The ``file.googleapis.com`` service implements the Filestore API and + defines the following resource model for managing instances: - The service works with a collection of cloud projects, named: ``/projects/*`` @@ -74,13 +74,13 @@ class CloudFilestoreManagerAsyncClient: ``/locations/*`` - Each location has a collection of instances and backups, named: ``/instances/*`` and ``/backups/*`` respectively. - - As such, Cloud Filestore instances are resources of the form: + - As such, Filestore instances are resources of the form: ``/projects/{project_number}/locations/{location_id}/instances/{instance_id}`` and backups are resources of the form: ``/projects/{project_number}/locations/{location_id}/backup/{backup_id}`` - Note that location_id must be a GCP ``zone`` for instances and but - to a GCP ``region`` for backups; for example: + Note that location_id must be a Google Cloud ``zone`` for instances, + but a Google Cloud ``region`` for backups; for example: - ``projects/12345/locations/us-central1-c/instances/my-filestore`` - ``projects/12345/locations/us-central1/backups/my-backup`` @@ -95,6 +95,8 @@ class CloudFilestoreManagerAsyncClient: parse_backup_path = staticmethod(CloudFilestoreManagerClient.parse_backup_path) instance_path = staticmethod(CloudFilestoreManagerClient.instance_path) parse_instance_path = staticmethod(CloudFilestoreManagerClient.parse_instance_path) + snapshot_path = staticmethod(CloudFilestoreManagerClient.snapshot_path) + parse_snapshot_path = staticmethod(CloudFilestoreManagerClient.parse_snapshot_path) common_billing_account_path = staticmethod( CloudFilestoreManagerClient.common_billing_account_path ) @@ -301,9 +303,9 @@ async def sample_list_instances(): Required. The project and location for which to retrieve instance information, in the format ``projects/{project_id}/locations/{location}``. In Cloud - Filestore, locations map to GCP zones, for example - **us-west1-b**. To retrieve instance information for all - locations, use "-" for the ``{location}`` value. + Filestore, locations map to Google Cloud zones, for + example **us-west1-b**. To retrieve instance information + for all locations, use "-" for the ``{location}`` value. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -441,7 +443,7 @@ async def sample_get_instance(): Returns: google.cloud.filestore_v1.types.Instance: - A Cloud Filestore instance. + A Filestore instance. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have @@ -551,7 +553,7 @@ async def sample_create_instance(): parent (:class:`str`): Required. The instance's project and location, in the format ``projects/{project_id}/locations/{location}``. - In Cloud Filestore, locations map to GCP zones, for + In Filestore, locations map to Google Cloud zones, for example **us-west1-b**. This corresponds to the ``parent`` field @@ -584,7 +586,7 @@ async def sample_create_instance(): The result type for the operation will be :class:`google.cloud.filestore_v1.types.Instance` A - Cloud Filestore instance. + Filestore instance. """ # Create or coerce a protobuf request object. @@ -717,7 +719,7 @@ async def sample_update_instance(): The result type for the operation will be :class:`google.cloud.filestore_v1.types.Instance` A - Cloud Filestore instance. + Filestore instance. """ # Create or coerce a protobuf request object. @@ -825,7 +827,7 @@ async def sample_restore_instance(): Args: request (Optional[Union[google.cloud.filestore_v1.types.RestoreInstanceRequest, dict]]): The request object. RestoreInstanceRequest restores an - existing instances's file share from a backup. + existing instance's file share from a backup. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -838,7 +840,7 @@ async def sample_restore_instance(): The result type for the operation will be :class:`google.cloud.filestore_v1.types.Instance` A - Cloud Filestore instance. + Filestore instance. """ # Create or coerce a protobuf request object. @@ -1003,6 +1005,626 @@ async def sample_delete_instance(): # Done; return the response. return response + async def list_snapshots( + self, + request: Optional[ + Union[cloud_filestore_service.ListSnapshotsRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListSnapshotsAsyncPager: + r"""Lists all snapshots in a project for either a + specified location or for all locations. + + .. 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 filestore_v1 + + async def sample_list_snapshots(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.ListSnapshotsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_snapshots(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.filestore_v1.types.ListSnapshotsRequest, dict]]): + The request object. ListSnapshotsRequest lists + snapshots. + parent (:class:`str`): + Required. The instance for which to retrieve snapshot + information, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}``. + + 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.filestore_v1.services.cloud_filestore_manager.pagers.ListSnapshotsAsyncPager: + ListSnapshotsResponse is the result + of ListSnapshotsRequest. + 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 = cloud_filestore_service.ListSnapshotsRequest(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_snapshots, + 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.ListSnapshotsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.GetSnapshotRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_filestore_service.Snapshot: + r"""Gets the details of a specific snapshot. + + .. 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 filestore_v1 + + async def sample_get_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.GetSnapshotRequest( + name="name_value", + ) + + # Make the request + response = await client.get_snapshot(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.filestore_v1.types.GetSnapshotRequest, dict]]): + The request object. GetSnapshotRequest gets the state of + a snapshot. + name (:class:`str`): + Required. The snapshot resource name, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}/snapshots/{snapshot_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.filestore_v1.types.Snapshot: + A Filestore snapshot. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = cloud_filestore_service.GetSnapshotRequest(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.get_snapshot, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.CreateSnapshotRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + snapshot: Optional[cloud_filestore_service.Snapshot] = None, + snapshot_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a snapshot. + + .. 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 filestore_v1 + + async def sample_create_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.CreateSnapshotRequest( + parent="parent_value", + snapshot_id="snapshot_id_value", + ) + + # Make the request + operation = client.create_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.filestore_v1.types.CreateSnapshotRequest, dict]]): + The request object. CreateSnapshotRequest creates a + snapshot. + parent (:class:`str`): + Required. The Filestore Instance to create the snapshots + of, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + snapshot (:class:`google.cloud.filestore_v1.types.Snapshot`): + Required. A snapshot resource. + This corresponds to the ``snapshot`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + snapshot_id (:class:`str`): + Required. The ID to use for the + snapshot. The ID must be unique within + the specified instance. + This value must start with a lowercase + letter followed by up to 62 lowercase + letters, numbers, or hyphens, and cannot + end with a hyphen. + + This corresponds to the ``snapshot_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.filestore_v1.types.Snapshot` A + Filestore snapshot. + + """ + # 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, snapshot, snapshot_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 = cloud_filestore_service.CreateSnapshotRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if snapshot is not None: + request.snapshot = snapshot + if snapshot_id is not None: + request.snapshot_id = snapshot_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_snapshot, + 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, + cloud_filestore_service.Snapshot, + metadata_type=operation_metadata_pb2.OperationMetadata, + ) + + # Done; return the response. + return response + + async def delete_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.DeleteSnapshotRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a snapshot. + + .. 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 filestore_v1 + + async def sample_delete_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.DeleteSnapshotRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.filestore_v1.types.DeleteSnapshotRequest, dict]]): + The request object. DeleteSnapshotRequest deletes a + snapshot. + name (:class:`str`): + Required. The snapshot resource name, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}/snapshots/{snapshot_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = cloud_filestore_service.DeleteSnapshotRequest(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_snapshot, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=operation_metadata_pb2.OperationMetadata, + ) + + # Done; return the response. + return response + + async def update_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.UpdateSnapshotRequest, dict] + ] = None, + *, + snapshot: Optional[cloud_filestore_service.Snapshot] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates the settings of a specific snapshot. + + .. 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 filestore_v1 + + async def sample_update_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.UpdateSnapshotRequest( + ) + + # Make the request + operation = client.update_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.filestore_v1.types.UpdateSnapshotRequest, dict]]): + The request object. UpdateSnapshotRequest updates + description and/or labels for a snapshot. + snapshot (:class:`google.cloud.filestore_v1.types.Snapshot`): + Required. A snapshot resource. + This corresponds to the ``snapshot`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. Mask of fields to update. + At least one path must be supplied in + this field. + + 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.filestore_v1.types.Snapshot` A + Filestore snapshot. + + """ + # 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([snapshot, 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 = cloud_filestore_service.UpdateSnapshotRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if snapshot is not None: + request.snapshot = snapshot + 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_snapshot, + 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( + (("snapshot.name", request.snapshot.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + cloud_filestore_service.Snapshot, + metadata_type=operation_metadata_pb2.OperationMetadata, + ) + + # Done; return the response. + return response + async def list_backups( self, request: Optional[ @@ -1051,7 +1673,7 @@ async def sample_list_backups(): Required. The project and location for which to retrieve backup information, in the format ``projects/{project_number}/locations/{location}``. In - Cloud Filestore, backup locations map to GCP regions, + Filestore, backup locations map to Google Cloud regions, for example **us-west1**. To retrieve backup information for all locations, use "-" for the ``{location}`` value. @@ -1189,7 +1811,7 @@ async def sample_get_backup(): Returns: google.cloud.filestore_v1.types.Backup: - A Cloud Filestore backup. + A Filestore backup. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have @@ -1296,7 +1918,7 @@ async def sample_create_backup(): Required. The backup's project and location, in the format ``projects/{project_number}/locations/{location}``. In - Cloud Filestore, backup locations map to GCP regions, + Filestore, backup locations map to Google Cloud regions, for example **us-west1**. This corresponds to the ``parent`` field @@ -1332,7 +1954,7 @@ async def sample_create_backup(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.filestore_v1.types.Backup` A Cloud + :class:`google.cloud.filestore_v1.types.Backup` A Filestore backup. """ @@ -1589,7 +2211,7 @@ async def sample_update_backup(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.filestore_v1.types.Backup` A Cloud + :class:`google.cloud.filestore_v1.types.Backup` A Filestore backup. """ diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py index 59449e6a070e..6b8f56ffee03 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py @@ -103,12 +103,12 @@ def get_transport_class( class CloudFilestoreManagerClient(metaclass=CloudFilestoreManagerClientMeta): - """Configures and manages Cloud Filestore resources. + """Configures and manages Filestore resources. - Cloud Filestore Manager v1. + Filestore Manager v1. - The ``file.googleapis.com`` service implements the Cloud Filestore - API and defines the following resource model for managing instances: + The ``file.googleapis.com`` service implements the Filestore API and + defines the following resource model for managing instances: - The service works with a collection of cloud projects, named: ``/projects/*`` @@ -116,13 +116,13 @@ class CloudFilestoreManagerClient(metaclass=CloudFilestoreManagerClientMeta): ``/locations/*`` - Each location has a collection of instances and backups, named: ``/instances/*`` and ``/backups/*`` respectively. - - As such, Cloud Filestore instances are resources of the form: + - As such, Filestore instances are resources of the form: ``/projects/{project_number}/locations/{location_id}/instances/{instance_id}`` and backups are resources of the form: ``/projects/{project_number}/locations/{location_id}/backup/{backup_id}`` - Note that location_id must be a GCP ``zone`` for instances and but - to a GCP ``region`` for backups; for example: + Note that location_id must be a Google Cloud ``zone`` for instances, + but a Google Cloud ``region`` for backups; for example: - ``projects/12345/locations/us-central1-c/instances/my-filestore`` - ``projects/12345/locations/us-central1/backups/my-backup`` @@ -254,6 +254,30 @@ def parse_instance_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def snapshot_path( + project: str, + location: str, + instance: str, + snapshot: str, + ) -> str: + """Returns a fully-qualified snapshot string.""" + return "projects/{project}/locations/{location}/instances/{instance}/snapshots/{snapshot}".format( + project=project, + location=location, + instance=instance, + snapshot=snapshot, + ) + + @staticmethod + def parse_snapshot_path(path: str) -> Dict[str, str]: + """Parses a snapshot path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/instances/(?P.+?)/snapshots/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def common_billing_account_path( billing_account: str, @@ -547,9 +571,9 @@ def sample_list_instances(): Required. The project and location for which to retrieve instance information, in the format ``projects/{project_id}/locations/{location}``. In Cloud - Filestore, locations map to GCP zones, for example - **us-west1-b**. To retrieve instance information for all - locations, use "-" for the ``{location}`` value. + Filestore, locations map to Google Cloud zones, for + example **us-west1-b**. To retrieve instance information + for all locations, use "-" for the ``{location}`` value. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -678,7 +702,7 @@ def sample_get_instance(): Returns: google.cloud.filestore_v1.types.Instance: - A Cloud Filestore instance. + A Filestore instance. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have @@ -779,7 +803,7 @@ def sample_create_instance(): parent (str): Required. The instance's project and location, in the format ``projects/{project_id}/locations/{location}``. - In Cloud Filestore, locations map to GCP zones, for + In Filestore, locations map to Google Cloud zones, for example **us-west1-b**. This corresponds to the ``parent`` field @@ -812,7 +836,7 @@ def sample_create_instance(): The result type for the operation will be :class:`google.cloud.filestore_v1.types.Instance` A - Cloud Filestore instance. + Filestore instance. """ # Create or coerce a protobuf request object. @@ -945,7 +969,7 @@ def sample_update_instance(): The result type for the operation will be :class:`google.cloud.filestore_v1.types.Instance` A - Cloud Filestore instance. + Filestore instance. """ # Create or coerce a protobuf request object. @@ -1053,7 +1077,7 @@ def sample_restore_instance(): Args: request (Union[google.cloud.filestore_v1.types.RestoreInstanceRequest, dict]): The request object. RestoreInstanceRequest restores an - existing instances's file share from a backup. + existing instance's file share from a backup. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1066,7 +1090,7 @@ def sample_restore_instance(): The result type for the operation will be :class:`google.cloud.filestore_v1.types.Instance` A - Cloud Filestore instance. + Filestore instance. """ # Create or coerce a protobuf request object. @@ -1232,6 +1256,626 @@ def sample_delete_instance(): # Done; return the response. return response + def list_snapshots( + self, + request: Optional[ + Union[cloud_filestore_service.ListSnapshotsRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListSnapshotsPager: + r"""Lists all snapshots in a project for either a + specified location or for all locations. + + .. 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 filestore_v1 + + def sample_list_snapshots(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.ListSnapshotsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_snapshots(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.filestore_v1.types.ListSnapshotsRequest, dict]): + The request object. ListSnapshotsRequest lists + snapshots. + parent (str): + Required. The instance for which to retrieve snapshot + information, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}``. + + 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.filestore_v1.services.cloud_filestore_manager.pagers.ListSnapshotsPager: + ListSnapshotsResponse is the result + of ListSnapshotsRequest. + 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 cloud_filestore_service.ListSnapshotsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_filestore_service.ListSnapshotsRequest): + request = cloud_filestore_service.ListSnapshotsRequest(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_snapshots] + + # 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.ListSnapshotsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.GetSnapshotRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_filestore_service.Snapshot: + r"""Gets the details of a specific snapshot. + + .. 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 filestore_v1 + + def sample_get_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.GetSnapshotRequest( + name="name_value", + ) + + # Make the request + response = client.get_snapshot(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.filestore_v1.types.GetSnapshotRequest, dict]): + The request object. GetSnapshotRequest gets the state of + a snapshot. + name (str): + Required. The snapshot resource name, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}/snapshots/{snapshot_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.filestore_v1.types.Snapshot: + A Filestore snapshot. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a cloud_filestore_service.GetSnapshotRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_filestore_service.GetSnapshotRequest): + request = cloud_filestore_service.GetSnapshotRequest(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.get_snapshot] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.CreateSnapshotRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + snapshot: Optional[cloud_filestore_service.Snapshot] = None, + snapshot_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Creates a snapshot. + + .. 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 filestore_v1 + + def sample_create_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.CreateSnapshotRequest( + parent="parent_value", + snapshot_id="snapshot_id_value", + ) + + # Make the request + operation = client.create_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.filestore_v1.types.CreateSnapshotRequest, dict]): + The request object. CreateSnapshotRequest creates a + snapshot. + parent (str): + Required. The Filestore Instance to create the snapshots + of, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + snapshot (google.cloud.filestore_v1.types.Snapshot): + Required. A snapshot resource. + This corresponds to the ``snapshot`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + snapshot_id (str): + Required. The ID to use for the + snapshot. The ID must be unique within + the specified instance. + This value must start with a lowercase + letter followed by up to 62 lowercase + letters, numbers, or hyphens, and cannot + end with a hyphen. + + This corresponds to the ``snapshot_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.filestore_v1.types.Snapshot` A + Filestore snapshot. + + """ + # 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, snapshot, snapshot_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 cloud_filestore_service.CreateSnapshotRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_filestore_service.CreateSnapshotRequest): + request = cloud_filestore_service.CreateSnapshotRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if snapshot is not None: + request.snapshot = snapshot + if snapshot_id is not None: + request.snapshot_id = snapshot_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_snapshot] + + # 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, + cloud_filestore_service.Snapshot, + metadata_type=operation_metadata_pb2.OperationMetadata, + ) + + # Done; return the response. + return response + + def delete_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.DeleteSnapshotRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Deletes a snapshot. + + .. 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 filestore_v1 + + def sample_delete_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.DeleteSnapshotRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.filestore_v1.types.DeleteSnapshotRequest, dict]): + The request object. DeleteSnapshotRequest deletes a + snapshot. + name (str): + Required. The snapshot resource name, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}/snapshots/{snapshot_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a cloud_filestore_service.DeleteSnapshotRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_filestore_service.DeleteSnapshotRequest): + request = cloud_filestore_service.DeleteSnapshotRequest(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_snapshot] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=operation_metadata_pb2.OperationMetadata, + ) + + # Done; return the response. + return response + + def update_snapshot( + self, + request: Optional[ + Union[cloud_filestore_service.UpdateSnapshotRequest, dict] + ] = None, + *, + snapshot: Optional[cloud_filestore_service.Snapshot] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Updates the settings of a specific snapshot. + + .. 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 filestore_v1 + + def sample_update_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.UpdateSnapshotRequest( + ) + + # Make the request + operation = client.update_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.filestore_v1.types.UpdateSnapshotRequest, dict]): + The request object. UpdateSnapshotRequest updates + description and/or labels for a snapshot. + snapshot (google.cloud.filestore_v1.types.Snapshot): + Required. A snapshot resource. + This corresponds to the ``snapshot`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Mask of fields to update. + At least one path must be supplied in + this field. + + 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.filestore_v1.types.Snapshot` A + Filestore snapshot. + + """ + # 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([snapshot, 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 cloud_filestore_service.UpdateSnapshotRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_filestore_service.UpdateSnapshotRequest): + request = cloud_filestore_service.UpdateSnapshotRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if snapshot is not None: + request.snapshot = snapshot + 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_snapshot] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("snapshot.name", request.snapshot.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + cloud_filestore_service.Snapshot, + metadata_type=operation_metadata_pb2.OperationMetadata, + ) + + # Done; return the response. + return response + def list_backups( self, request: Optional[ @@ -1280,7 +1924,7 @@ def sample_list_backups(): Required. The project and location for which to retrieve backup information, in the format ``projects/{project_number}/locations/{location}``. In - Cloud Filestore, backup locations map to GCP regions, + Filestore, backup locations map to Google Cloud regions, for example **us-west1**. To retrieve backup information for all locations, use "-" for the ``{location}`` value. @@ -1409,7 +2053,7 @@ def sample_get_backup(): Returns: google.cloud.filestore_v1.types.Backup: - A Cloud Filestore backup. + A Filestore backup. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have @@ -1507,7 +2151,7 @@ def sample_create_backup(): Required. The backup's project and location, in the format ``projects/{project_number}/locations/{location}``. In - Cloud Filestore, backup locations map to GCP regions, + Filestore, backup locations map to Google Cloud regions, for example **us-west1**. This corresponds to the ``parent`` field @@ -1543,7 +2187,7 @@ def sample_create_backup(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.filestore_v1.types.Backup` A Cloud + :class:`google.cloud.filestore_v1.types.Backup` A Filestore backup. """ @@ -1800,7 +2444,7 @@ def sample_update_backup(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.filestore_v1.types.Backup` A Cloud + :class:`google.cloud.filestore_v1.types.Backup` A Filestore backup. """ diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/pagers.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/pagers.py index 70de209607c3..bb8b245fe250 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/pagers.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/pagers.py @@ -157,6 +157,136 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) +class ListSnapshotsPager: + """A pager for iterating through ``list_snapshots`` requests. + + This class thinly wraps an initial + :class:`google.cloud.filestore_v1.types.ListSnapshotsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``snapshots`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListSnapshots`` requests and continue to iterate + through the ``snapshots`` field on the + corresponding responses. + + All the usual :class:`google.cloud.filestore_v1.types.ListSnapshotsResponse` + 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[..., cloud_filestore_service.ListSnapshotsResponse], + request: cloud_filestore_service.ListSnapshotsRequest, + response: cloud_filestore_service.ListSnapshotsResponse, + *, + 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.filestore_v1.types.ListSnapshotsRequest): + The initial request object. + response (google.cloud.filestore_v1.types.ListSnapshotsResponse): + 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 = cloud_filestore_service.ListSnapshotsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[cloud_filestore_service.ListSnapshotsResponse]: + 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[cloud_filestore_service.Snapshot]: + for page in self.pages: + yield from page.snapshots + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListSnapshotsAsyncPager: + """A pager for iterating through ``list_snapshots`` requests. + + This class thinly wraps an initial + :class:`google.cloud.filestore_v1.types.ListSnapshotsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``snapshots`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListSnapshots`` requests and continue to iterate + through the ``snapshots`` field on the + corresponding responses. + + All the usual :class:`google.cloud.filestore_v1.types.ListSnapshotsResponse` + 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[cloud_filestore_service.ListSnapshotsResponse]], + request: cloud_filestore_service.ListSnapshotsRequest, + response: cloud_filestore_service.ListSnapshotsResponse, + *, + 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.filestore_v1.types.ListSnapshotsRequest): + The initial request object. + response (google.cloud.filestore_v1.types.ListSnapshotsResponse): + 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 = cloud_filestore_service.ListSnapshotsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[cloud_filestore_service.ListSnapshotsResponse]: + 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[cloud_filestore_service.Snapshot]: + async def async_generator(): + async for page in self.pages: + for response in page.snapshots: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + class ListBackupsPager: """A pager for iterating through ``list_backups`` requests. diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py index 9c7ae5cfa1ab..71c4e9768d1a 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py @@ -171,6 +171,31 @@ def _prep_wrapped_messages(self, client_info): default_timeout=600.0, client_info=client_info, ), + self.list_snapshots: gapic_v1.method.wrap_method( + self.list_snapshots, + default_timeout=None, + client_info=client_info, + ), + self.get_snapshot: gapic_v1.method.wrap_method( + self.get_snapshot, + default_timeout=None, + client_info=client_info, + ), + self.create_snapshot: gapic_v1.method.wrap_method( + self.create_snapshot, + default_timeout=None, + client_info=client_info, + ), + self.delete_snapshot: gapic_v1.method.wrap_method( + self.delete_snapshot, + default_timeout=None, + client_info=client_info, + ), + self.update_snapshot: gapic_v1.method.wrap_method( + self.update_snapshot, + default_timeout=None, + client_info=client_info, + ), self.list_backups: gapic_v1.method.wrap_method( self.list_backups, default_retry=retries.Retry( @@ -290,6 +315,57 @@ def delete_instance( ]: raise NotImplementedError() + @property + def list_snapshots( + self, + ) -> Callable[ + [cloud_filestore_service.ListSnapshotsRequest], + Union[ + cloud_filestore_service.ListSnapshotsResponse, + Awaitable[cloud_filestore_service.ListSnapshotsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.GetSnapshotRequest], + Union[ + cloud_filestore_service.Snapshot, + Awaitable[cloud_filestore_service.Snapshot], + ], + ]: + raise NotImplementedError() + + @property + def create_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.CreateSnapshotRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.DeleteSnapshotRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def update_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.UpdateSnapshotRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def list_backups( self, diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py index eca0d576cd6b..ca0653423a80 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py @@ -31,12 +31,12 @@ class CloudFilestoreManagerGrpcTransport(CloudFilestoreManagerTransport): """gRPC backend transport for CloudFilestoreManager. - Configures and manages Cloud Filestore resources. + Configures and manages Filestore resources. - Cloud Filestore Manager v1. + Filestore Manager v1. - The ``file.googleapis.com`` service implements the Cloud Filestore - API and defines the following resource model for managing instances: + The ``file.googleapis.com`` service implements the Filestore API and + defines the following resource model for managing instances: - The service works with a collection of cloud projects, named: ``/projects/*`` @@ -44,13 +44,13 @@ class CloudFilestoreManagerGrpcTransport(CloudFilestoreManagerTransport): ``/locations/*`` - Each location has a collection of instances and backups, named: ``/instances/*`` and ``/backups/*`` respectively. - - As such, Cloud Filestore instances are resources of the form: + - As such, Filestore instances are resources of the form: ``/projects/{project_number}/locations/{location_id}/instances/{instance_id}`` and backups are resources of the form: ``/projects/{project_number}/locations/{location_id}/backup/{backup_id}`` - Note that location_id must be a GCP ``zone`` for instances and but - to a GCP ``region`` for backups; for example: + Note that location_id must be a Google Cloud ``zone`` for instances, + but a Google Cloud ``region`` for backups; for example: - ``projects/12345/locations/us-central1-c/instances/my-filestore`` - ``projects/12345/locations/us-central1/backups/my-backup`` @@ -444,6 +444,148 @@ def delete_instance( ) return self._stubs["delete_instance"] + @property + def list_snapshots( + self, + ) -> Callable[ + [cloud_filestore_service.ListSnapshotsRequest], + cloud_filestore_service.ListSnapshotsResponse, + ]: + r"""Return a callable for the list snapshots method over gRPC. + + Lists all snapshots in a project for either a + specified location or for all locations. + + Returns: + Callable[[~.ListSnapshotsRequest], + ~.ListSnapshotsResponse]: + 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_snapshots" not in self._stubs: + self._stubs["list_snapshots"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/ListSnapshots", + request_serializer=cloud_filestore_service.ListSnapshotsRequest.serialize, + response_deserializer=cloud_filestore_service.ListSnapshotsResponse.deserialize, + ) + return self._stubs["list_snapshots"] + + @property + def get_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.GetSnapshotRequest], cloud_filestore_service.Snapshot + ]: + r"""Return a callable for the get snapshot method over gRPC. + + Gets the details of a specific snapshot. + + Returns: + Callable[[~.GetSnapshotRequest], + ~.Snapshot]: + 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 "get_snapshot" not in self._stubs: + self._stubs["get_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/GetSnapshot", + request_serializer=cloud_filestore_service.GetSnapshotRequest.serialize, + response_deserializer=cloud_filestore_service.Snapshot.deserialize, + ) + return self._stubs["get_snapshot"] + + @property + def create_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.CreateSnapshotRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create snapshot method over gRPC. + + Creates a snapshot. + + Returns: + Callable[[~.CreateSnapshotRequest], + ~.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_snapshot" not in self._stubs: + self._stubs["create_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/CreateSnapshot", + request_serializer=cloud_filestore_service.CreateSnapshotRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_snapshot"] + + @property + def delete_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.DeleteSnapshotRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete snapshot method over gRPC. + + Deletes a snapshot. + + Returns: + Callable[[~.DeleteSnapshotRequest], + ~.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 "delete_snapshot" not in self._stubs: + self._stubs["delete_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/DeleteSnapshot", + request_serializer=cloud_filestore_service.DeleteSnapshotRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_snapshot"] + + @property + def update_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.UpdateSnapshotRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update snapshot method over gRPC. + + Updates the settings of a specific snapshot. + + Returns: + Callable[[~.UpdateSnapshotRequest], + ~.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_snapshot" not in self._stubs: + self._stubs["update_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/UpdateSnapshot", + request_serializer=cloud_filestore_service.UpdateSnapshotRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_snapshot"] + @property def list_backups( self, diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py index 4a9ec40ab65a..5cc917637a81 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py @@ -32,12 +32,12 @@ class CloudFilestoreManagerGrpcAsyncIOTransport(CloudFilestoreManagerTransport): """gRPC AsyncIO backend transport for CloudFilestoreManager. - Configures and manages Cloud Filestore resources. + Configures and manages Filestore resources. - Cloud Filestore Manager v1. + Filestore Manager v1. - The ``file.googleapis.com`` service implements the Cloud Filestore - API and defines the following resource model for managing instances: + The ``file.googleapis.com`` service implements the Filestore API and + defines the following resource model for managing instances: - The service works with a collection of cloud projects, named: ``/projects/*`` @@ -45,13 +45,13 @@ class CloudFilestoreManagerGrpcAsyncIOTransport(CloudFilestoreManagerTransport): ``/locations/*`` - Each location has a collection of instances and backups, named: ``/instances/*`` and ``/backups/*`` respectively. - - As such, Cloud Filestore instances are resources of the form: + - As such, Filestore instances are resources of the form: ``/projects/{project_number}/locations/{location_id}/instances/{instance_id}`` and backups are resources of the form: ``/projects/{project_number}/locations/{location_id}/backup/{backup_id}`` - Note that location_id must be a GCP ``zone`` for instances and but - to a GCP ``region`` for backups; for example: + Note that location_id must be a Google Cloud ``zone`` for instances, + but a Google Cloud ``region`` for backups; for example: - ``projects/12345/locations/us-central1-c/instances/my-filestore`` - ``projects/12345/locations/us-central1/backups/my-backup`` @@ -454,6 +454,152 @@ def delete_instance( ) return self._stubs["delete_instance"] + @property + def list_snapshots( + self, + ) -> Callable[ + [cloud_filestore_service.ListSnapshotsRequest], + Awaitable[cloud_filestore_service.ListSnapshotsResponse], + ]: + r"""Return a callable for the list snapshots method over gRPC. + + Lists all snapshots in a project for either a + specified location or for all locations. + + Returns: + Callable[[~.ListSnapshotsRequest], + Awaitable[~.ListSnapshotsResponse]]: + 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_snapshots" not in self._stubs: + self._stubs["list_snapshots"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/ListSnapshots", + request_serializer=cloud_filestore_service.ListSnapshotsRequest.serialize, + response_deserializer=cloud_filestore_service.ListSnapshotsResponse.deserialize, + ) + return self._stubs["list_snapshots"] + + @property + def get_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.GetSnapshotRequest], + Awaitable[cloud_filestore_service.Snapshot], + ]: + r"""Return a callable for the get snapshot method over gRPC. + + Gets the details of a specific snapshot. + + Returns: + Callable[[~.GetSnapshotRequest], + Awaitable[~.Snapshot]]: + 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 "get_snapshot" not in self._stubs: + self._stubs["get_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/GetSnapshot", + request_serializer=cloud_filestore_service.GetSnapshotRequest.serialize, + response_deserializer=cloud_filestore_service.Snapshot.deserialize, + ) + return self._stubs["get_snapshot"] + + @property + def create_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.CreateSnapshotRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create snapshot method over gRPC. + + Creates a snapshot. + + Returns: + Callable[[~.CreateSnapshotRequest], + 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_snapshot" not in self._stubs: + self._stubs["create_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/CreateSnapshot", + request_serializer=cloud_filestore_service.CreateSnapshotRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_snapshot"] + + @property + def delete_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.DeleteSnapshotRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete snapshot method over gRPC. + + Deletes a snapshot. + + Returns: + Callable[[~.DeleteSnapshotRequest], + 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 "delete_snapshot" not in self._stubs: + self._stubs["delete_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/DeleteSnapshot", + request_serializer=cloud_filestore_service.DeleteSnapshotRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_snapshot"] + + @property + def update_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.UpdateSnapshotRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update snapshot method over gRPC. + + Updates the settings of a specific snapshot. + + Returns: + Callable[[~.UpdateSnapshotRequest], + 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_snapshot" not in self._stubs: + self._stubs["update_snapshot"] = self.grpc_channel.unary_unary( + "/google.cloud.filestore.v1.CloudFilestoreManager/UpdateSnapshot", + request_serializer=cloud_filestore_service.UpdateSnapshotRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_snapshot"] + @property def list_backups( self, diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py index a8244951a540..63936a5b41f5 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py @@ -87,6 +87,14 @@ def post_create_instance(self, response): logging.log(f"Received response: {response}") return response + def pre_create_snapshot(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_snapshot(self, response): + logging.log(f"Received response: {response}") + return response + def pre_delete_backup(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -103,6 +111,14 @@ def post_delete_instance(self, response): logging.log(f"Received response: {response}") return response + def pre_delete_snapshot(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_delete_snapshot(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_backup(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -119,6 +135,14 @@ def post_get_instance(self, response): logging.log(f"Received response: {response}") return response + def pre_get_snapshot(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_snapshot(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_backups(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -135,6 +159,14 @@ def post_list_instances(self, response): logging.log(f"Received response: {response}") return response + def pre_list_snapshots(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_snapshots(self, response): + logging.log(f"Received response: {response}") + return response + def pre_restore_instance(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -159,6 +191,14 @@ def post_update_instance(self, response): logging.log(f"Received response: {response}") return response + def pre_update_snapshot(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_snapshot(self, response): + logging.log(f"Received response: {response}") + return response + transport = CloudFilestoreManagerRestTransport(interceptor=MyCustomCloudFilestoreManagerInterceptor()) client = CloudFilestoreManagerClient(transport=transport) @@ -213,6 +253,31 @@ def post_create_instance( """ return response + def pre_create_snapshot( + self, + request: cloud_filestore_service.CreateSnapshotRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + cloud_filestore_service.CreateSnapshotRequest, Sequence[Tuple[str, str]] + ]: + """Pre-rpc interceptor for create_snapshot + + Override in a subclass to manipulate the request or metadata + before they are sent to the CloudFilestoreManager server. + """ + return request, metadata + + def post_create_snapshot( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for create_snapshot + + Override in a subclass to manipulate the response + after it is returned by the CloudFilestoreManager server but before + it is returned to user code. + """ + return response + def pre_delete_backup( self, request: cloud_filestore_service.DeleteBackupRequest, @@ -261,6 +326,31 @@ def post_delete_instance( """ return response + def pre_delete_snapshot( + self, + request: cloud_filestore_service.DeleteSnapshotRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + cloud_filestore_service.DeleteSnapshotRequest, Sequence[Tuple[str, str]] + ]: + """Pre-rpc interceptor for delete_snapshot + + Override in a subclass to manipulate the request or metadata + before they are sent to the CloudFilestoreManager server. + """ + return request, metadata + + def post_delete_snapshot( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for delete_snapshot + + Override in a subclass to manipulate the response + after it is returned by the CloudFilestoreManager server but before + it is returned to user code. + """ + return response + def pre_get_backup( self, request: cloud_filestore_service.GetBackupRequest, @@ -307,6 +397,29 @@ def post_get_instance( """ return response + def pre_get_snapshot( + self, + request: cloud_filestore_service.GetSnapshotRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[cloud_filestore_service.GetSnapshotRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_snapshot + + Override in a subclass to manipulate the request or metadata + before they are sent to the CloudFilestoreManager server. + """ + return request, metadata + + def post_get_snapshot( + self, response: cloud_filestore_service.Snapshot + ) -> cloud_filestore_service.Snapshot: + """Post-rpc interceptor for get_snapshot + + Override in a subclass to manipulate the response + after it is returned by the CloudFilestoreManager server but before + it is returned to user code. + """ + return response + def pre_list_backups( self, request: cloud_filestore_service.ListBackupsRequest, @@ -353,6 +466,29 @@ def post_list_instances( """ return response + def pre_list_snapshots( + self, + request: cloud_filestore_service.ListSnapshotsRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[cloud_filestore_service.ListSnapshotsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_snapshots + + Override in a subclass to manipulate the request or metadata + before they are sent to the CloudFilestoreManager server. + """ + return request, metadata + + def post_list_snapshots( + self, response: cloud_filestore_service.ListSnapshotsResponse + ) -> cloud_filestore_service.ListSnapshotsResponse: + """Post-rpc interceptor for list_snapshots + + Override in a subclass to manipulate the response + after it is returned by the CloudFilestoreManager server but before + it is returned to user code. + """ + return response + def pre_restore_instance( self, request: cloud_filestore_service.RestoreInstanceRequest, @@ -426,6 +562,31 @@ def post_update_instance( """ return response + def pre_update_snapshot( + self, + request: cloud_filestore_service.UpdateSnapshotRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + cloud_filestore_service.UpdateSnapshotRequest, Sequence[Tuple[str, str]] + ]: + """Pre-rpc interceptor for update_snapshot + + Override in a subclass to manipulate the request or metadata + before they are sent to the CloudFilestoreManager server. + """ + return request, metadata + + def post_update_snapshot( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for update_snapshot + + Override in a subclass to manipulate the response + after it is returned by the CloudFilestoreManager server but before + it is returned to user code. + """ + return response + @dataclasses.dataclass class CloudFilestoreManagerRestStub: @@ -437,12 +598,12 @@ class CloudFilestoreManagerRestStub: class CloudFilestoreManagerRestTransport(CloudFilestoreManagerTransport): """REST backend transport for CloudFilestoreManager. - Configures and manages Cloud Filestore resources. + Configures and manages Filestore resources. - Cloud Filestore Manager v1. + Filestore Manager v1. - The ``file.googleapis.com`` service implements the Cloud Filestore - API and defines the following resource model for managing instances: + The ``file.googleapis.com`` service implements the Filestore API and + defines the following resource model for managing instances: - The service works with a collection of cloud projects, named: ``/projects/*`` @@ -450,13 +611,13 @@ class CloudFilestoreManagerRestTransport(CloudFilestoreManagerTransport): ``/locations/*`` - Each location has a collection of instances and backups, named: ``/instances/*`` and ``/backups/*`` respectively. - - As such, Cloud Filestore instances are resources of the form: + - As such, Filestore instances are resources of the form: ``/projects/{project_number}/locations/{location_id}/instances/{instance_id}`` and backups are resources of the form: ``/projects/{project_number}/locations/{location_id}/backup/{backup_id}`` - Note that location_id must be a GCP ``zone`` for instances and but - to a GCP ``region`` for backups; for example: + Note that location_id must be a Google Cloud ``zone`` for instances, + but a Google Cloud ``region`` for backups; for example: - ``projects/12345/locations/us-central1-c/instances/my-filestore`` - ``projects/12345/locations/us-central1/backups/my-backup`` @@ -797,11 +958,13 @@ def __call__( resp = self._interceptor.post_create_instance(resp) return resp - class _DeleteBackup(CloudFilestoreManagerRestStub): + class _CreateSnapshot(CloudFilestoreManagerRestStub): def __hash__(self): - return hash("DeleteBackup") + return hash("CreateSnapshot") - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "snapshotId": "", + } @classmethod def _get_unset_required_fields(cls, message_dict): @@ -813,17 +976,19 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: cloud_filestore_service.DeleteBackupRequest, + request: cloud_filestore_service.CreateSnapshotRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.Operation: - r"""Call the delete backup method over HTTP. + r"""Call the create snapshot method over HTTP. Args: - request (~.cloud_filestore_service.DeleteBackupRequest): - The request object. DeleteBackupRequest deletes a backup. + request (~.cloud_filestore_service.CreateSnapshotRequest): + The request object. CreateSnapshotRequest creates a + snapshot. + retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -840,14 +1005,22 @@ def __call__( http_options: List[Dict[str, str]] = [ { - "method": "delete", - "uri": "/v1/{name=projects/*/locations/*/backups/*}", + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*/instances/*}/snapshots", + "body": "snapshot", }, ] - request, metadata = self._interceptor.pre_delete_backup(request, metadata) - pb_request = cloud_filestore_service.DeleteBackupRequest.pb(request) + request, metadata = self._interceptor.pre_create_snapshot(request, metadata) + pb_request = cloud_filestore_service.CreateSnapshotRequest.pb(request) transcoded_request = path_template.transcode(http_options, pb_request) + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) uri = transcoded_request["uri"] method = transcoded_request["method"] @@ -871,6 +1044,7 @@ def __call__( timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -881,12 +1055,12 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_delete_backup(resp) + resp = self._interceptor.post_create_snapshot(resp) return resp - class _DeleteInstance(CloudFilestoreManagerRestStub): + class _DeleteBackup(CloudFilestoreManagerRestStub): def __hash__(self): - return hash("DeleteInstance") + return hash("DeleteBackup") __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @@ -900,19 +1074,17 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: cloud_filestore_service.DeleteInstanceRequest, + request: cloud_filestore_service.DeleteBackupRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.Operation: - r"""Call the delete instance method over HTTP. + r"""Call the delete backup method over HTTP. Args: - request (~.cloud_filestore_service.DeleteInstanceRequest): - The request object. DeleteInstanceRequest deletes an - instance. - + request (~.cloud_filestore_service.DeleteBackupRequest): + The request object. DeleteBackupRequest deletes a backup. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -930,11 +1102,11 @@ def __call__( http_options: List[Dict[str, str]] = [ { "method": "delete", - "uri": "/v1/{name=projects/*/locations/*/instances/*}", + "uri": "/v1/{name=projects/*/locations/*/backups/*}", }, ] - request, metadata = self._interceptor.pre_delete_instance(request, metadata) - pb_request = cloud_filestore_service.DeleteInstanceRequest.pb(request) + request, metadata = self._interceptor.pre_delete_backup(request, metadata) + pb_request = cloud_filestore_service.DeleteBackupRequest.pb(request) transcoded_request = path_template.transcode(http_options, pb_request) uri = transcoded_request["uri"] @@ -970,12 +1142,12 @@ def __call__( # Return the response resp = operations_pb2.Operation() json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_delete_instance(resp) + resp = self._interceptor.post_delete_backup(resp) return resp - class _GetBackup(CloudFilestoreManagerRestStub): + class _DeleteInstance(CloudFilestoreManagerRestStub): def __hash__(self): - return hash("GetBackup") + return hash("DeleteInstance") __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @@ -989,18 +1161,18 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: cloud_filestore_service.GetBackupRequest, + request: cloud_filestore_service.DeleteInstanceRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> cloud_filestore_service.Backup: - r"""Call the get backup method over HTTP. + ) -> operations_pb2.Operation: + r"""Call the delete instance method over HTTP. Args: - request (~.cloud_filestore_service.GetBackupRequest): - The request object. GetBackupRequest gets the state of a - backup. + request (~.cloud_filestore_service.DeleteInstanceRequest): + The request object. DeleteInstanceRequest deletes an + instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -1009,18 +1181,21 @@ def __call__( sent along with the request as metadata. Returns: - ~.cloud_filestore_service.Backup: - A Cloud Filestore backup. + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + """ http_options: List[Dict[str, str]] = [ { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/backups/*}", + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/instances/*}", }, ] - request, metadata = self._interceptor.pre_get_backup(request, metadata) - pb_request = cloud_filestore_service.GetBackupRequest.pb(request) + request, metadata = self._interceptor.pre_delete_instance(request, metadata) + pb_request = cloud_filestore_service.DeleteInstanceRequest.pb(request) transcoded_request = path_template.transcode(http_options, pb_request) uri = transcoded_request["uri"] @@ -1054,16 +1229,14 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = cloud_filestore_service.Backup() - pb_resp = cloud_filestore_service.Backup.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_backup(resp) + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_instance(resp) return resp - class _GetInstance(CloudFilestoreManagerRestStub): + class _DeleteSnapshot(CloudFilestoreManagerRestStub): def __hash__(self): - return hash("GetInstance") + return hash("DeleteSnapshot") __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @@ -1077,18 +1250,18 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: cloud_filestore_service.GetInstanceRequest, + request: cloud_filestore_service.DeleteSnapshotRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> cloud_filestore_service.Instance: - r"""Call the get instance method over HTTP. + ) -> operations_pb2.Operation: + r"""Call the delete snapshot method over HTTP. Args: - request (~.cloud_filestore_service.GetInstanceRequest): - The request object. GetInstanceRequest gets the state of - an instance. + request (~.cloud_filestore_service.DeleteSnapshotRequest): + The request object. DeleteSnapshotRequest deletes a + snapshot. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -1097,18 +1270,21 @@ def __call__( sent along with the request as metadata. Returns: - ~.cloud_filestore_service.Instance: - A Cloud Filestore instance. + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + """ http_options: List[Dict[str, str]] = [ { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/instances/*}", + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/instances/*/snapshots/*}", }, ] - request, metadata = self._interceptor.pre_get_instance(request, metadata) - pb_request = cloud_filestore_service.GetInstanceRequest.pb(request) + request, metadata = self._interceptor.pre_delete_snapshot(request, metadata) + pb_request = cloud_filestore_service.DeleteSnapshotRequest.pb(request) transcoded_request = path_template.transcode(http_options, pb_request) uri = transcoded_request["uri"] @@ -1142,16 +1318,14 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = cloud_filestore_service.Instance() - pb_resp = cloud_filestore_service.Instance.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_instance(resp) + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_delete_snapshot(resp) return resp - class _ListBackups(CloudFilestoreManagerRestStub): + class _GetBackup(CloudFilestoreManagerRestStub): def __hash__(self): - return hash("ListBackups") + return hash("GetBackup") __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @@ -1165,17 +1339,19 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: cloud_filestore_service.ListBackupsRequest, + request: cloud_filestore_service.GetBackupRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> cloud_filestore_service.ListBackupsResponse: - r"""Call the list backups method over HTTP. + ) -> cloud_filestore_service.Backup: + r"""Call the get backup method over HTTP. Args: - request (~.cloud_filestore_service.ListBackupsRequest): - The request object. ListBackupsRequest lists backups. + request (~.cloud_filestore_service.GetBackupRequest): + The request object. GetBackupRequest gets the state of a + backup. + retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1183,20 +1359,18 @@ def __call__( sent along with the request as metadata. Returns: - ~.cloud_filestore_service.ListBackupsResponse: - ListBackupsResponse is the result of - ListBackupsRequest. - + ~.cloud_filestore_service.Backup: + A Filestore backup. """ http_options: List[Dict[str, str]] = [ { "method": "get", - "uri": "/v1/{parent=projects/*/locations/*}/backups", + "uri": "/v1/{name=projects/*/locations/*/backups/*}", }, ] - request, metadata = self._interceptor.pre_list_backups(request, metadata) - pb_request = cloud_filestore_service.ListBackupsRequest.pb(request) + request, metadata = self._interceptor.pre_get_backup(request, metadata) + pb_request = cloud_filestore_service.GetBackupRequest.pb(request) transcoded_request = path_template.transcode(http_options, pb_request) uri = transcoded_request["uri"] @@ -1230,7 +1404,271 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = cloud_filestore_service.ListBackupsResponse() + resp = cloud_filestore_service.Backup() + pb_resp = cloud_filestore_service.Backup.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_backup(resp) + return resp + + class _GetInstance(CloudFilestoreManagerRestStub): + def __hash__(self): + return hash("GetInstance") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: cloud_filestore_service.GetInstanceRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_filestore_service.Instance: + r"""Call the get instance method over HTTP. + + Args: + request (~.cloud_filestore_service.GetInstanceRequest): + The request object. GetInstanceRequest gets the state of + an instance. + + 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: + ~.cloud_filestore_service.Instance: + A Filestore instance. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/instances/*}", + }, + ] + request, metadata = self._interceptor.pre_get_instance(request, metadata) + pb_request = cloud_filestore_service.GetInstanceRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = cloud_filestore_service.Instance() + pb_resp = cloud_filestore_service.Instance.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance(resp) + return resp + + class _GetSnapshot(CloudFilestoreManagerRestStub): + def __hash__(self): + return hash("GetSnapshot") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: cloud_filestore_service.GetSnapshotRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_filestore_service.Snapshot: + r"""Call the get snapshot method over HTTP. + + Args: + request (~.cloud_filestore_service.GetSnapshotRequest): + The request object. GetSnapshotRequest gets the state of + a snapshot. + + 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: + ~.cloud_filestore_service.Snapshot: + A Filestore snapshot. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/instances/*/snapshots/*}", + }, + ] + request, metadata = self._interceptor.pre_get_snapshot(request, metadata) + pb_request = cloud_filestore_service.GetSnapshotRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = cloud_filestore_service.Snapshot() + pb_resp = cloud_filestore_service.Snapshot.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_snapshot(resp) + return resp + + class _ListBackups(CloudFilestoreManagerRestStub): + def __hash__(self): + return hash("ListBackups") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: cloud_filestore_service.ListBackupsRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_filestore_service.ListBackupsResponse: + r"""Call the list backups method over HTTP. + + Args: + request (~.cloud_filestore_service.ListBackupsRequest): + The request object. ListBackupsRequest lists backups. + 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: + ~.cloud_filestore_service.ListBackupsResponse: + ListBackupsResponse is the result of + ListBackupsRequest. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*}/backups", + }, + ] + request, metadata = self._interceptor.pre_list_backups(request, metadata) + pb_request = cloud_filestore_service.ListBackupsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = cloud_filestore_service.ListBackupsResponse() pb_resp = cloud_filestore_service.ListBackupsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) @@ -1325,6 +1763,94 @@ def __call__( resp = self._interceptor.post_list_instances(resp) return resp + class _ListSnapshots(CloudFilestoreManagerRestStub): + def __hash__(self): + return hash("ListSnapshots") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: cloud_filestore_service.ListSnapshotsRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_filestore_service.ListSnapshotsResponse: + r"""Call the list snapshots method over HTTP. + + Args: + request (~.cloud_filestore_service.ListSnapshotsRequest): + The request object. ListSnapshotsRequest lists snapshots. + 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: + ~.cloud_filestore_service.ListSnapshotsResponse: + ListSnapshotsResponse is the result + of ListSnapshotsRequest. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*/instances/*}/snapshots", + }, + ] + request, metadata = self._interceptor.pre_list_snapshots(request, metadata) + pb_request = cloud_filestore_service.ListSnapshotsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = cloud_filestore_service.ListSnapshotsResponse() + pb_resp = cloud_filestore_service.ListSnapshotsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_snapshots(resp) + return resp + class _RestoreInstance(CloudFilestoreManagerRestStub): def __hash__(self): return hash("RestoreInstance") @@ -1352,7 +1878,7 @@ def __call__( Args: request (~.cloud_filestore_service.RestoreInstanceRequest): The request object. RestoreInstanceRequest restores an - existing instances's file share from a + existing instance's file share from a backup. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1613,6 +2139,107 @@ def __call__( resp = self._interceptor.post_update_instance(resp) return resp + class _UpdateSnapshot(CloudFilestoreManagerRestStub): + def __hash__(self): + return hash("UpdateSnapshot") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask": {}, + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: cloud_filestore_service.UpdateSnapshotRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Call the update snapshot method over HTTP. + + Args: + request (~.cloud_filestore_service.UpdateSnapshotRequest): + The request object. UpdateSnapshotRequest updates + description and/or labels for a + snapshot. + + 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: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{snapshot.name=projects/*/locations/*/instances/*/snapshots/*}", + "body": "snapshot", + }, + ] + request, metadata = self._interceptor.pre_update_snapshot(request, metadata) + pb_request = cloud_filestore_service.UpdateSnapshotRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_snapshot(resp) + return resp + @property def create_backup( self, @@ -1633,6 +2260,16 @@ def create_instance( # In C++ this would require a dynamic_cast return self._CreateInstance(self._session, self._host, self._interceptor) # type: ignore + @property + def create_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.CreateSnapshotRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateSnapshot(self._session, self._host, self._interceptor) # type: ignore + @property def delete_backup( self, @@ -1653,6 +2290,16 @@ def delete_instance( # In C++ this would require a dynamic_cast return self._DeleteInstance(self._session, self._host, self._interceptor) # type: ignore + @property + def delete_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.DeleteSnapshotRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteSnapshot(self._session, self._host, self._interceptor) # type: ignore + @property def get_backup( self, @@ -1673,6 +2320,16 @@ def get_instance( # In C++ this would require a dynamic_cast return self._GetInstance(self._session, self._host, self._interceptor) # type: ignore + @property + def get_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.GetSnapshotRequest], cloud_filestore_service.Snapshot + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetSnapshot(self._session, self._host, self._interceptor) # type: ignore + @property def list_backups( self, @@ -1695,6 +2352,17 @@ def list_instances( # In C++ this would require a dynamic_cast return self._ListInstances(self._session, self._host, self._interceptor) # type: ignore + @property + def list_snapshots( + self, + ) -> Callable[ + [cloud_filestore_service.ListSnapshotsRequest], + cloud_filestore_service.ListSnapshotsResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListSnapshots(self._session, self._host, self._interceptor) # type: ignore + @property def restore_instance( self, @@ -1725,6 +2393,16 @@ def update_instance( # In C++ this would require a dynamic_cast return self._UpdateInstance(self._session, self._host, self._interceptor) # type: ignore + @property + def update_snapshot( + self, + ) -> Callable[ + [cloud_filestore_service.UpdateSnapshotRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateSnapshot(self._session, self._host, self._interceptor) # type: ignore + @property def kind(self) -> str: return "rest" diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/types/__init__.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/types/__init__.py index 541b73771694..fdc23445e36d 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/types/__init__.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/types/__init__.py @@ -17,40 +17,54 @@ Backup, CreateBackupRequest, CreateInstanceRequest, + CreateSnapshotRequest, DeleteBackupRequest, DeleteInstanceRequest, + DeleteSnapshotRequest, FileShareConfig, GetBackupRequest, GetInstanceRequest, + GetSnapshotRequest, Instance, ListBackupsRequest, ListBackupsResponse, ListInstancesRequest, ListInstancesResponse, + ListSnapshotsRequest, + ListSnapshotsResponse, NetworkConfig, NfsExportOptions, RestoreInstanceRequest, + Snapshot, UpdateBackupRequest, UpdateInstanceRequest, + UpdateSnapshotRequest, ) __all__ = ( "Backup", "CreateBackupRequest", "CreateInstanceRequest", + "CreateSnapshotRequest", "DeleteBackupRequest", "DeleteInstanceRequest", + "DeleteSnapshotRequest", "FileShareConfig", "GetBackupRequest", "GetInstanceRequest", + "GetSnapshotRequest", "Instance", "ListBackupsRequest", "ListBackupsResponse", "ListInstancesRequest", "ListInstancesResponse", + "ListSnapshotsRequest", + "ListSnapshotsResponse", "NetworkConfig", "NfsExportOptions", "RestoreInstanceRequest", + "Snapshot", "UpdateBackupRequest", "UpdateInstanceRequest", + "UpdateSnapshotRequest", ) diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/types/cloud_filestore_service.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/types/cloud_filestore_service.py index a6934dcc2bfc..994dd19f6e4a 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/types/cloud_filestore_service.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/types/cloud_filestore_service.py @@ -36,6 +36,13 @@ "DeleteInstanceRequest", "ListInstancesRequest", "ListInstancesResponse", + "Snapshot", + "CreateSnapshotRequest", + "GetSnapshotRequest", + "DeleteSnapshotRequest", + "UpdateSnapshotRequest", + "ListSnapshotsRequest", + "ListSnapshotsResponse", "Backup", "CreateBackupRequest", "DeleteBackupRequest", @@ -60,22 +67,39 @@ class NetworkConfig(proto.Message): addresses assigned. For this version, only MODE_IPV4 is supported. reserved_ip_range (str): - A /29 CIDR block in one of the `internal IP address + Optional, reserved_ip_range can have one of the following + two types of values. + + - CIDR range value when using DIRECT_PEERING connect mode. + - `Allocated IP address + range `__ + when using PRIVATE_SERVICE_ACCESS connect mode. + + When the name of an allocated IP address range is specified, + it must be one of the ranges associated with the private + service access connection. When specified as a direct CIDR + value, it must be a /29 CIDR block for Basic tier, a /24 + CIDR block for High Scale tier, or a /26 CIDR block for + Enterprise tier in one of the `internal IP address ranges `__ that identifies the range of IP addresses reserved for this - instance. For example, 10.0.0.0/29 or 192.168.0.0/29. The - range you specify can't overlap with either existing subnets - or assigned IP address ranges for other Cloud Filestore - instances in the selected VPC network. + instance. For example, 10.0.0.0/29, 192.168.0.0/24 or + 192.168.0.0/26, respectively. The range you specify can't + overlap with either existing subnets or assigned IP address + ranges for other Filestore instances in the selected VPC + network. ip_addresses (MutableSequence[str]): - Output only. IPv4 addresses in the format IPv4 addresses in - the format ``{octet1}.{octet2}.{octet3}.{octet4}`` or IPv6 - addresses in the format + Output only. IPv4 addresses in the format + ``{octet1}.{octet2}.{octet3}.{octet4}`` or IPv6 addresses in + the format ``{block1}:{block2}:{block3}:{block4}:{block5}:{block6}:{block7}:{block8}``. + connect_mode (google.cloud.filestore_v1.types.NetworkConfig.ConnectMode): + The network connect mode of the Filestore instance. If not + provided, the connect mode defaults to DIRECT_PEERING. """ class AddressMode(proto.Enum): - r"""Internet protocol versions supported by Cloud Filestore. + r"""Internet protocol versions supported by Filestore. Values: ADDRESS_MODE_UNSPECIFIED (0): @@ -86,6 +110,25 @@ class AddressMode(proto.Enum): ADDRESS_MODE_UNSPECIFIED = 0 MODE_IPV4 = 1 + class ConnectMode(proto.Enum): + r"""Available connection modes. + + Values: + CONNECT_MODE_UNSPECIFIED (0): + Not set. + DIRECT_PEERING (1): + Connect via direct peering to the Filestore + service. + PRIVATE_SERVICE_ACCESS (2): + Connect to your Filestore instance using + Private Service Access. Private services access + provides an IP address range for multiple Google + Cloud services, including Filestore. + """ + CONNECT_MODE_UNSPECIFIED = 0 + DIRECT_PEERING = 1 + PRIVATE_SERVICE_ACCESS = 2 + network: str = proto.Field( proto.STRING, number=1, @@ -103,6 +146,11 @@ class AddressMode(proto.Enum): proto.STRING, number=5, ) + connect_mode: ConnectMode = proto.Field( + proto.ENUM, + number=6, + enum=ConnectMode, + ) class FileShareConfig(proto.Message): @@ -116,7 +164,7 @@ class FileShareConfig(proto.Message): characters or less). capacity_gb (int): File share capacity in gigabytes (GB). - Cloud Filestore defines 1 GB as 1024^3 bytes. + Filestore defines 1 GB as 1024^3 bytes. source_backup (str): The resource name of the backup, in the format ``projects/{project_number}/locations/{location_id}/backups/{backup_id}``, @@ -240,7 +288,7 @@ class SquashMode(proto.Enum): class Instance(proto.Message): - r"""A Cloud Filestore instance. + r"""A Filestore instance. Attributes: name (str): @@ -277,6 +325,11 @@ class Instance(proto.Message): overwriting each other. satisfies_pzs (google.protobuf.wrappers_pb2.BoolValue): Output only. Reserved for future use. + kms_key_name (str): + KMS key name used for data encryption. + suspension_reasons (MutableSequence[google.cloud.filestore_v1.types.Instance.SuspensionReason]): + Output only. Field indicates all the reasons + the instance is in "SUSPENDED" state. """ class State(proto.Enum): @@ -303,6 +356,16 @@ class State(proto.Enum): The instance is restoring a backup to an existing file share and may be unusable during this time. + SUSPENDED (8): + The instance is suspended. You can get further details from + the ``suspension_reasons`` field of the ``Instance`` + resource. + SUSPENDING (9): + The instance is in the process of becoming + suspended. + RESUMING (10): + The instance is in the process of becoming + active. """ STATE_UNSPECIFIED = 0 CREATING = 1 @@ -311,6 +374,9 @@ class State(proto.Enum): DELETING = 4 ERROR = 6 RESTORING = 7 + SUSPENDED = 8 + SUSPENDING = 9 + RESUMING = 10 class Tier(proto.Enum): r"""Available service tiers. @@ -319,9 +385,10 @@ class Tier(proto.Enum): TIER_UNSPECIFIED (0): Not set. STANDARD (1): - STANDARD tier. + STANDARD tier. BASIC_HDD is the preferred term for this + tier. PREMIUM (2): - PREMIUM tier. + PREMIUM tier. BASIC_SSD is the preferred term for this tier. BASIC_HDD (3): BASIC instances offer a maximum capacity of 63.9 TB. BASIC_HDD is an alias for STANDARD Tier, offering economical @@ -333,6 +400,10 @@ class Tier(proto.Enum): HIGH_SCALE_SSD (5): HIGH_SCALE instances offer expanded capacity and performance scaling capabilities. + ENTERPRISE (6): + ENTERPRISE instances offer the features and + availability needed for mission-critical + workloads. """ TIER_UNSPECIFIED = 0 STANDARD = 1 @@ -340,6 +411,21 @@ class Tier(proto.Enum): BASIC_HDD = 3 BASIC_SSD = 4 HIGH_SCALE_SSD = 5 + ENTERPRISE = 6 + + class SuspensionReason(proto.Enum): + r"""SuspensionReason contains the possible reasons for a + suspension. + + Values: + SUSPENSION_REASON_UNSPECIFIED (0): + Not set. + KMS_KEY_ISSUE (1): + The KMS key used by the instance is either + revoked or denied access to. + """ + SUSPENSION_REASON_UNSPECIFIED = 0 + KMS_KEY_ISSUE = 1 name: str = proto.Field( proto.STRING, @@ -392,6 +478,15 @@ class Tier(proto.Enum): number=13, message=wrappers_pb2.BoolValue, ) + kms_key_name: str = proto.Field( + proto.STRING, + number=14, + ) + suspension_reasons: MutableSequence[SuspensionReason] = proto.RepeatedField( + proto.ENUM, + number=15, + enum=SuspensionReason, + ) class CreateInstanceRequest(proto.Message): @@ -400,8 +495,8 @@ class CreateInstanceRequest(proto.Message): Attributes: parent (str): Required. The instance's project and location, in the format - ``projects/{project_id}/locations/{location}``. In Cloud - Filestore, locations map to GCP zones, for example + ``projects/{project_id}/locations/{location}``. In + Filestore, locations map to Google Cloud zones, for example **us-west1-b**. instance_id (str): Required. The name of the instance to create. @@ -471,7 +566,7 @@ class UpdateInstanceRequest(proto.Message): class RestoreInstanceRequest(proto.Message): - r"""RestoreInstanceRequest restores an existing instances's file + r"""RestoreInstanceRequest restores an existing instance's file share from a backup. @@ -482,7 +577,7 @@ class RestoreInstanceRequest(proto.Message): Required. The resource name of the instance, in the format ``projects/{project_number}/locations/{location_id}/instances/{instance_id}``. file_share (str): - Required. Name of the file share in the Cloud + Required. Name of the file share in the Filestore instance that the backup is being restored to. source_backup (str): @@ -514,12 +609,21 @@ class DeleteInstanceRequest(proto.Message): name (str): Required. The instance resource name, in the format ``projects/{project_id}/locations/{location}/instances/{instance_id}`` + force (bool): + If set to true, all snapshots of the instance + will also be deleted. (Otherwise, the request + will only work if the instance has no + snapshots.) """ name: str = proto.Field( proto.STRING, number=1, ) + force: bool = proto.Field( + proto.BOOL, + number=2, + ) class ListInstancesRequest(proto.Message): @@ -530,7 +634,7 @@ class ListInstancesRequest(proto.Message): Required. The project and location for which to retrieve instance information, in the format ``projects/{project_id}/locations/{location}``. In Cloud - Filestore, locations map to GCP zones, for example + Filestore, locations map to Google Cloud zones, for example **us-west1-b**. To retrieve instance information for all locations, use "-" for the ``{location}`` value. page_size (int): @@ -607,8 +711,238 @@ def raw_page(self): ) +class Snapshot(proto.Message): + r"""A Filestore snapshot. + + Attributes: + name (str): + Output only. The resource name of the snapshot, in the + format + ``projects/{project_id}/locations/{location_id}/instances/{instance_id}/snapshots/{snapshot_id}``. + description (str): + A description of the snapshot with 2048 + characters or less. Requests with longer + descriptions will be rejected. + state (google.cloud.filestore_v1.types.Snapshot.State): + Output only. The snapshot state. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time when the snapshot was + created. + labels (MutableMapping[str, str]): + Resource labels to represent user provided + metadata. + filesystem_used_bytes (int): + Output only. The amount of bytes needed to + allocate a full copy of the snapshot content + """ + + class State(proto.Enum): + r"""The snapshot state. + + Values: + STATE_UNSPECIFIED (0): + State not set. + CREATING (1): + Snapshot is being created. + READY (2): + Snapshot is available for use. + DELETING (3): + Snapshot is being deleted. + """ + STATE_UNSPECIFIED = 0 + CREATING = 1 + READY = 2 + DELETING = 3 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + description: str = proto.Field( + proto.STRING, + number=2, + ) + state: State = proto.Field( + proto.ENUM, + number=3, + enum=State, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + labels: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=5, + ) + filesystem_used_bytes: int = proto.Field( + proto.INT64, + number=6, + ) + + +class CreateSnapshotRequest(proto.Message): + r"""CreateSnapshotRequest creates a snapshot. + + Attributes: + parent (str): + Required. The Filestore Instance to create the snapshots of, + in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}`` + snapshot_id (str): + Required. The ID to use for the snapshot. + The ID must be unique within the specified + instance. + This value must start with a lowercase letter + followed by up to 62 lowercase letters, numbers, + or hyphens, and cannot end with a hyphen. + snapshot (google.cloud.filestore_v1.types.Snapshot): + Required. A snapshot resource. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + snapshot_id: str = proto.Field( + proto.STRING, + number=2, + ) + snapshot: "Snapshot" = proto.Field( + proto.MESSAGE, + number=3, + message="Snapshot", + ) + + +class GetSnapshotRequest(proto.Message): + r"""GetSnapshotRequest gets the state of a snapshot. + + Attributes: + name (str): + Required. The snapshot resource name, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}/snapshots/{snapshot_id}`` + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteSnapshotRequest(proto.Message): + r"""DeleteSnapshotRequest deletes a snapshot. + + Attributes: + name (str): + Required. The snapshot resource name, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}/snapshots/{snapshot_id}`` + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateSnapshotRequest(proto.Message): + r"""UpdateSnapshotRequest updates description and/or labels for a + snapshot. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Mask of fields to update. At least + one path must be supplied in this field. + snapshot (google.cloud.filestore_v1.types.Snapshot): + Required. A snapshot resource. + """ + + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, + ) + snapshot: "Snapshot" = proto.Field( + proto.MESSAGE, + number=2, + message="Snapshot", + ) + + +class ListSnapshotsRequest(proto.Message): + r"""ListSnapshotsRequest lists snapshots. + + Attributes: + parent (str): + Required. The instance for which to retrieve snapshot + information, in the format + ``projects/{project_id}/locations/{location}/instances/{instance_id}``. + page_size (int): + The maximum number of items to return. + page_token (str): + The next_page_token value to use if there are additional + results to retrieve for this list request. + order_by (str): + Sort results. Supported values are "name", + "name desc" or "" (unsorted). + filter (str): + List filter. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + order_by: str = proto.Field( + proto.STRING, + number=4, + ) + filter: str = proto.Field( + proto.STRING, + number=5, + ) + + +class ListSnapshotsResponse(proto.Message): + r"""ListSnapshotsResponse is the result of ListSnapshotsRequest. + + Attributes: + snapshots (MutableSequence[google.cloud.filestore_v1.types.Snapshot]): + A list of snapshots in the project for the + specified instance. + next_page_token (str): + The token you can use to retrieve the next + page of results. Not returned if there are no + more results in the list. + """ + + @property + def raw_page(self): + return self + + snapshots: MutableSequence["Snapshot"] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Snapshot", + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + class Backup(proto.Message): - r"""A Cloud Filestore backup. + r"""A Filestore backup. Attributes: name (str): @@ -635,18 +969,18 @@ class Backup(proto.Message): number is expected to change with backup creation/deletion. source_instance (str): - The resource name of the source Cloud Filestore instance, in - the format + The resource name of the source Filestore instance, in the + format ``projects/{project_number}/locations/{location_id}/instances/{instance_id}``, used to create this backup. source_file_share (str): - Name of the file share in the source Cloud + Name of the file share in the source Filestore instance that the backup is created from. source_instance_tier (google.cloud.filestore_v1.types.Instance.Tier): Output only. The service tier of the source - Cloud Filestore instance that this backup is - created from. + Filestore instance that this backup is created + from. download_bytes (int): Output only. Amount of bytes that will be downloaded if the backup is restored. This may @@ -655,6 +989,9 @@ class Backup(proto.Message): storage. satisfies_pzs (google.protobuf.wrappers_pb2.BoolValue): Output only. Reserved for future use. + kms_key (str): + Immutable. KMS key name used for data + encryption. """ class State(proto.Enum): @@ -733,6 +1070,10 @@ class State(proto.Enum): number=12, message=wrappers_pb2.BoolValue, ) + kms_key: str = proto.Field( + proto.STRING, + number=13, + ) class CreateBackupRequest(proto.Message): @@ -741,9 +1082,9 @@ class CreateBackupRequest(proto.Message): Attributes: parent (str): Required. The backup's project and location, in the format - ``projects/{project_number}/locations/{location}``. In Cloud - Filestore, backup locations map to GCP regions, for example - **us-west1**. + ``projects/{project_number}/locations/{location}``. In + Filestore, backup locations map to Google Cloud regions, for + example **us-west1**. backup (google.cloud.filestore_v1.types.Backup): Required. A [backup resource][google.cloud.filestore.v1.Backup] @@ -834,9 +1175,9 @@ class ListBackupsRequest(proto.Message): parent (str): Required. The project and location for which to retrieve backup information, in the format - ``projects/{project_number}/locations/{location}``. In Cloud - Filestore, backup locations map to GCP regions, for example - **us-west1**. To retrieve backup information for all + ``projects/{project_number}/locations/{location}``. In + Filestore, backup locations map to Google Cloud regions, for + example **us-west1**. To retrieve backup information for all locations, use "-" for the ``{location}`` value. page_size (int): The maximum number of items to return. diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_create_snapshot_async.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_create_snapshot_async.py new file mode 100644 index 000000000000..07d68635a8d6 --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_create_snapshot_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 CreateSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_CreateSnapshot_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 filestore_v1 + + +async def sample_create_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.CreateSnapshotRequest( + parent="parent_value", + snapshot_id="snapshot_id_value", + ) + + # Make the request + operation = client.create_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_CreateSnapshot_async] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_create_snapshot_sync.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_create_snapshot_sync.py new file mode 100644 index 000000000000..080734be18f0 --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_create_snapshot_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 CreateSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_CreateSnapshot_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 filestore_v1 + + +def sample_create_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.CreateSnapshotRequest( + parent="parent_value", + snapshot_id="snapshot_id_value", + ) + + # Make the request + operation = client.create_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_CreateSnapshot_sync] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_delete_snapshot_async.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_delete_snapshot_async.py new file mode 100644 index 000000000000..9240df7484b3 --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_delete_snapshot_async.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_DeleteSnapshot_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 filestore_v1 + + +async def sample_delete_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.DeleteSnapshotRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_DeleteSnapshot_async] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_delete_snapshot_sync.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_delete_snapshot_sync.py new file mode 100644 index 000000000000..cbcea910707d --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_delete_snapshot_sync.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_DeleteSnapshot_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 filestore_v1 + + +def sample_delete_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.DeleteSnapshotRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_DeleteSnapshot_sync] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_get_snapshot_async.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_get_snapshot_async.py new file mode 100644 index 000000000000..82b46812e148 --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_get_snapshot_async.py @@ -0,0 +1,52 @@ +# -*- 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 GetSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_GetSnapshot_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 filestore_v1 + + +async def sample_get_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.GetSnapshotRequest( + name="name_value", + ) + + # Make the request + response = await client.get_snapshot(request=request) + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_GetSnapshot_async] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_get_snapshot_sync.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_get_snapshot_sync.py new file mode 100644 index 000000000000..54c8e350d387 --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_get_snapshot_sync.py @@ -0,0 +1,52 @@ +# -*- 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 GetSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_GetSnapshot_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 filestore_v1 + + +def sample_get_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.GetSnapshotRequest( + name="name_value", + ) + + # Make the request + response = client.get_snapshot(request=request) + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_GetSnapshot_sync] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_list_snapshots_async.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_list_snapshots_async.py new file mode 100644 index 000000000000..8daafb514735 --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_list_snapshots_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 ListSnapshots +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_ListSnapshots_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 filestore_v1 + + +async def sample_list_snapshots(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.ListSnapshotsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_snapshots(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END file_v1_generated_CloudFilestoreManager_ListSnapshots_async] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_list_snapshots_sync.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_list_snapshots_sync.py new file mode 100644 index 000000000000..5dc11f44d62b --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_list_snapshots_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 ListSnapshots +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_ListSnapshots_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 filestore_v1 + + +def sample_list_snapshots(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.ListSnapshotsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_snapshots(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END file_v1_generated_CloudFilestoreManager_ListSnapshots_sync] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_update_snapshot_async.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_update_snapshot_async.py new file mode 100644 index 000000000000..4aee0d89ddfa --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_update_snapshot_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 UpdateSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_UpdateSnapshot_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 filestore_v1 + + +async def sample_update_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerAsyncClient() + + # Initialize request argument(s) + request = filestore_v1.UpdateSnapshotRequest( + ) + + # Make the request + operation = client.update_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_UpdateSnapshot_async] diff --git a/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_update_snapshot_sync.py b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_update_snapshot_sync.py new file mode 100644 index 000000000000..c61ce04bf9f4 --- /dev/null +++ b/packages/google-cloud-filestore/samples/generated_samples/file_v1_generated_cloud_filestore_manager_update_snapshot_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 UpdateSnapshot +# 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-filestore + + +# [START file_v1_generated_CloudFilestoreManager_UpdateSnapshot_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 filestore_v1 + + +def sample_update_snapshot(): + # Create a client + client = filestore_v1.CloudFilestoreManagerClient() + + # Initialize request argument(s) + request = filestore_v1.UpdateSnapshotRequest( + ) + + # Make the request + operation = client.update_snapshot(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END file_v1_generated_CloudFilestoreManager_UpdateSnapshot_sync] diff --git a/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json b/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json index dd1a74f164b7..a9b49588c20d 100644 --- a/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json +++ b/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json @@ -365,6 +365,183 @@ ], "title": "file_v1_generated_cloud_filestore_manager_create_instance_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", + "shortName": "CloudFilestoreManagerAsyncClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.create_snapshot", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.CreateSnapshot", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "CreateSnapshot" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.CreateSnapshotRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "snapshot", + "type": "google.cloud.filestore_v1.types.Snapshot" + }, + { + "name": "snapshot_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_snapshot" + }, + "description": "Sample for CreateSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_create_snapshot_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_CreateSnapshot_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": "file_v1_generated_cloud_filestore_manager_create_snapshot_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", + "shortName": "CloudFilestoreManagerClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.create_snapshot", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.CreateSnapshot", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "CreateSnapshot" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.CreateSnapshotRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "snapshot", + "type": "google.cloud.filestore_v1.types.Snapshot" + }, + { + "name": "snapshot_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_snapshot" + }, + "description": "Sample for CreateSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_create_snapshot_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_CreateSnapshot_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": "file_v1_generated_cloud_filestore_manager_create_snapshot_sync.py" + }, { "canonical": true, "clientMethod": { @@ -695,19 +872,19 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", "shortName": "CloudFilestoreManagerAsyncClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.get_backup", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.delete_snapshot", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetBackup", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.DeleteSnapshot", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "GetBackup" + "shortName": "DeleteSnapshot" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.GetBackupRequest" + "type": "google.cloud.filestore_v1.types.DeleteSnapshotRequest" }, { "name": "name", @@ -726,22 +903,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.types.Backup", - "shortName": "get_backup" + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_snapshot" }, - "description": "Sample for GetBackup", - "file": "file_v1_generated_cloud_filestore_manager_get_backup_async.py", + "description": "Sample for DeleteSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_delete_snapshot_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_GetBackup_async", + "regionTag": "file_v1_generated_CloudFilestoreManager_DeleteSnapshot_async", "segments": [ { - "end": 51, + "end": 55, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 55, "start": 27, "type": "SHORT" }, @@ -756,17 +933,17 @@ "type": "REQUEST_INITIALIZATION" }, { - "end": 48, + "end": 52, "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 52, - "start": 49, + "end": 56, + "start": 53, "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_get_backup_async.py" + "title": "file_v1_generated_cloud_filestore_manager_delete_snapshot_async.py" }, { "canonical": true, @@ -775,19 +952,19 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", "shortName": "CloudFilestoreManagerClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.get_backup", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.delete_snapshot", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetBackup", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.DeleteSnapshot", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "GetBackup" + "shortName": "DeleteSnapshot" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.GetBackupRequest" + "type": "google.cloud.filestore_v1.types.DeleteSnapshotRequest" }, { "name": "name", @@ -806,22 +983,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.types.Backup", - "shortName": "get_backup" + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_snapshot" }, - "description": "Sample for GetBackup", - "file": "file_v1_generated_cloud_filestore_manager_get_backup_sync.py", + "description": "Sample for DeleteSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_delete_snapshot_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_GetBackup_sync", + "regionTag": "file_v1_generated_CloudFilestoreManager_DeleteSnapshot_sync", "segments": [ { - "end": 51, + "end": 55, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 55, "start": 27, "type": "SHORT" }, @@ -836,17 +1013,17 @@ "type": "REQUEST_INITIALIZATION" }, { - "end": 48, + "end": 52, "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 52, - "start": 49, + "end": 56, + "start": 53, "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_get_backup_sync.py" + "title": "file_v1_generated_cloud_filestore_manager_delete_snapshot_sync.py" }, { "canonical": true, @@ -856,22 +1033,505 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", "shortName": "CloudFilestoreManagerAsyncClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.get_instance", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.get_backup", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetInstance", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetBackup", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "GetInstance" + "shortName": "GetBackup" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.GetInstanceRequest" + "type": "google.cloud.filestore_v1.types.GetBackupRequest" + }, + { + "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.filestore_v1.types.Backup", + "shortName": "get_backup" + }, + "description": "Sample for GetBackup", + "file": "file_v1_generated_cloud_filestore_manager_get_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_GetBackup_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": "file_v1_generated_cloud_filestore_manager_get_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", + "shortName": "CloudFilestoreManagerClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.get_backup", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetBackup", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "GetBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.GetBackupRequest" + }, + { + "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.filestore_v1.types.Backup", + "shortName": "get_backup" + }, + "description": "Sample for GetBackup", + "file": "file_v1_generated_cloud_filestore_manager_get_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_GetBackup_sync", + "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": "file_v1_generated_cloud_filestore_manager_get_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", + "shortName": "CloudFilestoreManagerAsyncClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.get_instance", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetInstance", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "GetInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.GetInstanceRequest" + }, + { + "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.filestore_v1.types.Instance", + "shortName": "get_instance" + }, + "description": "Sample for GetInstance", + "file": "file_v1_generated_cloud_filestore_manager_get_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_GetInstance_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": "file_v1_generated_cloud_filestore_manager_get_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", + "shortName": "CloudFilestoreManagerClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.get_instance", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetInstance", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "GetInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.GetInstanceRequest" + }, + { + "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.filestore_v1.types.Instance", + "shortName": "get_instance" + }, + "description": "Sample for GetInstance", + "file": "file_v1_generated_cloud_filestore_manager_get_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_GetInstance_sync", + "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": "file_v1_generated_cloud_filestore_manager_get_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", + "shortName": "CloudFilestoreManagerAsyncClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.get_snapshot", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetSnapshot", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "GetSnapshot" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.GetSnapshotRequest" + }, + { + "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.filestore_v1.types.Snapshot", + "shortName": "get_snapshot" + }, + "description": "Sample for GetSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_get_snapshot_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_GetSnapshot_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": "file_v1_generated_cloud_filestore_manager_get_snapshot_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", + "shortName": "CloudFilestoreManagerClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.get_snapshot", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetSnapshot", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "GetSnapshot" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.GetSnapshotRequest" + }, + { + "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.filestore_v1.types.Snapshot", + "shortName": "get_snapshot" + }, + "description": "Sample for GetSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_get_snapshot_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_GetSnapshot_sync", + "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": "file_v1_generated_cloud_filestore_manager_get_snapshot_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", + "shortName": "CloudFilestoreManagerAsyncClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.list_backups", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListBackups", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "ListBackups" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.ListBackupsRequest" }, { - "name": "name", + "name": "parent", "type": "str" }, { @@ -887,22 +1547,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.types.Instance", - "shortName": "get_instance" + "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListBackupsAsyncPager", + "shortName": "list_backups" }, - "description": "Sample for GetInstance", - "file": "file_v1_generated_cloud_filestore_manager_get_instance_async.py", + "description": "Sample for ListBackups", + "file": "file_v1_generated_cloud_filestore_manager_list_backups_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_GetInstance_async", + "regionTag": "file_v1_generated_CloudFilestoreManager_ListBackups_async", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, @@ -922,12 +1582,12 @@ "type": "REQUEST_EXECUTION" }, { - "end": 52, + "end": 53, "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_get_instance_async.py" + "title": "file_v1_generated_cloud_filestore_manager_list_backups_async.py" }, { "canonical": true, @@ -936,22 +1596,22 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", "shortName": "CloudFilestoreManagerClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.get_instance", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.list_backups", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.GetInstance", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListBackups", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "GetInstance" + "shortName": "ListBackups" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.GetInstanceRequest" + "type": "google.cloud.filestore_v1.types.ListBackupsRequest" }, { - "name": "name", + "name": "parent", "type": "str" }, { @@ -967,22 +1627,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.types.Instance", - "shortName": "get_instance" + "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListBackupsPager", + "shortName": "list_backups" }, - "description": "Sample for GetInstance", - "file": "file_v1_generated_cloud_filestore_manager_get_instance_sync.py", + "description": "Sample for ListBackups", + "file": "file_v1_generated_cloud_filestore_manager_list_backups_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_GetInstance_sync", + "regionTag": "file_v1_generated_CloudFilestoreManager_ListBackups_sync", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, @@ -1002,12 +1662,12 @@ "type": "REQUEST_EXECUTION" }, { - "end": 52, + "end": 53, "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_get_instance_sync.py" + "title": "file_v1_generated_cloud_filestore_manager_list_backups_sync.py" }, { "canonical": true, @@ -1017,19 +1677,19 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", "shortName": "CloudFilestoreManagerAsyncClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.list_backups", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.list_instances", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListBackups", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListInstances", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "ListBackups" + "shortName": "ListInstances" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.ListBackupsRequest" + "type": "google.cloud.filestore_v1.types.ListInstancesRequest" }, { "name": "parent", @@ -1048,14 +1708,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListBackupsAsyncPager", - "shortName": "list_backups" + "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListInstancesAsyncPager", + "shortName": "list_instances" }, - "description": "Sample for ListBackups", - "file": "file_v1_generated_cloud_filestore_manager_list_backups_async.py", + "description": "Sample for ListInstances", + "file": "file_v1_generated_cloud_filestore_manager_list_instances_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_ListBackups_async", + "regionTag": "file_v1_generated_CloudFilestoreManager_ListInstances_async", "segments": [ { "end": 52, @@ -1088,7 +1748,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_list_backups_async.py" + "title": "file_v1_generated_cloud_filestore_manager_list_instances_async.py" }, { "canonical": true, @@ -1097,19 +1757,19 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", "shortName": "CloudFilestoreManagerClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.list_backups", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.list_instances", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListBackups", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListInstances", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "ListBackups" + "shortName": "ListInstances" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.ListBackupsRequest" + "type": "google.cloud.filestore_v1.types.ListInstancesRequest" }, { "name": "parent", @@ -1128,14 +1788,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListBackupsPager", - "shortName": "list_backups" + "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListInstancesPager", + "shortName": "list_instances" }, - "description": "Sample for ListBackups", - "file": "file_v1_generated_cloud_filestore_manager_list_backups_sync.py", + "description": "Sample for ListInstances", + "file": "file_v1_generated_cloud_filestore_manager_list_instances_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_ListBackups_sync", + "regionTag": "file_v1_generated_CloudFilestoreManager_ListInstances_sync", "segments": [ { "end": 52, @@ -1168,7 +1828,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_list_backups_sync.py" + "title": "file_v1_generated_cloud_filestore_manager_list_instances_sync.py" }, { "canonical": true, @@ -1178,19 +1838,19 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", "shortName": "CloudFilestoreManagerAsyncClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.list_instances", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.list_snapshots", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListInstances", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListSnapshots", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "ListInstances" + "shortName": "ListSnapshots" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.ListInstancesRequest" + "type": "google.cloud.filestore_v1.types.ListSnapshotsRequest" }, { "name": "parent", @@ -1209,14 +1869,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListInstancesAsyncPager", - "shortName": "list_instances" + "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListSnapshotsAsyncPager", + "shortName": "list_snapshots" }, - "description": "Sample for ListInstances", - "file": "file_v1_generated_cloud_filestore_manager_list_instances_async.py", + "description": "Sample for ListSnapshots", + "file": "file_v1_generated_cloud_filestore_manager_list_snapshots_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_ListInstances_async", + "regionTag": "file_v1_generated_CloudFilestoreManager_ListSnapshots_async", "segments": [ { "end": 52, @@ -1249,7 +1909,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_list_instances_async.py" + "title": "file_v1_generated_cloud_filestore_manager_list_snapshots_async.py" }, { "canonical": true, @@ -1258,19 +1918,19 @@ "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", "shortName": "CloudFilestoreManagerClient" }, - "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.list_instances", + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.list_snapshots", "method": { - "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListInstances", + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.ListSnapshots", "service": { "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", "shortName": "CloudFilestoreManager" }, - "shortName": "ListInstances" + "shortName": "ListSnapshots" }, "parameters": [ { "name": "request", - "type": "google.cloud.filestore_v1.types.ListInstancesRequest" + "type": "google.cloud.filestore_v1.types.ListSnapshotsRequest" }, { "name": "parent", @@ -1289,14 +1949,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListInstancesPager", - "shortName": "list_instances" + "resultType": "google.cloud.filestore_v1.services.cloud_filestore_manager.pagers.ListSnapshotsPager", + "shortName": "list_snapshots" }, - "description": "Sample for ListInstances", - "file": "file_v1_generated_cloud_filestore_manager_list_instances_sync.py", + "description": "Sample for ListSnapshots", + "file": "file_v1_generated_cloud_filestore_manager_list_snapshots_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "file_v1_generated_CloudFilestoreManager_ListInstances_sync", + "regionTag": "file_v1_generated_CloudFilestoreManager_ListSnapshots_sync", "segments": [ { "end": 52, @@ -1329,7 +1989,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "file_v1_generated_cloud_filestore_manager_list_instances_sync.py" + "title": "file_v1_generated_cloud_filestore_manager_list_snapshots_sync.py" }, { "canonical": true, @@ -1821,6 +2481,175 @@ } ], "title": "file_v1_generated_cloud_filestore_manager_update_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient", + "shortName": "CloudFilestoreManagerAsyncClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerAsyncClient.update_snapshot", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.UpdateSnapshot", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "UpdateSnapshot" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.UpdateSnapshotRequest" + }, + { + "name": "snapshot", + "type": "google.cloud.filestore_v1.types.Snapshot" + }, + { + "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_snapshot" + }, + "description": "Sample for UpdateSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_update_snapshot_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_UpdateSnapshot_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": "file_v1_generated_cloud_filestore_manager_update_snapshot_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient", + "shortName": "CloudFilestoreManagerClient" + }, + "fullName": "google.cloud.filestore_v1.CloudFilestoreManagerClient.update_snapshot", + "method": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager.UpdateSnapshot", + "service": { + "fullName": "google.cloud.filestore.v1.CloudFilestoreManager", + "shortName": "CloudFilestoreManager" + }, + "shortName": "UpdateSnapshot" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.filestore_v1.types.UpdateSnapshotRequest" + }, + { + "name": "snapshot", + "type": "google.cloud.filestore_v1.types.Snapshot" + }, + { + "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_snapshot" + }, + "description": "Sample for UpdateSnapshot", + "file": "file_v1_generated_cloud_filestore_manager_update_snapshot_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "file_v1_generated_CloudFilestoreManager_UpdateSnapshot_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": "file_v1_generated_cloud_filestore_manager_update_snapshot_sync.py" } ] } diff --git a/packages/google-cloud-filestore/scripts/fixup_filestore_v1_keywords.py b/packages/google-cloud-filestore/scripts/fixup_filestore_v1_keywords.py index a8b975ff2275..1ac12923818a 100644 --- a/packages/google-cloud-filestore/scripts/fixup_filestore_v1_keywords.py +++ b/packages/google-cloud-filestore/scripts/fixup_filestore_v1_keywords.py @@ -41,15 +41,20 @@ class filestoreCallTransformer(cst.CSTTransformer): METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { 'create_backup': ('parent', 'backup', 'backup_id', ), 'create_instance': ('parent', 'instance_id', 'instance', ), + 'create_snapshot': ('parent', 'snapshot_id', 'snapshot', ), 'delete_backup': ('name', ), - 'delete_instance': ('name', ), + 'delete_instance': ('name', 'force', ), + 'delete_snapshot': ('name', ), 'get_backup': ('name', ), 'get_instance': ('name', ), + 'get_snapshot': ('name', ), 'list_backups': ('parent', 'page_size', 'page_token', 'order_by', 'filter', ), 'list_instances': ('parent', 'page_size', 'page_token', 'order_by', 'filter', ), + 'list_snapshots': ('parent', 'page_size', 'page_token', 'order_by', 'filter', ), 'restore_instance': ('name', 'file_share', 'source_backup', ), 'update_backup': ('backup', 'update_mask', ), 'update_instance': ('update_mask', 'instance', ), + 'update_snapshot': ('update_mask', 'snapshot', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: diff --git a/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py b/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py index b30144528773..24b2025cac7e 100644 --- a/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py +++ b/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py @@ -1217,6 +1217,10 @@ def test_get_instance(request_type, transport: str = "grpc"): status_message="status_message_value", tier=cloud_filestore_service.Instance.Tier.STANDARD, etag="etag_value", + kms_key_name="kms_key_name_value", + suspension_reasons=[ + cloud_filestore_service.Instance.SuspensionReason.KMS_KEY_ISSUE + ], ) response = client.get_instance(request) @@ -1233,6 +1237,10 @@ def test_get_instance(request_type, transport: str = "grpc"): assert response.status_message == "status_message_value" assert response.tier == cloud_filestore_service.Instance.Tier.STANDARD assert response.etag == "etag_value" + assert response.kms_key_name == "kms_key_name_value" + assert response.suspension_reasons == [ + cloud_filestore_service.Instance.SuspensionReason.KMS_KEY_ISSUE + ] def test_get_instance_empty_call(): @@ -1276,6 +1284,10 @@ async def test_get_instance_async( status_message="status_message_value", tier=cloud_filestore_service.Instance.Tier.STANDARD, etag="etag_value", + kms_key_name="kms_key_name_value", + suspension_reasons=[ + cloud_filestore_service.Instance.SuspensionReason.KMS_KEY_ISSUE + ], ) ) response = await client.get_instance(request) @@ -1293,6 +1305,10 @@ async def test_get_instance_async( assert response.status_message == "status_message_value" assert response.tier == cloud_filestore_service.Instance.Tier.STANDARD assert response.etag == "etag_value" + assert response.kms_key_name == "kms_key_name_value" + assert response.suspension_reasons == [ + cloud_filestore_service.Instance.SuspensionReason.KMS_KEY_ISSUE + ] @pytest.mark.asyncio @@ -2302,11 +2318,11 @@ async def test_delete_instance_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.ListBackupsRequest, + cloud_filestore_service.ListSnapshotsRequest, dict, ], ) -def test_list_backups(request_type, transport: str = "grpc"): +def test_list_snapshots(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2317,26 +2333,24 @@ def test_list_backups(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_filestore_service.ListBackupsResponse( + call.return_value = cloud_filestore_service.ListSnapshotsResponse( next_page_token="next_page_token_value", - unreachable=["unreachable_value"], ) - response = client.list_backups(request) + response = client.list_snapshots(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.ListBackupsRequest() + assert args[0] == cloud_filestore_service.ListSnapshotsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupsPager) + assert isinstance(response, pagers.ListSnapshotsPager) assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] -def test_list_backups_empty_call(): +def test_list_snapshots_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 = CloudFilestoreManagerClient( @@ -2345,17 +2359,17 @@ def test_list_backups_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_backups), "__call__") as call: - client.list_backups() + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: + client.list_snapshots() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.ListBackupsRequest() + assert args[0] == cloud_filestore_service.ListSnapshotsRequest() @pytest.mark.asyncio -async def test_list_backups_async( +async def test_list_snapshots_async( transport: str = "grpc_asyncio", - request_type=cloud_filestore_service.ListBackupsRequest, + request_type=cloud_filestore_service.ListSnapshotsRequest, ): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2367,47 +2381,45 @@ async def test_list_backups_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_filestore_service.ListBackupsResponse( + cloud_filestore_service.ListSnapshotsResponse( next_page_token="next_page_token_value", - unreachable=["unreachable_value"], ) ) - response = await client.list_backups(request) + response = await client.list_snapshots(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.ListBackupsRequest() + assert args[0] == cloud_filestore_service.ListSnapshotsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupsAsyncPager) + assert isinstance(response, pagers.ListSnapshotsAsyncPager) assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @pytest.mark.asyncio -async def test_list_backups_async_from_dict(): - await test_list_backups_async(request_type=dict) +async def test_list_snapshots_async_from_dict(): + await test_list_snapshots_async(request_type=dict) -def test_list_backups_field_headers(): +def test_list_snapshots_field_headers(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.ListBackupsRequest() + request = cloud_filestore_service.ListSnapshotsRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_backups), "__call__") as call: - call.return_value = cloud_filestore_service.ListBackupsResponse() - client.list_backups(request) + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: + call.return_value = cloud_filestore_service.ListSnapshotsResponse() + client.list_snapshots(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2423,23 +2435,23 @@ def test_list_backups_field_headers(): @pytest.mark.asyncio -async def test_list_backups_field_headers_async(): +async def test_list_snapshots_field_headers_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.ListBackupsRequest() + request = cloud_filestore_service.ListSnapshotsRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_filestore_service.ListBackupsResponse() + cloud_filestore_service.ListSnapshotsResponse() ) - await client.list_backups(request) + await client.list_snapshots(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2454,18 +2466,18 @@ async def test_list_backups_field_headers_async(): ) in kw["metadata"] -def test_list_backups_flattened(): +def test_list_snapshots_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_filestore_service.ListBackupsResponse() + call.return_value = cloud_filestore_service.ListSnapshotsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_backups( + client.list_snapshots( parent="parent_value", ) @@ -2478,7 +2490,7 @@ def test_list_backups_flattened(): assert arg == mock_val -def test_list_backups_flattened_error(): +def test_list_snapshots_flattened_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2486,29 +2498,29 @@ def test_list_backups_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_backups( - cloud_filestore_service.ListBackupsRequest(), + client.list_snapshots( + cloud_filestore_service.ListSnapshotsRequest(), parent="parent_value", ) @pytest.mark.asyncio -async def test_list_backups_flattened_async(): +async def test_list_snapshots_flattened_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_filestore_service.ListBackupsResponse() + call.return_value = cloud_filestore_service.ListSnapshotsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_filestore_service.ListBackupsResponse() + cloud_filestore_service.ListSnapshotsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_backups( + response = await client.list_snapshots( parent="parent_value", ) @@ -2522,7 +2534,7 @@ async def test_list_backups_flattened_async(): @pytest.mark.asyncio -async def test_list_backups_flattened_error_async(): +async def test_list_snapshots_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2530,44 +2542,44 @@ async def test_list_backups_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_backups( - cloud_filestore_service.ListBackupsRequest(), + await client.list_snapshots( + cloud_filestore_service.ListSnapshotsRequest(), parent="parent_value", ) -def test_list_backups_pager(transport_name: str = "grpc"): +def test_list_snapshots_pager(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( 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_backups), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], next_page_token="abc", ), - cloud_filestore_service.ListBackupsResponse( - backups=[], + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[], next_page_token="def", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), ], next_page_token="ghi", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], ), RuntimeError, @@ -2577,95 +2589,95 @@ def test_list_backups_pager(transport_name: str = "grpc"): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.list_backups(request={}) + pager = client.list_snapshots(request={}) assert pager._metadata == metadata results = list(pager) assert len(results) == 6 - assert all(isinstance(i, cloud_filestore_service.Backup) for i in results) + assert all(isinstance(i, cloud_filestore_service.Snapshot) for i in results) -def test_list_backups_pages(transport_name: str = "grpc"): +def test_list_snapshots_pages(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( 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_backups), "__call__") as call: + with mock.patch.object(type(client.transport.list_snapshots), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], next_page_token="abc", ), - cloud_filestore_service.ListBackupsResponse( - backups=[], + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[], next_page_token="def", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), ], next_page_token="ghi", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], ), RuntimeError, ) - pages = list(client.list_backups(request={}).pages) + pages = list(client.list_snapshots(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_backups_async_pager(): +async def test_list_snapshots_async_pager(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_backups), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_snapshots), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], next_page_token="abc", ), - cloud_filestore_service.ListBackupsResponse( - backups=[], + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[], next_page_token="def", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), ], next_page_token="ghi", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], ), RuntimeError, ) - async_pager = await client.list_backups( + async_pager = await client.list_snapshots( request={}, ) assert async_pager.next_page_token == "abc" @@ -2674,50 +2686,50 @@ async def test_list_backups_async_pager(): responses.append(response) assert len(responses) == 6 - assert all(isinstance(i, cloud_filestore_service.Backup) for i in responses) + assert all(isinstance(i, cloud_filestore_service.Snapshot) for i in responses) @pytest.mark.asyncio -async def test_list_backups_async_pages(): +async def test_list_snapshots_async_pages(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_backups), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_snapshots), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], next_page_token="abc", ), - cloud_filestore_service.ListBackupsResponse( - backups=[], + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[], next_page_token="def", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), ], next_page_token="ghi", ), - cloud_filestore_service.ListBackupsResponse( - backups=[ - cloud_filestore_service.Backup(), - cloud_filestore_service.Backup(), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), ], ), RuntimeError, ) pages = [] async for page_ in ( - await client.list_backups(request={}) + await client.list_snapshots(request={}) ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): @@ -2727,11 +2739,11 @@ async def test_list_backups_async_pages(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.GetBackupRequest, + cloud_filestore_service.GetSnapshotRequest, dict, ], ) -def test_get_backup(request_type, transport: str = "grpc"): +def test_get_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2742,42 +2754,30 @@ def test_get_backup(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_filestore_service.Backup( + call.return_value = cloud_filestore_service.Snapshot( name="name_value", description="description_value", - state=cloud_filestore_service.Backup.State.CREATING, - capacity_gb=1142, - storage_bytes=1403, - source_instance="source_instance_value", - source_file_share="source_file_share_value", - source_instance_tier=cloud_filestore_service.Instance.Tier.STANDARD, - download_bytes=1502, + state=cloud_filestore_service.Snapshot.State.CREATING, + filesystem_used_bytes=2267, ) - response = client.get_backup(request) + response = client.get_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.GetBackupRequest() + assert args[0] == cloud_filestore_service.GetSnapshotRequest() # Establish that the response is the type that we expect. - assert isinstance(response, cloud_filestore_service.Backup) + assert isinstance(response, cloud_filestore_service.Snapshot) assert response.name == "name_value" assert response.description == "description_value" - assert response.state == cloud_filestore_service.Backup.State.CREATING - assert response.capacity_gb == 1142 - assert response.storage_bytes == 1403 - assert response.source_instance == "source_instance_value" - assert response.source_file_share == "source_file_share_value" - assert ( - response.source_instance_tier == cloud_filestore_service.Instance.Tier.STANDARD - ) - assert response.download_bytes == 1502 + assert response.state == cloud_filestore_service.Snapshot.State.CREATING + assert response.filesystem_used_bytes == 2267 -def test_get_backup_empty_call(): +def test_get_snapshot_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 = CloudFilestoreManagerClient( @@ -2786,17 +2786,17 @@ def test_get_backup_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_backup), "__call__") as call: - client.get_backup() + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: + client.get_snapshot() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.GetBackupRequest() + assert args[0] == cloud_filestore_service.GetSnapshotRequest() @pytest.mark.asyncio -async def test_get_backup_async( +async def test_get_snapshot_async( transport: str = "grpc_asyncio", - request_type=cloud_filestore_service.GetBackupRequest, + request_type=cloud_filestore_service.GetSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2808,63 +2808,51 @@ async def test_get_backup_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_filestore_service.Backup( + cloud_filestore_service.Snapshot( name="name_value", description="description_value", - state=cloud_filestore_service.Backup.State.CREATING, - capacity_gb=1142, - storage_bytes=1403, - source_instance="source_instance_value", - source_file_share="source_file_share_value", - source_instance_tier=cloud_filestore_service.Instance.Tier.STANDARD, - download_bytes=1502, + state=cloud_filestore_service.Snapshot.State.CREATING, + filesystem_used_bytes=2267, ) ) - response = await client.get_backup(request) + response = await client.get_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.GetBackupRequest() + assert args[0] == cloud_filestore_service.GetSnapshotRequest() # Establish that the response is the type that we expect. - assert isinstance(response, cloud_filestore_service.Backup) + assert isinstance(response, cloud_filestore_service.Snapshot) assert response.name == "name_value" assert response.description == "description_value" - assert response.state == cloud_filestore_service.Backup.State.CREATING - assert response.capacity_gb == 1142 - assert response.storage_bytes == 1403 - assert response.source_instance == "source_instance_value" - assert response.source_file_share == "source_file_share_value" - assert ( - response.source_instance_tier == cloud_filestore_service.Instance.Tier.STANDARD - ) - assert response.download_bytes == 1502 + assert response.state == cloud_filestore_service.Snapshot.State.CREATING + assert response.filesystem_used_bytes == 2267 @pytest.mark.asyncio -async def test_get_backup_async_from_dict(): - await test_get_backup_async(request_type=dict) +async def test_get_snapshot_async_from_dict(): + await test_get_snapshot_async(request_type=dict) -def test_get_backup_field_headers(): +def test_get_snapshot_field_headers(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.GetBackupRequest() + request = cloud_filestore_service.GetSnapshotRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_backup), "__call__") as call: - call.return_value = cloud_filestore_service.Backup() - client.get_backup(request) + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: + call.return_value = cloud_filestore_service.Snapshot() + client.get_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2880,23 +2868,23 @@ def test_get_backup_field_headers(): @pytest.mark.asyncio -async def test_get_backup_field_headers_async(): +async def test_get_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.GetBackupRequest() + request = cloud_filestore_service.GetSnapshotRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_filestore_service.Backup() + cloud_filestore_service.Snapshot() ) - await client.get_backup(request) + await client.get_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2911,18 +2899,18 @@ async def test_get_backup_field_headers_async(): ) in kw["metadata"] -def test_get_backup_flattened(): +def test_get_snapshot_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_filestore_service.Backup() + call.return_value = cloud_filestore_service.Snapshot() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_backup( + client.get_snapshot( name="name_value", ) @@ -2935,7 +2923,7 @@ def test_get_backup_flattened(): assert arg == mock_val -def test_get_backup_flattened_error(): +def test_get_snapshot_flattened_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2943,29 +2931,29 @@ def test_get_backup_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_backup( - cloud_filestore_service.GetBackupRequest(), + client.get_snapshot( + cloud_filestore_service.GetSnapshotRequest(), name="name_value", ) @pytest.mark.asyncio -async def test_get_backup_flattened_async(): +async def test_get_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + with mock.patch.object(type(client.transport.get_snapshot), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = cloud_filestore_service.Backup() + call.return_value = cloud_filestore_service.Snapshot() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cloud_filestore_service.Backup() + cloud_filestore_service.Snapshot() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_backup( + response = await client.get_snapshot( name="name_value", ) @@ -2979,7 +2967,7 @@ async def test_get_backup_flattened_async(): @pytest.mark.asyncio -async def test_get_backup_flattened_error_async(): +async def test_get_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2987,8 +2975,8 @@ async def test_get_backup_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_backup( - cloud_filestore_service.GetBackupRequest(), + await client.get_snapshot( + cloud_filestore_service.GetSnapshotRequest(), name="name_value", ) @@ -2996,11 +2984,11 @@ async def test_get_backup_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.CreateBackupRequest, + cloud_filestore_service.CreateSnapshotRequest, dict, ], ) -def test_create_backup(request_type, transport: str = "grpc"): +def test_create_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3011,21 +2999,21 @@ def test_create_backup(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_backup(request) + response = client.create_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.CreateBackupRequest() + assert args[0] == cloud_filestore_service.CreateSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_create_backup_empty_call(): +def test_create_snapshot_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 = CloudFilestoreManagerClient( @@ -3034,17 +3022,17 @@ def test_create_backup_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_backup), "__call__") as call: - client.create_backup() + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: + client.create_snapshot() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.CreateBackupRequest() + assert args[0] == cloud_filestore_service.CreateSnapshotRequest() @pytest.mark.asyncio -async def test_create_backup_async( +async def test_create_snapshot_async( transport: str = "grpc_asyncio", - request_type=cloud_filestore_service.CreateBackupRequest, + request_type=cloud_filestore_service.CreateSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3056,42 +3044,42 @@ async def test_create_backup_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__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_backup(request) + response = await client.create_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.CreateBackupRequest() + assert args[0] == cloud_filestore_service.CreateSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_create_backup_async_from_dict(): - await test_create_backup_async(request_type=dict) +async def test_create_snapshot_async_from_dict(): + await test_create_snapshot_async(request_type=dict) -def test_create_backup_field_headers(): +def test_create_snapshot_field_headers(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.CreateBackupRequest() + request = cloud_filestore_service.CreateSnapshotRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_backup(request) + client.create_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3107,23 +3095,23 @@ def test_create_backup_field_headers(): @pytest.mark.asyncio -async def test_create_backup_field_headers_async(): +async def test_create_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.CreateBackupRequest() + request = cloud_filestore_service.CreateSnapshotRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_backup(request) + await client.create_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3138,21 +3126,21 @@ async def test_create_backup_field_headers_async(): ) in kw["metadata"] -def test_create_backup_flattened(): +def test_create_snapshot_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__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_backup( + client.create_snapshot( parent="parent_value", - backup=cloud_filestore_service.Backup(name="name_value"), - backup_id="backup_id_value", + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + snapshot_id="snapshot_id_value", ) # Establish that the underlying call was made with the expected @@ -3162,15 +3150,15 @@ def test_create_backup_flattened(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val - arg = args[0].backup - mock_val = cloud_filestore_service.Backup(name="name_value") + arg = args[0].snapshot + mock_val = cloud_filestore_service.Snapshot(name="name_value") assert arg == mock_val - arg = args[0].backup_id - mock_val = "backup_id_value" + arg = args[0].snapshot_id + mock_val = "snapshot_id_value" assert arg == mock_val -def test_create_backup_flattened_error(): +def test_create_snapshot_flattened_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3178,22 +3166,22 @@ def test_create_backup_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_backup( - cloud_filestore_service.CreateBackupRequest(), + client.create_snapshot( + cloud_filestore_service.CreateSnapshotRequest(), parent="parent_value", - backup=cloud_filestore_service.Backup(name="name_value"), - backup_id="backup_id_value", + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + snapshot_id="snapshot_id_value", ) @pytest.mark.asyncio -async def test_create_backup_flattened_async(): +async def test_create_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + with mock.patch.object(type(client.transport.create_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3202,10 +3190,10 @@ async def test_create_backup_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_backup( + response = await client.create_snapshot( parent="parent_value", - backup=cloud_filestore_service.Backup(name="name_value"), - backup_id="backup_id_value", + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + snapshot_id="snapshot_id_value", ) # Establish that the underlying call was made with the expected @@ -3215,16 +3203,16 @@ async def test_create_backup_flattened_async(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val - arg = args[0].backup - mock_val = cloud_filestore_service.Backup(name="name_value") + arg = args[0].snapshot + mock_val = cloud_filestore_service.Snapshot(name="name_value") assert arg == mock_val - arg = args[0].backup_id - mock_val = "backup_id_value" + arg = args[0].snapshot_id + mock_val = "snapshot_id_value" assert arg == mock_val @pytest.mark.asyncio -async def test_create_backup_flattened_error_async(): +async def test_create_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3232,22 +3220,22 @@ async def test_create_backup_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.create_backup( - cloud_filestore_service.CreateBackupRequest(), + await client.create_snapshot( + cloud_filestore_service.CreateSnapshotRequest(), parent="parent_value", - backup=cloud_filestore_service.Backup(name="name_value"), - backup_id="backup_id_value", + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + snapshot_id="snapshot_id_value", ) @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.DeleteBackupRequest, + cloud_filestore_service.DeleteSnapshotRequest, dict, ], ) -def test_delete_backup(request_type, transport: str = "grpc"): +def test_delete_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3258,21 +3246,21 @@ def test_delete_backup(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_backup(request) + response = client.delete_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.DeleteBackupRequest() + assert args[0] == cloud_filestore_service.DeleteSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_delete_backup_empty_call(): +def test_delete_snapshot_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 = CloudFilestoreManagerClient( @@ -3281,17 +3269,17 @@ def test_delete_backup_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: - client.delete_backup() + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: + client.delete_snapshot() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.DeleteBackupRequest() + assert args[0] == cloud_filestore_service.DeleteSnapshotRequest() @pytest.mark.asyncio -async def test_delete_backup_async( +async def test_delete_snapshot_async( transport: str = "grpc_asyncio", - request_type=cloud_filestore_service.DeleteBackupRequest, + request_type=cloud_filestore_service.DeleteSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3303,42 +3291,42 @@ async def test_delete_backup_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__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.delete_backup(request) + response = await client.delete_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.DeleteBackupRequest() + assert args[0] == cloud_filestore_service.DeleteSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_delete_backup_async_from_dict(): - await test_delete_backup_async(request_type=dict) +async def test_delete_snapshot_async_from_dict(): + await test_delete_snapshot_async(request_type=dict) -def test_delete_backup_field_headers(): +def test_delete_snapshot_field_headers(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.DeleteBackupRequest() + request = cloud_filestore_service.DeleteSnapshotRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_backup(request) + client.delete_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3354,23 +3342,23 @@ def test_delete_backup_field_headers(): @pytest.mark.asyncio -async def test_delete_backup_field_headers_async(): +async def test_delete_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.DeleteBackupRequest() + request = cloud_filestore_service.DeleteSnapshotRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_backup(request) + await client.delete_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3385,18 +3373,18 @@ async def test_delete_backup_field_headers_async(): ) in kw["metadata"] -def test_delete_backup_flattened(): +def test_delete_snapshot_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__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.delete_backup( + client.delete_snapshot( name="name_value", ) @@ -3409,7 +3397,7 @@ def test_delete_backup_flattened(): assert arg == mock_val -def test_delete_backup_flattened_error(): +def test_delete_snapshot_flattened_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3417,20 +3405,20 @@ def test_delete_backup_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_backup( - cloud_filestore_service.DeleteBackupRequest(), + client.delete_snapshot( + cloud_filestore_service.DeleteSnapshotRequest(), name="name_value", ) @pytest.mark.asyncio -async def test_delete_backup_flattened_async(): +async def test_delete_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + with mock.patch.object(type(client.transport.delete_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3439,7 +3427,7 @@ async def test_delete_backup_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_backup( + response = await client.delete_snapshot( name="name_value", ) @@ -3453,7 +3441,7 @@ async def test_delete_backup_flattened_async(): @pytest.mark.asyncio -async def test_delete_backup_flattened_error_async(): +async def test_delete_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3461,8 +3449,8 @@ async def test_delete_backup_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_backup( - cloud_filestore_service.DeleteBackupRequest(), + await client.delete_snapshot( + cloud_filestore_service.DeleteSnapshotRequest(), name="name_value", ) @@ -3470,11 +3458,11 @@ async def test_delete_backup_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.UpdateBackupRequest, + cloud_filestore_service.UpdateSnapshotRequest, dict, ], ) -def test_update_backup(request_type, transport: str = "grpc"): +def test_update_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3485,21 +3473,21 @@ def test_update_backup(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_backup(request) + response = client.update_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.UpdateBackupRequest() + assert args[0] == cloud_filestore_service.UpdateSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_update_backup_empty_call(): +def test_update_snapshot_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 = CloudFilestoreManagerClient( @@ -3508,17 +3496,17 @@ def test_update_backup_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_backup), "__call__") as call: - client.update_backup() + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: + client.update_snapshot() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.UpdateBackupRequest() + assert args[0] == cloud_filestore_service.UpdateSnapshotRequest() @pytest.mark.asyncio -async def test_update_backup_async( +async def test_update_snapshot_async( transport: str = "grpc_asyncio", - request_type=cloud_filestore_service.UpdateBackupRequest, + request_type=cloud_filestore_service.UpdateSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3530,42 +3518,42 @@ async def test_update_backup_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__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_backup(request) + response = await client.update_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == cloud_filestore_service.UpdateBackupRequest() + assert args[0] == cloud_filestore_service.UpdateSnapshotRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_update_backup_async_from_dict(): - await test_update_backup_async(request_type=dict) +async def test_update_snapshot_async_from_dict(): + await test_update_snapshot_async(request_type=dict) -def test_update_backup_field_headers(): +def test_update_snapshot_field_headers(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.UpdateBackupRequest() + request = cloud_filestore_service.UpdateSnapshotRequest() - request.backup.name = "name_value" + request.snapshot.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_backup(request) + client.update_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3576,28 +3564,28 @@ def test_update_backup_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "backup.name=name_value", + "snapshot.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_backup_field_headers_async(): +async def test_update_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = cloud_filestore_service.UpdateBackupRequest() + request = cloud_filestore_service.UpdateSnapshotRequest() - request.backup.name = "name_value" + request.snapshot.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_backup(request) + await client.update_snapshot(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3608,23 +3596,23 @@ async def test_update_backup_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "backup.name=name_value", + "snapshot.name=name_value", ) in kw["metadata"] -def test_update_backup_flattened(): +def test_update_snapshot_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__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_backup( - backup=cloud_filestore_service.Backup(name="name_value"), + client.update_snapshot( + snapshot=cloud_filestore_service.Snapshot(name="name_value"), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -3632,15 +3620,15 @@ def test_update_backup_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - arg = args[0].backup - mock_val = cloud_filestore_service.Backup(name="name_value") + arg = args[0].snapshot + mock_val = cloud_filestore_service.Snapshot(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_backup_flattened_error(): +def test_update_snapshot_flattened_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3648,21 +3636,21 @@ def test_update_backup_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_backup( - cloud_filestore_service.UpdateBackupRequest(), - backup=cloud_filestore_service.Backup(name="name_value"), + client.update_snapshot( + cloud_filestore_service.UpdateSnapshotRequest(), + snapshot=cloud_filestore_service.Snapshot(name="name_value"), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_update_backup_flattened_async(): +async def test_update_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + with mock.patch.object(type(client.transport.update_snapshot), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3671,8 +3659,8 @@ async def test_update_backup_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_backup( - backup=cloud_filestore_service.Backup(name="name_value"), + response = await client.update_snapshot( + snapshot=cloud_filestore_service.Snapshot(name="name_value"), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -3680,8 +3668,8 @@ async def test_update_backup_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - arg = args[0].backup - mock_val = cloud_filestore_service.Backup(name="name_value") + arg = args[0].snapshot + mock_val = cloud_filestore_service.Snapshot(name="name_value") assert arg == mock_val arg = args[0].update_mask mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) @@ -3689,7 +3677,7 @@ async def test_update_backup_flattened_async(): @pytest.mark.asyncio -async def test_update_backup_flattened_error_async(): +async def test_update_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3697,9 +3685,9 @@ async def test_update_backup_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_backup( - cloud_filestore_service.UpdateBackupRequest(), - backup=cloud_filestore_service.Backup(name="name_value"), + await client.update_snapshot( + cloud_filestore_service.UpdateSnapshotRequest(), + snapshot=cloud_filestore_service.Snapshot(name="name_value"), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -3707,130 +3695,1539 @@ async def test_update_backup_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.ListInstancesRequest, + cloud_filestore_service.ListBackupsRequest, dict, ], ) -def test_list_instances_rest(request_type): +def test_list_backups(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} - request = request_type(**request_init) + # 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 http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = cloud_filestore_service.ListInstancesResponse( + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_filestore_service.ListBackupsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) + response = client.list_backups(request) - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = cloud_filestore_service.ListInstancesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - response = client.list_instances(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.ListBackupsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstancesPager) + assert isinstance(response, pagers.ListBackupsPager) assert response.next_page_token == "next_page_token_value" assert response.unreachable == ["unreachable_value"] -def test_list_instances_rest_required_fields( - request_type=cloud_filestore_service.ListInstancesRequest, -): - transport_class = transports.CloudFilestoreManagerRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) +def test_list_backups_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 = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) - # verify fields with default values are dropped + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + client.list_backups() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.ListBackupsRequest() - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).list_instances._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - # verify required fields with default values are now present +@pytest.mark.asyncio +async def test_list_backups_async( + transport: str = "grpc_asyncio", + request_type=cloud_filestore_service.ListBackupsRequest, +): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - jsonified_request["parent"] = "parent_value" + # 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() - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).list_instances._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "filter", - "order_by", - "page_size", - "page_token", + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_filestore_service.ListBackupsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) ) - ) - jsonified_request.update(unset_fields) + response = await client.list_backups(request) - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.ListBackupsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBackupsAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.asyncio +async def test_list_backups_async_from_dict(): + await test_list_backups_async(request_type=dict) + +def test_list_backups_field_headers(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - request = request_type(**request_init) - # Designate an appropriate value for the returned response. - return_value = cloud_filestore_service.ListInstancesResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "get", - "query_params": pb_request, - } - transcode.return_value = transcode_result + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.ListBackupsRequest() - response_value = Response() - response_value.status_code = 200 + request.parent = "parent_value" - pb_return_value = cloud_filestore_service.ListInstancesResponse.pb( - return_value - ) - json_return_value = json_format.MessageToJson(pb_return_value) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + call.return_value = cloud_filestore_service.ListBackupsResponse() + client.list_backups(request) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - response = client.list_instances(request) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert expected_params == actual_params + +@pytest.mark.asyncio +async def test_list_backups_field_headers_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.ListBackupsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_filestore_service.ListBackupsResponse() + ) + await client.list_backups(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_backups_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_filestore_service.ListBackupsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_backups( + 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_backups_flattened_error(): + client = CloudFilestoreManagerClient( + 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_backups( + cloud_filestore_service.ListBackupsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_backups_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_backups), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_filestore_service.ListBackupsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_filestore_service.ListBackupsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_backups( + 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_backups_flattened_error_async(): + client = CloudFilestoreManagerAsyncClient( + 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_backups( + cloud_filestore_service.ListBackupsRequest(), + parent="parent_value", + ) + + +def test_list_backups_pager(transport_name: str = "grpc"): + client = CloudFilestoreManagerClient( + 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_backups), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + next_page_token="abc", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[], + next_page_token="def", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + ], + next_page_token="ghi", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_backups(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, cloud_filestore_service.Backup) for i in results) + + +def test_list_backups_pages(transport_name: str = "grpc"): + client = CloudFilestoreManagerClient( + 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_backups), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + next_page_token="abc", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[], + next_page_token="def", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + ], + next_page_token="ghi", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + ), + RuntimeError, + ) + pages = list(client.list_backups(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_backups_async_pager(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + next_page_token="abc", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[], + next_page_token="def", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + ], + next_page_token="ghi", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_backups( + 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, cloud_filestore_service.Backup) for i in responses) + + +@pytest.mark.asyncio +async def test_list_backups_async_pages(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + next_page_token="abc", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[], + next_page_token="def", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + ], + next_page_token="ghi", + ), + cloud_filestore_service.ListBackupsResponse( + backups=[ + cloud_filestore_service.Backup(), + cloud_filestore_service.Backup(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_backups(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", + [ + cloud_filestore_service.GetBackupRequest, + dict, + ], +) +def test_get_backup(request_type, transport: str = "grpc"): + client = CloudFilestoreManagerClient( + 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.get_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_filestore_service.Backup( + name="name_value", + description="description_value", + state=cloud_filestore_service.Backup.State.CREATING, + capacity_gb=1142, + storage_bytes=1403, + source_instance="source_instance_value", + source_file_share="source_file_share_value", + source_instance_tier=cloud_filestore_service.Instance.Tier.STANDARD, + download_bytes=1502, + kms_key="kms_key_value", + ) + response = client.get_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.GetBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, cloud_filestore_service.Backup) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.state == cloud_filestore_service.Backup.State.CREATING + assert response.capacity_gb == 1142 + assert response.storage_bytes == 1403 + assert response.source_instance == "source_instance_value" + assert response.source_file_share == "source_file_share_value" + assert ( + response.source_instance_tier == cloud_filestore_service.Instance.Tier.STANDARD + ) + assert response.download_bytes == 1502 + assert response.kms_key == "kms_key_value" + + +def test_get_backup_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 = CloudFilestoreManagerClient( + 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.get_backup), "__call__") as call: + client.get_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.GetBackupRequest() + + +@pytest.mark.asyncio +async def test_get_backup_async( + transport: str = "grpc_asyncio", + request_type=cloud_filestore_service.GetBackupRequest, +): + client = CloudFilestoreManagerAsyncClient( + 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.get_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_filestore_service.Backup( + name="name_value", + description="description_value", + state=cloud_filestore_service.Backup.State.CREATING, + capacity_gb=1142, + storage_bytes=1403, + source_instance="source_instance_value", + source_file_share="source_file_share_value", + source_instance_tier=cloud_filestore_service.Instance.Tier.STANDARD, + download_bytes=1502, + kms_key="kms_key_value", + ) + ) + response = await client.get_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.GetBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, cloud_filestore_service.Backup) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.state == cloud_filestore_service.Backup.State.CREATING + assert response.capacity_gb == 1142 + assert response.storage_bytes == 1403 + assert response.source_instance == "source_instance_value" + assert response.source_file_share == "source_file_share_value" + assert ( + response.source_instance_tier == cloud_filestore_service.Instance.Tier.STANDARD + ) + assert response.download_bytes == 1502 + assert response.kms_key == "kms_key_value" + + +@pytest.mark.asyncio +async def test_get_backup_async_from_dict(): + await test_get_backup_async(request_type=dict) + + +def test_get_backup_field_headers(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.GetBackupRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + call.return_value = cloud_filestore_service.Backup() + client.get_backup(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_get_backup_field_headers_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.GetBackupRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_filestore_service.Backup() + ) + await client.get_backup(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_get_backup_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_filestore_service.Backup() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_backup( + 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_get_backup_flattened_error(): + client = CloudFilestoreManagerClient( + 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.get_backup( + cloud_filestore_service.GetBackupRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_backup_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_filestore_service.Backup() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_filestore_service.Backup() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_backup( + 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_get_backup_flattened_error_async(): + client = CloudFilestoreManagerAsyncClient( + 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.get_backup( + cloud_filestore_service.GetBackupRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.CreateBackupRequest, + dict, + ], +) +def test_create_backup(request_type, transport: str = "grpc"): + client = CloudFilestoreManagerClient( + 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_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.CreateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_backup_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 = CloudFilestoreManagerClient( + 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_backup), "__call__") as call: + client.create_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.CreateBackupRequest() + + +@pytest.mark.asyncio +async def test_create_backup_async( + transport: str = "grpc_asyncio", + request_type=cloud_filestore_service.CreateBackupRequest, +): + client = CloudFilestoreManagerAsyncClient( + 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_backup), "__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_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.CreateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_backup_async_from_dict(): + await test_create_backup_async(request_type=dict) + + +def test_create_backup_field_headers(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.CreateBackupRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_backup(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_backup_field_headers_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.CreateBackupRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_backup), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_backup(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_backup_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_backup), "__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_backup( + parent="parent_value", + backup=cloud_filestore_service.Backup(name="name_value"), + backup_id="backup_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].backup + mock_val = cloud_filestore_service.Backup(name="name_value") + assert arg == mock_val + arg = args[0].backup_id + mock_val = "backup_id_value" + assert arg == mock_val + + +def test_create_backup_flattened_error(): + client = CloudFilestoreManagerClient( + 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_backup( + cloud_filestore_service.CreateBackupRequest(), + parent="parent_value", + backup=cloud_filestore_service.Backup(name="name_value"), + backup_id="backup_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_backup_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_backup), "__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_backup( + parent="parent_value", + backup=cloud_filestore_service.Backup(name="name_value"), + backup_id="backup_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].backup + mock_val = cloud_filestore_service.Backup(name="name_value") + assert arg == mock_val + arg = args[0].backup_id + mock_val = "backup_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_backup_flattened_error_async(): + client = CloudFilestoreManagerAsyncClient( + 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_backup( + cloud_filestore_service.CreateBackupRequest(), + parent="parent_value", + backup=cloud_filestore_service.Backup(name="name_value"), + backup_id="backup_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.DeleteBackupRequest, + dict, + ], +) +def test_delete_backup(request_type, transport: str = "grpc"): + client = CloudFilestoreManagerClient( + 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_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.DeleteBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_backup_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 = CloudFilestoreManagerClient( + 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_backup), "__call__") as call: + client.delete_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.DeleteBackupRequest() + + +@pytest.mark.asyncio +async def test_delete_backup_async( + transport: str = "grpc_asyncio", + request_type=cloud_filestore_service.DeleteBackupRequest, +): + client = CloudFilestoreManagerAsyncClient( + 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_backup), "__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.delete_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.DeleteBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_backup_async_from_dict(): + await test_delete_backup_async(request_type=dict) + + +def test_delete_backup_field_headers(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.DeleteBackupRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_backup(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_backup_field_headers_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.DeleteBackupRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_backup(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_backup_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_backup), "__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.delete_backup( + 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_backup_flattened_error(): + client = CloudFilestoreManagerClient( + 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_backup( + cloud_filestore_service.DeleteBackupRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_backup_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_backup), "__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.delete_backup( + 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_backup_flattened_error_async(): + client = CloudFilestoreManagerAsyncClient( + 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_backup( + cloud_filestore_service.DeleteBackupRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.UpdateBackupRequest, + dict, + ], +) +def test_update_backup(request_type, transport: str = "grpc"): + client = CloudFilestoreManagerClient( + 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_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.UpdateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_backup_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 = CloudFilestoreManagerClient( + 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_backup), "__call__") as call: + client.update_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.UpdateBackupRequest() + + +@pytest.mark.asyncio +async def test_update_backup_async( + transport: str = "grpc_asyncio", + request_type=cloud_filestore_service.UpdateBackupRequest, +): + client = CloudFilestoreManagerAsyncClient( + 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_backup), "__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_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_filestore_service.UpdateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_backup_async_from_dict(): + await test_update_backup_async(request_type=dict) + + +def test_update_backup_field_headers(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.UpdateBackupRequest() + + request.backup.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_backup(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", + "backup.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_backup_field_headers_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_filestore_service.UpdateBackupRequest() + + request.backup.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_backup), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_backup(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", + "backup.name=name_value", + ) in kw["metadata"] + + +def test_update_backup_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_backup), "__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_backup( + backup=cloud_filestore_service.Backup(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].backup + mock_val = cloud_filestore_service.Backup(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_backup_flattened_error(): + client = CloudFilestoreManagerClient( + 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_backup( + cloud_filestore_service.UpdateBackupRequest(), + backup=cloud_filestore_service.Backup(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_backup_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_backup), "__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_backup( + backup=cloud_filestore_service.Backup(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].backup + mock_val = cloud_filestore_service.Backup(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_backup_flattened_error_async(): + client = CloudFilestoreManagerAsyncClient( + 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_backup( + cloud_filestore_service.UpdateBackupRequest(), + backup=cloud_filestore_service.Backup(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.ListInstancesRequest, + dict, + ], +) +def test_list_instances_rest(request_type): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = cloud_filestore_service.ListInstancesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = cloud_filestore_service.ListInstancesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.list_instances(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstancesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +def test_list_instances_rest_required_fields( + request_type=cloud_filestore_service.ListInstancesRequest, +): + transport_class = transports.CloudFilestoreManagerRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_instances._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_instances._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = cloud_filestore_service.ListInstancesResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = cloud_filestore_service.ListInstancesResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.list_instances(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params def test_list_instances_rest_unset_required_fields(): @@ -3838,22 +5235,1272 @@ def test_list_instances_rest_unset_required_fields(): credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_instances._get_unset_required_fields({}) + unset_fields = transport.list_instances._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_instances_rest_interceptors(null_interceptor): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.CloudFilestoreManagerRestInterceptor(), + ) + client = CloudFilestoreManagerClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_list_instances" + ) as post, mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_list_instances" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = cloud_filestore_service.ListInstancesRequest.pb( + cloud_filestore_service.ListInstancesRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = ( + cloud_filestore_service.ListInstancesResponse.to_json( + cloud_filestore_service.ListInstancesResponse() + ) + ) + + request = cloud_filestore_service.ListInstancesRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = cloud_filestore_service.ListInstancesResponse() + + client.list_instances( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_instances_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.ListInstancesRequest +): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_instances(request) + + +def test_list_instances_rest_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = cloud_filestore_service.ListInstancesResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = cloud_filestore_service.ListInstancesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.list_instances(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/instances" % client.transport._host, + args[1], + ) + + +def test_list_instances_rest_flattened_error(transport: str = "rest"): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_instances( + cloud_filestore_service.ListInstancesRequest(), + parent="parent_value", + ) + + +def test_list_instances_rest_pager(transport: str = "rest"): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + cloud_filestore_service.ListInstancesResponse( + instances=[ + cloud_filestore_service.Instance(), + cloud_filestore_service.Instance(), + cloud_filestore_service.Instance(), + ], + next_page_token="abc", + ), + cloud_filestore_service.ListInstancesResponse( + instances=[], + next_page_token="def", + ), + cloud_filestore_service.ListInstancesResponse( + instances=[ + cloud_filestore_service.Instance(), + ], + next_page_token="ghi", + ), + cloud_filestore_service.ListInstancesResponse( + instances=[ + cloud_filestore_service.Instance(), + cloud_filestore_service.Instance(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + cloud_filestore_service.ListInstancesResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_instances(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, cloud_filestore_service.Instance) for i in results) + + pages = list(client.list_instances(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.GetInstanceRequest, + dict, + ], +) +def test_get_instance_rest(request_type): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = cloud_filestore_service.Instance( + name="name_value", + description="description_value", + state=cloud_filestore_service.Instance.State.CREATING, + status_message="status_message_value", + tier=cloud_filestore_service.Instance.Tier.STANDARD, + etag="etag_value", + kms_key_name="kms_key_name_value", + suspension_reasons=[ + cloud_filestore_service.Instance.SuspensionReason.KMS_KEY_ISSUE + ], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = cloud_filestore_service.Instance.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.get_instance(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, cloud_filestore_service.Instance) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.state == cloud_filestore_service.Instance.State.CREATING + assert response.status_message == "status_message_value" + assert response.tier == cloud_filestore_service.Instance.Tier.STANDARD + assert response.etag == "etag_value" + assert response.kms_key_name == "kms_key_name_value" + assert response.suspension_reasons == [ + cloud_filestore_service.Instance.SuspensionReason.KMS_KEY_ISSUE + ] + + +def test_get_instance_rest_required_fields( + request_type=cloud_filestore_service.GetInstanceRequest, +): + transport_class = transports.CloudFilestoreManagerRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = cloud_filestore_service.Instance() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = cloud_filestore_service.Instance.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.get_instance(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_instance_rest_unset_required_fields(): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_instance._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_instance_rest_interceptors(null_interceptor): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.CloudFilestoreManagerRestInterceptor(), + ) + client = CloudFilestoreManagerClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_get_instance" + ) as post, mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_get_instance" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = cloud_filestore_service.GetInstanceRequest.pb( + cloud_filestore_service.GetInstanceRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = cloud_filestore_service.Instance.to_json( + cloud_filestore_service.Instance() + ) + + request = cloud_filestore_service.GetInstanceRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = cloud_filestore_service.Instance() + + client.get_instance( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_instance_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.GetInstanceRequest +): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_instance(request) + + +def test_get_instance_rest_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = cloud_filestore_service.Instance() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/instances/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = cloud_filestore_service.Instance.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.get_instance(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/instances/*}" % client.transport._host, + args[1], + ) + + +def test_get_instance_rest_flattened_error(transport: str = "rest"): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_instance( + cloud_filestore_service.GetInstanceRequest(), + name="name_value", + ) + + +def test_get_instance_rest_error(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.CreateInstanceRequest, + dict, + ], +) +def test_create_instance_rest(request_type): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["instance"] = { + "name": "name_value", + "description": "description_value", + "state": 1, + "status_message": "status_message_value", + "create_time": {"seconds": 751, "nanos": 543}, + "tier": 1, + "labels": {}, + "file_shares": [ + { + "name": "name_value", + "capacity_gb": 1142, + "source_backup": "source_backup_value", + "nfs_export_options": [ + { + "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], + "access_mode": 1, + "squash_mode": 1, + "anon_uid": 845, + "anon_gid": 831, + } + ], + } + ], + "networks": [ + { + "network": "network_value", + "modes": [1], + "reserved_ip_range": "reserved_ip_range_value", + "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], + "connect_mode": 1, + } + ], + "etag": "etag_value", + "satisfies_pzs": {"value": True}, + "kms_key_name": "kms_key_name_value", + "suspension_reasons": [1], + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.create_instance(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_create_instance_rest_required_fields( + request_type=cloud_filestore_service.CreateInstanceRequest, +): + transport_class = transports.CloudFilestoreManagerRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["instance_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + assert "instanceId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "instanceId" in jsonified_request + assert jsonified_request["instanceId"] == request_init["instance_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["instanceId"] = "instance_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_instance._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("instance_id",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "instanceId" in jsonified_request + assert jsonified_request["instanceId"] == "instance_id_value" + + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_instance(request) + + expected_params = [ + ( + "instanceId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_instance_rest_unset_required_fields(): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_instance._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("instanceId",)) + & set( + ( + "parent", + "instanceId", + "instance", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_instance_rest_interceptors(null_interceptor): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.CloudFilestoreManagerRestInterceptor(), + ) + client = CloudFilestoreManagerClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_create_instance" + ) as post, mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_create_instance" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = cloud_filestore_service.CreateInstanceRequest.pb( + cloud_filestore_service.CreateInstanceRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) + + request = cloud_filestore_service.CreateInstanceRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.create_instance( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_instance_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.CreateInstanceRequest +): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["instance"] = { + "name": "name_value", + "description": "description_value", + "state": 1, + "status_message": "status_message_value", + "create_time": {"seconds": 751, "nanos": 543}, + "tier": 1, + "labels": {}, + "file_shares": [ + { + "name": "name_value", + "capacity_gb": 1142, + "source_backup": "source_backup_value", + "nfs_export_options": [ + { + "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], + "access_mode": 1, + "squash_mode": 1, + "anon_uid": 845, + "anon_gid": 831, + } + ], + } + ], + "networks": [ + { + "network": "network_value", + "modes": [1], + "reserved_ip_range": "reserved_ip_range_value", + "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], + "connect_mode": 1, + } + ], + "etag": "etag_value", + "satisfies_pzs": {"value": True}, + "kms_key_name": "kms_key_name_value", + "suspension_reasons": [1], + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_instance(request) + + +def test_create_instance_rest_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + instance=cloud_filestore_service.Instance(name="name_value"), + instance_id="instance_id_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.create_instance(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/instances" % client.transport._host, + args[1], + ) + + +def test_create_instance_rest_flattened_error(transport: str = "rest"): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_instance( + cloud_filestore_service.CreateInstanceRequest(), + parent="parent_value", + instance=cloud_filestore_service.Instance(name="name_value"), + instance_id="instance_id_value", + ) + + +def test_create_instance_rest_error(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.UpdateInstanceRequest, + dict, + ], +) +def test_update_instance_rest(request_type): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = { + "instance": {"name": "projects/sample1/locations/sample2/instances/sample3"} + } + request_init["instance"] = { + "name": "projects/sample1/locations/sample2/instances/sample3", + "description": "description_value", + "state": 1, + "status_message": "status_message_value", + "create_time": {"seconds": 751, "nanos": 543}, + "tier": 1, + "labels": {}, + "file_shares": [ + { + "name": "name_value", + "capacity_gb": 1142, + "source_backup": "source_backup_value", + "nfs_export_options": [ + { + "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], + "access_mode": 1, + "squash_mode": 1, + "anon_uid": 845, + "anon_gid": 831, + } + ], + } + ], + "networks": [ + { + "network": "network_value", + "modes": [1], + "reserved_ip_range": "reserved_ip_range_value", + "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], + "connect_mode": 1, + } + ], + "etag": "etag_value", + "satisfies_pzs": {"value": True}, + "kms_key_name": "kms_key_name_value", + "suspension_reasons": [1], + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.update_instance(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_instance_rest_interceptors(null_interceptor): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.CloudFilestoreManagerRestInterceptor(), + ) + client = CloudFilestoreManagerClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_update_instance" + ) as post, mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_update_instance" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = cloud_filestore_service.UpdateInstanceRequest.pb( + cloud_filestore_service.UpdateInstanceRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) + + request = cloud_filestore_service.UpdateInstanceRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.update_instance( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_instance_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.UpdateInstanceRequest +): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = { + "instance": {"name": "projects/sample1/locations/sample2/instances/sample3"} + } + request_init["instance"] = { + "name": "projects/sample1/locations/sample2/instances/sample3", + "description": "description_value", + "state": 1, + "status_message": "status_message_value", + "create_time": {"seconds": 751, "nanos": 543}, + "tier": 1, + "labels": {}, + "file_shares": [ + { + "name": "name_value", + "capacity_gb": 1142, + "source_backup": "source_backup_value", + "nfs_export_options": [ + { + "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], + "access_mode": 1, + "squash_mode": 1, + "anon_uid": 845, + "anon_gid": 831, + } + ], + } + ], + "networks": [ + { + "network": "network_value", + "modes": [1], + "reserved_ip_range": "reserved_ip_range_value", + "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], + "connect_mode": 1, + } + ], + "etag": "etag_value", + "satisfies_pzs": {"value": True}, + "kms_key_name": "kms_key_name_value", + "suspension_reasons": [1], + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_instance(request) + + +def test_update_instance_rest_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "instance": {"name": "projects/sample1/locations/sample2/instances/sample3"} + } + + # get truthy value for each flattened field + mock_args = dict( + instance=cloud_filestore_service.Instance(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.update_instance(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{instance.name=projects/*/locations/*/instances/*}" + % client.transport._host, + args[1], + ) + + +def test_update_instance_rest_flattened_error(transport: str = "rest"): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_instance( + cloud_filestore_service.UpdateInstanceRequest(), + instance=cloud_filestore_service.Instance(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_update_instance_rest_error(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.RestoreInstanceRequest, + dict, + ], +) +def test_restore_instance_rest(request_type): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.restore_instance(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_restore_instance_rest_required_fields( + request_type=cloud_filestore_service.RestoreInstanceRequest, +): + transport_class = transports.CloudFilestoreManagerRestTransport + + request_init = {} + request_init["name"] = "" + request_init["file_share"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).restore_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + jsonified_request["fileShare"] = "file_share_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).restore_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + assert "fileShare" in jsonified_request + assert jsonified_request["fileShare"] == "file_share_value" + + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.restore_instance(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_restore_instance_rest_unset_required_fields(): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.restore_instance._get_unset_required_fields({}) assert set(unset_fields) == ( - set( + set(()) + & set( ( - "filter", - "orderBy", - "pageSize", - "pageToken", + "name", + "fileShare", ) ) - & set(("parent",)) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_instances_rest_interceptors(null_interceptor): +def test_restore_instance_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -3866,14 +6513,16 @@ def test_list_instances_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_list_instances" + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_restore_instance" ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_list_instances" + transports.CloudFilestoreManagerRestInterceptor, "pre_restore_instance" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = cloud_filestore_service.ListInstancesRequest.pb( - cloud_filestore_service.ListInstancesRequest() + pb_message = cloud_filestore_service.RestoreInstanceRequest.pb( + cloud_filestore_service.RestoreInstanceRequest() ) transcode.return_value = { "method": "post", @@ -3885,21 +6534,19 @@ def test_list_instances_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = ( - cloud_filestore_service.ListInstancesResponse.to_json( - cloud_filestore_service.ListInstancesResponse() - ) + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() ) - request = cloud_filestore_service.ListInstancesRequest() + request = cloud_filestore_service.RestoreInstanceRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = cloud_filestore_service.ListInstancesResponse() + post.return_value = operations_pb2.Operation() - client.list_instances( + client.restore_instance( request, metadata=[ ("key", "val"), @@ -3911,8 +6558,8 @@ def test_list_instances_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_instances_rest_bad_request( - transport: str = "rest", request_type=cloud_filestore_service.ListInstancesRequest +def test_restore_instance_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.RestoreInstanceRequest ): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3920,7 +6567,7 @@ def test_list_instances_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} + request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -3932,10 +6579,220 @@ def test_list_instances_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_instances(request) + client.restore_instance(request) -def test_list_instances_rest_flattened(): +def test_restore_instance_rest_error(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + cloud_filestore_service.DeleteInstanceRequest, + dict, + ], +) +def test_delete_instance_rest(request_type): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.delete_instance(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_delete_instance_rest_required_fields( + request_type=cloud_filestore_service.DeleteInstanceRequest, +): + transport_class = transports.CloudFilestoreManagerRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_instance._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("force",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.delete_instance(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_instance_rest_unset_required_fields(): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_instance._get_unset_required_fields({}) + assert set(unset_fields) == (set(("force",)) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_instance_rest_interceptors(null_interceptor): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.CloudFilestoreManagerRestInterceptor(), + ) + client = CloudFilestoreManagerClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_delete_instance" + ) as post, mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_delete_instance" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = cloud_filestore_service.DeleteInstanceRequest.pb( + cloud_filestore_service.DeleteInstanceRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) + + request = cloud_filestore_service.DeleteInstanceRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.delete_instance( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_delete_instance_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.DeleteInstanceRequest +): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_instance(request) + + +def test_delete_instance_rest_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -3944,38 +6801,39 @@ def test_list_instances_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = cloud_filestore_service.ListInstancesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "name": "projects/sample1/locations/sample2/instances/sample3" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = cloud_filestore_service.ListInstancesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_instances(**mock_args) + client.delete_instance(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/instances" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/instances/*}" % client.transport._host, args[1], ) -def test_list_instances_rest_flattened_error(transport: str = "rest"): +def test_delete_instance_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3984,131 +6842,64 @@ def test_list_instances_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_instances( - cloud_filestore_service.ListInstancesRequest(), - parent="parent_value", + client.delete_instance( + cloud_filestore_service.DeleteInstanceRequest(), + name="name_value", ) -def test_list_instances_rest_pager(transport: str = "rest"): +def test_delete_instance_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - cloud_filestore_service.ListInstancesResponse( - instances=[ - cloud_filestore_service.Instance(), - cloud_filestore_service.Instance(), - cloud_filestore_service.Instance(), - ], - next_page_token="abc", - ), - cloud_filestore_service.ListInstancesResponse( - instances=[], - next_page_token="def", - ), - cloud_filestore_service.ListInstancesResponse( - instances=[ - cloud_filestore_service.Instance(), - ], - next_page_token="ghi", - ), - cloud_filestore_service.ListInstancesResponse( - instances=[ - cloud_filestore_service.Instance(), - cloud_filestore_service.Instance(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple( - cloud_filestore_service.ListInstancesResponse.to_json(x) for x in response - ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "projects/sample1/locations/sample2"} - - pager = client.list_instances(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, cloud_filestore_service.Instance) for i in results) - - pages = list(client.list_instances(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.GetInstanceRequest, + cloud_filestore_service.ListSnapshotsRequest, dict, ], ) -def test_get_instance_rest(request_type): +def test_list_snapshots_rest(request_type): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2/instances/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = cloud_filestore_service.Instance( - name="name_value", - description="description_value", - state=cloud_filestore_service.Instance.State.CREATING, - status_message="status_message_value", - tier=cloud_filestore_service.Instance.Tier.STANDARD, - etag="etag_value", + return_value = cloud_filestore_service.ListSnapshotsResponse( + next_page_token="next_page_token_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = cloud_filestore_service.Instance.pb(return_value) + pb_return_value = cloud_filestore_service.ListSnapshotsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_instance(request) + response = client.list_snapshots(request) # Establish that the response is the type that we expect. - assert isinstance(response, cloud_filestore_service.Instance) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.state == cloud_filestore_service.Instance.State.CREATING - assert response.status_message == "status_message_value" - assert response.tier == cloud_filestore_service.Instance.Tier.STANDARD - assert response.etag == "etag_value" + assert isinstance(response, pagers.ListSnapshotsPager) + assert response.next_page_token == "next_page_token_value" -def test_get_instance_rest_required_fields( - request_type=cloud_filestore_service.GetInstanceRequest, +def test_list_snapshots_rest_required_fields( + request_type=cloud_filestore_service.ListSnapshotsRequest, ): transport_class = transports.CloudFilestoreManagerRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -4123,21 +6914,30 @@ def test_get_instance_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_instance._get_unset_required_fields(jsonified_request) + ).list_snapshots._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_instance._get_unset_required_fields(jsonified_request) + ).list_snapshots._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4146,7 +6946,7 @@ def test_get_instance_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = cloud_filestore_service.Instance() + return_value = cloud_filestore_service.ListSnapshotsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -4166,30 +6966,42 @@ def test_get_instance_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = cloud_filestore_service.Instance.pb(return_value) + pb_return_value = cloud_filestore_service.ListSnapshotsResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_instance(request) + response = client.list_snapshots(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_instance_rest_unset_required_fields(): +def test_list_snapshots_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_instance._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.list_snapshots._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_instance_rest_interceptors(null_interceptor): +def test_list_snapshots_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -4202,14 +7014,14 @@ def test_get_instance_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_get_instance" + transports.CloudFilestoreManagerRestInterceptor, "post_list_snapshots" ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_get_instance" + transports.CloudFilestoreManagerRestInterceptor, "pre_list_snapshots" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = cloud_filestore_service.GetInstanceRequest.pb( - cloud_filestore_service.GetInstanceRequest() + pb_message = cloud_filestore_service.ListSnapshotsRequest.pb( + cloud_filestore_service.ListSnapshotsRequest() ) transcode.return_value = { "method": "post", @@ -4221,19 +7033,21 @@ def test_get_instance_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = cloud_filestore_service.Instance.to_json( - cloud_filestore_service.Instance() + req.return_value._content = ( + cloud_filestore_service.ListSnapshotsResponse.to_json( + cloud_filestore_service.ListSnapshotsResponse() + ) ) - request = cloud_filestore_service.GetInstanceRequest() + request = cloud_filestore_service.ListSnapshotsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = cloud_filestore_service.Instance() + post.return_value = cloud_filestore_service.ListSnapshotsResponse() - client.get_instance( + client.list_snapshots( request, metadata=[ ("key", "val"), @@ -4245,8 +7059,8 @@ def test_get_instance_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_instance_rest_bad_request( - transport: str = "rest", request_type=cloud_filestore_service.GetInstanceRequest +def test_list_snapshots_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.ListSnapshotsRequest ): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4254,7 +7068,7 @@ def test_get_instance_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request_init = {"parent": "projects/sample1/locations/sample2/instances/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -4266,10 +7080,10 @@ def test_get_instance_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_instance(request) + client.list_snapshots(request) -def test_get_instance_rest_flattened(): +def test_list_snapshots_rest_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -4278,40 +7092,41 @@ def test_get_instance_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = cloud_filestore_service.Instance() + return_value = cloud_filestore_service.ListSnapshotsResponse() # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/instances/sample3" + "parent": "projects/sample1/locations/sample2/instances/sample3" } # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = cloud_filestore_service.Instance.pb(return_value) + pb_return_value = cloud_filestore_service.ListSnapshotsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_instance(**mock_args) + client.list_snapshots(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/instances/*}" % client.transport._host, + "%s/v1/{parent=projects/*/locations/*/instances/*}/snapshots" + % client.transport._host, args[1], ) -def test_get_instance_rest_flattened_error(transport: str = "rest"): +def test_list_snapshots_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -4320,96 +7135,131 @@ def test_get_instance_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_instance( - cloud_filestore_service.GetInstanceRequest(), - name="name_value", + client.list_snapshots( + cloud_filestore_service.ListSnapshotsRequest(), + parent="parent_value", ) -def test_get_instance_rest_error(): +def test_list_snapshots_rest_pager(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), + ], + next_page_token="abc", + ), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[], + next_page_token="def", + ), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + ], + next_page_token="ghi", + ), + cloud_filestore_service.ListSnapshotsResponse( + snapshots=[ + cloud_filestore_service.Snapshot(), + cloud_filestore_service.Snapshot(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + cloud_filestore_service.ListSnapshotsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = { + "parent": "projects/sample1/locations/sample2/instances/sample3" + } + + pager = client.list_snapshots(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, cloud_filestore_service.Snapshot) for i in results) + + pages = list(client.list_snapshots(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.CreateInstanceRequest, + cloud_filestore_service.GetSnapshotRequest, dict, ], ) -def test_create_instance_rest(request_type): +def test_get_snapshot_rest(request_type): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["instance"] = { - "name": "name_value", - "description": "description_value", - "state": 1, - "status_message": "status_message_value", - "create_time": {"seconds": 751, "nanos": 543}, - "tier": 1, - "labels": {}, - "file_shares": [ - { - "name": "name_value", - "capacity_gb": 1142, - "source_backup": "source_backup_value", - "nfs_export_options": [ - { - "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], - "access_mode": 1, - "squash_mode": 1, - "anon_uid": 845, - "anon_gid": 831, - } - ], - } - ], - "networks": [ - { - "network": "network_value", - "modes": [1], - "reserved_ip_range": "reserved_ip_range_value", - "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], - } - ], - "etag": "etag_value", - "satisfies_pzs": {"value": True}, + request_init = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = cloud_filestore_service.Snapshot( + name="name_value", + description="description_value", + state=cloud_filestore_service.Snapshot.State.CREATING, + filesystem_used_bytes=2267, + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + pb_return_value = cloud_filestore_service.Snapshot.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_instance(request) + response = client.get_snapshot(request) # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + assert isinstance(response, cloud_filestore_service.Snapshot) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.state == cloud_filestore_service.Snapshot.State.CREATING + assert response.filesystem_used_bytes == 2267 -def test_create_instance_rest_required_fields( - request_type=cloud_filestore_service.CreateInstanceRequest, +def test_get_snapshot_rest_required_fields( + request_type=cloud_filestore_service.GetSnapshotRequest, ): transport_class = transports.CloudFilestoreManagerRestTransport request_init = {} - request_init["parent"] = "" - request_init["instance_id"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -4421,32 +7271,24 @@ def test_create_instance_rest_required_fields( ) # verify fields with default values are dropped - assert "instanceId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_instance._get_unset_required_fields(jsonified_request) + ).get_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "instanceId" in jsonified_request - assert jsonified_request["instanceId"] == request_init["instance_id"] - jsonified_request["parent"] = "parent_value" - jsonified_request["instanceId"] = "instance_id_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_instance._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("instance_id",)) + ).get_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" - assert "instanceId" in jsonified_request - assert jsonified_request["instanceId"] == "instance_id_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4455,7 +7297,7 @@ def test_create_instance_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = cloud_filestore_service.Snapshot() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -4467,52 +7309,38 @@ def test_create_instance_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + + pb_return_value = cloud_filestore_service.Snapshot.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_instance(request) + response = client.get_snapshot(request) - expected_params = [ - ( - "instanceId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_instance_rest_unset_required_fields(): +def test_get_snapshot_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_instance._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(("instanceId",)) - & set( - ( - "parent", - "instanceId", - "instance", - ) - ) - ) + unset_fields = transport.get_snapshot._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_instance_rest_interceptors(null_interceptor): +def test_get_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -4525,16 +7353,14 @@ def test_create_instance_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_create_instance" + transports.CloudFilestoreManagerRestInterceptor, "post_get_snapshot" ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_create_instance" + transports.CloudFilestoreManagerRestInterceptor, "pre_get_snapshot" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = cloud_filestore_service.CreateInstanceRequest.pb( - cloud_filestore_service.CreateInstanceRequest() + pb_message = cloud_filestore_service.GetSnapshotRequest.pb( + cloud_filestore_service.GetSnapshotRequest() ) transcode.return_value = { "method": "post", @@ -4546,19 +7372,19 @@ def test_create_instance_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() + req.return_value._content = cloud_filestore_service.Snapshot.to_json( + cloud_filestore_service.Snapshot() ) - request = cloud_filestore_service.CreateInstanceRequest() + request = cloud_filestore_service.GetSnapshotRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() + post.return_value = cloud_filestore_service.Snapshot() - client.create_instance( + client.get_snapshot( request, metadata=[ ("key", "val"), @@ -4570,8 +7396,8 @@ def test_create_instance_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_instance_rest_bad_request( - transport: str = "rest", request_type=cloud_filestore_service.CreateInstanceRequest +def test_get_snapshot_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.GetSnapshotRequest ): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4579,41 +7405,8 @@ def test_create_instance_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["instance"] = { - "name": "name_value", - "description": "description_value", - "state": 1, - "status_message": "status_message_value", - "create_time": {"seconds": 751, "nanos": 543}, - "tier": 1, - "labels": {}, - "file_shares": [ - { - "name": "name_value", - "capacity_gb": 1142, - "source_backup": "source_backup_value", - "nfs_export_options": [ - { - "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], - "access_mode": 1, - "squash_mode": 1, - "anon_uid": 845, - "anon_gid": 831, - } - ], - } - ], - "networks": [ - { - "network": "network_value", - "modes": [1], - "reserved_ip_range": "reserved_ip_range_value", - "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], - } - ], - "etag": "etag_value", - "satisfies_pzs": {"value": True}, + request_init = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" } request = request_type(**request_init) @@ -4626,10 +7419,10 @@ def test_create_instance_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_instance(request) + client.get_snapshot(request) -def test_create_instance_rest_flattened(): +def test_get_snapshot_rest_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -4638,39 +7431,41 @@ def test_create_instance_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = cloud_filestore_service.Snapshot() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "projects/sample1/locations/sample2"} + sample_request = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - instance=cloud_filestore_service.Instance(name="name_value"), - instance_id="instance_id_value", + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + pb_return_value = cloud_filestore_service.Snapshot.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_instance(**mock_args) + client.get_snapshot(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=projects/*/locations/*}/instances" % client.transport._host, + "%s/v1/{name=projects/*/locations/*/instances/*/snapshots/*}" + % client.transport._host, args[1], ) -def test_create_instance_rest_flattened_error(transport: str = "rest"): +def test_get_snapshot_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -4679,15 +7474,13 @@ def test_create_instance_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_instance( - cloud_filestore_service.CreateInstanceRequest(), - parent="parent_value", - instance=cloud_filestore_service.Instance(name="name_value"), - instance_id="instance_id_value", + client.get_snapshot( + cloud_filestore_service.GetSnapshotRequest(), + name="name_value", ) -def test_create_instance_rest_error(): +def test_get_snapshot_rest_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -4696,54 +7489,25 @@ def test_create_instance_rest_error(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.UpdateInstanceRequest, + cloud_filestore_service.CreateSnapshotRequest, dict, ], ) -def test_update_instance_rest(request_type): +def test_create_snapshot_rest(request_type): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = { - "instance": {"name": "projects/sample1/locations/sample2/instances/sample3"} - } - request_init["instance"] = { - "name": "projects/sample1/locations/sample2/instances/sample3", + request_init = {"parent": "projects/sample1/locations/sample2/instances/sample3"} + request_init["snapshot"] = { + "name": "name_value", "description": "description_value", "state": 1, - "status_message": "status_message_value", "create_time": {"seconds": 751, "nanos": 543}, - "tier": 1, "labels": {}, - "file_shares": [ - { - "name": "name_value", - "capacity_gb": 1142, - "source_backup": "source_backup_value", - "nfs_export_options": [ - { - "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], - "access_mode": 1, - "squash_mode": 1, - "anon_uid": 845, - "anon_gid": 831, - } - ], - } - ], - "networks": [ - { - "network": "network_value", - "modes": [1], - "reserved_ip_range": "reserved_ip_range_value", - "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], - } - ], - "etag": "etag_value", - "satisfies_pzs": {"value": True}, + "filesystem_used_bytes": 2267, } request = request_type(**request_init) @@ -4759,14 +7523,123 @@ def test_update_instance_rest(request_type): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_instance(request) + response = client.create_snapshot(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_create_snapshot_rest_required_fields( + request_type=cloud_filestore_service.CreateSnapshotRequest, +): + transport_class = transports.CloudFilestoreManagerRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["snapshot_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + assert "snapshotId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_snapshot._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "snapshotId" in jsonified_request + assert jsonified_request["snapshotId"] == request_init["snapshot_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["snapshotId"] = "snapshot_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_snapshot._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("snapshot_id",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "snapshotId" in jsonified_request + assert jsonified_request["snapshotId"] == "snapshot_id_value" + + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_snapshot(request) + + expected_params = [ + ( + "snapshotId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_snapshot_rest_unset_required_fields(): + transport = transports.CloudFilestoreManagerRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + unset_fields = transport.create_snapshot._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("snapshotId",)) + & set( + ( + "parent", + "snapshotId", + "snapshot", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_instance_rest_interceptors(null_interceptor): +def test_create_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -4781,14 +7654,14 @@ def test_update_instance_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_update_instance" + transports.CloudFilestoreManagerRestInterceptor, "post_create_snapshot" ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_update_instance" + transports.CloudFilestoreManagerRestInterceptor, "pre_create_snapshot" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = cloud_filestore_service.UpdateInstanceRequest.pb( - cloud_filestore_service.UpdateInstanceRequest() + pb_message = cloud_filestore_service.CreateSnapshotRequest.pb( + cloud_filestore_service.CreateSnapshotRequest() ) transcode.return_value = { "method": "post", @@ -4804,7 +7677,7 @@ def test_update_instance_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = cloud_filestore_service.UpdateInstanceRequest() + request = cloud_filestore_service.CreateSnapshotRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -4812,7 +7685,7 @@ def test_update_instance_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.update_instance( + client.create_snapshot( request, metadata=[ ("key", "val"), @@ -4824,8 +7697,8 @@ def test_update_instance_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_instance_rest_bad_request( - transport: str = "rest", request_type=cloud_filestore_service.UpdateInstanceRequest +def test_create_snapshot_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.CreateSnapshotRequest ): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4833,43 +7706,14 @@ def test_update_instance_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = { - "instance": {"name": "projects/sample1/locations/sample2/instances/sample3"} - } - request_init["instance"] = { - "name": "projects/sample1/locations/sample2/instances/sample3", + request_init = {"parent": "projects/sample1/locations/sample2/instances/sample3"} + request_init["snapshot"] = { + "name": "name_value", "description": "description_value", "state": 1, - "status_message": "status_message_value", "create_time": {"seconds": 751, "nanos": 543}, - "tier": 1, "labels": {}, - "file_shares": [ - { - "name": "name_value", - "capacity_gb": 1142, - "source_backup": "source_backup_value", - "nfs_export_options": [ - { - "ip_ranges": ["ip_ranges_value1", "ip_ranges_value2"], - "access_mode": 1, - "squash_mode": 1, - "anon_uid": 845, - "anon_gid": 831, - } - ], - } - ], - "networks": [ - { - "network": "network_value", - "modes": [1], - "reserved_ip_range": "reserved_ip_range_value", - "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], - } - ], - "etag": "etag_value", - "satisfies_pzs": {"value": True}, + "filesystem_used_bytes": 2267, } request = request_type(**request_init) @@ -4882,10 +7726,10 @@ def test_update_instance_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_instance(request) + client.create_snapshot(request) -def test_update_instance_rest_flattened(): +def test_create_snapshot_rest_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -4898,13 +7742,14 @@ def test_update_instance_rest_flattened(): # get arguments that satisfy an http rule for this method sample_request = { - "instance": {"name": "projects/sample1/locations/sample2/instances/sample3"} + "parent": "projects/sample1/locations/sample2/instances/sample3" } # get truthy value for each flattened field mock_args = dict( - instance=cloud_filestore_service.Instance(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + parent="parent_value", + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + snapshot_id="snapshot_id_value", ) mock_args.update(sample_request) @@ -4915,20 +7760,20 @@ def test_update_instance_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_instance(**mock_args) + client.create_snapshot(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{instance.name=projects/*/locations/*/instances/*}" + "%s/v1/{parent=projects/*/locations/*/instances/*}/snapshots" % client.transport._host, args[1], ) -def test_update_instance_rest_flattened_error(transport: str = "rest"): +def test_create_snapshot_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -4937,14 +7782,15 @@ def test_update_instance_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_instance( - cloud_filestore_service.UpdateInstanceRequest(), - instance=cloud_filestore_service.Instance(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.create_snapshot( + cloud_filestore_service.CreateSnapshotRequest(), + parent="parent_value", + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + snapshot_id="snapshot_id_value", ) -def test_update_instance_rest_error(): +def test_create_snapshot_rest_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -4953,18 +7799,20 @@ def test_update_instance_rest_error(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.RestoreInstanceRequest, + cloud_filestore_service.DeleteSnapshotRequest, dict, ], ) -def test_restore_instance_rest(request_type): +def test_delete_snapshot_rest(request_type): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -4979,20 +7827,19 @@ def test_restore_instance_rest(request_type): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.restore_instance(request) + response = client.delete_snapshot(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_restore_instance_rest_required_fields( - request_type=cloud_filestore_service.RestoreInstanceRequest, +def test_delete_snapshot_rest_required_fields( + request_type=cloud_filestore_service.DeleteSnapshotRequest, ): transport_class = transports.CloudFilestoreManagerRestTransport request_init = {} request_init["name"] = "" - request_init["file_share"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -5007,24 +7854,21 @@ def test_restore_instance_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).restore_instance._get_unset_required_fields(jsonified_request) + ).delete_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present jsonified_request["name"] = "name_value" - jsonified_request["fileShare"] = "file_share_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).restore_instance._get_unset_required_fields(jsonified_request) + ).delete_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "name" in jsonified_request assert jsonified_request["name"] == "name_value" - assert "fileShare" in jsonified_request - assert jsonified_request["fileShare"] == "file_share_value" client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5045,10 +7889,9 @@ def test_restore_instance_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "delete", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -5058,32 +7901,24 @@ def test_restore_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.restore_instance(request) + response = client.delete_snapshot(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_restore_instance_rest_unset_required_fields(): +def test_delete_snapshot_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.restore_instance._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(()) - & set( - ( - "name", - "fileShare", - ) - ) - ) + unset_fields = transport.delete_snapshot._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_restore_instance_rest_interceptors(null_interceptor): +def test_delete_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -5098,14 +7933,14 @@ def test_restore_instance_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_restore_instance" + transports.CloudFilestoreManagerRestInterceptor, "post_delete_snapshot" ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_restore_instance" + transports.CloudFilestoreManagerRestInterceptor, "pre_delete_snapshot" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = cloud_filestore_service.RestoreInstanceRequest.pb( - cloud_filestore_service.RestoreInstanceRequest() + pb_message = cloud_filestore_service.DeleteSnapshotRequest.pb( + cloud_filestore_service.DeleteSnapshotRequest() ) transcode.return_value = { "method": "post", @@ -5121,7 +7956,7 @@ def test_restore_instance_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = cloud_filestore_service.RestoreInstanceRequest() + request = cloud_filestore_service.DeleteSnapshotRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -5129,7 +7964,7 @@ def test_restore_instance_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.restore_instance( + client.delete_snapshot( request, metadata=[ ("key", "val"), @@ -5141,8 +7976,8 @@ def test_restore_instance_rest_interceptors(null_interceptor): post.assert_called_once() -def test_restore_instance_rest_bad_request( - transport: str = "rest", request_type=cloud_filestore_service.RestoreInstanceRequest +def test_delete_snapshot_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.DeleteSnapshotRequest ): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5150,7 +7985,9 @@ def test_restore_instance_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request_init = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -5162,10 +7999,67 @@ def test_restore_instance_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.restore_instance(request) + client.delete_snapshot(request) -def test_restore_instance_rest_error(): +def test_delete_snapshot_rest_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.delete_snapshot(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/instances/*/snapshots/*}" + % client.transport._host, + args[1], + ) + + +def test_delete_snapshot_rest_flattened_error(transport: str = "rest"): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_snapshot( + cloud_filestore_service.DeleteSnapshotRequest(), + name="name_value", + ) + + +def test_delete_snapshot_rest_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -5174,18 +8068,30 @@ def test_restore_instance_rest_error(): @pytest.mark.parametrize( "request_type", [ - cloud_filestore_service.DeleteInstanceRequest, + cloud_filestore_service.UpdateSnapshotRequest, dict, ], ) -def test_delete_instance_rest(request_type): +def test_update_snapshot_rest(request_type): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request_init = { + "snapshot": { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" + } + } + request_init["snapshot"] = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4", + "description": "description_value", + "state": 1, + "create_time": {"seconds": 751, "nanos": 543}, + "labels": {}, + "filesystem_used_bytes": 2267, + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -5200,19 +8106,18 @@ def test_delete_instance_rest(request_type): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_instance(request) + response = client.update_snapshot(request) # Establish that the response is the type that we expect. assert response.operation.name == "operations/spam" -def test_delete_instance_rest_required_fields( - request_type=cloud_filestore_service.DeleteInstanceRequest, +def test_update_snapshot_rest_required_fields( + request_type=cloud_filestore_service.UpdateSnapshotRequest, ): transport_class = transports.CloudFilestoreManagerRestTransport request_init = {} - request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -5227,21 +8132,19 @@ def test_delete_instance_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_instance._get_unset_required_fields(jsonified_request) + ).update_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_instance._get_unset_required_fields(jsonified_request) + ).update_snapshot._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5262,9 +8165,10 @@ def test_delete_instance_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "patch", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -5274,24 +8178,32 @@ def test_delete_instance_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_instance(request) + response = client.update_snapshot(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_instance_rest_unset_required_fields(): +def test_update_snapshot_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_instance._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.update_snapshot._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("updateMask",)) + & set( + ( + "updateMask", + "snapshot", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_instance_rest_interceptors(null_interceptor): +def test_update_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -5306,14 +8218,14 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) as transcode, mock.patch.object( operation.Operation, "_set_result_from_operation" ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_delete_instance" + transports.CloudFilestoreManagerRestInterceptor, "post_update_snapshot" ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_delete_instance" + transports.CloudFilestoreManagerRestInterceptor, "pre_update_snapshot" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = cloud_filestore_service.DeleteInstanceRequest.pb( - cloud_filestore_service.DeleteInstanceRequest() + pb_message = cloud_filestore_service.UpdateSnapshotRequest.pb( + cloud_filestore_service.UpdateSnapshotRequest() ) transcode.return_value = { "method": "post", @@ -5329,7 +8241,7 @@ def test_delete_instance_rest_interceptors(null_interceptor): operations_pb2.Operation() ) - request = cloud_filestore_service.DeleteInstanceRequest() + request = cloud_filestore_service.UpdateSnapshotRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -5337,7 +8249,7 @@ def test_delete_instance_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = operations_pb2.Operation() - client.delete_instance( + client.update_snapshot( request, metadata=[ ("key", "val"), @@ -5349,8 +8261,8 @@ def test_delete_instance_rest_interceptors(null_interceptor): post.assert_called_once() -def test_delete_instance_rest_bad_request( - transport: str = "rest", request_type=cloud_filestore_service.DeleteInstanceRequest +def test_update_snapshot_rest_bad_request( + transport: str = "rest", request_type=cloud_filestore_service.UpdateSnapshotRequest ): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5358,7 +8270,19 @@ def test_delete_instance_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "projects/sample1/locations/sample2/instances/sample3"} + request_init = { + "snapshot": { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" + } + } + request_init["snapshot"] = { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4", + "description": "description_value", + "state": 1, + "create_time": {"seconds": 751, "nanos": 543}, + "labels": {}, + "filesystem_used_bytes": 2267, + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -5370,10 +8294,10 @@ def test_delete_instance_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.delete_instance(request) + client.update_snapshot(request) -def test_delete_instance_rest_flattened(): +def test_update_snapshot_rest_flattened(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -5386,12 +8310,15 @@ def test_delete_instance_rest_flattened(): # get arguments that satisfy an http rule for this method sample_request = { - "name": "projects/sample1/locations/sample2/instances/sample3" + "snapshot": { + "name": "projects/sample1/locations/sample2/instances/sample3/snapshots/sample4" + } } # get truthy value for each flattened field mock_args = dict( - name="name_value", + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -5402,19 +8329,20 @@ def test_delete_instance_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.delete_instance(**mock_args) + client.update_snapshot(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=projects/*/locations/*/instances/*}" % client.transport._host, + "%s/v1/{snapshot.name=projects/*/locations/*/instances/*/snapshots/*}" + % client.transport._host, args[1], ) -def test_delete_instance_rest_flattened_error(transport: str = "rest"): +def test_update_snapshot_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -5423,13 +8351,14 @@ def test_delete_instance_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_instance( - cloud_filestore_service.DeleteInstanceRequest(), - name="name_value", + client.update_snapshot( + cloud_filestore_service.UpdateSnapshotRequest(), + snapshot=cloud_filestore_service.Snapshot(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_delete_instance_rest_error(): +def test_update_snapshot_rest_error(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -5812,6 +8741,7 @@ def test_get_backup_rest(request_type): source_file_share="source_file_share_value", source_instance_tier=cloud_filestore_service.Instance.Tier.STANDARD, download_bytes=1502, + kms_key="kms_key_value", ) # Wrap the value into a proper Response obj @@ -5837,6 +8767,7 @@ def test_get_backup_rest(request_type): response.source_instance_tier == cloud_filestore_service.Instance.Tier.STANDARD ) assert response.download_bytes == 1502 + assert response.kms_key == "kms_key_value" def test_get_backup_rest_required_fields( @@ -6095,6 +9026,7 @@ def test_create_backup_rest(request_type): "source_instance_tier": 1, "download_bytes": 1502, "satisfies_pzs": {"value": True}, + "kms_key": "kms_key_value", } request = request_type(**request_init) @@ -6307,6 +9239,7 @@ def test_create_backup_rest_bad_request( "source_instance_tier": 1, "download_bytes": 1502, "satisfies_pzs": {"value": True}, + "kms_key": "kms_key_value", } request = request_type(**request_init) @@ -6678,6 +9611,7 @@ def test_update_backup_rest(request_type): "source_instance_tier": 1, "download_bytes": 1502, "satisfies_pzs": {"value": True}, + "kms_key": "kms_key_value", } request = request_type(**request_init) @@ -6873,6 +9807,7 @@ def test_update_backup_rest_bad_request( "source_instance_tier": 1, "download_bytes": 1502, "satisfies_pzs": {"value": True}, + "kms_key": "kms_key_value", } request = request_type(**request_init) @@ -7098,6 +10033,11 @@ def test_cloud_filestore_manager_base_transport(): "update_instance", "restore_instance", "delete_instance", + "list_snapshots", + "get_snapshot", + "create_snapshot", + "delete_snapshot", + "update_snapshot", "list_backups", "get_backup", "create_backup", @@ -7403,6 +10343,21 @@ def test_cloud_filestore_manager_client_transport_session_collision(transport_na session1 = client1.transport.delete_instance._session session2 = client2.transport.delete_instance._session assert session1 != session2 + session1 = client1.transport.list_snapshots._session + session2 = client2.transport.list_snapshots._session + assert session1 != session2 + session1 = client1.transport.get_snapshot._session + session2 = client2.transport.get_snapshot._session + assert session1 != session2 + session1 = client1.transport.create_snapshot._session + session2 = client2.transport.create_snapshot._session + assert session1 != session2 + session1 = client1.transport.delete_snapshot._session + session2 = client2.transport.delete_snapshot._session + assert session1 != session2 + session1 = client1.transport.update_snapshot._session + session2 = client2.transport.update_snapshot._session + assert session1 != session2 session1 = client1.transport.list_backups._session session2 = client2.transport.list_backups._session assert session1 != session2 @@ -7632,8 +10587,39 @@ def test_parse_instance_path(): assert expected == actual +def test_snapshot_path(): + project = "squid" + location = "clam" + instance = "whelk" + snapshot = "octopus" + expected = "projects/{project}/locations/{location}/instances/{instance}/snapshots/{snapshot}".format( + project=project, + location=location, + instance=instance, + snapshot=snapshot, + ) + actual = CloudFilestoreManagerClient.snapshot_path( + project, location, instance, snapshot + ) + assert expected == actual + + +def test_parse_snapshot_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "instance": "cuttlefish", + "snapshot": "mussel", + } + path = CloudFilestoreManagerClient.snapshot_path(**expected) + + # Check that the path construction is reversible. + actual = CloudFilestoreManagerClient.parse_snapshot_path(path) + assert expected == actual + + def test_common_billing_account_path(): - billing_account = "squid" + billing_account = "winkle" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -7643,7 +10629,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "clam", + "billing_account": "nautilus", } path = CloudFilestoreManagerClient.common_billing_account_path(**expected) @@ -7653,7 +10639,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "whelk" + folder = "scallop" expected = "folders/{folder}".format( folder=folder, ) @@ -7663,7 +10649,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "octopus", + "folder": "abalone", } path = CloudFilestoreManagerClient.common_folder_path(**expected) @@ -7673,7 +10659,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "oyster" + organization = "squid" expected = "organizations/{organization}".format( organization=organization, ) @@ -7683,7 +10669,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nudibranch", + "organization": "clam", } path = CloudFilestoreManagerClient.common_organization_path(**expected) @@ -7693,7 +10679,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "cuttlefish" + project = "whelk" expected = "projects/{project}".format( project=project, ) @@ -7703,7 +10689,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "mussel", + "project": "octopus", } path = CloudFilestoreManagerClient.common_project_path(**expected) @@ -7713,8 +10699,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "oyster" + location = "nudibranch" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -7725,8 +10711,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "cuttlefish", + "location": "mussel", } path = CloudFilestoreManagerClient.common_location_path(**expected)