diff --git a/.coveragerc b/.coveragerc index 52a514b..6c1d048 100644 --- a/.coveragerc +++ b/.coveragerc @@ -10,8 +10,3 @@ exclude_lines = pragma: NO COVER # Ignore debug-only repr def __repr__ - # Ignore pkg_resources exceptions. - # This is added at the module level as a safeguard for if someone - # generates the code and tries to run it without pip installing. This - # makes it virtually impossible to test properly. - except pkg_resources.DistributionNotFound diff --git a/.github/release-please.yml b/.github/release-please.yml index 6def37a..e9a4f00 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1,5 +1,6 @@ releaseType: python handleGHRelease: true +manifest: true # NOTE: this section is generated by synthtool.languages.python # See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py branches: diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..50f0c45 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "1.4.4" +} diff --git a/docs/notebooks_v1/types.rst b/docs/notebooks_v1/types.rst index 657fd1f..a8095db 100644 --- a/docs/notebooks_v1/types.rst +++ b/docs/notebooks_v1/types.rst @@ -3,5 +3,4 @@ Types for Google Cloud Notebooks v1 API .. automodule:: google.cloud.notebooks_v1.types :members: - :undoc-members: :show-inheritance: diff --git a/docs/notebooks_v1beta1/types.rst b/docs/notebooks_v1beta1/types.rst index 7cdeaf4..b981f31 100644 --- a/docs/notebooks_v1beta1/types.rst +++ b/docs/notebooks_v1beta1/types.rst @@ -3,5 +3,4 @@ Types for Google Cloud Notebooks v1beta1 API .. automodule:: google.cloud.notebooks_v1beta1.types :members: - :undoc-members: :show-inheritance: diff --git a/google/cloud/notebooks/__init__.py b/google/cloud/notebooks/__init__.py index b6572db..5d3e144 100644 --- a/google/cloud/notebooks/__init__.py +++ b/google/cloud/notebooks/__init__.py @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.notebooks import gapic_version as package_version + +__version__ = package_version.__version__ + from google.cloud.notebooks_v1.services.managed_notebook_service.async_client import ( ManagedNotebookServiceAsyncClient, @@ -26,6 +30,7 @@ from google.cloud.notebooks_v1.services.notebook_service.client import ( NotebookServiceClient, ) +from google.cloud.notebooks_v1.types.diagnostic_config import DiagnosticConfig from google.cloud.notebooks_v1.types.environment import ( ContainerImage, Environment, @@ -38,6 +43,7 @@ from google.cloud.notebooks_v1.types.managed_service import ( CreateRuntimeRequest, DeleteRuntimeRequest, + DiagnoseRuntimeRequest, GetRuntimeRequest, ListRuntimesRequest, ListRuntimesResponse, @@ -48,6 +54,8 @@ StartRuntimeRequest, StopRuntimeRequest, SwitchRuntimeRequest, + UpdateRuntimeRequest, + UpgradeRuntimeRequest, ) from google.cloud.notebooks_v1.types.runtime import ( EncryptionConfig, @@ -72,6 +80,7 @@ DeleteExecutionRequest, DeleteInstanceRequest, DeleteScheduleRequest, + DiagnoseInstanceRequest, GetEnvironmentRequest, GetExecutionRequest, GetInstanceHealthRequest, @@ -113,6 +122,7 @@ "ManagedNotebookServiceAsyncClient", "NotebookServiceClient", "NotebookServiceAsyncClient", + "DiagnosticConfig", "ContainerImage", "Environment", "VmImage", @@ -124,6 +134,7 @@ "InstanceConfig", "CreateRuntimeRequest", "DeleteRuntimeRequest", + "DiagnoseRuntimeRequest", "GetRuntimeRequest", "ListRuntimesRequest", "ListRuntimesResponse", @@ -134,6 +145,8 @@ "StartRuntimeRequest", "StopRuntimeRequest", "SwitchRuntimeRequest", + "UpdateRuntimeRequest", + "UpgradeRuntimeRequest", "EncryptionConfig", "LocalDisk", "LocalDiskInitializeParams", @@ -154,6 +167,7 @@ "DeleteExecutionRequest", "DeleteInstanceRequest", "DeleteScheduleRequest", + "DiagnoseInstanceRequest", "GetEnvironmentRequest", "GetExecutionRequest", "GetInstanceHealthRequest", diff --git a/google/cloud/notebooks/gapic_version.py b/google/cloud/notebooks/gapic_version.py new file mode 100644 index 0000000..25e4dd6 --- /dev/null +++ b/google/cloud/notebooks/gapic_version.py @@ -0,0 +1,16 @@ +# -*- 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. +# +__version__ = "1.4.4" # {x-release-please-version} diff --git a/google/cloud/notebooks_v1/__init__.py b/google/cloud/notebooks_v1/__init__.py index dde5426..d39d286 100644 --- a/google/cloud/notebooks_v1/__init__.py +++ b/google/cloud/notebooks_v1/__init__.py @@ -13,12 +13,17 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.notebooks import gapic_version as package_version + +__version__ = package_version.__version__ + from .services.managed_notebook_service import ( ManagedNotebookServiceAsyncClient, ManagedNotebookServiceClient, ) from .services.notebook_service import NotebookServiceAsyncClient, NotebookServiceClient +from .types.diagnostic_config import DiagnosticConfig from .types.environment import ContainerImage, Environment, VmImage from .types.event import Event from .types.execution import Execution, ExecutionTemplate @@ -27,6 +32,7 @@ from .types.managed_service import ( CreateRuntimeRequest, DeleteRuntimeRequest, + DiagnoseRuntimeRequest, GetRuntimeRequest, ListRuntimesRequest, ListRuntimesResponse, @@ -37,6 +43,8 @@ StartRuntimeRequest, StopRuntimeRequest, SwitchRuntimeRequest, + UpdateRuntimeRequest, + UpgradeRuntimeRequest, ) from .types.runtime import ( EncryptionConfig, @@ -61,6 +69,7 @@ DeleteExecutionRequest, DeleteInstanceRequest, DeleteScheduleRequest, + DiagnoseInstanceRequest, GetEnvironmentRequest, GetExecutionRequest, GetInstanceHealthRequest, @@ -111,6 +120,9 @@ "DeleteInstanceRequest", "DeleteRuntimeRequest", "DeleteScheduleRequest", + "DiagnoseInstanceRequest", + "DiagnoseRuntimeRequest", + "DiagnosticConfig", "EncryptionConfig", "Environment", "Event", @@ -170,9 +182,11 @@ "UpdateInstanceConfigRequest", "UpdateInstanceMetadataItemsRequest", "UpdateInstanceMetadataItemsResponse", + "UpdateRuntimeRequest", "UpdateShieldedInstanceConfigRequest", "UpgradeInstanceInternalRequest", "UpgradeInstanceRequest", + "UpgradeRuntimeRequest", "UpgradeType", "VirtualMachine", "VirtualMachineConfig", diff --git a/google/cloud/notebooks_v1/gapic_metadata.json b/google/cloud/notebooks_v1/gapic_metadata.json index aa528ae..4f92c87 100644 --- a/google/cloud/notebooks_v1/gapic_metadata.json +++ b/google/cloud/notebooks_v1/gapic_metadata.json @@ -20,6 +20,11 @@ "delete_runtime" ] }, + "DiagnoseRuntime": { + "methods": [ + "diagnose_runtime" + ] + }, "GetRuntime": { "methods": [ "get_runtime" @@ -59,6 +64,16 @@ "methods": [ "switch_runtime" ] + }, + "UpdateRuntime": { + "methods": [ + "update_runtime" + ] + }, + "UpgradeRuntime": { + "methods": [ + "upgrade_runtime" + ] } } }, @@ -75,6 +90,11 @@ "delete_runtime" ] }, + "DiagnoseRuntime": { + "methods": [ + "diagnose_runtime" + ] + }, "GetRuntime": { "methods": [ "get_runtime" @@ -114,6 +134,16 @@ "methods": [ "switch_runtime" ] + }, + "UpdateRuntime": { + "methods": [ + "update_runtime" + ] + }, + "UpgradeRuntime": { + "methods": [ + "upgrade_runtime" + ] } } } @@ -164,6 +194,11 @@ "delete_schedule" ] }, + "DiagnoseInstance": { + "methods": [ + "diagnose_instance" + ] + }, "GetEnvironment": { "methods": [ "get_environment" @@ -334,6 +369,11 @@ "delete_schedule" ] }, + "DiagnoseInstance": { + "methods": [ + "diagnose_instance" + ] + }, "GetEnvironment": { "methods": [ "get_environment" diff --git a/google/cloud/notebooks_v1/gapic_version.py b/google/cloud/notebooks_v1/gapic_version.py new file mode 100644 index 0000000..25e4dd6 --- /dev/null +++ b/google/cloud/notebooks_v1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- 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. +# +__version__ = "1.4.4" # {x-release-please-version} diff --git a/google/cloud/notebooks_v1/services/managed_notebook_service/async_client.py b/google/cloud/notebooks_v1/services/managed_notebook_service/async_client.py index f801099..b0b867d 100644 --- a/google/cloud/notebooks_v1/services/managed_notebook_service/async_client.py +++ b/google/cloud/notebooks_v1/services/managed_notebook_service/async_client.py @@ -16,7 +16,17 @@ from collections import OrderedDict import functools import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, +) from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 @@ -24,7 +34,8 @@ from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources + +from google.cloud.notebooks_v1 import gapic_version as package_version try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -33,10 +44,16 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.notebooks_v1.services.managed_notebook_service import pagers +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import managed_service from google.cloud.notebooks_v1.types import runtime from google.cloud.notebooks_v1.types import runtime as gcn_runtime @@ -170,9 +187,9 @@ def transport(self) -> ManagedNotebookServiceTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, ManagedNotebookServiceTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the managed notebook service client. @@ -216,11 +233,11 @@ def __init__( async def list_runtimes( self, - request: Union[managed_service.ListRuntimesRequest, dict] = None, + request: Optional[Union[managed_service.ListRuntimesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListRuntimesAsyncPager: r"""Lists Runtimes in a given project and location. @@ -253,7 +270,7 @@ async def sample_list_runtimes(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ListRuntimesRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ListRuntimesRequest, dict]]): The request object. Request for listing Managed Notebook Runtimes. parent (:class:`str`): @@ -331,11 +348,11 @@ async def sample_list_runtimes(): async def get_runtime( self, - request: Union[managed_service.GetRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.GetRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> runtime.Runtime: r"""Gets details of a single Runtime. The location must @@ -368,7 +385,7 @@ async def sample_get_runtime(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.GetRuntimeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.GetRuntimeRequest, dict]]): The request object. Request for getting a Managed Notebook Runtime. name (:class:`str`): @@ -434,13 +451,13 @@ async def sample_get_runtime(): async def create_runtime( self, - request: Union[managed_service.CreateRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.CreateRuntimeRequest, dict]] = None, *, - parent: str = None, - runtime_id: str = None, - runtime: gcn_runtime.Runtime = None, + parent: Optional[str] = None, + runtime_id: Optional[str] = None, + runtime: Optional[gcn_runtime.Runtime] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Runtime in a given project and @@ -472,13 +489,13 @@ async def sample_create_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.CreateRuntimeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.CreateRuntimeRequest, dict]]): The request object. Request for creating a Managed Notebook Runtime. parent (:class:`str`): @@ -569,13 +586,163 @@ async def sample_create_runtime(): # Done; return the response. return response + async def update_runtime( + self, + request: Optional[Union[managed_service.UpdateRuntimeRequest, dict]] = None, + *, + runtime: Optional[gcn_runtime.Runtime] = 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"""Update Notebook Runtime configuration. + + .. 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 notebooks_v1 + + async def sample_update_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceAsyncClient() + + # Initialize request argument(s) + request = notebooks_v1.UpdateRuntimeRequest( + ) + + # Make the request + operation = client.update_runtime(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.notebooks_v1.types.UpdateRuntimeRequest, dict]]): + The request object. Request for updating a Managed + Notebook configuration. + runtime (:class:`google.cloud.notebooks_v1.types.Runtime`): + Required. The Runtime to be updated. + This corresponds to the ``runtime`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. Specifies the path, relative to ``Runtime``, + of the field to update. For example, to change the + software configuration kernels, the ``update_mask`` + parameter would be specified as + ``software_config.kernels``, and the ``PATCH`` request + body would specify the new value, as follows: + + :: + + { + "software_config":{ + "kernels": [{ + 'repository': + 'gcr.io/deeplearning-platform-release/pytorch-gpu', 'tag': + 'latest' }], + } + } + + Currently, only the following fields can be updated: + + - software_config.kernels + - software_config.post_startup_script + - software_config.custom_gpu_driver_path + - software_config.idle_shutdown + - software_config.idle_shutdown_timeout + - software_config.disable_terminal + + 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.notebooks_v1.types.Runtime` The + definition of a Runtime for a managed notebook instance. + + """ + # 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([runtime, 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 = managed_service.UpdateRuntimeRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if runtime is not None: + request.runtime = runtime + 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_runtime, + default_timeout=60.0, + 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( + (("runtime.name", request.runtime.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, + gcn_runtime.Runtime, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + async def delete_runtime( self, - request: Union[managed_service.DeleteRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.DeleteRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Runtime. @@ -605,13 +772,13 @@ async def sample_delete_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.DeleteRuntimeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.DeleteRuntimeRequest, dict]]): The request object. Request for deleting a Managed Notebook Runtime. name (:class:`str`): @@ -695,11 +862,11 @@ async def sample_delete_runtime(): async def start_runtime( self, - request: Union[managed_service.StartRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.StartRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Starts a Managed Notebook Runtime. @@ -733,13 +900,13 @@ async def sample_start_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.StartRuntimeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.StartRuntimeRequest, dict]]): The request object. Request for starting a Managed Notebook Runtime. name (:class:`str`): @@ -816,11 +983,11 @@ async def sample_start_runtime(): async def stop_runtime( self, - request: Union[managed_service.StopRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.StopRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Stops a Managed Notebook Runtime. @@ -854,13 +1021,13 @@ async def sample_stop_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.StopRuntimeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.StopRuntimeRequest, dict]]): The request object. Request for stopping a Managed Notebook Runtime. name (:class:`str`): @@ -937,11 +1104,11 @@ async def sample_stop_runtime(): async def switch_runtime( self, - request: Union[managed_service.SwitchRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.SwitchRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Switch a Managed Notebook Runtime. @@ -971,13 +1138,13 @@ async def sample_switch_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.SwitchRuntimeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.SwitchRuntimeRequest, dict]]): The request object. Request for switching a Managed Notebook Runtime. name (:class:`str`): @@ -1054,11 +1221,11 @@ async def sample_switch_runtime(): async def reset_runtime( self, - request: Union[managed_service.ResetRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.ResetRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Resets a Managed Notebook Runtime. @@ -1088,13 +1255,13 @@ async def sample_reset_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ResetRuntimeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ResetRuntimeRequest, dict]]): The request object. Request for resetting a Managed Notebook Runtime. name (:class:`str`): @@ -1169,13 +1336,135 @@ async def sample_reset_runtime(): # Done; return the response. return response + async def upgrade_runtime( + self, + request: Optional[Union[managed_service.UpgradeRuntimeRequest, 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"""Upgrades a Managed Notebook Runtime to the latest + version. + + .. 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 notebooks_v1 + + async def sample_upgrade_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceAsyncClient() + + # Initialize request argument(s) + request = notebooks_v1.UpgradeRuntimeRequest( + name="name_value", + ) + + # Make the request + operation = client.upgrade_runtime(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.notebooks_v1.types.UpgradeRuntimeRequest, dict]]): + The request object. Request for upgrading a Managed + Notebook Runtime to the latest version. option + (google.api.message_visibility).restriction = + "TRUSTED_TESTER,SPECIAL_TESTER"; + name (:class:`str`): + Required. Format: + ``projects/{project_id}/locations/{location}/runtimes/{runtime_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.cloud.notebooks_v1.types.Runtime` The + definition of a Runtime for a managed notebook instance. + + """ + # 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 = managed_service.UpgradeRuntimeRequest(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.upgrade_runtime, + 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, + runtime.Runtime, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + async def report_runtime_event( self, - request: Union[managed_service.ReportRuntimeEventRequest, dict] = None, + request: Optional[ + Union[managed_service.ReportRuntimeEventRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Report and process a runtime event. @@ -1206,13 +1495,13 @@ async def sample_report_runtime_event(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ReportRuntimeEventRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ReportRuntimeEventRequest, dict]]): The request object. Request for reporting a Managed Notebook Event. name (:class:`str`): @@ -1289,12 +1578,14 @@ async def sample_report_runtime_event(): async def refresh_runtime_token_internal( self, - request: Union[managed_service.RefreshRuntimeTokenInternalRequest, dict] = None, + request: Optional[ + Union[managed_service.RefreshRuntimeTokenInternalRequest, dict] + ] = None, *, - name: str = None, - vm_id: str = None, + name: Optional[str] = None, + vm_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> managed_service.RefreshRuntimeTokenInternalResponse: r"""Gets an access token for the consumer service account @@ -1329,7 +1620,7 @@ async def sample_refresh_runtime_token_internal(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.RefreshRuntimeTokenInternalRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.RefreshRuntimeTokenInternalRequest, dict]]): The request object. Request for getting a new access token. name (:class:`str`): @@ -1401,21 +1692,773 @@ async def sample_refresh_runtime_token_internal(): # Done; return the response. return response - async def __aenter__(self): - return self + async def diagnose_runtime( + self, + request: Optional[Union[managed_service.DiagnoseRuntimeRequest, dict]] = None, + *, + name: Optional[str] = None, + diagnostic_config: Optional[gcn_diagnostic_config.DiagnosticConfig] = 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 Diagnostic File and runs Diagnostic Tool + given a Runtime. - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() + .. 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 notebooks_v1 -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + async def sample_diagnose_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceAsyncClient() + + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" + + request = notebooks_v1.DiagnoseRuntimeRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_runtime(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.notebooks_v1.types.DiagnoseRuntimeRequest, dict]]): + The request object. Request for creating a notebook + instance diagnostic file. + name (:class:`str`): + Required. Format: + ``projects/{project_id}/locations/{location}/runtimes/{runtimes_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + diagnostic_config (:class:`google.cloud.notebooks_v1.types.DiagnosticConfig`): + Required. Defines flags that are used + to run the diagnostic tool + + This corresponds to the ``diagnostic_config`` 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.notebooks_v1.types.Runtime` The + definition of a Runtime for a managed notebook instance. + + """ + # 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, diagnostic_config]) + 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 = managed_service.DiagnoseRuntimeRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if diagnostic_config is not None: + request.diagnostic_config = diagnostic_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.diagnose_runtime, + default_timeout=60.0, + 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, + runtime.Runtime, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + 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 delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def set_iam_policy( + self, + request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: Optional[locations_pb2.GetLocationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + 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 list_locations( + self, + request: Optional[locations_pb2.ListLocationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("ManagedNotebookServiceAsyncClient",) diff --git a/google/cloud/notebooks_v1/services/managed_notebook_service/client.py b/google/cloud/notebooks_v1/services/managed_notebook_service/client.py index 287922b..ea5079f 100644 --- a/google/cloud/notebooks_v1/services/managed_notebook_service/client.py +++ b/google/cloud/notebooks_v1/services/managed_notebook_service/client.py @@ -16,7 +16,18 @@ from collections import OrderedDict import os import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, + cast, +) from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -27,7 +38,8 @@ from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources + +from google.cloud.notebooks_v1 import gapic_version as package_version try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -36,10 +48,16 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.notebooks_v1.services.managed_notebook_service import pagers +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import managed_service from google.cloud.notebooks_v1.types import runtime from google.cloud.notebooks_v1.types import runtime as gcn_runtime @@ -66,7 +84,7 @@ class ManagedNotebookServiceClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[ManagedNotebookServiceTransport]: """Returns an appropriate transport class. @@ -341,8 +359,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, ManagedNotebookServiceTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, ManagedNotebookServiceTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the managed notebook service client. @@ -356,7 +374,7 @@ def __init__( transport (Union[str, ManagedNotebookServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -386,6 +404,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -438,11 +457,11 @@ def __init__( def list_runtimes( self, - request: Union[managed_service.ListRuntimesRequest, dict] = None, + request: Optional[Union[managed_service.ListRuntimesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListRuntimesPager: r"""Lists Runtimes in a given project and location. @@ -553,11 +572,11 @@ def sample_list_runtimes(): def get_runtime( self, - request: Union[managed_service.GetRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.GetRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> runtime.Runtime: r"""Gets details of a single Runtime. The location must @@ -656,13 +675,13 @@ def sample_get_runtime(): def create_runtime( self, - request: Union[managed_service.CreateRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.CreateRuntimeRequest, dict]] = None, *, - parent: str = None, - runtime_id: str = None, - runtime: gcn_runtime.Runtime = None, + parent: Optional[str] = None, + runtime_id: Optional[str] = None, + runtime: Optional[gcn_runtime.Runtime] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a new Runtime in a given project and @@ -791,13 +810,163 @@ def sample_create_runtime(): # Done; return the response. return response + def update_runtime( + self, + request: Optional[Union[managed_service.UpdateRuntimeRequest, dict]] = None, + *, + runtime: Optional[gcn_runtime.Runtime] = 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"""Update Notebook Runtime configuration. + + .. 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 notebooks_v1 + + def sample_update_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceClient() + + # Initialize request argument(s) + request = notebooks_v1.UpdateRuntimeRequest( + ) + + # Make the request + operation = client.update_runtime(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.notebooks_v1.types.UpdateRuntimeRequest, dict]): + The request object. Request for updating a Managed + Notebook configuration. + runtime (google.cloud.notebooks_v1.types.Runtime): + Required. The Runtime to be updated. + This corresponds to the ``runtime`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Specifies the path, relative to ``Runtime``, + of the field to update. For example, to change the + software configuration kernels, the ``update_mask`` + parameter would be specified as + ``software_config.kernels``, and the ``PATCH`` request + body would specify the new value, as follows: + + :: + + { + "software_config":{ + "kernels": [{ + 'repository': + 'gcr.io/deeplearning-platform-release/pytorch-gpu', 'tag': + 'latest' }], + } + } + + Currently, only the following fields can be updated: + + - software_config.kernels + - software_config.post_startup_script + - software_config.custom_gpu_driver_path + - software_config.idle_shutdown + - software_config.idle_shutdown_timeout + - software_config.disable_terminal + + 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.notebooks_v1.types.Runtime` The + definition of a Runtime for a managed notebook instance. + + """ + # 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([runtime, 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 managed_service.UpdateRuntimeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, managed_service.UpdateRuntimeRequest): + request = managed_service.UpdateRuntimeRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if runtime is not None: + request.runtime = runtime + 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_runtime] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("runtime.name", request.runtime.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, + gcn_runtime.Runtime, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + def delete_runtime( self, - request: Union[managed_service.DeleteRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.DeleteRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes a single Runtime. @@ -917,11 +1086,11 @@ def sample_delete_runtime(): def start_runtime( self, - request: Union[managed_service.StartRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.StartRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Starts a Managed Notebook Runtime. @@ -1038,11 +1207,11 @@ def sample_start_runtime(): def stop_runtime( self, - request: Union[managed_service.StopRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.StopRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Stops a Managed Notebook Runtime. @@ -1159,11 +1328,11 @@ def sample_stop_runtime(): def switch_runtime( self, - request: Union[managed_service.SwitchRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.SwitchRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Switch a Managed Notebook Runtime. @@ -1276,11 +1445,11 @@ def sample_switch_runtime(): def reset_runtime( self, - request: Union[managed_service.ResetRuntimeRequest, dict] = None, + request: Optional[Union[managed_service.ResetRuntimeRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Resets a Managed Notebook Runtime. @@ -1391,13 +1560,135 @@ def sample_reset_runtime(): # Done; return the response. return response + def upgrade_runtime( + self, + request: Optional[Union[managed_service.UpgradeRuntimeRequest, 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"""Upgrades a Managed Notebook Runtime to the latest + version. + + .. 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 notebooks_v1 + + def sample_upgrade_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceClient() + + # Initialize request argument(s) + request = notebooks_v1.UpgradeRuntimeRequest( + name="name_value", + ) + + # Make the request + operation = client.upgrade_runtime(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.notebooks_v1.types.UpgradeRuntimeRequest, dict]): + The request object. Request for upgrading a Managed + Notebook Runtime to the latest version. option + (google.api.message_visibility).restriction = + "TRUSTED_TESTER,SPECIAL_TESTER"; + name (str): + Required. Format: + ``projects/{project_id}/locations/{location}/runtimes/{runtime_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.cloud.notebooks_v1.types.Runtime` The + definition of a Runtime for a managed notebook instance. + + """ + # 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 managed_service.UpgradeRuntimeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, managed_service.UpgradeRuntimeRequest): + request = managed_service.UpgradeRuntimeRequest(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.upgrade_runtime] + + # 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, + runtime.Runtime, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + def report_runtime_event( self, - request: Union[managed_service.ReportRuntimeEventRequest, dict] = None, + request: Optional[ + Union[managed_service.ReportRuntimeEventRequest, dict] + ] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Report and process a runtime event. @@ -1511,12 +1802,14 @@ def sample_report_runtime_event(): def refresh_runtime_token_internal( self, - request: Union[managed_service.RefreshRuntimeTokenInternalRequest, dict] = None, + request: Optional[ + Union[managed_service.RefreshRuntimeTokenInternalRequest, dict] + ] = None, *, - name: str = None, - vm_id: str = None, + name: Optional[str] = None, + vm_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> managed_service.RefreshRuntimeTokenInternalResponse: r"""Gets an access token for the consumer service account @@ -1625,28 +1918,780 @@ def sample_refresh_runtime_token_internal(): # Done; return the response. return response - def __enter__(self): - return self + def diagnose_runtime( + self, + request: Optional[Union[managed_service.DiagnoseRuntimeRequest, dict]] = None, + *, + name: Optional[str] = None, + diagnostic_config: Optional[gcn_diagnostic_config.DiagnosticConfig] = 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 Diagnostic File and runs Diagnostic Tool + given a Runtime. - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. + .. code-block:: python - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() + # 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 notebooks_v1 + + def sample_diagnose_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceClient() + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + request = notebooks_v1.DiagnoseRuntimeRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_runtime(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.notebooks_v1.types.DiagnoseRuntimeRequest, dict]): + The request object. Request for creating a notebook + instance diagnostic file. + name (str): + Required. Format: + ``projects/{project_id}/locations/{location}/runtimes/{runtimes_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + diagnostic_config (google.cloud.notebooks_v1.types.DiagnosticConfig): + Required. Defines flags that are used + to run the diagnostic tool + + This corresponds to the ``diagnostic_config`` 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.notebooks_v1.types.Runtime` The + definition of a Runtime for a managed notebook instance. + + """ + # 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, diagnostic_config]) + 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 managed_service.DiagnoseRuntimeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, managed_service.DiagnoseRuntimeRequest): + request = managed_service.DiagnoseRuntimeRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if diagnostic_config is not None: + request.diagnostic_config = diagnostic_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.diagnose_runtime] + + # 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, + runtime.Runtime, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def set_iam_policy( + self, + request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: Optional[locations_pb2.GetLocationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: Optional[locations_pb2.ListLocationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("ManagedNotebookServiceClient",) diff --git a/google/cloud/notebooks_v1/services/managed_notebook_service/transports/base.py b/google/cloud/notebooks_v1/services/managed_notebook_service/transports/base.py index 7328af5..72d7c1f 100644 --- a/google/cloud/notebooks_v1/services/managed_notebook_service/transports/base.py +++ b/google/cloud/notebooks_v1/services/managed_notebook_service/transports/base.py @@ -22,20 +22,18 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources +from google.cloud.notebooks_v1 import gapic_version as package_version from google.cloud.notebooks_v1.types import managed_service, runtime -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class ManagedNotebookServiceTransport(abc.ABC): @@ -49,7 +47,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -143,6 +141,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.update_runtime: gapic_v1.method.wrap_method( + self.update_runtime, + default_timeout=60.0, + client_info=client_info, + ), self.delete_runtime: gapic_v1.method.wrap_method( self.delete_runtime, default_timeout=60.0, @@ -168,6 +171,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.upgrade_runtime: gapic_v1.method.wrap_method( + self.upgrade_runtime, + default_timeout=None, + client_info=client_info, + ), self.report_runtime_event: gapic_v1.method.wrap_method( self.report_runtime_event, default_timeout=60.0, @@ -178,6 +186,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.diagnose_runtime: gapic_v1.method.wrap_method( + self.diagnose_runtime, + default_timeout=60.0, + client_info=client_info, + ), } def close(self): @@ -224,6 +237,15 @@ def create_runtime( ]: raise NotImplementedError() + @property + def update_runtime( + self, + ) -> Callable[ + [managed_service.UpdateRuntimeRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def delete_runtime( self, @@ -269,6 +291,15 @@ def reset_runtime( ]: raise NotImplementedError() + @property + def upgrade_runtime( + self, + ) -> Callable[ + [managed_service.UpgradeRuntimeRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def report_runtime_event( self, @@ -290,6 +321,99 @@ def refresh_runtime_token_internal( ]: raise NotImplementedError() + @property + def diagnose_runtime( + self, + ) -> Callable[ + [managed_service.DiagnoseRuntimeRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + @property def kind(self) -> str: raise NotImplementedError() diff --git a/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc.py b/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc.py index dd3ca57..5f759e9 100644 --- a/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc.py +++ b/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc.py @@ -20,6 +20,9 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore @@ -47,14 +50,14 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -182,8 +185,8 @@ def __init__( def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, @@ -326,6 +329,32 @@ def create_runtime( ) return self._stubs["create_runtime"] + @property + def update_runtime( + self, + ) -> Callable[[managed_service.UpdateRuntimeRequest], operations_pb2.Operation]: + r"""Return a callable for the update runtime method over gRPC. + + Update Notebook Runtime configuration. + + Returns: + Callable[[~.UpdateRuntimeRequest], + ~.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_runtime" not in self._stubs: + self._stubs["update_runtime"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.ManagedNotebookService/UpdateRuntime", + request_serializer=managed_service.UpdateRuntimeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_runtime"] + @property def delete_runtime( self, @@ -464,6 +493,33 @@ def reset_runtime( ) return self._stubs["reset_runtime"] + @property + def upgrade_runtime( + self, + ) -> Callable[[managed_service.UpgradeRuntimeRequest], operations_pb2.Operation]: + r"""Return a callable for the upgrade runtime method over gRPC. + + Upgrades a Managed Notebook Runtime to the latest + version. + + Returns: + Callable[[~.UpgradeRuntimeRequest], + ~.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 "upgrade_runtime" not in self._stubs: + self._stubs["upgrade_runtime"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.ManagedNotebookService/UpgradeRuntime", + request_serializer=managed_service.UpgradeRuntimeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["upgrade_runtime"] + @property def report_runtime_event( self, @@ -525,9 +581,222 @@ def refresh_runtime_token_internal( ) return self._stubs["refresh_runtime_token_internal"] + @property + def diagnose_runtime( + self, + ) -> Callable[[managed_service.DiagnoseRuntimeRequest], operations_pb2.Operation]: + r"""Return a callable for the diagnose runtime method over gRPC. + + Creates a Diagnostic File and runs Diagnostic Tool + given a Runtime. + + Returns: + Callable[[~.DiagnoseRuntimeRequest], + ~.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 "diagnose_runtime" not in self._stubs: + self._stubs["diagnose_runtime"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.ManagedNotebookService/DiagnoseRuntime", + request_serializer=managed_service.DiagnoseRuntimeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["diagnose_runtime"] + def close(self): self.grpc_channel.close() + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # 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 "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # 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_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + 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 "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + 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_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + 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 "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + @property def kind(self) -> str: return "grpc" diff --git a/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc_asyncio.py b/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc_asyncio.py index b80198d..0d988e4 100644 --- a/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc_asyncio.py +++ b/google/cloud/notebooks_v1/services/managed_notebook_service/transports/grpc_asyncio.py @@ -19,6 +19,9 @@ from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -49,7 +52,7 @@ class ManagedNotebookServiceGrpcAsyncIOTransport(ManagedNotebookServiceTransport def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -92,15 +95,15 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, @@ -334,6 +337,34 @@ def create_runtime( ) return self._stubs["create_runtime"] + @property + def update_runtime( + self, + ) -> Callable[ + [managed_service.UpdateRuntimeRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the update runtime method over gRPC. + + Update Notebook Runtime configuration. + + Returns: + Callable[[~.UpdateRuntimeRequest], + 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_runtime" not in self._stubs: + self._stubs["update_runtime"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.ManagedNotebookService/UpdateRuntime", + request_serializer=managed_service.UpdateRuntimeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_runtime"] + @property def delete_runtime( self, @@ -482,6 +513,35 @@ def reset_runtime( ) return self._stubs["reset_runtime"] + @property + def upgrade_runtime( + self, + ) -> Callable[ + [managed_service.UpgradeRuntimeRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the upgrade runtime method over gRPC. + + Upgrades a Managed Notebook Runtime to the latest + version. + + Returns: + Callable[[~.UpgradeRuntimeRequest], + 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 "upgrade_runtime" not in self._stubs: + self._stubs["upgrade_runtime"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.ManagedNotebookService/UpgradeRuntime", + request_serializer=managed_service.UpgradeRuntimeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["upgrade_runtime"] + @property def report_runtime_event( self, @@ -543,8 +603,223 @@ def refresh_runtime_token_internal( ) return self._stubs["refresh_runtime_token_internal"] + @property + def diagnose_runtime( + self, + ) -> Callable[ + [managed_service.DiagnoseRuntimeRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the diagnose runtime method over gRPC. + + Creates a Diagnostic File and runs Diagnostic Tool + given a Runtime. + + Returns: + Callable[[~.DiagnoseRuntimeRequest], + 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 "diagnose_runtime" not in self._stubs: + self._stubs["diagnose_runtime"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.ManagedNotebookService/DiagnoseRuntime", + request_serializer=managed_service.DiagnoseRuntimeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["diagnose_runtime"] + def close(self): return self.grpc_channel.close() + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # 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 "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # 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_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + 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 "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + 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_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + 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 "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("ManagedNotebookServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/notebooks_v1/services/notebook_service/async_client.py b/google/cloud/notebooks_v1/services/notebook_service/async_client.py index 8aafe80..d7dd615 100644 --- a/google/cloud/notebooks_v1/services/notebook_service/async_client.py +++ b/google/cloud/notebooks_v1/services/notebook_service/async_client.py @@ -16,7 +16,17 @@ from collections import OrderedDict import functools import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, +) from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 @@ -24,7 +34,8 @@ from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources + +from google.cloud.notebooks_v1 import gapic_version as package_version try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -33,10 +44,15 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.notebooks_v1.services.notebook_service import pagers +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import environment from google.cloud.notebooks_v1.types import environment as gcn_environment from google.cloud.notebooks_v1.types import execution @@ -180,9 +196,9 @@ def transport(self) -> NotebookServiceTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, NotebookServiceTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the notebook service client. @@ -226,11 +242,11 @@ def __init__( async def list_instances( self, - request: Union[service.ListInstancesRequest, dict] = None, + request: Optional[Union[service.ListInstancesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListInstancesAsyncPager: r"""Lists instances in a given project and location. @@ -263,7 +279,7 @@ async def sample_list_instances(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ListInstancesRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ListInstancesRequest, dict]]): The request object. Request for listing notebook instances. parent (:class:`str`): @@ -341,11 +357,11 @@ async def sample_list_instances(): async def get_instance( self, - request: Union[service.GetInstanceRequest, dict] = None, + request: Optional[Union[service.GetInstanceRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> instance.Instance: r"""Gets details of a single Instance. @@ -377,7 +393,7 @@ async def sample_get_instance(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.GetInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.GetInstanceRequest, dict]]): The request object. Request for getting a notebook instance. name (:class:`str`): @@ -443,13 +459,13 @@ async def sample_get_instance(): async def create_instance( self, - request: Union[service.CreateInstanceRequest, dict] = None, + request: Optional[Union[service.CreateInstanceRequest, dict]] = None, *, - parent: str = None, - instance: gcn_instance.Instance = None, - instance_id: str = None, + parent: Optional[str] = None, + instance: Optional[gcn_instance.Instance] = None, + instance_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Instance in a given project and @@ -487,13 +503,13 @@ async def sample_create_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.CreateInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.CreateInstanceRequest, dict]]): The request object. Request for creating a notebook instance. parent (:class:`str`): @@ -586,10 +602,10 @@ async def sample_create_instance(): async def register_instance( self, - request: Union[service.RegisterInstanceRequest, dict] = None, + request: Optional[Union[service.RegisterInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Registers an existing legacy notebook instance to the @@ -625,13 +641,13 @@ async def sample_register_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.RegisterInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.RegisterInstanceRequest, dict]]): The request object. Request for registering a notebook instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -687,10 +703,10 @@ async def sample_register_instance(): async def set_instance_accelerator( self, - request: Union[service.SetInstanceAcceleratorRequest, dict] = None, + request: Optional[Union[service.SetInstanceAcceleratorRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the guest accelerators of a single Instance. @@ -722,13 +738,13 @@ async def sample_set_instance_accelerator(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.SetInstanceAcceleratorRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.SetInstanceAcceleratorRequest, dict]]): The request object. Request for setting instance accelerator. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -784,10 +800,10 @@ async def sample_set_instance_accelerator(): async def set_instance_machine_type( self, - request: Union[service.SetInstanceMachineTypeRequest, dict] = None, + request: Optional[Union[service.SetInstanceMachineTypeRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the machine type of a single Instance. @@ -818,13 +834,13 @@ async def sample_set_instance_machine_type(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.SetInstanceMachineTypeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.SetInstanceMachineTypeRequest, dict]]): The request object. Request for setting instance machine type. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -880,10 +896,10 @@ async def sample_set_instance_machine_type(): async def update_instance_config( self, - request: Union[service.UpdateInstanceConfigRequest, dict] = None, + request: Optional[Union[service.UpdateInstanceConfigRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Update Notebook Instance configurations. @@ -913,13 +929,13 @@ async def sample_update_instance_config(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.UpdateInstanceConfigRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.UpdateInstanceConfigRequest, dict]]): The request object. Request for updating instance configurations. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -975,10 +991,12 @@ async def sample_update_instance_config(): async def update_shielded_instance_config( self, - request: Union[service.UpdateShieldedInstanceConfigRequest, dict] = None, + request: Optional[ + Union[service.UpdateShieldedInstanceConfigRequest, dict] + ] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the Shielded instance configuration of a @@ -1009,13 +1027,13 @@ async def sample_update_shielded_instance_config(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.UpdateShieldedInstanceConfigRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.UpdateShieldedInstanceConfigRequest, dict]]): The request object. Request for updating the Shielded Instance config for a notebook instance. You can only use this method on a stopped instance @@ -1072,10 +1090,10 @@ async def sample_update_shielded_instance_config(): async def set_instance_labels( self, - request: Union[service.SetInstanceLabelsRequest, dict] = None, + request: Optional[Union[service.SetInstanceLabelsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Replaces all the labels of an Instance. @@ -1105,13 +1123,13 @@ async def sample_set_instance_labels(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.SetInstanceLabelsRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.SetInstanceLabelsRequest, dict]]): The request object. Request for setting instance labels. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -1166,10 +1184,12 @@ async def sample_set_instance_labels(): async def update_instance_metadata_items( self, - request: Union[service.UpdateInstanceMetadataItemsRequest, dict] = None, + request: Optional[ + Union[service.UpdateInstanceMetadataItemsRequest, dict] + ] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.UpdateInstanceMetadataItemsResponse: r"""Add/update metadata items for an instance. @@ -1201,7 +1221,7 @@ async def sample_update_instance_metadata_items(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.UpdateInstanceMetadataItemsRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.UpdateInstanceMetadataItemsRequest, dict]]): The request object. Request for adding/changing metadata items for an instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1246,11 +1266,11 @@ async def sample_update_instance_metadata_items(): async def delete_instance( self, - request: Union[service.DeleteInstanceRequest, dict] = None, + request: Optional[Union[service.DeleteInstanceRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Instance. @@ -1280,13 +1300,13 @@ async def sample_delete_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.DeleteInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.DeleteInstanceRequest, dict]]): The request object. Request for deleting a notebook instance. name (:class:`str`): @@ -1370,10 +1390,10 @@ async def sample_delete_instance(): async def start_instance( self, - request: Union[service.StartInstanceRequest, dict] = None, + request: Optional[Union[service.StartInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Starts a notebook instance. @@ -1403,13 +1423,13 @@ async def sample_start_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.StartInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.StartInstanceRequest, dict]]): The request object. Request for starting a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1465,10 +1485,10 @@ async def sample_start_instance(): async def stop_instance( self, - request: Union[service.StopInstanceRequest, dict] = None, + request: Optional[Union[service.StopInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Stops a notebook instance. @@ -1498,13 +1518,13 @@ async def sample_stop_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.StopInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.StopInstanceRequest, dict]]): The request object. Request for stopping a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1560,10 +1580,10 @@ async def sample_stop_instance(): async def reset_instance( self, - request: Union[service.ResetInstanceRequest, dict] = None, + request: Optional[Union[service.ResetInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Resets a notebook instance. @@ -1593,13 +1613,13 @@ async def sample_reset_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ResetInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ResetInstanceRequest, dict]]): The request object. Request for resetting a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1655,10 +1675,10 @@ async def sample_reset_instance(): async def report_instance_info( self, - request: Union[service.ReportInstanceInfoRequest, dict] = None, + request: Optional[Union[service.ReportInstanceInfoRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Allows notebook instances to @@ -1693,13 +1713,13 @@ async def sample_report_instance_info(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ReportInstanceInfoRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ReportInstanceInfoRequest, dict]]): The request object. Request for notebook instances to report information to Notebooks API. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1755,10 +1775,10 @@ async def sample_report_instance_info(): async def is_instance_upgradeable( self, - request: Union[service.IsInstanceUpgradeableRequest, dict] = None, + request: Optional[Union[service.IsInstanceUpgradeableRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.IsInstanceUpgradeableResponse: r"""Check if a notebook instance is upgradable. @@ -1790,7 +1810,7 @@ async def sample_is_instance_upgradeable(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.IsInstanceUpgradeableRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.IsInstanceUpgradeableRequest, dict]]): The request object. Request for checking if a notebook instance is upgradeable. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1837,11 +1857,11 @@ async def sample_is_instance_upgradeable(): async def get_instance_health( self, - request: Union[service.GetInstanceHealthRequest, dict] = None, + request: Optional[Union[service.GetInstanceHealthRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.GetInstanceHealthResponse: r"""Check if a notebook instance is healthy. @@ -1873,7 +1893,7 @@ async def sample_get_instance_health(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.GetInstanceHealthRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.GetInstanceHealthRequest, dict]]): The request object. Request for checking if a notebook instance is healthy. name (:class:`str`): @@ -1939,10 +1959,10 @@ async def sample_get_instance_health(): async def upgrade_instance( self, - request: Union[service.UpgradeInstanceRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Upgrades a notebook instance to the latest version. @@ -1972,13 +1992,13 @@ async def sample_upgrade_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.UpgradeInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.UpgradeInstanceRequest, dict]]): The request object. Request for upgrading a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -2034,10 +2054,10 @@ async def sample_upgrade_instance(): async def rollback_instance( self, - request: Union[service.RollbackInstanceRequest, dict] = None, + request: Optional[Union[service.RollbackInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Rollbacks a notebook instance to the previous @@ -2069,13 +2089,13 @@ async def sample_rollback_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.RollbackInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.RollbackInstanceRequest, dict]]): The request object. Request for rollbacking a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -2129,12 +2149,144 @@ async def sample_rollback_instance(): # Done; return the response. return response + async def diagnose_instance( + self, + request: Optional[Union[service.DiagnoseInstanceRequest, dict]] = None, + *, + name: Optional[str] = None, + diagnostic_config: Optional[gcn_diagnostic_config.DiagnosticConfig] = 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 Diagnostic File and runs Diagnostic Tool + given an Instance. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import notebooks_v1 + + async def sample_diagnose_instance(): + # Create a client + client = notebooks_v1.NotebookServiceAsyncClient() + + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" + + request = notebooks_v1.DiagnoseInstanceRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_instance(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.notebooks_v1.types.DiagnoseInstanceRequest, dict]]): + The request object. Request for creating a notebook + instance diagnostic file. + name (:class:`str`): + Required. Format: + ``projects/{project_id}/locations/{location}/instances/{instance_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + diagnostic_config (:class:`google.cloud.notebooks_v1.types.DiagnosticConfig`): + Required. Defines flags that are used + to run the diagnostic tool + + This corresponds to the ``diagnostic_config`` 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.notebooks_v1.types.Instance` The + definition of a notebook instance. + + """ + # 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, diagnostic_config]) + 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 = service.DiagnoseInstanceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if diagnostic_config is not None: + request.diagnostic_config = diagnostic_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.diagnose_instance, + default_timeout=60.0, + 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, + instance.Instance, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + async def upgrade_instance_internal( self, - request: Union[service.UpgradeInstanceInternalRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceInternalRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Allows notebook instances to @@ -2167,13 +2319,13 @@ async def sample_upgrade_instance_internal(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.UpgradeInstanceInternalRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.UpgradeInstanceInternalRequest, dict]]): The request object. Request for upgrading a notebook instance from within the VM retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -2229,11 +2381,11 @@ async def sample_upgrade_instance_internal(): async def list_environments( self, - request: Union[service.ListEnvironmentsRequest, dict] = None, + request: Optional[Union[service.ListEnvironmentsRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEnvironmentsAsyncPager: r"""Lists environments in a project. @@ -2266,7 +2418,7 @@ async def sample_list_environments(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ListEnvironmentsRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ListEnvironmentsRequest, dict]]): The request object. Request for listing environments. parent (:class:`str`): Required. Format: @@ -2342,11 +2494,11 @@ async def sample_list_environments(): async def get_environment( self, - request: Union[service.GetEnvironmentRequest, dict] = None, + request: Optional[Union[service.GetEnvironmentRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Gets details of a single Environment. @@ -2378,7 +2530,7 @@ async def sample_get_environment(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.GetEnvironmentRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.GetEnvironmentRequest, dict]]): The request object. Request for getting a notebook environment. name (:class:`str`): @@ -2445,13 +2597,13 @@ async def sample_get_environment(): async def create_environment( self, - request: Union[service.CreateEnvironmentRequest, dict] = None, + request: Optional[Union[service.CreateEnvironmentRequest, dict]] = None, *, - parent: str = None, - environment: gcn_environment.Environment = None, - environment_id: str = None, + parent: Optional[str] = None, + environment: Optional[gcn_environment.Environment] = None, + environment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Environment. @@ -2487,13 +2639,13 @@ async def sample_create_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.CreateEnvironmentRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.CreateEnvironmentRequest, dict]]): The request object. Request for creating a notebook environment. parent (:class:`str`): @@ -2590,11 +2742,11 @@ async def sample_create_environment(): async def delete_environment( self, - request: Union[service.DeleteEnvironmentRequest, dict] = None, + request: Optional[Union[service.DeleteEnvironmentRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Environment. @@ -2624,13 +2776,13 @@ async def sample_delete_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.DeleteEnvironmentRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.DeleteEnvironmentRequest, dict]]): The request object. Request for deleting a notebook environment. name (:class:`str`): @@ -2714,11 +2866,11 @@ async def sample_delete_environment(): async def list_schedules( self, - request: Union[service.ListSchedulesRequest, dict] = None, + request: Optional[Union[service.ListSchedulesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSchedulesAsyncPager: r"""Lists schedules in a given project and location. @@ -2751,7 +2903,7 @@ async def sample_list_schedules(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ListSchedulesRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ListSchedulesRequest, dict]]): The request object. Request for listing scheduled notebook job. parent (:class:`str`): @@ -2829,11 +2981,11 @@ async def sample_list_schedules(): async def get_schedule( self, - request: Union[service.GetScheduleRequest, dict] = None, + request: Optional[Union[service.GetScheduleRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> schedule.Schedule: r"""Gets details of schedule @@ -2865,7 +3017,7 @@ async def sample_get_schedule(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.GetScheduleRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.GetScheduleRequest, dict]]): The request object. Request for getting scheduled notebook. name (:class:`str`): @@ -2929,11 +3081,11 @@ async def sample_get_schedule(): async def delete_schedule( self, - request: Union[service.DeleteScheduleRequest, dict] = None, + request: Optional[Union[service.DeleteScheduleRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes schedule and all underlying jobs @@ -2963,13 +3115,13 @@ async def sample_delete_schedule(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.DeleteScheduleRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.DeleteScheduleRequest, dict]]): The request object. Request for deleting an Schedule name (:class:`str`): Required. Format: @@ -3052,13 +3204,13 @@ async def sample_delete_schedule(): async def create_schedule( self, - request: Union[service.CreateScheduleRequest, dict] = None, + request: Optional[Union[service.CreateScheduleRequest, dict]] = None, *, - parent: str = None, - schedule: gcn_schedule.Schedule = None, - schedule_id: str = None, + parent: Optional[str] = None, + schedule: Optional[gcn_schedule.Schedule] = None, + schedule_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Scheduled Notebook in a given project @@ -3090,13 +3242,13 @@ async def sample_create_schedule(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.CreateScheduleRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.CreateScheduleRequest, dict]]): The request object. Request for created scheduled notebooks parent (:class:`str`): @@ -3189,10 +3341,10 @@ async def sample_create_schedule(): async def trigger_schedule( self, - request: Union[service.TriggerScheduleRequest, dict] = None, + request: Optional[Union[service.TriggerScheduleRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Triggers execution of an existing schedule. @@ -3222,13 +3374,13 @@ async def sample_trigger_schedule(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.TriggerScheduleRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.TriggerScheduleRequest, dict]]): The request object. Request for created scheduled notebooks retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -3284,11 +3436,11 @@ async def sample_trigger_schedule(): async def list_executions( self, - request: Union[service.ListExecutionsRequest, dict] = None, + request: Optional[Union[service.ListExecutionsRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListExecutionsAsyncPager: r"""Lists executions in a given project and location @@ -3321,7 +3473,7 @@ async def sample_list_executions(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.ListExecutionsRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.ListExecutionsRequest, dict]]): The request object. Request for listing scheduled notebook executions. parent (:class:`str`): @@ -3399,11 +3551,11 @@ async def sample_list_executions(): async def get_execution( self, - request: Union[service.GetExecutionRequest, dict] = None, + request: Optional[Union[service.GetExecutionRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> execution.Execution: r"""Gets details of executions @@ -3435,7 +3587,7 @@ async def sample_get_execution(): print(response) Args: - request (Union[google.cloud.notebooks_v1.types.GetExecutionRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.GetExecutionRequest, dict]]): The request object. Request for getting scheduled notebook execution name (:class:`str`): @@ -3501,11 +3653,11 @@ async def sample_get_execution(): async def delete_execution( self, - request: Union[service.DeleteExecutionRequest, dict] = None, + request: Optional[Union[service.DeleteExecutionRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes execution @@ -3535,13 +3687,13 @@ async def sample_delete_execution(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.DeleteExecutionRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.DeleteExecutionRequest, dict]]): The request object. Request for deleting a scheduled notebook execution name (:class:`str`): @@ -3625,13 +3777,13 @@ async def sample_delete_execution(): async def create_execution( self, - request: Union[service.CreateExecutionRequest, dict] = None, + request: Optional[Union[service.CreateExecutionRequest, dict]] = None, *, - parent: str = None, - execution: gcn_execution.Execution = None, - execution_id: str = None, + parent: Optional[str] = None, + execution: Optional[gcn_execution.Execution] = None, + execution_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Execution in a given project and @@ -3663,13 +3815,13 @@ async def sample_create_execution(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1.types.CreateExecutionRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1.types.CreateExecutionRequest, dict]]): The request object. Request to create notebook execution parent (:class:`str`): Required. Format: @@ -3761,6 +3913,631 @@ async def sample_create_execution(): # Done; return the response. return response + async def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + 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 delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def set_iam_policy( + self, + request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: Optional[locations_pb2.GetLocationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + 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 list_locations( + self, + request: Optional[locations_pb2.ListLocationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + 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 __aenter__(self): return self @@ -3768,14 +4545,9 @@ async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("NotebookServiceAsyncClient",) diff --git a/google/cloud/notebooks_v1/services/notebook_service/client.py b/google/cloud/notebooks_v1/services/notebook_service/client.py index ecbf82f..c72faaa 100644 --- a/google/cloud/notebooks_v1/services/notebook_service/client.py +++ b/google/cloud/notebooks_v1/services/notebook_service/client.py @@ -16,7 +16,18 @@ from collections import OrderedDict import os import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, + cast, +) from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -27,7 +38,8 @@ from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources + +from google.cloud.notebooks_v1 import gapic_version as package_version try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -36,10 +48,15 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.notebooks_v1.services.notebook_service import pagers +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import environment from google.cloud.notebooks_v1.types import environment as gcn_environment from google.cloud.notebooks_v1.types import execution @@ -71,7 +88,7 @@ class NotebookServiceClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[NotebookServiceTransport]: """Returns an appropriate transport class. @@ -428,8 +445,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, NotebookServiceTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, NotebookServiceTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the notebook service client. @@ -443,7 +460,7 @@ def __init__( transport (Union[str, NotebookServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -473,6 +490,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -525,11 +543,11 @@ def __init__( def list_instances( self, - request: Union[service.ListInstancesRequest, dict] = None, + request: Optional[Union[service.ListInstancesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListInstancesPager: r"""Lists instances in a given project and location. @@ -640,11 +658,11 @@ def sample_list_instances(): def get_instance( self, - request: Union[service.GetInstanceRequest, dict] = None, + request: Optional[Union[service.GetInstanceRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> instance.Instance: r"""Gets details of a single Instance. @@ -742,13 +760,13 @@ def sample_get_instance(): def create_instance( self, - request: Union[service.CreateInstanceRequest, dict] = None, + request: Optional[Union[service.CreateInstanceRequest, dict]] = None, *, - parent: str = None, - instance: gcn_instance.Instance = None, - instance_id: str = None, + parent: Optional[str] = None, + instance: Optional[gcn_instance.Instance] = None, + instance_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a new Instance in a given project and @@ -885,10 +903,10 @@ def sample_create_instance(): def register_instance( self, - request: Union[service.RegisterInstanceRequest, dict] = None, + request: Optional[Union[service.RegisterInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Registers an existing legacy notebook instance to the @@ -987,10 +1005,10 @@ def sample_register_instance(): def set_instance_accelerator( self, - request: Union[service.SetInstanceAcceleratorRequest, dict] = None, + request: Optional[Union[service.SetInstanceAcceleratorRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the guest accelerators of a single Instance. @@ -1085,10 +1103,10 @@ def sample_set_instance_accelerator(): def set_instance_machine_type( self, - request: Union[service.SetInstanceMachineTypeRequest, dict] = None, + request: Optional[Union[service.SetInstanceMachineTypeRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the machine type of a single Instance. @@ -1184,10 +1202,10 @@ def sample_set_instance_machine_type(): def update_instance_config( self, - request: Union[service.UpdateInstanceConfigRequest, dict] = None, + request: Optional[Union[service.UpdateInstanceConfigRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Update Notebook Instance configurations. @@ -1280,10 +1298,12 @@ def sample_update_instance_config(): def update_shielded_instance_config( self, - request: Union[service.UpdateShieldedInstanceConfigRequest, dict] = None, + request: Optional[ + Union[service.UpdateShieldedInstanceConfigRequest, dict] + ] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the Shielded instance configuration of a @@ -1380,10 +1400,10 @@ def sample_update_shielded_instance_config(): def set_instance_labels( self, - request: Union[service.SetInstanceLabelsRequest, dict] = None, + request: Optional[Union[service.SetInstanceLabelsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Replaces all the labels of an Instance. @@ -1475,10 +1495,12 @@ def sample_set_instance_labels(): def update_instance_metadata_items( self, - request: Union[service.UpdateInstanceMetadataItemsRequest, dict] = None, + request: Optional[ + Union[service.UpdateInstanceMetadataItemsRequest, dict] + ] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.UpdateInstanceMetadataItemsResponse: r"""Add/update metadata items for an instance. @@ -1558,11 +1580,11 @@ def sample_update_instance_metadata_items(): def delete_instance( self, - request: Union[service.DeleteInstanceRequest, dict] = None, + request: Optional[Union[service.DeleteInstanceRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes a single Instance. @@ -1682,10 +1704,10 @@ def sample_delete_instance(): def start_instance( self, - request: Union[service.StartInstanceRequest, dict] = None, + request: Optional[Union[service.StartInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Starts a notebook instance. @@ -1778,10 +1800,10 @@ def sample_start_instance(): def stop_instance( self, - request: Union[service.StopInstanceRequest, dict] = None, + request: Optional[Union[service.StopInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Stops a notebook instance. @@ -1874,10 +1896,10 @@ def sample_stop_instance(): def reset_instance( self, - request: Union[service.ResetInstanceRequest, dict] = None, + request: Optional[Union[service.ResetInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Resets a notebook instance. @@ -1970,10 +1992,10 @@ def sample_reset_instance(): def report_instance_info( self, - request: Union[service.ReportInstanceInfoRequest, dict] = None, + request: Optional[Union[service.ReportInstanceInfoRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Allows notebook instances to @@ -2071,10 +2093,10 @@ def sample_report_instance_info(): def is_instance_upgradeable( self, - request: Union[service.IsInstanceUpgradeableRequest, dict] = None, + request: Optional[Union[service.IsInstanceUpgradeableRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.IsInstanceUpgradeableResponse: r"""Check if a notebook instance is upgradable. @@ -2154,11 +2176,11 @@ def sample_is_instance_upgradeable(): def get_instance_health( self, - request: Union[service.GetInstanceHealthRequest, dict] = None, + request: Optional[Union[service.GetInstanceHealthRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.GetInstanceHealthResponse: r"""Check if a notebook instance is healthy. @@ -2256,10 +2278,10 @@ def sample_get_instance_health(): def upgrade_instance( self, - request: Union[service.UpgradeInstanceRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Upgrades a notebook instance to the latest version. @@ -2352,10 +2374,10 @@ def sample_upgrade_instance(): def rollback_instance( self, - request: Union[service.RollbackInstanceRequest, dict] = None, + request: Optional[Union[service.RollbackInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Rollbacks a notebook instance to the previous @@ -2448,12 +2470,144 @@ def sample_rollback_instance(): # Done; return the response. return response + def diagnose_instance( + self, + request: Optional[Union[service.DiagnoseInstanceRequest, dict]] = None, + *, + name: Optional[str] = None, + diagnostic_config: Optional[gcn_diagnostic_config.DiagnosticConfig] = 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 Diagnostic File and runs Diagnostic Tool + given an Instance. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import notebooks_v1 + + def sample_diagnose_instance(): + # Create a client + client = notebooks_v1.NotebookServiceClient() + + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" + + request = notebooks_v1.DiagnoseInstanceRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.notebooks_v1.types.DiagnoseInstanceRequest, dict]): + The request object. Request for creating a notebook + instance diagnostic file. + name (str): + Required. Format: + ``projects/{project_id}/locations/{location}/instances/{instance_id}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + diagnostic_config (google.cloud.notebooks_v1.types.DiagnosticConfig): + Required. Defines flags that are used + to run the diagnostic tool + + This corresponds to the ``diagnostic_config`` 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.notebooks_v1.types.Instance` The + definition of a notebook instance. + + """ + # 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, diagnostic_config]) + 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 service.DiagnoseInstanceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, service.DiagnoseInstanceRequest): + request = service.DiagnoseInstanceRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if diagnostic_config is not None: + request.diagnostic_config = diagnostic_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.diagnose_instance] + + # 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, + instance.Instance, + metadata_type=service.OperationMetadata, + ) + + # Done; return the response. + return response + def upgrade_instance_internal( self, - request: Union[service.UpgradeInstanceInternalRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceInternalRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Allows notebook instances to @@ -2551,11 +2705,11 @@ def sample_upgrade_instance_internal(): def list_environments( self, - request: Union[service.ListEnvironmentsRequest, dict] = None, + request: Optional[Union[service.ListEnvironmentsRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEnvironmentsPager: r"""Lists environments in a project. @@ -2664,11 +2818,11 @@ def sample_list_environments(): def get_environment( self, - request: Union[service.GetEnvironmentRequest, dict] = None, + request: Optional[Union[service.GetEnvironmentRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Gets details of a single Environment. @@ -2767,13 +2921,13 @@ def sample_get_environment(): def create_environment( self, - request: Union[service.CreateEnvironmentRequest, dict] = None, + request: Optional[Union[service.CreateEnvironmentRequest, dict]] = None, *, - parent: str = None, - environment: gcn_environment.Environment = None, - environment_id: str = None, + parent: Optional[str] = None, + environment: Optional[gcn_environment.Environment] = None, + environment_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a new Environment. @@ -2912,11 +3066,11 @@ def sample_create_environment(): def delete_environment( self, - request: Union[service.DeleteEnvironmentRequest, dict] = None, + request: Optional[Union[service.DeleteEnvironmentRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes a single Environment. @@ -3036,11 +3190,11 @@ def sample_delete_environment(): def list_schedules( self, - request: Union[service.ListSchedulesRequest, dict] = None, + request: Optional[Union[service.ListSchedulesRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSchedulesPager: r"""Lists schedules in a given project and location. @@ -3151,11 +3305,11 @@ def sample_list_schedules(): def get_schedule( self, - request: Union[service.GetScheduleRequest, dict] = None, + request: Optional[Union[service.GetScheduleRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> schedule.Schedule: r"""Gets details of schedule @@ -3251,11 +3405,11 @@ def sample_get_schedule(): def delete_schedule( self, - request: Union[service.DeleteScheduleRequest, dict] = None, + request: Optional[Union[service.DeleteScheduleRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes schedule and all underlying jobs @@ -3374,13 +3528,13 @@ def sample_delete_schedule(): def create_schedule( self, - request: Union[service.CreateScheduleRequest, dict] = None, + request: Optional[Union[service.CreateScheduleRequest, dict]] = None, *, - parent: str = None, - schedule: gcn_schedule.Schedule = None, - schedule_id: str = None, + parent: Optional[str] = None, + schedule: Optional[gcn_schedule.Schedule] = None, + schedule_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a new Scheduled Notebook in a given project @@ -3511,10 +3665,10 @@ def sample_create_schedule(): def trigger_schedule( self, - request: Union[service.TriggerScheduleRequest, dict] = None, + request: Optional[Union[service.TriggerScheduleRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Triggers execution of an existing schedule. @@ -3607,11 +3761,11 @@ def sample_trigger_schedule(): def list_executions( self, - request: Union[service.ListExecutionsRequest, dict] = None, + request: Optional[Union[service.ListExecutionsRequest, dict]] = None, *, - parent: str = None, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListExecutionsPager: r"""Lists executions in a given project and location @@ -3722,11 +3876,11 @@ def sample_list_executions(): def get_execution( self, - request: Union[service.GetExecutionRequest, dict] = None, + request: Optional[Union[service.GetExecutionRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> execution.Execution: r"""Gets details of executions @@ -3824,11 +3978,11 @@ def sample_get_execution(): def delete_execution( self, - request: Union[service.DeleteExecutionRequest, dict] = None, + request: Optional[Union[service.DeleteExecutionRequest, dict]] = None, *, - name: str = None, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes execution @@ -3948,13 +4102,13 @@ def sample_delete_execution(): def create_execution( self, - request: Union[service.CreateExecutionRequest, dict] = None, + request: Optional[Union[service.CreateExecutionRequest, dict]] = None, *, - parent: str = None, - execution: gcn_execution.Execution = None, - execution_id: str = None, + parent: Optional[str] = None, + execution: Optional[gcn_execution.Execution] = None, + execution_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a new Execution in a given project and @@ -4097,15 +4251,635 @@ def __exit__(self, type, value, traceback): """ self.transport.close() + def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def set_iam_policy( + self, + request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: Optional[locations_pb2.GetLocationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: Optional[locations_pb2.ListLocationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("NotebookServiceClient",) diff --git a/google/cloud/notebooks_v1/services/notebook_service/transports/base.py b/google/cloud/notebooks_v1/services/notebook_service/transports/base.py index 9da250d..cc96d23 100644 --- a/google/cloud/notebooks_v1/services/notebook_service/transports/base.py +++ b/google/cloud/notebooks_v1/services/notebook_service/transports/base.py @@ -22,10 +22,13 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources +from google.cloud.notebooks_v1 import gapic_version as package_version from google.cloud.notebooks_v1.types import ( environment, execution, @@ -34,14 +37,9 @@ service, ) -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class NotebookServiceTransport(abc.ABC): @@ -55,7 +53,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -229,6 +227,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.diagnose_instance: gapic_v1.method.wrap_method( + self.diagnose_instance, + default_timeout=60.0, + client_info=client_info, + ), self.upgrade_instance_internal: gapic_v1.method.wrap_method( self.upgrade_instance_internal, default_timeout=60.0, @@ -495,6 +498,15 @@ def rollback_instance( ]: raise NotImplementedError() + @property + def diagnose_instance( + self, + ) -> Callable[ + [service.DiagnoseInstanceRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def upgrade_instance_internal( self, @@ -626,6 +638,90 @@ def create_execution( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + @property def kind(self) -> str: raise NotImplementedError() diff --git a/google/cloud/notebooks_v1/services/notebook_service/transports/grpc.py b/google/cloud/notebooks_v1/services/notebook_service/transports/grpc.py index d7e9dc9..2c709e5 100644 --- a/google/cloud/notebooks_v1/services/notebook_service/transports/grpc.py +++ b/google/cloud/notebooks_v1/services/notebook_service/transports/grpc.py @@ -20,6 +20,9 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore @@ -53,14 +56,14 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -188,8 +191,8 @@ def __init__( def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, @@ -768,6 +771,33 @@ def rollback_instance( ) return self._stubs["rollback_instance"] + @property + def diagnose_instance( + self, + ) -> Callable[[service.DiagnoseInstanceRequest], operations_pb2.Operation]: + r"""Return a callable for the diagnose instance method over gRPC. + + Creates a Diagnostic File and runs Diagnostic Tool + given an Instance. + + Returns: + Callable[[~.DiagnoseInstanceRequest], + ~.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 "diagnose_instance" not in self._stubs: + self._stubs["diagnose_instance"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.NotebookService/DiagnoseInstance", + request_serializer=service.DiagnoseInstanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["diagnose_instance"] + @property def upgrade_instance_internal( self, @@ -1137,6 +1167,192 @@ def create_execution( def close(self): self.grpc_channel.close() + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # 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 "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # 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_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + 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 "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + 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_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + 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 "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + @property def kind(self) -> str: return "grpc" diff --git a/google/cloud/notebooks_v1/services/notebook_service/transports/grpc_asyncio.py b/google/cloud/notebooks_v1/services/notebook_service/transports/grpc_asyncio.py index 3c42a24..e2eab20 100644 --- a/google/cloud/notebooks_v1/services/notebook_service/transports/grpc_asyncio.py +++ b/google/cloud/notebooks_v1/services/notebook_service/transports/grpc_asyncio.py @@ -19,6 +19,9 @@ from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -55,7 +58,7 @@ class NotebookServiceGrpcAsyncIOTransport(NotebookServiceTransport): def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -98,15 +101,15 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, @@ -795,6 +798,35 @@ def rollback_instance( ) return self._stubs["rollback_instance"] + @property + def diagnose_instance( + self, + ) -> Callable[ + [service.DiagnoseInstanceRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the diagnose instance method over gRPC. + + Creates a Diagnostic File and runs Diagnostic Tool + given an Instance. + + Returns: + Callable[[~.DiagnoseInstanceRequest], + 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 "diagnose_instance" not in self._stubs: + self._stubs["diagnose_instance"] = self.grpc_channel.unary_unary( + "/google.cloud.notebooks.v1.NotebookService/DiagnoseInstance", + request_serializer=service.DiagnoseInstanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["diagnose_instance"] + @property def upgrade_instance_internal( self, @@ -1184,5 +1216,191 @@ def create_execution( def close(self): return self.grpc_channel.close() + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # 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 "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # 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_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + 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 "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + 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_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + 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 "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("NotebookServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/notebooks_v1/types/__init__.py b/google/cloud/notebooks_v1/types/__init__.py index fe6617e..976ef8b 100644 --- a/google/cloud/notebooks_v1/types/__init__.py +++ b/google/cloud/notebooks_v1/types/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from .diagnostic_config import DiagnosticConfig from .environment import ContainerImage, Environment, VmImage from .event import Event from .execution import Execution, ExecutionTemplate @@ -21,6 +22,7 @@ from .managed_service import ( CreateRuntimeRequest, DeleteRuntimeRequest, + DiagnoseRuntimeRequest, GetRuntimeRequest, ListRuntimesRequest, ListRuntimesResponse, @@ -31,6 +33,8 @@ StartRuntimeRequest, StopRuntimeRequest, SwitchRuntimeRequest, + UpdateRuntimeRequest, + UpgradeRuntimeRequest, ) from .runtime import ( EncryptionConfig, @@ -55,6 +59,7 @@ DeleteExecutionRequest, DeleteInstanceRequest, DeleteScheduleRequest, + DiagnoseInstanceRequest, GetEnvironmentRequest, GetExecutionRequest, GetInstanceHealthRequest, @@ -92,6 +97,7 @@ ) __all__ = ( + "DiagnosticConfig", "ContainerImage", "Environment", "VmImage", @@ -103,6 +109,7 @@ "InstanceConfig", "CreateRuntimeRequest", "DeleteRuntimeRequest", + "DiagnoseRuntimeRequest", "GetRuntimeRequest", "ListRuntimesRequest", "ListRuntimesResponse", @@ -113,6 +120,8 @@ "StartRuntimeRequest", "StopRuntimeRequest", "SwitchRuntimeRequest", + "UpdateRuntimeRequest", + "UpgradeRuntimeRequest", "EncryptionConfig", "LocalDisk", "LocalDiskInitializeParams", @@ -133,6 +142,7 @@ "DeleteExecutionRequest", "DeleteInstanceRequest", "DeleteScheduleRequest", + "DiagnoseInstanceRequest", "GetEnvironmentRequest", "GetExecutionRequest", "GetInstanceHealthRequest", diff --git a/google/cloud/notebooks_v1/types/diagnostic_config.py b/google/cloud/notebooks_v1/types/diagnostic_config.py new file mode 100644 index 0000000..01110d7 --- /dev/null +++ b/google/cloud/notebooks_v1/types/diagnostic_config.py @@ -0,0 +1,86 @@ +# -*- 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. +# +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +__protobuf__ = proto.module( + package="google.cloud.notebooks.v1", + manifest={ + "DiagnosticConfig", + }, +) + + +class DiagnosticConfig(proto.Message): + r"""Defines flags that are used to run the diagnostic tool + + Attributes: + gcs_bucket (str): + Required. User Cloud Storage bucket location (REQUIRED). + Must be formatted with path prefix (``gs://$GCS_BUCKET``). + + Permissions: User Managed Notebooks: + + - storage.buckets.writer: Must be given to the project's + service account attached to VM. Google Managed Notebooks: + - storage.buckets.writer: Must be given to the project's + service account or user credentials attached to VM + depending on authentication mode. + + Cloud Storage bucket Log file will be written to + ``gs://$GCS_BUCKET/$RELATIVE_PATH/$VM_DATE_$TIME.tar.gz`` + relative_path (str): + Optional. Defines the relative storage path in the Cloud + Storage bucket where the diagnostic logs will be written: + Default path will be the root directory of the Cloud Storage + bucket (``gs://$GCS_BUCKET/$DATE_$TIME.tar.gz``) Example of + full path where Log file will be written: + ``gs://$GCS_BUCKET/$RELATIVE_PATH/`` + repair_flag_enabled (bool): + Optional. Enables flag to repair service for + instance + packet_capture_flag_enabled (bool): + Optional. Enables flag to capture packets + from the instance for 30 seconds + copy_home_files_flag_enabled (bool): + Optional. Enables flag to copy all ``/home/jupyter`` folder + contents + """ + + gcs_bucket: str = proto.Field( + proto.STRING, + number=1, + ) + relative_path: str = proto.Field( + proto.STRING, + number=2, + ) + repair_flag_enabled: bool = proto.Field( + proto.BOOL, + number=3, + ) + packet_capture_flag_enabled: bool = proto.Field( + proto.BOOL, + number=4, + ) + copy_home_files_flag_enabled: bool = proto.Field( + proto.BOOL, + number=5, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/notebooks_v1/types/environment.py b/google/cloud/notebooks_v1/types/environment.py index fb7f2b0..927ab9f 100644 --- a/google/cloud/notebooks_v1/types/environment.py +++ b/google/cloud/notebooks_v1/types/environment.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -65,35 +67,35 @@ class Environment(proto.Message): environment was created. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - display_name = proto.Field( + display_name: str = proto.Field( proto.STRING, number=2, ) - description = proto.Field( + description: str = proto.Field( proto.STRING, number=3, ) - vm_image = proto.Field( + vm_image: "VmImage" = proto.Field( proto.MESSAGE, number=6, oneof="image_type", message="VmImage", ) - container_image = proto.Field( + container_image: "ContainerImage" = proto.Field( proto.MESSAGE, number=7, oneof="image_type", message="ContainerImage", ) - post_startup_script = proto.Field( + post_startup_script: str = proto.Field( proto.STRING, number=8, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp, @@ -127,16 +129,16 @@ class VmImage(proto.Message): This field is a member of `oneof`_ ``image``. """ - project = proto.Field( + project: str = proto.Field( proto.STRING, number=1, ) - image_name = proto.Field( + image_name: str = proto.Field( proto.STRING, number=2, oneof="image", ) - image_family = proto.Field( + image_family: str = proto.Field( proto.STRING, number=3, oneof="image", @@ -156,11 +158,11 @@ class ContainerImage(proto.Message): specified, this defaults to the latest tag. """ - repository = proto.Field( + repository: str = proto.Field( proto.STRING, number=1, ) - tag = proto.Field( + tag: str = proto.Field( proto.STRING, number=2, ) diff --git a/google/cloud/notebooks_v1/types/event.py b/google/cloud/notebooks_v1/types/event.py index 76c73ef..12440ec 100644 --- a/google/cloud/notebooks_v1/types/event.py +++ b/google/cloud/notebooks_v1/types/event.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -33,7 +35,7 @@ class Event(proto.Message): Event report time. type_ (google.cloud.notebooks_v1.types.Event.EventType): Event type. - details (Mapping[str, str]): + details (MutableMapping[str, str]): Optional. Event details. This field is used to pass event information. """ @@ -46,17 +48,17 @@ class EventType(proto.Enum): HEALTH = 3 MAINTENANCE = 4 - report_time = proto.Field( + report_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) - type_ = proto.Field( + type_: EventType = proto.Field( proto.ENUM, number=2, enum=EventType, ) - details = proto.MapField( + details: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=3, diff --git a/google/cloud/notebooks_v1/types/execution.py b/google/cloud/notebooks_v1/types/execution.py index 14234b5..cd850be 100644 --- a/google/cloud/notebooks_v1/types/execution.py +++ b/google/cloud/notebooks_v1/types/execution.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -92,7 +94,7 @@ class ExecutionTemplate(proto.Message): accelerator_config (google.cloud.notebooks_v1.types.ExecutionTemplate.SchedulerAcceleratorConfig): Configuration (count and accelerator type) for hardware running notebook execution. - labels (Mapping[str, str]): + labels (MutableMapping[str, str]): Labels for execution. If execution is scheduled, a field included will be 'nbs-scheduled'. Otherwise, it is an @@ -195,12 +197,12 @@ class SchedulerAcceleratorConfig(proto.Message): Count of cores of this accelerator. """ - type_ = proto.Field( + type_: "ExecutionTemplate.SchedulerAcceleratorType" = proto.Field( proto.ENUM, number=1, enum="ExecutionTemplate.SchedulerAcceleratorType", ) - core_count = proto.Field( + core_count: int = proto.Field( proto.INT64, number=2, ) @@ -214,7 +216,7 @@ class DataprocParameters(proto.Message): ``projects/{PROJECT_ID}/regions/{REGION}/clusters/{CLUSTER_NAME}`` """ - cluster = proto.Field( + cluster: str = proto.Field( proto.STRING, number=1, ) @@ -237,87 +239,87 @@ class VertexAIParameters(proto.Message): Private services access must already be configured for the network. If left unspecified, the job is not peered with any network. - env (Mapping[str, str]): + env (MutableMapping[str, str]): Environment variables. At most 100 environment variables can be specified and unique. Example: GCP_BUCKET=gs://my-bucket/samples/ """ - network = proto.Field( + network: str = proto.Field( proto.STRING, number=1, ) - env = proto.MapField( + env: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=2, ) - scale_tier = proto.Field( + scale_tier: ScaleTier = proto.Field( proto.ENUM, number=1, enum=ScaleTier, ) - master_type = proto.Field( + master_type: str = proto.Field( proto.STRING, number=2, ) - accelerator_config = proto.Field( + accelerator_config: SchedulerAcceleratorConfig = proto.Field( proto.MESSAGE, number=3, message=SchedulerAcceleratorConfig, ) - labels = proto.MapField( + labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=4, ) - input_notebook_file = proto.Field( + input_notebook_file: str = proto.Field( proto.STRING, number=5, ) - container_image_uri = proto.Field( + container_image_uri: str = proto.Field( proto.STRING, number=6, ) - output_notebook_folder = proto.Field( + output_notebook_folder: str = proto.Field( proto.STRING, number=7, ) - params_yaml_file = proto.Field( + params_yaml_file: str = proto.Field( proto.STRING, number=8, ) - parameters = proto.Field( + parameters: str = proto.Field( proto.STRING, number=9, ) - service_account = proto.Field( + service_account: str = proto.Field( proto.STRING, number=10, ) - job_type = proto.Field( + job_type: JobType = proto.Field( proto.ENUM, number=11, enum=JobType, ) - dataproc_parameters = proto.Field( + dataproc_parameters: DataprocParameters = proto.Field( proto.MESSAGE, number=12, oneof="job_parameters", message=DataprocParameters, ) - vertex_ai_parameters = proto.Field( + vertex_ai_parameters: VertexAIParameters = proto.Field( proto.MESSAGE, number=13, oneof="job_parameters", message=VertexAIParameters, ) - kernel_spec = proto.Field( + kernel_spec: str = proto.Field( proto.STRING, number=14, ) - tensorboard = proto.Field( + tensorboard: str = proto.Field( proto.STRING, number=15, ) @@ -368,43 +370,43 @@ class State(proto.Enum): EXPIRED = 9 INITIALIZING = 10 - execution_template = proto.Field( + execution_template: "ExecutionTemplate" = proto.Field( proto.MESSAGE, number=1, message="ExecutionTemplate", ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=2, ) - display_name = proto.Field( + display_name: str = proto.Field( proto.STRING, number=3, ) - description = proto.Field( + description: str = proto.Field( proto.STRING, number=4, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp, ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=7, enum=State, ) - output_notebook_file = proto.Field( + output_notebook_file: str = proto.Field( proto.STRING, number=8, ) - job_uri = proto.Field( + job_uri: str = proto.Field( proto.STRING, number=9, ) diff --git a/google/cloud/notebooks_v1/types/instance.py b/google/cloud/notebooks_v1/types/instance.py index c3b9747..69b9f8d 100644 --- a/google/cloud/notebooks_v1/types/instance.py +++ b/google/cloud/notebooks_v1/types/instance.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -36,7 +38,7 @@ class ReservationAffinity(proto.Message): key (str): Optional. Corresponds to the label key of reservation resource. - values (Sequence[str]): + values (MutableSequence[str]): Optional. Corresponds to the label values of reservation resource. """ @@ -50,16 +52,16 @@ class Type(proto.Enum): ANY_RESERVATION = 2 SPECIFIC_RESERVATION = 3 - consume_reservation_type = proto.Field( + consume_reservation_type: Type = proto.Field( proto.ENUM, number=1, enum=Type, ) - key = proto.Field( + key: str = proto.Field( proto.STRING, number=2, ) - values = proto.RepeatedField( + values: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -96,7 +98,7 @@ class Instance(proto.Message): proxy_uri (str): Output only. The proxy endpoint that is used to access the Jupyter notebook. - instance_owners (Sequence[str]): + instance_owners (MutableSequence[str]): Input only. The owner of this instance after creation. Format: ``alias@example.com`` @@ -112,7 +114,7 @@ class Instance(proto.Message): If not specified, the `Compute Engine default service account `__ is used. - service_account_scopes (Sequence[str]): + service_account_scopes (MutableSequence[str]): Optional. The URIs of service account scopes to be included in Compute Engine instances. @@ -178,7 +180,7 @@ class Instance(proto.Message): Learn more about `using your own encryption keys `__. - disks (Sequence[google.cloud.notebooks_v1.types.Instance.Disk]): + disks (MutableSequence[google.cloud.notebooks_v1.types.Instance.Disk]): Output only. Attached disks to notebook instance. shielded_instance_config (google.cloud.notebooks_v1.types.Instance.ShieldedInstanceConfig): @@ -197,17 +199,17 @@ class Instance(proto.Message): subnet (str): The name of the subnet that this instance is in. Format: ``projects/{project_id}/regions/{region}/subnetworks/{subnetwork_id}`` - labels (Mapping[str, str]): + labels (MutableMapping[str, str]): Labels to apply to this instance. These can be later modified by the setLabels method. - metadata (Mapping[str, str]): + metadata (MutableMapping[str, str]): Custom metadata to apply to this instance. - tags (Sequence[str]): + tags (MutableSequence[str]): Optional. The Compute Engine tags to add to runtime (see `Tagging instances `__). - upgrade_history (Sequence[google.cloud.notebooks_v1.types.Instance.UpgradeHistoryEntry]): + upgrade_history (MutableSequence[google.cloud.notebooks_v1.types.Instance.UpgradeHistoryEntry]): The upgrade history of this instance. nic_type (google.cloud.notebooks_v1.types.Instance.NicType): Optional. The type of vNIC to be used on this @@ -295,12 +297,12 @@ class AcceleratorConfig(proto.Message): Count of cores of this accelerator. """ - type_ = proto.Field( + type_: "Instance.AcceleratorType" = proto.Field( proto.ENUM, number=1, enum="Instance.AcceleratorType", ) - core_count = proto.Field( + core_count: int = proto.Field( proto.INT64, number=2, ) @@ -331,7 +333,7 @@ class Disk(proto.Message): is only applicable for persistent disks. disk_size_gb (int): Indicates the size of the disk in base-2 GB. - guest_os_features (Sequence[google.cloud.notebooks_v1.types.Instance.Disk.GuestOsFeature]): + guest_os_features (MutableSequence[google.cloud.notebooks_v1.types.Instance.Disk.GuestOsFeature]): Indicates a list of features to enable on the guest operating system. Applicable only for bootable images. Read Enabling guest operating @@ -356,7 +358,7 @@ class Disk(proto.Message): kind (str): Type of the resource. Always compute#attachedDisk for attached disks. - licenses (Sequence[str]): + licenses (MutableSequence[str]): A list of publicly visible licenses. Reserved for Google's use. A License represents billing and aggregate usage data for public and @@ -396,57 +398,59 @@ class GuestOsFeature(proto.Message): - WINDOWS """ - type_ = proto.Field( + type_: str = proto.Field( proto.STRING, number=1, ) - auto_delete = proto.Field( + auto_delete: bool = proto.Field( proto.BOOL, number=1, ) - boot = proto.Field( + boot: bool = proto.Field( proto.BOOL, number=2, ) - device_name = proto.Field( + device_name: str = proto.Field( proto.STRING, number=3, ) - disk_size_gb = proto.Field( + disk_size_gb: int = proto.Field( proto.INT64, number=4, ) - guest_os_features = proto.RepeatedField( + guest_os_features: MutableSequence[ + "Instance.Disk.GuestOsFeature" + ] = proto.RepeatedField( proto.MESSAGE, number=5, message="Instance.Disk.GuestOsFeature", ) - index = proto.Field( + index: int = proto.Field( proto.INT64, number=6, ) - interface = proto.Field( + interface: str = proto.Field( proto.STRING, number=7, ) - kind = proto.Field( + kind: str = proto.Field( proto.STRING, number=8, ) - licenses = proto.RepeatedField( + licenses: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=9, ) - mode = proto.Field( + mode: str = proto.Field( proto.STRING, number=10, ) - source = proto.Field( + source: str = proto.Field( proto.STRING, number=11, ) - type_ = proto.Field( + type_: str = proto.Field( proto.STRING, number=12, ) @@ -478,15 +482,15 @@ class ShieldedInstanceConfig(proto.Message): is created. Enabled by default. """ - enable_secure_boot = proto.Field( + enable_secure_boot: bool = proto.Field( proto.BOOL, number=1, ) - enable_vtpm = proto.Field( + enable_vtpm: bool = proto.Field( proto.BOOL, number=2, ) - enable_integrity_monitoring = proto.Field( + enable_integrity_monitoring: bool = proto.Field( proto.BOOL, number=3, ) @@ -536,208 +540,208 @@ class Action(proto.Enum): UPGRADE = 1 ROLLBACK = 2 - snapshot = proto.Field( + snapshot: str = proto.Field( proto.STRING, number=1, ) - vm_image = proto.Field( + vm_image: str = proto.Field( proto.STRING, number=2, ) - container_image = proto.Field( + container_image: str = proto.Field( proto.STRING, number=3, ) - framework = proto.Field( + framework: str = proto.Field( proto.STRING, number=4, ) - version = proto.Field( + version: str = proto.Field( proto.STRING, number=5, ) - state = proto.Field( + state: "Instance.UpgradeHistoryEntry.State" = proto.Field( proto.ENUM, number=6, enum="Instance.UpgradeHistoryEntry.State", ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, ) - target_image = proto.Field( + target_image: str = proto.Field( proto.STRING, number=8, ) - action = proto.Field( + action: "Instance.UpgradeHistoryEntry.Action" = proto.Field( proto.ENUM, number=9, enum="Instance.UpgradeHistoryEntry.Action", ) - target_version = proto.Field( + target_version: str = proto.Field( proto.STRING, number=10, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_image = proto.Field( + vm_image: environment.VmImage = proto.Field( proto.MESSAGE, number=2, oneof="environment", message=environment.VmImage, ) - container_image = proto.Field( + container_image: environment.ContainerImage = proto.Field( proto.MESSAGE, number=3, oneof="environment", message=environment.ContainerImage, ) - post_startup_script = proto.Field( + post_startup_script: str = proto.Field( proto.STRING, number=4, ) - proxy_uri = proto.Field( + proxy_uri: str = proto.Field( proto.STRING, number=5, ) - instance_owners = proto.RepeatedField( + instance_owners: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=6, ) - service_account = proto.Field( + service_account: str = proto.Field( proto.STRING, number=7, ) - service_account_scopes = proto.RepeatedField( + service_account_scopes: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=31, ) - machine_type = proto.Field( + machine_type: str = proto.Field( proto.STRING, number=8, ) - accelerator_config = proto.Field( + accelerator_config: AcceleratorConfig = proto.Field( proto.MESSAGE, number=9, message=AcceleratorConfig, ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=10, enum=State, ) - install_gpu_driver = proto.Field( + install_gpu_driver: bool = proto.Field( proto.BOOL, number=11, ) - custom_gpu_driver_path = proto.Field( + custom_gpu_driver_path: str = proto.Field( proto.STRING, number=12, ) - boot_disk_type = proto.Field( + boot_disk_type: DiskType = proto.Field( proto.ENUM, number=13, enum=DiskType, ) - boot_disk_size_gb = proto.Field( + boot_disk_size_gb: int = proto.Field( proto.INT64, number=14, ) - data_disk_type = proto.Field( + data_disk_type: DiskType = proto.Field( proto.ENUM, number=25, enum=DiskType, ) - data_disk_size_gb = proto.Field( + data_disk_size_gb: int = proto.Field( proto.INT64, number=26, ) - no_remove_data_disk = proto.Field( + no_remove_data_disk: bool = proto.Field( proto.BOOL, number=27, ) - disk_encryption = proto.Field( + disk_encryption: DiskEncryption = proto.Field( proto.ENUM, number=15, enum=DiskEncryption, ) - kms_key = proto.Field( + kms_key: str = proto.Field( proto.STRING, number=16, ) - disks = proto.RepeatedField( + disks: MutableSequence[Disk] = proto.RepeatedField( proto.MESSAGE, number=28, message=Disk, ) - shielded_instance_config = proto.Field( + shielded_instance_config: ShieldedInstanceConfig = proto.Field( proto.MESSAGE, number=30, message=ShieldedInstanceConfig, ) - no_public_ip = proto.Field( + no_public_ip: bool = proto.Field( proto.BOOL, number=17, ) - no_proxy_access = proto.Field( + no_proxy_access: bool = proto.Field( proto.BOOL, number=18, ) - network = proto.Field( + network: str = proto.Field( proto.STRING, number=19, ) - subnet = proto.Field( + subnet: str = proto.Field( proto.STRING, number=20, ) - labels = proto.MapField( + labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=21, ) - metadata = proto.MapField( + metadata: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=22, ) - tags = proto.RepeatedField( + tags: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=32, ) - upgrade_history = proto.RepeatedField( + upgrade_history: MutableSequence[UpgradeHistoryEntry] = proto.RepeatedField( proto.MESSAGE, number=29, message=UpgradeHistoryEntry, ) - nic_type = proto.Field( + nic_type: NicType = proto.Field( proto.ENUM, number=33, enum=NicType, ) - reservation_affinity = proto.Field( + reservation_affinity: "ReservationAffinity" = proto.Field( proto.MESSAGE, number=34, message="ReservationAffinity", ) - creator = proto.Field( + creator: str = proto.Field( proto.STRING, number=36, ) - can_ip_forward = proto.Field( + can_ip_forward: bool = proto.Field( proto.BOOL, number=39, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=23, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=24, message=timestamp_pb2.Timestamp, diff --git a/google/cloud/notebooks_v1/types/instance_config.py b/google/cloud/notebooks_v1/types/instance_config.py index 1544c40..0183dae 100644 --- a/google/cloud/notebooks_v1/types/instance_config.py +++ b/google/cloud/notebooks_v1/types/instance_config.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + import proto # type: ignore __protobuf__ = proto.module( @@ -35,11 +37,11 @@ class InstanceConfig(proto.Message): Verifies core internal services are running. """ - notebook_upgrade_schedule = proto.Field( + notebook_upgrade_schedule: str = proto.Field( proto.STRING, number=1, ) - enable_health_monitoring = proto.Field( + enable_health_monitoring: bool = proto.Field( proto.BOOL, number=2, ) diff --git a/google/cloud/notebooks_v1/types/managed_service.py b/google/cloud/notebooks_v1/types/managed_service.py index c727515..09e3f59 100644 --- a/google/cloud/notebooks_v1/types/managed_service.py +++ b/google/cloud/notebooks_v1/types/managed_service.py @@ -13,9 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import event as gcn_event from google.cloud.notebooks_v1.types import runtime as gcn_runtime @@ -31,9 +35,12 @@ "StopRuntimeRequest", "SwitchRuntimeRequest", "ResetRuntimeRequest", + "UpgradeRuntimeRequest", "ReportRuntimeEventRequest", + "UpdateRuntimeRequest", "RefreshRuntimeTokenInternalRequest", "RefreshRuntimeTokenInternalResponse", + "DiagnoseRuntimeRequest", }, ) @@ -52,15 +59,15 @@ class ListRuntimesRequest(proto.Message): used to continue listing from the last result. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -70,13 +77,13 @@ class ListRuntimesResponse(proto.Message): r"""Response for listing Managed Notebook Runtimes. Attributes: - runtimes (Sequence[google.cloud.notebooks_v1.types.Runtime]): + runtimes (MutableSequence[google.cloud.notebooks_v1.types.Runtime]): A list of returned Runtimes. next_page_token (str): Page token that can be used to continue listing from the last result in the next list call. - unreachable (Sequence[str]): + unreachable (MutableSequence[str]): Locations that could not be reached. For example, ['us-west1', 'us-central1']. A ListRuntimesResponse will only contain either runtimes or unreachables, @@ -86,16 +93,16 @@ class ListRuntimesResponse(proto.Message): def raw_page(self): return self - runtimes = proto.RepeatedField( + runtimes: MutableSequence[gcn_runtime.Runtime] = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_runtime.Runtime, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) - unreachable = proto.RepeatedField( + unreachable: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -110,7 +117,7 @@ class GetRuntimeRequest(proto.Message): ``projects/{project_id}/locations/{location}/runtimes/{runtime_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -132,20 +139,20 @@ class CreateRuntimeRequest(proto.Message): Idempotent request UUID. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - runtime_id = proto.Field( + runtime_id: str = proto.Field( proto.STRING, number=2, ) - runtime = proto.Field( + runtime: gcn_runtime.Runtime = proto.Field( proto.MESSAGE, number=3, message=gcn_runtime.Runtime, ) - request_id = proto.Field( + request_id: str = proto.Field( proto.STRING, number=4, ) @@ -162,11 +169,11 @@ class DeleteRuntimeRequest(proto.Message): Idempotent request UUID. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - request_id = proto.Field( + request_id: str = proto.Field( proto.STRING, number=2, ) @@ -183,11 +190,11 @@ class StartRuntimeRequest(proto.Message): Idempotent request UUID. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - request_id = proto.Field( + request_id: str = proto.Field( proto.STRING, number=2, ) @@ -204,11 +211,11 @@ class StopRuntimeRequest(proto.Message): Idempotent request UUID. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - request_id = proto.Field( + request_id: str = proto.Field( proto.STRING, number=2, ) @@ -229,20 +236,20 @@ class SwitchRuntimeRequest(proto.Message): Idempotent request UUID. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - machine_type = proto.Field( + machine_type: str = proto.Field( proto.STRING, number=2, ) - accelerator_config = proto.Field( + accelerator_config: gcn_runtime.RuntimeAcceleratorConfig = proto.Field( proto.MESSAGE, number=3, message=gcn_runtime.RuntimeAcceleratorConfig, ) - request_id = proto.Field( + request_id: str = proto.Field( proto.STRING, number=4, ) @@ -259,11 +266,34 @@ class ResetRuntimeRequest(proto.Message): Idempotent request UUID. """ - name = proto.Field( + name: str = proto.Field( + proto.STRING, + number=1, + ) + request_id: str = proto.Field( + proto.STRING, + number=2, + ) + + +class UpgradeRuntimeRequest(proto.Message): + r"""Request for upgrading a Managed Notebook Runtime to the latest + version. option (google.api.message_visibility).restriction = + "TRUSTED_TESTER,SPECIAL_TESTER"; + + Attributes: + name (str): + Required. Format: + ``projects/{project_id}/locations/{location}/runtimes/{runtime_id}`` + request_id (str): + Idempotent request UUID. + """ + + name: str = proto.Field( proto.STRING, number=1, ) - request_id = proto.Field( + request_id: str = proto.Field( proto.STRING, number=2, ) @@ -284,21 +314,74 @@ class ReportRuntimeEventRequest(proto.Message): Required. The Event to be reported. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_id = proto.Field( + vm_id: str = proto.Field( proto.STRING, number=2, ) - event = proto.Field( + event: gcn_event.Event = proto.Field( proto.MESSAGE, number=3, message=gcn_event.Event, ) +class UpdateRuntimeRequest(proto.Message): + r"""Request for updating a Managed Notebook configuration. + + Attributes: + runtime (google.cloud.notebooks_v1.types.Runtime): + Required. The Runtime to be updated. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Specifies the path, relative to ``Runtime``, of + the field to update. For example, to change the software + configuration kernels, the ``update_mask`` parameter would + be specified as ``software_config.kernels``, and the + ``PATCH`` request body would specify the new value, as + follows: + + :: + + { + "software_config":{ + "kernels": [{ + 'repository': + 'gcr.io/deeplearning-platform-release/pytorch-gpu', 'tag': + 'latest' }], + } + } + + Currently, only the following fields can be updated: + + - software_config.kernels + - software_config.post_startup_script + - software_config.custom_gpu_driver_path + - software_config.idle_shutdown + - software_config.idle_shutdown_timeout + - software_config.disable_terminal + request_id (str): + Idempotent request UUID. + """ + + runtime: gcn_runtime.Runtime = proto.Field( + proto.MESSAGE, + number=1, + message=gcn_runtime.Runtime, + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + request_id: str = proto.Field( + proto.STRING, + number=3, + ) + + class RefreshRuntimeTokenInternalRequest(proto.Message): r"""Request for getting a new access token. @@ -312,11 +395,11 @@ class RefreshRuntimeTokenInternalRequest(proto.Message): https://cloud.google.com/compute/docs/instances/verifying-instance-identity """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_id = proto.Field( + vm_id: str = proto.Field( proto.STRING, number=2, ) @@ -332,15 +415,38 @@ class RefreshRuntimeTokenInternalResponse(proto.Message): Output only. Token expiration time. """ - access_token = proto.Field( + access_token: str = proto.Field( proto.STRING, number=1, ) - expire_time = proto.Field( + expire_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, ) +class DiagnoseRuntimeRequest(proto.Message): + r"""Request for creating a notebook instance diagnostic file. + + Attributes: + name (str): + Required. Format: + ``projects/{project_id}/locations/{location}/runtimes/{runtimes_id}`` + diagnostic_config (google.cloud.notebooks_v1.types.DiagnosticConfig): + Required. Defines flags that are used to run + the diagnostic tool + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + diagnostic_config: gcn_diagnostic_config.DiagnosticConfig = proto.Field( + proto.MESSAGE, + number=2, + message=gcn_diagnostic_config.DiagnosticConfig, + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/notebooks_v1/types/runtime.py b/google/cloud/notebooks_v1/types/runtime.py index ccc43fa..b1cea89 100644 --- a/google/cloud/notebooks_v1/types/runtime.py +++ b/google/cloud/notebooks_v1/types/runtime.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -88,47 +90,47 @@ class HealthState(proto.Enum): AGENT_NOT_INSTALLED = 3 AGENT_NOT_RUNNING = 4 - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - virtual_machine = proto.Field( + virtual_machine: "VirtualMachine" = proto.Field( proto.MESSAGE, number=2, oneof="runtime_type", message="VirtualMachine", ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=3, enum=State, ) - health_state = proto.Field( + health_state: HealthState = proto.Field( proto.ENUM, number=4, enum=HealthState, ) - access_config = proto.Field( + access_config: "RuntimeAccessConfig" = proto.Field( proto.MESSAGE, number=5, message="RuntimeAccessConfig", ) - software_config = proto.Field( + software_config: "RuntimeSoftwareConfig" = proto.Field( proto.MESSAGE, number=6, message="RuntimeSoftwareConfig", ) - metrics = proto.Field( + metrics: "RuntimeMetrics" = proto.Field( proto.MESSAGE, number=7, message="RuntimeMetrics", ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=20, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=21, message=timestamp_pb2.Timestamp, @@ -171,12 +173,12 @@ class AcceleratorType(proto.Enum): NVIDIA_TESLA_P100_VWS = 10 NVIDIA_TESLA_P4_VWS = 11 - type_ = proto.Field( + type_: AcceleratorType = proto.Field( proto.ENUM, number=1, enum=AcceleratorType, ) - core_count = proto.Field( + core_count: int = proto.Field( proto.INT64, number=2, ) @@ -195,7 +197,7 @@ class EncryptionConfig(proto.Message): ``projects/{PROJECT_ID}/locations/{REGION}/keyRings/{KEY_RING_NAME}/cryptoKeys/{KEY_NAME}`` """ - kms_key = proto.Field( + kms_key: str = proto.Field( proto.STRING, number=1, ) @@ -227,7 +229,7 @@ class LocalDisk(proto.Message): to apply to this disk, in the form persistent-disk-x, where x is a number assigned by Google Compute Engine. This field is only applicable for persistent disks. - guest_os_features (Sequence[google.cloud.notebooks_v1.types.LocalDisk.RuntimeGuestOsFeature]): + guest_os_features (MutableSequence[google.cloud.notebooks_v1.types.LocalDisk.RuntimeGuestOsFeature]): Output only. Indicates a list of features to enable on the guest operating system. Applicable only for bootable images. Read Enabling guest @@ -261,7 +263,7 @@ class LocalDisk(proto.Message): kind (str): Output only. Type of the resource. Always compute#attachedDisk for attached disks. - licenses (Sequence[str]): + licenses (MutableSequence[str]): Output only. Any valid publicly visible licenses. mode (str): @@ -307,58 +309,58 @@ class RuntimeGuestOsFeature(proto.Message): - WINDOWS """ - type_ = proto.Field( + type_: str = proto.Field( proto.STRING, number=1, ) - auto_delete = proto.Field( + auto_delete: bool = proto.Field( proto.BOOL, number=1, ) - boot = proto.Field( + boot: bool = proto.Field( proto.BOOL, number=2, ) - device_name = proto.Field( + device_name: str = proto.Field( proto.STRING, number=3, ) - guest_os_features = proto.RepeatedField( + guest_os_features: MutableSequence[RuntimeGuestOsFeature] = proto.RepeatedField( proto.MESSAGE, number=4, message=RuntimeGuestOsFeature, ) - index = proto.Field( + index: int = proto.Field( proto.INT32, number=5, ) - initialize_params = proto.Field( + initialize_params: "LocalDiskInitializeParams" = proto.Field( proto.MESSAGE, number=6, message="LocalDiskInitializeParams", ) - interface = proto.Field( + interface: str = proto.Field( proto.STRING, number=7, ) - kind = proto.Field( + kind: str = proto.Field( proto.STRING, number=8, ) - licenses = proto.RepeatedField( + licenses: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=9, ) - mode = proto.Field( + mode: str = proto.Field( proto.STRING, number=10, ) - source = proto.Field( + source: str = proto.Field( proto.STRING, number=11, ) - type_ = proto.Field( + type_: str = proto.Field( proto.STRING, number=12, ) @@ -392,7 +394,7 @@ class LocalDiskInitializeParams(proto.Message): Input only. The type of the boot disk attached to this instance, defaults to standard persistent disk (``PD_STANDARD``). - labels (Mapping[str, str]): + labels (MutableMapping[str, str]): Optional. Labels to apply to this disk. These can be later modified by the disks.setLabels method. This field is only applicable for @@ -407,24 +409,24 @@ class DiskType(proto.Enum): PD_BALANCED = 3 PD_EXTREME = 4 - description = proto.Field( + description: str = proto.Field( proto.STRING, number=1, ) - disk_name = proto.Field( + disk_name: str = proto.Field( proto.STRING, number=2, ) - disk_size_gb = proto.Field( + disk_size_gb: int = proto.Field( proto.INT64, number=3, ) - disk_type = proto.Field( + disk_type: DiskType = proto.Field( proto.ENUM, number=4, enum=DiskType, ) - labels = proto.MapField( + labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=5, @@ -453,16 +455,16 @@ class RuntimeAccessType(proto.Enum): SINGLE_USER = 1 SERVICE_ACCOUNT = 2 - access_type = proto.Field( + access_type: RuntimeAccessType = proto.Field( proto.ENUM, number=1, enum=RuntimeAccessType, ) - runtime_owner = proto.Field( + runtime_owner: str = proto.Field( proto.STRING, number=2, ) - proxy_uri = proto.Field( + proxy_uri: str = proto.Field( proto.STRING, number=3, ) @@ -506,7 +508,7 @@ class RuntimeSoftwareConfig(proto.Message): Path to a Bash script that automatically runs after a notebook instance fully boots up. The path must be a URL or Cloud Storage path (``gs://path-to-file/file-name``). - kernels (Sequence[google.cloud.notebooks_v1.types.ContainerImage]): + kernels (MutableSequence[google.cloud.notebooks_v1.types.ContainerImage]): Optional. Use a list of container images to use as Kernels in the notebook instance. upgradeable (bool): @@ -514,48 +516,81 @@ class RuntimeSoftwareConfig(proto.Message): image is available in an image family. This field is a member of `oneof`_ ``_upgradeable``. + post_startup_script_behavior (google.cloud.notebooks_v1.types.RuntimeSoftwareConfig.PostStartupScriptBehavior): + Behavior for the post startup script. + disable_terminal (bool): + Bool indicating whether JupyterLab terminal + will be available or not. Default: False + + This field is a member of `oneof`_ ``_disable_terminal``. + version (str): + Output only. version of boot image such as + M100, from release label of the image. + + This field is a member of `oneof`_ ``_version``. """ - notebook_upgrade_schedule = proto.Field( + class PostStartupScriptBehavior(proto.Enum): + r"""Behavior for the post startup script.""" + POST_STARTUP_SCRIPT_BEHAVIOR_UNSPECIFIED = 0 + RUN_EVERY_START = 1 + DOWNLOAD_AND_RUN_EVERY_START = 2 + + notebook_upgrade_schedule: str = proto.Field( proto.STRING, number=1, ) - enable_health_monitoring = proto.Field( + enable_health_monitoring: bool = proto.Field( proto.BOOL, number=2, optional=True, ) - idle_shutdown = proto.Field( + idle_shutdown: bool = proto.Field( proto.BOOL, number=3, optional=True, ) - idle_shutdown_timeout = proto.Field( + idle_shutdown_timeout: int = proto.Field( proto.INT32, number=4, ) - install_gpu_driver = proto.Field( + install_gpu_driver: bool = proto.Field( proto.BOOL, number=5, ) - custom_gpu_driver_path = proto.Field( + custom_gpu_driver_path: str = proto.Field( proto.STRING, number=6, ) - post_startup_script = proto.Field( + post_startup_script: str = proto.Field( proto.STRING, number=7, ) - kernels = proto.RepeatedField( + kernels: MutableSequence[environment.ContainerImage] = proto.RepeatedField( proto.MESSAGE, number=8, message=environment.ContainerImage, ) - upgradeable = proto.Field( + upgradeable: bool = proto.Field( proto.BOOL, number=9, optional=True, ) + post_startup_script_behavior: PostStartupScriptBehavior = proto.Field( + proto.ENUM, + number=10, + enum=PostStartupScriptBehavior, + ) + disable_terminal: bool = proto.Field( + proto.BOOL, + number=11, + optional=True, + ) + version: str = proto.Field( + proto.STRING, + number=12, + optional=True, + ) class RuntimeMetrics(proto.Message): @@ -563,11 +598,11 @@ class RuntimeMetrics(proto.Message): sessions stats. Attributes: - system_metrics (Mapping[str, str]): + system_metrics (MutableMapping[str, str]): Output only. The system metrics. """ - system_metrics = proto.MapField( + system_metrics: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=1, @@ -603,15 +638,15 @@ class RuntimeShieldedInstanceConfig(proto.Message): is created. Enabled by default. """ - enable_secure_boot = proto.Field( + enable_secure_boot: bool = proto.Field( proto.BOOL, number=1, ) - enable_vtpm = proto.Field( + enable_vtpm: bool = proto.Field( proto.BOOL, number=2, ) - enable_integrity_monitoring = proto.Field( + enable_integrity_monitoring: bool = proto.Field( proto.BOOL, number=3, ) @@ -631,15 +666,15 @@ class VirtualMachine(proto.Message): Virtual Machine configuration settings. """ - instance_name = proto.Field( + instance_name: str = proto.Field( proto.STRING, number=1, ) - instance_id = proto.Field( + instance_id: str = proto.Field( proto.STRING, number=2, ) - virtual_machine_config = proto.Field( + virtual_machine_config: "VirtualMachineConfig" = proto.Field( proto.MESSAGE, number=3, message="VirtualMachineConfig", @@ -663,7 +698,7 @@ class VirtualMachineConfig(proto.Message): - ``n1-standard-2`` - ``e2-standard-8`` - container_images (Sequence[google.cloud.notebooks_v1.types.ContainerImage]): + container_images (MutableSequence[google.cloud.notebooks_v1.types.ContainerImage]): Optional. Use a list of container images to use as Kernels in the notebook instance. data_disk (google.cloud.notebooks_v1.types.LocalDisk): @@ -686,8 +721,8 @@ class VirtualMachineConfig(proto.Message): A full URL or partial URI. Examples: - - ``https://www.googleapis.com/compute/v1/projects/[project_id]/regions/global/default`` - - ``projects/[project_id]/regions/global/default`` + - ``https://www.googleapis.com/compute/v1/projects/[project_id]/global/networks/default`` + - ``projects/[project_id]/global/networks/default`` Runtimes are managed resources inside Google Infrastructure. Runtimes support the following network configurations: @@ -713,19 +748,19 @@ class VirtualMachineConfig(proto.Message): restriction can only be enabled for subnetwork enabled networks, and all dependencies must be configured to be accessible without external IP addresses. - tags (Sequence[str]): + tags (MutableSequence[str]): Optional. The Compute Engine tags to add to runtime (see `Tagging instances `__). - guest_attributes (Mapping[str, str]): + guest_attributes (MutableMapping[str, str]): Output only. The Compute Engine guest attributes. (see `Project and instance guest attributes `__). - metadata (Mapping[str, str]): + metadata (MutableMapping[str, str]): Optional. The Compute Engine metadata entries to add to virtual machine. (see `Project and instance metadata `__). - labels (Mapping[str, str]): + labels (MutableMapping[str, str]): Optional. The labels to associate with this runtime. Label **keys** must contain 1 to 63 characters, and must conform to `RFC 1035 `__. @@ -769,80 +804,80 @@ class BootImage(proto.Message): """ - zone = proto.Field( + zone: str = proto.Field( proto.STRING, number=1, ) - machine_type = proto.Field( + machine_type: str = proto.Field( proto.STRING, number=2, ) - container_images = proto.RepeatedField( + container_images: MutableSequence[environment.ContainerImage] = proto.RepeatedField( proto.MESSAGE, number=3, message=environment.ContainerImage, ) - data_disk = proto.Field( + data_disk: "LocalDisk" = proto.Field( proto.MESSAGE, number=4, message="LocalDisk", ) - encryption_config = proto.Field( + encryption_config: "EncryptionConfig" = proto.Field( proto.MESSAGE, number=5, message="EncryptionConfig", ) - shielded_instance_config = proto.Field( + shielded_instance_config: "RuntimeShieldedInstanceConfig" = proto.Field( proto.MESSAGE, number=6, message="RuntimeShieldedInstanceConfig", ) - accelerator_config = proto.Field( + accelerator_config: "RuntimeAcceleratorConfig" = proto.Field( proto.MESSAGE, number=7, message="RuntimeAcceleratorConfig", ) - network = proto.Field( + network: str = proto.Field( proto.STRING, number=8, ) - subnet = proto.Field( + subnet: str = proto.Field( proto.STRING, number=9, ) - internal_ip_only = proto.Field( + internal_ip_only: bool = proto.Field( proto.BOOL, number=10, ) - tags = proto.RepeatedField( + tags: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=13, ) - guest_attributes = proto.MapField( + guest_attributes: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=14, ) - metadata = proto.MapField( + metadata: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=15, ) - labels = proto.MapField( + labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=16, ) - nic_type = proto.Field( + nic_type: NicType = proto.Field( proto.ENUM, number=17, enum=NicType, ) - reserved_ip_range = proto.Field( + reserved_ip_range: str = proto.Field( proto.STRING, number=18, ) - boot_image = proto.Field( + boot_image: BootImage = proto.Field( proto.MESSAGE, number=19, message=BootImage, diff --git a/google/cloud/notebooks_v1/types/schedule.py b/google/cloud/notebooks_v1/types/schedule.py index 5279a8b..c53b49d 100644 --- a/google/cloud/notebooks_v1/types/schedule.py +++ b/google/cloud/notebooks_v1/types/schedule.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -64,7 +66,7 @@ class Schedule(proto.Message): execution_template (google.cloud.notebooks_v1.types.ExecutionTemplate): Notebook Execution Template corresponding to this schedule. - recent_executions (Sequence[google.cloud.notebooks_v1.types.Execution]): + recent_executions (MutableSequence[google.cloud.notebooks_v1.types.Execution]): Output only. The most recent execution names triggered from this schedule and their corresponding states. @@ -80,47 +82,47 @@ class State(proto.Enum): INITIALIZING = 5 DELETING = 6 - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - display_name = proto.Field( + display_name: str = proto.Field( proto.STRING, number=2, ) - description = proto.Field( + description: str = proto.Field( proto.STRING, number=3, ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=4, enum=State, ) - cron_schedule = proto.Field( + cron_schedule: str = proto.Field( proto.STRING, number=5, ) - time_zone = proto.Field( + time_zone: str = proto.Field( proto.STRING, number=6, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp, ) - execution_template = proto.Field( + execution_template: execution.ExecutionTemplate = proto.Field( proto.MESSAGE, number=9, message=execution.ExecutionTemplate, ) - recent_executions = proto.RepeatedField( + recent_executions: MutableSequence[execution.Execution] = proto.RepeatedField( proto.MESSAGE, number=10, message=execution.Execution, diff --git a/google/cloud/notebooks_v1/types/service.py b/google/cloud/notebooks_v1/types/service.py index 6a2d1a4..300d5f9 100644 --- a/google/cloud/notebooks_v1/types/service.py +++ b/google/cloud/notebooks_v1/types/service.py @@ -13,9 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import environment as gcn_environment from google.cloud.notebooks_v1.types import execution as gcn_execution from google.cloud.notebooks_v1.types import instance as gcn_instance @@ -52,6 +55,7 @@ "RollbackInstanceRequest", "UpgradeInstanceInternalRequest", "ListEnvironmentsRequest", + "DiagnoseInstanceRequest", "ListEnvironmentsResponse", "GetEnvironmentRequest", "CreateEnvironmentRequest", @@ -110,37 +114,37 @@ class OperationMetadata(proto.Message): API endpoint name of this operation. """ - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) - end_time = proto.Field( + end_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, ) - target = proto.Field( + target: str = proto.Field( proto.STRING, number=3, ) - verb = proto.Field( + verb: str = proto.Field( proto.STRING, number=4, ) - status_message = proto.Field( + status_message: str = proto.Field( proto.STRING, number=5, ) - requested_cancellation = proto.Field( + requested_cancellation: bool = proto.Field( proto.BOOL, number=6, ) - api_version = proto.Field( + api_version: str = proto.Field( proto.STRING, number=7, ) - endpoint = proto.Field( + endpoint: str = proto.Field( proto.STRING, number=8, ) @@ -160,15 +164,15 @@ class ListInstancesRequest(proto.Message): used to continue listing from the last result. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -178,13 +182,13 @@ class ListInstancesResponse(proto.Message): r"""Response for listing notebook instances. Attributes: - instances (Sequence[google.cloud.notebooks_v1.types.Instance]): + instances (MutableSequence[google.cloud.notebooks_v1.types.Instance]): A list of returned instances. next_page_token (str): Page token that can be used to continue listing from the last result in the next list call. - unreachable (Sequence[str]): + unreachable (MutableSequence[str]): Locations that could not be reached. For example, ['us-west1-a', 'us-central1-b']. A ListInstancesResponse will only contain either instances or unreachables, @@ -194,16 +198,16 @@ class ListInstancesResponse(proto.Message): def raw_page(self): return self - instances = proto.RepeatedField( + instances: MutableSequence[gcn_instance.Instance] = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_instance.Instance, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) - unreachable = proto.RepeatedField( + unreachable: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -218,7 +222,7 @@ class GetInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -238,15 +242,15 @@ class CreateInstanceRequest(proto.Message): Required. The instance to be created. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - instance_id = proto.Field( + instance_id: str = proto.Field( proto.STRING, number=2, ) - instance = proto.Field( + instance: gcn_instance.Instance = proto.Field( proto.MESSAGE, number=3, message=gcn_instance.Instance, @@ -268,11 +272,11 @@ class RegisterInstanceRequest(proto.Message): character cannot be a dash. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - instance_id = proto.Field( + instance_id: str = proto.Field( proto.STRING, number=2, ) @@ -295,16 +299,16 @@ class SetInstanceAcceleratorRequest(proto.Message): to find a valid combination. TPUs are not supported. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - type_ = proto.Field( + type_: gcn_instance.Instance.AcceleratorType = proto.Field( proto.ENUM, number=2, enum=gcn_instance.Instance.AcceleratorType, ) - core_count = proto.Field( + core_count: int = proto.Field( proto.INT64, number=3, ) @@ -322,11 +326,11 @@ class SetInstanceMachineTypeRequest(proto.Message): type `__. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - machine_type = proto.Field( + machine_type: str = proto.Field( proto.STRING, number=2, ) @@ -343,11 +347,11 @@ class UpdateInstanceConfigRequest(proto.Message): The instance configurations to be updated. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - config = proto.Field( + config: instance_config.InstanceConfig = proto.Field( proto.MESSAGE, number=2, message=instance_config.InstanceConfig, @@ -361,17 +365,17 @@ class SetInstanceLabelsRequest(proto.Message): name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` - labels (Mapping[str, str]): + labels (MutableMapping[str, str]): Labels to apply to this instance. These can be later modified by the setLabels method """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - labels = proto.MapField( + labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=2, @@ -385,16 +389,16 @@ class UpdateInstanceMetadataItemsRequest(proto.Message): name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` - items (Mapping[str, str]): + items (MutableMapping[str, str]): Metadata items to add/update for the instance. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - items = proto.MapField( + items: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=2, @@ -405,12 +409,12 @@ class UpdateInstanceMetadataItemsResponse(proto.Message): r"""Response for adding/changing metadata items for an instance. Attributes: - items (Mapping[str, str]): + items (MutableMapping[str, str]): Map of items that were added/updated to/in the metadata. """ - items = proto.MapField( + items: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=1, @@ -430,14 +434,16 @@ class UpdateShieldedInstanceConfigRequest(proto.Message): ShieldedInstance configuration to be updated. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - shielded_instance_config = proto.Field( - proto.MESSAGE, - number=2, - message=gcn_instance.Instance.ShieldedInstanceConfig, + shielded_instance_config: gcn_instance.Instance.ShieldedInstanceConfig = ( + proto.Field( + proto.MESSAGE, + number=2, + message=gcn_instance.Instance.ShieldedInstanceConfig, + ) ) @@ -450,7 +456,7 @@ class DeleteInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -465,7 +471,7 @@ class StartInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -480,7 +486,7 @@ class StopInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -495,7 +501,7 @@ class ResetInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -513,20 +519,20 @@ class ReportInstanceInfoRequest(proto.Message): Required. The VM hardware token for authenticating the VM. https://cloud.google.com/compute/docs/instances/verifying-instance-identity - metadata (Mapping[str, str]): + metadata (MutableMapping[str, str]): The metadata reported to Notebooks API. This will be merged to the instance metadata store """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_id = proto.Field( + vm_id: str = proto.Field( proto.STRING, number=2, ) - metadata = proto.MapField( + metadata: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=3, @@ -546,11 +552,11 @@ class IsInstanceUpgradeableRequest(proto.Message): images to upgrade this instance. """ - notebook_instance = proto.Field( + notebook_instance: str = proto.Field( proto.STRING, number=1, ) - type_ = proto.Field( + type_: "UpgradeType" = proto.Field( proto.ENUM, number=2, enum="UpgradeType", @@ -576,19 +582,19 @@ class IsInstanceUpgradeableResponse(proto.Message): upgradeable is true. """ - upgradeable = proto.Field( + upgradeable: bool = proto.Field( proto.BOOL, number=1, ) - upgrade_version = proto.Field( + upgrade_version: str = proto.Field( proto.STRING, number=2, ) - upgrade_info = proto.Field( + upgrade_info: str = proto.Field( proto.STRING, number=3, ) - upgrade_image = proto.Field( + upgrade_image: str = proto.Field( proto.STRING, number=4, ) @@ -603,7 +609,7 @@ class GetInstanceHealthRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -615,7 +621,7 @@ class GetInstanceHealthResponse(proto.Message): Attributes: health_state (google.cloud.notebooks_v1.types.GetInstanceHealthResponse.HealthState): Output only. Runtime health_state. - health_info (Mapping[str, str]): + health_info (MutableMapping[str, str]): Output only. Additional information about instance health. Example: healthInfo": { "docker_proxy_agent_status": "1", "docker_status": "1", "jupyterlab_api_status": "-1", @@ -631,12 +637,12 @@ class HealthState(proto.Enum): AGENT_NOT_INSTALLED = 3 AGENT_NOT_RUNNING = 4 - health_state = proto.Field( + health_state: HealthState = proto.Field( proto.ENUM, number=1, enum=HealthState, ) - health_info = proto.MapField( + health_info: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=2, @@ -656,11 +662,11 @@ class UpgradeInstanceRequest(proto.Message): images to upgrade this instance. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - type_ = proto.Field( + type_: "UpgradeType" = proto.Field( proto.ENUM, number=2, enum="UpgradeType", @@ -680,11 +686,11 @@ class RollbackInstanceRequest(proto.Message): "projects/test-project/global/snapshots/krwlzipynril". """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - target_snapshot = proto.Field( + target_snapshot: str = proto.Field( proto.STRING, number=2, ) @@ -707,15 +713,15 @@ class UpgradeInstanceInternalRequest(proto.Message): images to upgrade this instance. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_id = proto.Field( + vm_id: str = proto.Field( proto.STRING, number=2, ) - type_ = proto.Field( + type_: "UpgradeType" = proto.Field( proto.ENUM, number=3, enum="UpgradeType", @@ -736,31 +742,54 @@ class ListEnvironmentsRequest(proto.Message): used to continue listing from the last result. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) +class DiagnoseInstanceRequest(proto.Message): + r"""Request for creating a notebook instance diagnostic file. + + Attributes: + name (str): + Required. Format: + ``projects/{project_id}/locations/{location}/instances/{instance_id}`` + diagnostic_config (google.cloud.notebooks_v1.types.DiagnosticConfig): + Required. Defines flags that are used to run + the diagnostic tool + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + diagnostic_config: gcn_diagnostic_config.DiagnosticConfig = proto.Field( + proto.MESSAGE, + number=2, + message=gcn_diagnostic_config.DiagnosticConfig, + ) + + class ListEnvironmentsResponse(proto.Message): r"""Response for listing environments. Attributes: - environments (Sequence[google.cloud.notebooks_v1.types.Environment]): + environments (MutableSequence[google.cloud.notebooks_v1.types.Environment]): A list of returned environments. next_page_token (str): A page token that can be used to continue listing from the last result in the next list call. - unreachable (Sequence[str]): + unreachable (MutableSequence[str]): Locations that could not be reached. """ @@ -768,16 +797,16 @@ class ListEnvironmentsResponse(proto.Message): def raw_page(self): return self - environments = proto.RepeatedField( + environments: MutableSequence[gcn_environment.Environment] = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_environment.Environment, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) - unreachable = proto.RepeatedField( + unreachable: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -792,7 +821,7 @@ class GetEnvironmentRequest(proto.Message): ``projects/{project_id}/locations/{location}/environments/{environment_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -815,15 +844,15 @@ class CreateEnvironmentRequest(proto.Message): Required. The environment to be created. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - environment_id = proto.Field( + environment_id: str = proto.Field( proto.STRING, number=2, ) - environment = proto.Field( + environment: gcn_environment.Environment = proto.Field( proto.MESSAGE, number=3, message=gcn_environment.Environment, @@ -839,7 +868,7 @@ class DeleteEnvironmentRequest(proto.Message): ``projects/{project_id}/locations/{location}/environments/{environment_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -863,23 +892,23 @@ class ListSchedulesRequest(proto.Message): Field to order results by. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) - filter = proto.Field( + filter: str = proto.Field( proto.STRING, number=4, ) - order_by = proto.Field( + order_by: str = proto.Field( proto.STRING, number=5, ) @@ -889,13 +918,13 @@ class ListSchedulesResponse(proto.Message): r"""Response for listing scheduled notebook job. Attributes: - schedules (Sequence[google.cloud.notebooks_v1.types.Schedule]): + schedules (MutableSequence[google.cloud.notebooks_v1.types.Schedule]): A list of returned instances. next_page_token (str): Page token that can be used to continue listing from the last result in the next list call. - unreachable (Sequence[str]): + unreachable (MutableSequence[str]): Schedules that could not be reached. For example: :: @@ -908,16 +937,16 @@ class ListSchedulesResponse(proto.Message): def raw_page(self): return self - schedules = proto.RepeatedField( + schedules: MutableSequence[gcn_schedule.Schedule] = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_schedule.Schedule, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) - unreachable = proto.RepeatedField( + unreachable: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -932,7 +961,7 @@ class GetScheduleRequest(proto.Message): ``projects/{project_id}/locations/{location}/schedules/{schedule_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -947,7 +976,7 @@ class DeleteScheduleRequest(proto.Message): ``projects/{project_id}/locations/{location}/schedules/{schedule_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -967,15 +996,15 @@ class CreateScheduleRequest(proto.Message): Required. The schedule to be created. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - schedule_id = proto.Field( + schedule_id: str = proto.Field( proto.STRING, number=2, ) - schedule = proto.Field( + schedule: gcn_schedule.Schedule = proto.Field( proto.MESSAGE, number=3, message=gcn_schedule.Schedule, @@ -991,7 +1020,7 @@ class TriggerScheduleRequest(proto.Message): ``parent=projects/{project_id}/locations/{location}/schedules/{schedule_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -1017,23 +1046,23 @@ class ListExecutionsRequest(proto.Message): Sort by field. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) - filter = proto.Field( + filter: str = proto.Field( proto.STRING, number=4, ) - order_by = proto.Field( + order_by: str = proto.Field( proto.STRING, number=5, ) @@ -1043,13 +1072,13 @@ class ListExecutionsResponse(proto.Message): r"""Response for listing scheduled notebook executions Attributes: - executions (Sequence[google.cloud.notebooks_v1.types.Execution]): + executions (MutableSequence[google.cloud.notebooks_v1.types.Execution]): A list of returned instances. next_page_token (str): Page token that can be used to continue listing from the last result in the next list call. - unreachable (Sequence[str]): + unreachable (MutableSequence[str]): Executions IDs that could not be reached. For example: :: @@ -1062,16 +1091,16 @@ class ListExecutionsResponse(proto.Message): def raw_page(self): return self - executions = proto.RepeatedField( + executions: MutableSequence[gcn_execution.Execution] = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_execution.Execution, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) - unreachable = proto.RepeatedField( + unreachable: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -1086,7 +1115,7 @@ class GetExecutionRequest(proto.Message): ``projects/{project_id}/locations/{location}/executions/{execution_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -1101,7 +1130,7 @@ class DeleteExecutionRequest(proto.Message): ``projects/{project_id}/locations/{location}/executions/{execution_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -1121,15 +1150,15 @@ class CreateExecutionRequest(proto.Message): Required. The execution to be created. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - execution_id = proto.Field( + execution_id: str = proto.Field( proto.STRING, number=2, ) - execution = proto.Field( + execution: gcn_execution.Execution = proto.Field( proto.MESSAGE, number=3, message=gcn_execution.Execution, diff --git a/google/cloud/notebooks_v1beta1/__init__.py b/google/cloud/notebooks_v1beta1/__init__.py index f0225be..c7fc929 100644 --- a/google/cloud/notebooks_v1beta1/__init__.py +++ b/google/cloud/notebooks_v1beta1/__init__.py @@ -13,10 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.notebooks import gapic_version as package_version + +__version__ = package_version.__version__ + from .services.notebook_service import NotebookServiceAsyncClient, NotebookServiceClient from .types.environment import ContainerImage, Environment, VmImage -from .types.instance import Instance +from .types.instance import Instance, ReservationAffinity from .types.service import ( CreateEnvironmentRequest, CreateInstanceRequest, @@ -64,6 +68,7 @@ "OperationMetadata", "RegisterInstanceRequest", "ReportInstanceInfoRequest", + "ReservationAffinity", "ResetInstanceRequest", "SetInstanceAcceleratorRequest", "SetInstanceLabelsRequest", diff --git a/google/cloud/notebooks_v1beta1/gapic_version.py b/google/cloud/notebooks_v1beta1/gapic_version.py new file mode 100644 index 0000000..25e4dd6 --- /dev/null +++ b/google/cloud/notebooks_v1beta1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- 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. +# +__version__ = "1.4.4" # {x-release-please-version} diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py b/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py index 4cc4103..8120066 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/async_client.py @@ -16,7 +16,18 @@ from collections import OrderedDict import functools import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, +) +import warnings from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 @@ -24,7 +35,8 @@ from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources + +from google.cloud.notebooks_v1beta1 import gapic_version as package_version try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -33,6 +45,10 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -166,9 +182,9 @@ def transport(self) -> NotebookServiceTransport: def __init__( self, *, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, NotebookServiceTransport] = "grpc_asyncio", - client_options: ClientOptions = None, + client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the notebook service client. @@ -212,10 +228,10 @@ def __init__( async def list_instances( self, - request: Union[service.ListInstancesRequest, dict] = None, + request: Optional[Union[service.ListInstancesRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListInstancesAsyncPager: r"""Lists instances in a given project and location. @@ -248,7 +264,7 @@ async def sample_list_instances(): print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.ListInstancesRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.ListInstancesRequest, dict]]): The request object. Request for listing notebook instances. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -305,10 +321,10 @@ async def sample_list_instances(): async def get_instance( self, - request: Union[service.GetInstanceRequest, dict] = None, + request: Optional[Union[service.GetInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> instance.Instance: r"""Gets details of a single Instance. @@ -340,7 +356,7 @@ async def sample_get_instance(): print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.GetInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.GetInstanceRequest, dict]]): The request object. Request for getting a notebook instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -385,10 +401,10 @@ async def sample_get_instance(): async def create_instance( self, - request: Union[service.CreateInstanceRequest, dict] = None, + request: Optional[Union[service.CreateInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Instance in a given project and @@ -426,13 +442,13 @@ async def sample_create_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.CreateInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.CreateInstanceRequest, dict]]): The request object. Request for creating a notebook instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -488,10 +504,10 @@ async def sample_create_instance(): async def register_instance( self, - request: Union[service.RegisterInstanceRequest, dict] = None, + request: Optional[Union[service.RegisterInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Registers an existing legacy notebook instance to the @@ -527,13 +543,13 @@ async def sample_register_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.RegisterInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.RegisterInstanceRequest, dict]]): The request object. Request for registering a notebook instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -589,10 +605,10 @@ async def sample_register_instance(): async def set_instance_accelerator( self, - request: Union[service.SetInstanceAcceleratorRequest, dict] = None, + request: Optional[Union[service.SetInstanceAcceleratorRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the guest accelerators of a single Instance. @@ -624,13 +640,13 @@ async def sample_set_instance_accelerator(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.SetInstanceAcceleratorRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.SetInstanceAcceleratorRequest, dict]]): The request object. Request for setting instance accelerator. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -686,10 +702,10 @@ async def sample_set_instance_accelerator(): async def set_instance_machine_type( self, - request: Union[service.SetInstanceMachineTypeRequest, dict] = None, + request: Optional[Union[service.SetInstanceMachineTypeRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the machine type of a single Instance. @@ -720,13 +736,13 @@ async def sample_set_instance_machine_type(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.SetInstanceMachineTypeRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.SetInstanceMachineTypeRequest, dict]]): The request object. Request for setting instance machine type. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -782,10 +798,10 @@ async def sample_set_instance_machine_type(): async def set_instance_labels( self, - request: Union[service.SetInstanceLabelsRequest, dict] = None, + request: Optional[Union[service.SetInstanceLabelsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the labels of an Instance. @@ -815,13 +831,13 @@ async def sample_set_instance_labels(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.SetInstanceLabelsRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.SetInstanceLabelsRequest, dict]]): The request object. Request for setting instance labels. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -876,10 +892,10 @@ async def sample_set_instance_labels(): async def delete_instance( self, - request: Union[service.DeleteInstanceRequest, dict] = None, + request: Optional[Union[service.DeleteInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Instance. @@ -909,13 +925,13 @@ async def sample_delete_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.DeleteInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.DeleteInstanceRequest, dict]]): The request object. Request for deleting a notebook instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -978,10 +994,10 @@ async def sample_delete_instance(): async def start_instance( self, - request: Union[service.StartInstanceRequest, dict] = None, + request: Optional[Union[service.StartInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Starts a notebook instance. @@ -1011,13 +1027,13 @@ async def sample_start_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.StartInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.StartInstanceRequest, dict]]): The request object. Request for starting a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1073,10 +1089,10 @@ async def sample_start_instance(): async def stop_instance( self, - request: Union[service.StopInstanceRequest, dict] = None, + request: Optional[Union[service.StopInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Stops a notebook instance. @@ -1106,13 +1122,13 @@ async def sample_stop_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.StopInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.StopInstanceRequest, dict]]): The request object. Request for stopping a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1168,10 +1184,10 @@ async def sample_stop_instance(): async def reset_instance( self, - request: Union[service.ResetInstanceRequest, dict] = None, + request: Optional[Union[service.ResetInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Resets a notebook instance. @@ -1201,13 +1217,13 @@ async def sample_reset_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.ResetInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.ResetInstanceRequest, dict]]): The request object. Request for reseting a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1263,10 +1279,10 @@ async def sample_reset_instance(): async def report_instance_info( self, - request: Union[service.ReportInstanceInfoRequest, dict] = None, + request: Optional[Union[service.ReportInstanceInfoRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Allows notebook instances to @@ -1301,13 +1317,13 @@ async def sample_report_instance_info(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.ReportInstanceInfoRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.ReportInstanceInfoRequest, dict]]): The request object. Request for notebook instances to report information to Notebooks API. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1363,13 +1379,14 @@ async def sample_report_instance_info(): async def is_instance_upgradeable( self, - request: Union[service.IsInstanceUpgradeableRequest, dict] = None, + request: Optional[Union[service.IsInstanceUpgradeableRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.IsInstanceUpgradeableResponse: r"""Check if a notebook instance is upgradable. + Deprecated. Please consider using v1. .. code-block:: python @@ -1398,7 +1415,7 @@ async def sample_is_instance_upgradeable(): print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.IsInstanceUpgradeableRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.IsInstanceUpgradeableRequest, dict]]): The request object. Request for checking if a notebook instance is upgradeable. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1413,6 +1430,11 @@ async def sample_is_instance_upgradeable(): instance is upgradeable. """ + warnings.warn( + "NotebookServiceAsyncClient.is_instance_upgradeable is deprecated", + DeprecationWarning, + ) + # Create or coerce a protobuf request object. request = service.IsInstanceUpgradeableRequest(request) @@ -1445,13 +1467,14 @@ async def sample_is_instance_upgradeable(): async def upgrade_instance( self, - request: Union[service.UpgradeInstanceRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Upgrades a notebook instance to the latest version. + Deprecated. Please consider using v1. .. code-block:: python @@ -1478,13 +1501,13 @@ async def sample_upgrade_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.UpgradeInstanceRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.UpgradeInstanceRequest, dict]]): The request object. Request for upgrading a notebook instance retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1502,6 +1525,11 @@ async def sample_upgrade_instance(): The definition of a notebook instance. """ + warnings.warn( + "NotebookServiceAsyncClient.upgrade_instance is deprecated", + DeprecationWarning, + ) + # Create or coerce a protobuf request object. request = service.UpgradeInstanceRequest(request) @@ -1540,15 +1568,16 @@ async def sample_upgrade_instance(): async def upgrade_instance_internal( self, - request: Union[service.UpgradeInstanceInternalRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceInternalRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Allows notebook instances to call this endpoint to upgrade themselves. Do not use - this method directly. + this method directly. Deprecated. Please consider using + v1. .. code-block:: python @@ -1576,13 +1605,13 @@ async def sample_upgrade_instance_internal(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.UpgradeInstanceInternalRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.UpgradeInstanceInternalRequest, dict]]): The request object. Request for upgrading a notebook instance from within the VM retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1600,6 +1629,11 @@ async def sample_upgrade_instance_internal(): The definition of a notebook instance. """ + warnings.warn( + "NotebookServiceAsyncClient.upgrade_instance_internal is deprecated", + DeprecationWarning, + ) + # Create or coerce a protobuf request object. request = service.UpgradeInstanceInternalRequest(request) @@ -1638,10 +1672,10 @@ async def sample_upgrade_instance_internal(): async def list_environments( self, - request: Union[service.ListEnvironmentsRequest, dict] = None, + request: Optional[Union[service.ListEnvironmentsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEnvironmentsAsyncPager: r"""Lists environments in a project. @@ -1674,7 +1708,7 @@ async def sample_list_environments(): print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.ListEnvironmentsRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.ListEnvironmentsRequest, dict]]): The request object. Request for listing environments. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -1729,10 +1763,10 @@ async def sample_list_environments(): async def get_environment( self, - request: Union[service.GetEnvironmentRequest, dict] = None, + request: Optional[Union[service.GetEnvironmentRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Gets details of a single Environment. @@ -1764,7 +1798,7 @@ async def sample_get_environment(): print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.GetEnvironmentRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.GetEnvironmentRequest, dict]]): The request object. Request for getting a notebook environment. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1810,10 +1844,10 @@ async def sample_get_environment(): async def create_environment( self, - request: Union[service.CreateEnvironmentRequest, dict] = None, + request: Optional[Union[service.CreateEnvironmentRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Environment. @@ -1849,13 +1883,13 @@ async def sample_create_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.CreateEnvironmentRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.CreateEnvironmentRequest, dict]]): The request object. Request for creating a notebook environment. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1910,10 +1944,10 @@ async def sample_create_environment(): async def delete_environment( self, - request: Union[service.DeleteEnvironmentRequest, dict] = None, + request: Optional[Union[service.DeleteEnvironmentRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Environment. @@ -1943,13 +1977,13 @@ async def sample_delete_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) Args: - request (Union[google.cloud.notebooks_v1beta1.types.DeleteEnvironmentRequest, dict]): + request (Optional[Union[google.cloud.notebooks_v1beta1.types.DeleteEnvironmentRequest, dict]]): The request object. Request for deleting a notebook environment. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -2010,6 +2044,631 @@ async def sample_delete_environment(): # Done; return the response. return response + async def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + 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 delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def set_iam_policy( + self, + request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: Optional[locations_pb2.GetLocationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + 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 list_locations( + self, + request: Optional[locations_pb2.ListLocationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + 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 __aenter__(self): return self @@ -2017,14 +2676,9 @@ async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("NotebookServiceAsyncClient",) diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/client.py b/google/cloud/notebooks_v1beta1/services/notebook_service/client.py index 26faa73..9e1cfa0 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/client.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/client.py @@ -16,7 +16,19 @@ from collections import OrderedDict import os import re -from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, + cast, +) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -27,7 +39,8 @@ from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources + +from google.cloud.notebooks_v1beta1 import gapic_version as package_version try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] @@ -36,6 +49,10 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -63,7 +80,7 @@ class NotebookServiceClientMeta(type): def get_transport_class( cls, - label: str = None, + label: Optional[str] = None, ) -> Type[NotebookServiceTransport]: """Returns an appropriate transport class. @@ -352,8 +369,8 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, NotebookServiceTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, + transport: Optional[Union[str, NotebookServiceTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiates the notebook service client. @@ -367,7 +384,7 @@ def __init__( transport (Union[str, NotebookServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -397,6 +414,7 @@ def __init__( client_options = client_options_lib.from_dict(client_options) if client_options is None: client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( client_options @@ -449,10 +467,10 @@ def __init__( def list_instances( self, - request: Union[service.ListInstancesRequest, dict] = None, + request: Optional[Union[service.ListInstancesRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListInstancesPager: r"""Lists instances in a given project and location. @@ -543,10 +561,10 @@ def sample_list_instances(): def get_instance( self, - request: Union[service.GetInstanceRequest, dict] = None, + request: Optional[Union[service.GetInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> instance.Instance: r"""Gets details of a single Instance. @@ -624,10 +642,10 @@ def sample_get_instance(): def create_instance( self, - request: Union[service.CreateInstanceRequest, dict] = None, + request: Optional[Union[service.CreateInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a new Instance in a given project and @@ -728,10 +746,10 @@ def sample_create_instance(): def register_instance( self, - request: Union[service.RegisterInstanceRequest, dict] = None, + request: Optional[Union[service.RegisterInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Registers an existing legacy notebook instance to the @@ -830,10 +848,10 @@ def sample_register_instance(): def set_instance_accelerator( self, - request: Union[service.SetInstanceAcceleratorRequest, dict] = None, + request: Optional[Union[service.SetInstanceAcceleratorRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the guest accelerators of a single Instance. @@ -928,10 +946,10 @@ def sample_set_instance_accelerator(): def set_instance_machine_type( self, - request: Union[service.SetInstanceMachineTypeRequest, dict] = None, + request: Optional[Union[service.SetInstanceMachineTypeRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the machine type of a single Instance. @@ -1027,10 +1045,10 @@ def sample_set_instance_machine_type(): def set_instance_labels( self, - request: Union[service.SetInstanceLabelsRequest, dict] = None, + request: Optional[Union[service.SetInstanceLabelsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates the labels of an Instance. @@ -1122,10 +1140,10 @@ def sample_set_instance_labels(): def delete_instance( self, - request: Union[service.DeleteInstanceRequest, dict] = None, + request: Optional[Union[service.DeleteInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes a single Instance. @@ -1225,10 +1243,10 @@ def sample_delete_instance(): def start_instance( self, - request: Union[service.StartInstanceRequest, dict] = None, + request: Optional[Union[service.StartInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Starts a notebook instance. @@ -1321,10 +1339,10 @@ def sample_start_instance(): def stop_instance( self, - request: Union[service.StopInstanceRequest, dict] = None, + request: Optional[Union[service.StopInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Stops a notebook instance. @@ -1417,10 +1435,10 @@ def sample_stop_instance(): def reset_instance( self, - request: Union[service.ResetInstanceRequest, dict] = None, + request: Optional[Union[service.ResetInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Resets a notebook instance. @@ -1513,10 +1531,10 @@ def sample_reset_instance(): def report_instance_info( self, - request: Union[service.ReportInstanceInfoRequest, dict] = None, + request: Optional[Union[service.ReportInstanceInfoRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Allows notebook instances to @@ -1614,13 +1632,14 @@ def sample_report_instance_info(): def is_instance_upgradeable( self, - request: Union[service.IsInstanceUpgradeableRequest, dict] = None, + request: Optional[Union[service.IsInstanceUpgradeableRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> service.IsInstanceUpgradeableResponse: r"""Check if a notebook instance is upgradable. + Deprecated. Please consider using v1. .. code-block:: python @@ -1664,6 +1683,11 @@ def sample_is_instance_upgradeable(): instance is upgradeable. """ + warnings.warn( + "NotebookServiceClient.is_instance_upgradeable is deprecated", + DeprecationWarning, + ) + # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a service.IsInstanceUpgradeableRequest. @@ -1697,13 +1721,14 @@ def sample_is_instance_upgradeable(): def upgrade_instance( self, - request: Union[service.UpgradeInstanceRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Upgrades a notebook instance to the latest version. + Deprecated. Please consider using v1. .. code-block:: python @@ -1754,6 +1779,10 @@ def sample_upgrade_instance(): The definition of a notebook instance. """ + warnings.warn( + "NotebookServiceClient.upgrade_instance is deprecated", DeprecationWarning + ) + # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a service.UpgradeInstanceRequest. @@ -1793,15 +1822,16 @@ def sample_upgrade_instance(): def upgrade_instance_internal( self, - request: Union[service.UpgradeInstanceInternalRequest, dict] = None, + request: Optional[Union[service.UpgradeInstanceInternalRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Allows notebook instances to call this endpoint to upgrade themselves. Do not use - this method directly. + this method directly. Deprecated. Please consider using + v1. .. code-block:: python @@ -1853,6 +1883,11 @@ def sample_upgrade_instance_internal(): The definition of a notebook instance. """ + warnings.warn( + "NotebookServiceClient.upgrade_instance_internal is deprecated", + DeprecationWarning, + ) + # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a service.UpgradeInstanceInternalRequest. @@ -1894,10 +1929,10 @@ def sample_upgrade_instance_internal(): def list_environments( self, - request: Union[service.ListEnvironmentsRequest, dict] = None, + request: Optional[Union[service.ListEnvironmentsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEnvironmentsPager: r"""Lists environments in a project. @@ -1986,10 +2021,10 @@ def sample_list_environments(): def get_environment( self, - request: Union[service.GetEnvironmentRequest, dict] = None, + request: Optional[Union[service.GetEnvironmentRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> environment.Environment: r"""Gets details of a single Environment. @@ -2068,10 +2103,10 @@ def sample_get_environment(): def create_environment( self, - request: Union[service.CreateEnvironmentRequest, dict] = None, + request: Optional[Union[service.CreateEnvironmentRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Creates a new Environment. @@ -2169,10 +2204,10 @@ def sample_create_environment(): def delete_environment( self, - request: Union[service.DeleteEnvironmentRequest, dict] = None, + request: Optional[Union[service.DeleteEnvironmentRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: float = None, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Deletes a single Environment. @@ -2283,15 +2318,635 @@ def __exit__(self, type, value, traceback): """ self.transport.close() + def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def set_iam_policy( + self, + request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + + **JSON Example** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + + **YAML Example** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: Optional[locations_pb2.GetLocationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: Optional[locations_pb2.ListLocationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) __all__ = ("NotebookServiceClient",) diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py index 47b4c16..05a1bd4 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/base.py @@ -22,20 +22,18 @@ from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore -import pkg_resources +from google.cloud.notebooks_v1beta1 import gapic_version as package_version from google.cloud.notebooks_v1beta1.types import environment, instance, service -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-notebooks", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) class NotebookServiceTransport(abc.ABC): @@ -49,7 +47,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -416,6 +414,90 @@ def delete_environment( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + @property def kind(self) -> str: raise NotImplementedError() diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py index 2edd785..e7942db 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc.py @@ -20,6 +20,9 @@ import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore @@ -47,14 +50,14 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, @@ -182,8 +185,8 @@ def __init__( def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, **kwargs, @@ -573,6 +576,7 @@ def is_instance_upgradeable( r"""Return a callable for the is instance upgradeable method over gRPC. Check if a notebook instance is upgradable. + Deprecated. Please consider using v1. Returns: Callable[[~.IsInstanceUpgradeableRequest], @@ -599,6 +603,7 @@ def upgrade_instance( r"""Return a callable for the upgrade instance method over gRPC. Upgrades a notebook instance to the latest version. + Deprecated. Please consider using v1. Returns: Callable[[~.UpgradeInstanceRequest], @@ -626,7 +631,8 @@ def upgrade_instance_internal( Allows notebook instances to call this endpoint to upgrade themselves. Do not use - this method directly. + this method directly. Deprecated. Please consider using + v1. Returns: Callable[[~.UpgradeInstanceInternalRequest], @@ -753,6 +759,192 @@ def delete_environment( def close(self): self.grpc_channel.close() + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # 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 "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # 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_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + 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 "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + 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_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + 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 "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + @property def kind(self) -> str: return "grpc" diff --git a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py index 97ea5a6..b3e25a3 100644 --- a/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py +++ b/google/cloud/notebooks_v1beta1/services/notebook_service/transports/grpc_asyncio.py @@ -19,6 +19,9 @@ from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -49,7 +52,7 @@ class NotebookServiceGrpcAsyncIOTransport(NotebookServiceTransport): def create_channel( cls, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -92,15 +95,15 @@ def __init__( self, *, host: str = "notebooks.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, api_audience: Optional[str] = None, @@ -593,6 +596,7 @@ def is_instance_upgradeable( r"""Return a callable for the is instance upgradeable method over gRPC. Check if a notebook instance is upgradable. + Deprecated. Please consider using v1. Returns: Callable[[~.IsInstanceUpgradeableRequest], @@ -621,6 +625,7 @@ def upgrade_instance( r"""Return a callable for the upgrade instance method over gRPC. Upgrades a notebook instance to the latest version. + Deprecated. Please consider using v1. Returns: Callable[[~.UpgradeInstanceRequest], @@ -650,7 +655,8 @@ def upgrade_instance_internal( Allows notebook instances to call this endpoint to upgrade themselves. Do not use - this method directly. + this method directly. Deprecated. Please consider using + v1. Returns: Callable[[~.UpgradeInstanceInternalRequest], @@ -783,5 +789,191 @@ def delete_environment( def close(self): return self.grpc_channel.close() + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # 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 "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # 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_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # 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_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # 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_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + 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 "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + 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_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + 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 "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("NotebookServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/notebooks_v1beta1/types/__init__.py b/google/cloud/notebooks_v1beta1/types/__init__.py index c2a45ad..6a05eae 100644 --- a/google/cloud/notebooks_v1beta1/types/__init__.py +++ b/google/cloud/notebooks_v1beta1/types/__init__.py @@ -14,7 +14,7 @@ # limitations under the License. # from .environment import ContainerImage, Environment, VmImage -from .instance import Instance +from .instance import Instance, ReservationAffinity from .service import ( CreateEnvironmentRequest, CreateInstanceRequest, @@ -46,6 +46,7 @@ "Environment", "VmImage", "Instance", + "ReservationAffinity", "CreateEnvironmentRequest", "CreateInstanceRequest", "DeleteEnvironmentRequest", diff --git a/google/cloud/notebooks_v1beta1/types/environment.py b/google/cloud/notebooks_v1beta1/types/environment.py index 7d4ca4e..ab53637 100644 --- a/google/cloud/notebooks_v1beta1/types/environment.py +++ b/google/cloud/notebooks_v1beta1/types/environment.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -65,35 +67,35 @@ class Environment(proto.Message): environment was created. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - display_name = proto.Field( + display_name: str = proto.Field( proto.STRING, number=2, ) - description = proto.Field( + description: str = proto.Field( proto.STRING, number=3, ) - vm_image = proto.Field( + vm_image: "VmImage" = proto.Field( proto.MESSAGE, number=6, oneof="image_type", message="VmImage", ) - container_image = proto.Field( + container_image: "ContainerImage" = proto.Field( proto.MESSAGE, number=7, oneof="image_type", message="ContainerImage", ) - post_startup_script = proto.Field( + post_startup_script: str = proto.Field( proto.STRING, number=8, ) - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp, @@ -127,16 +129,16 @@ class VmImage(proto.Message): This field is a member of `oneof`_ ``image``. """ - project = proto.Field( + project: str = proto.Field( proto.STRING, number=1, ) - image_name = proto.Field( + image_name: str = proto.Field( proto.STRING, number=2, oneof="image", ) - image_family = proto.Field( + image_family: str = proto.Field( proto.STRING, number=3, oneof="image", @@ -156,11 +158,11 @@ class ContainerImage(proto.Message): specified, this defaults to the latest tag. """ - repository = proto.Field( + repository: str = proto.Field( proto.STRING, number=1, ) - tag = proto.Field( + tag: str = proto.Field( proto.STRING, number=2, ) diff --git a/google/cloud/notebooks_v1beta1/types/instance.py b/google/cloud/notebooks_v1beta1/types/instance.py index 1194648..7049a72 100644 --- a/google/cloud/notebooks_v1beta1/types/instance.py +++ b/google/cloud/notebooks_v1beta1/types/instance.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -21,11 +23,50 @@ __protobuf__ = proto.module( package="google.cloud.notebooks.v1beta1", manifest={ + "ReservationAffinity", "Instance", }, ) +class ReservationAffinity(proto.Message): + r"""Reservation Affinity for consuming Zonal reservation. + + Attributes: + consume_reservation_type (google.cloud.notebooks_v1beta1.types.ReservationAffinity.Type): + Optional. Type of reservation to consume + key (str): + Optional. Corresponds to the label key of + reservation resource. + values (MutableSequence[str]): + Optional. Corresponds to the label values of + reservation resource. + """ + + class Type(proto.Enum): + r"""Indicates whether to consume capacity from an reservation or + not. + """ + TYPE_UNSPECIFIED = 0 + NO_RESERVATION = 1 + ANY_RESERVATION = 2 + SPECIFIC_RESERVATION = 3 + + consume_reservation_type: Type = proto.Field( + proto.ENUM, + number=1, + enum=Type, + ) + key: str = proto.Field( + proto.STRING, + number=2, + ) + values: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=3, + ) + + class Instance(proto.Message): r"""The definition of a notebook instance. @@ -51,13 +92,14 @@ class Instance(proto.Message): This field is a member of `oneof`_ ``environment``. post_startup_script (str): - Path to a Bash script that automatically runs after a - notebook instance fully boots up. The path must be a URL or - Cloud Storage path (``gs://path-to-file/file-name``). + Path to a Bash script that automatically runs + after a notebook instance fully boots up. The + path must be a URL or Cloud Storage path + (gs://path-to-file/file-name). proxy_uri (str): Output only. The proxy endpoint that is used to access the Jupyter notebook. - instance_owners (Sequence[str]): + instance_owners (MutableSequence[str]): Input only. The owner of this instance after creation. Format: ``alias@example.com`` @@ -75,13 +117,12 @@ class Instance(proto.Message): is used. machine_type (str): Required. The `Compute Engine machine - type `__ - of this instance. + type `__ of this instance. accelerator_config (google.cloud.notebooks_v1beta1.types.Instance.AcceleratorConfig): The hardware accelerator used on this instance. If you use accelerators, make sure that your configuration has `enough vCPUs and memory to support the ``machine_type`` you have - selected `__. + selected `__. state (google.cloud.notebooks_v1beta1.types.Instance.State): Output only. The state of this instance. install_gpu_driver (bool): @@ -127,7 +168,7 @@ class Instance(proto.Message): ``projects/{project_id}/locations/{location}/keyRings/{key_ring_id}/cryptoKeys/{key_id}`` Learn more about `using your own encryption - keys `__. + keys `__. no_public_ip (bool): If true, no public IP will be assigned to this instance. @@ -140,12 +181,24 @@ class Instance(proto.Message): subnet (str): The name of the subnet that this instance is in. Format: ``projects/{project_id}/regions/{region}/subnetworks/{subnetwork_id}`` - labels (Mapping[str, str]): + labels (MutableMapping[str, str]): Labels to apply to this instance. These can be later modified by the setLabels method. - metadata (Mapping[str, str]): + metadata (MutableMapping[str, str]): Custom metadata to apply to this instance. + nic_type (google.cloud.notebooks_v1beta1.types.Instance.NicType): + Optional. The type of vNIC to be used on this + interface. This may be gVNIC or VirtioNet. + reservation_affinity (google.cloud.notebooks_v1beta1.types.ReservationAffinity): + Optional. The optional reservation affinity. Setting this + field will apply the specified `Zonal Compute + Reservation `__ + to this notebook instance. + can_ip_forward (bool): + Optional. Flag to enable ip forwarding or + not, default false/off. + https://cloud.google.com/vpc/docs/using-routes#canipforward create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Instance creation time. update_time (google.protobuf.timestamp_pb2.Timestamp): @@ -180,6 +233,8 @@ class State(proto.Enum): UPGRADING = 7 INITIALIZING = 8 REGISTERING = 9 + SUSPENDING = 10 + SUSPENDED = 11 class DiskType(proto.Enum): r"""Possible disk types for notebook instances.""" @@ -194,6 +249,12 @@ class DiskEncryption(proto.Enum): GMEK = 1 CMEK = 2 + class NicType(proto.Enum): + r"""The type of vNIC driver.""" + UNSPECIFIED_NIC_TYPE = 0 + VIRTIO_NET = 1 + GVNIC = 2 + class AcceleratorConfig(proto.Message): r"""Definition of a hardware accelerator. Note that not all combinations of ``type`` and ``core_count`` are valid. Check `GPUs on Compute @@ -207,133 +268,147 @@ class AcceleratorConfig(proto.Message): Count of cores of this accelerator. """ - type_ = proto.Field( + type_: "Instance.AcceleratorType" = proto.Field( proto.ENUM, number=1, enum="Instance.AcceleratorType", ) - core_count = proto.Field( + core_count: int = proto.Field( proto.INT64, number=2, ) - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_image = proto.Field( + vm_image: environment.VmImage = proto.Field( proto.MESSAGE, number=2, oneof="environment", message=environment.VmImage, ) - container_image = proto.Field( + container_image: environment.ContainerImage = proto.Field( proto.MESSAGE, number=3, oneof="environment", message=environment.ContainerImage, ) - post_startup_script = proto.Field( + post_startup_script: str = proto.Field( proto.STRING, number=4, ) - proxy_uri = proto.Field( + proxy_uri: str = proto.Field( proto.STRING, number=5, ) - instance_owners = proto.RepeatedField( + instance_owners: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=6, ) - service_account = proto.Field( + service_account: str = proto.Field( proto.STRING, number=7, ) - machine_type = proto.Field( + machine_type: str = proto.Field( proto.STRING, number=8, ) - accelerator_config = proto.Field( + accelerator_config: AcceleratorConfig = proto.Field( proto.MESSAGE, number=9, message=AcceleratorConfig, ) - state = proto.Field( + state: State = proto.Field( proto.ENUM, number=10, enum=State, ) - install_gpu_driver = proto.Field( + install_gpu_driver: bool = proto.Field( proto.BOOL, number=11, ) - custom_gpu_driver_path = proto.Field( + custom_gpu_driver_path: str = proto.Field( proto.STRING, number=12, ) - boot_disk_type = proto.Field( + boot_disk_type: DiskType = proto.Field( proto.ENUM, number=13, enum=DiskType, ) - boot_disk_size_gb = proto.Field( + boot_disk_size_gb: int = proto.Field( proto.INT64, number=14, ) - data_disk_type = proto.Field( + data_disk_type: DiskType = proto.Field( proto.ENUM, number=25, enum=DiskType, ) - data_disk_size_gb = proto.Field( + data_disk_size_gb: int = proto.Field( proto.INT64, number=26, ) - no_remove_data_disk = proto.Field( + no_remove_data_disk: bool = proto.Field( proto.BOOL, number=27, ) - disk_encryption = proto.Field( + disk_encryption: DiskEncryption = proto.Field( proto.ENUM, number=15, enum=DiskEncryption, ) - kms_key = proto.Field( + kms_key: str = proto.Field( proto.STRING, number=16, ) - no_public_ip = proto.Field( + no_public_ip: bool = proto.Field( proto.BOOL, number=17, ) - no_proxy_access = proto.Field( + no_proxy_access: bool = proto.Field( proto.BOOL, number=18, ) - network = proto.Field( + network: str = proto.Field( proto.STRING, number=19, ) - subnet = proto.Field( + subnet: str = proto.Field( proto.STRING, number=20, ) - labels = proto.MapField( + labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=21, ) - metadata = proto.MapField( + metadata: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=22, ) - create_time = proto.Field( + nic_type: NicType = proto.Field( + proto.ENUM, + number=28, + enum=NicType, + ) + reservation_affinity: "ReservationAffinity" = proto.Field( + proto.MESSAGE, + number=29, + message="ReservationAffinity", + ) + can_ip_forward: bool = proto.Field( + proto.BOOL, + number=31, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=23, message=timestamp_pb2.Timestamp, ) - update_time = proto.Field( + update_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=24, message=timestamp_pb2.Timestamp, diff --git a/google/cloud/notebooks_v1beta1/types/service.py b/google/cloud/notebooks_v1beta1/types/service.py index e1468e4..13a4b7f 100644 --- a/google/cloud/notebooks_v1beta1/types/service.py +++ b/google/cloud/notebooks_v1beta1/types/service.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import MutableMapping, MutableSequence + from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore @@ -77,37 +79,37 @@ class OperationMetadata(proto.Message): API endpoint name of this operation. """ - create_time = proto.Field( + create_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, ) - end_time = proto.Field( + end_time: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, ) - target = proto.Field( + target: str = proto.Field( proto.STRING, number=3, ) - verb = proto.Field( + verb: str = proto.Field( proto.STRING, number=4, ) - status_message = proto.Field( + status_message: str = proto.Field( proto.STRING, number=5, ) - requested_cancellation = proto.Field( + requested_cancellation: bool = proto.Field( proto.BOOL, number=6, ) - api_version = proto.Field( + api_version: str = proto.Field( proto.STRING, number=7, ) - endpoint = proto.Field( + endpoint: str = proto.Field( proto.STRING, number=8, ) @@ -127,15 +129,15 @@ class ListInstancesRequest(proto.Message): used to continue listing from the last result. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -145,13 +147,13 @@ class ListInstancesResponse(proto.Message): r"""Response for listing notebook instances. Attributes: - instances (Sequence[google.cloud.notebooks_v1beta1.types.Instance]): + instances (MutableSequence[google.cloud.notebooks_v1beta1.types.Instance]): A list of returned instances. next_page_token (str): Page token that can be used to continue listing from the last result in the next list call. - unreachable (Sequence[str]): + unreachable (MutableSequence[str]): Locations that could not be reached. For example, ['us-west1-a', 'us-central1-b']. A ListInstancesResponse will only contain either instances or unreachables, @@ -161,16 +163,16 @@ class ListInstancesResponse(proto.Message): def raw_page(self): return self - instances = proto.RepeatedField( + instances: MutableSequence[gcn_instance.Instance] = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_instance.Instance, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) - unreachable = proto.RepeatedField( + unreachable: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -185,7 +187,7 @@ class GetInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -205,15 +207,15 @@ class CreateInstanceRequest(proto.Message): Required. The instance to be created. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - instance_id = proto.Field( + instance_id: str = proto.Field( proto.STRING, number=2, ) - instance = proto.Field( + instance: gcn_instance.Instance = proto.Field( proto.MESSAGE, number=3, message=gcn_instance.Instance, @@ -235,11 +237,11 @@ class RegisterInstanceRequest(proto.Message): character cannot be a dash. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - instance_id = proto.Field( + instance_id: str = proto.Field( proto.STRING, number=2, ) @@ -262,16 +264,16 @@ class SetInstanceAcceleratorRequest(proto.Message): to find a valid combination. TPUs are not supported. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - type_ = proto.Field( + type_: gcn_instance.Instance.AcceleratorType = proto.Field( proto.ENUM, number=2, enum=gcn_instance.Instance.AcceleratorType, ) - core_count = proto.Field( + core_count: int = proto.Field( proto.INT64, number=3, ) @@ -289,11 +291,11 @@ class SetInstanceMachineTypeRequest(proto.Message): type `__. """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - machine_type = proto.Field( + machine_type: str = proto.Field( proto.STRING, number=2, ) @@ -306,17 +308,17 @@ class SetInstanceLabelsRequest(proto.Message): name (str): Required. Format: ``projects/{project_id}/locations/{location}/instances/{instance_id}`` - labels (Mapping[str, str]): + labels (MutableMapping[str, str]): Labels to apply to this instance. These can be later modified by the setLabels method """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - labels = proto.MapField( + labels: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=2, @@ -332,7 +334,7 @@ class DeleteInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -347,7 +349,7 @@ class StartInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -362,7 +364,7 @@ class StopInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -377,7 +379,7 @@ class ResetInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -395,20 +397,20 @@ class ReportInstanceInfoRequest(proto.Message): Required. The VM hardware token for authenticating the VM. https://cloud.google.com/compute/docs/instances/verifying-instance-identity - metadata (Mapping[str, str]): + metadata (MutableMapping[str, str]): The metadata reported to Notebooks API. This will be merged to the instance metadata store """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_id = proto.Field( + vm_id: str = proto.Field( proto.STRING, number=2, ) - metadata = proto.MapField( + metadata: MutableMapping[str, str] = proto.MapField( proto.STRING, proto.STRING, number=3, @@ -424,7 +426,7 @@ class IsInstanceUpgradeableRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - notebook_instance = proto.Field( + notebook_instance: str = proto.Field( proto.STRING, number=1, ) @@ -442,20 +444,29 @@ class IsInstanceUpgradeableResponse(proto.Message): only be populated if field upgradeable is true. upgrade_info (str): Additional information about upgrade. + upgrade_image (str): + The new image self link this instance will be + upgraded to if calling the upgrade endpoint. + This field will only be populated if field + upgradeable is true. """ - upgradeable = proto.Field( + upgradeable: bool = proto.Field( proto.BOOL, number=1, ) - upgrade_version = proto.Field( + upgrade_version: str = proto.Field( proto.STRING, number=2, ) - upgrade_info = proto.Field( + upgrade_info: str = proto.Field( proto.STRING, number=3, ) + upgrade_image: str = proto.Field( + proto.STRING, + number=4, + ) class UpgradeInstanceRequest(proto.Message): @@ -467,7 +478,7 @@ class UpgradeInstanceRequest(proto.Message): ``projects/{project_id}/locations/{location}/instances/{instance_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -486,11 +497,11 @@ class UpgradeInstanceInternalRequest(proto.Message): https://cloud.google.com/compute/docs/instances/verifying-instance-identity """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) - vm_id = proto.Field( + vm_id: str = proto.Field( proto.STRING, number=2, ) @@ -510,15 +521,15 @@ class ListEnvironmentsRequest(proto.Message): used to continue listing from the last result. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - page_size = proto.Field( + page_size: int = proto.Field( proto.INT32, number=2, ) - page_token = proto.Field( + page_token: str = proto.Field( proto.STRING, number=3, ) @@ -528,13 +539,13 @@ class ListEnvironmentsResponse(proto.Message): r"""Response for listing environments. Attributes: - environments (Sequence[google.cloud.notebooks_v1beta1.types.Environment]): + environments (MutableSequence[google.cloud.notebooks_v1beta1.types.Environment]): A list of returned environments. next_page_token (str): A page token that can be used to continue listing from the last result in the next list call. - unreachable (Sequence[str]): + unreachable (MutableSequence[str]): Locations that could not be reached. """ @@ -542,16 +553,16 @@ class ListEnvironmentsResponse(proto.Message): def raw_page(self): return self - environments = proto.RepeatedField( + environments: MutableSequence[gcn_environment.Environment] = proto.RepeatedField( proto.MESSAGE, number=1, message=gcn_environment.Environment, ) - next_page_token = proto.Field( + next_page_token: str = proto.Field( proto.STRING, number=2, ) - unreachable = proto.RepeatedField( + unreachable: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=3, ) @@ -566,7 +577,7 @@ class GetEnvironmentRequest(proto.Message): ``projects/{project_id}/locations/{location}/environments/{environment_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) @@ -589,15 +600,15 @@ class CreateEnvironmentRequest(proto.Message): Required. The environment to be created. """ - parent = proto.Field( + parent: str = proto.Field( proto.STRING, number=1, ) - environment_id = proto.Field( + environment_id: str = proto.Field( proto.STRING, number=2, ) - environment = proto.Field( + environment: gcn_environment.Environment = proto.Field( proto.MESSAGE, number=3, message=gcn_environment.Environment, @@ -613,7 +624,7 @@ class DeleteEnvironmentRequest(proto.Message): ``projects/{project_id}/locations/{location}/environments/{environment_id}`` """ - name = proto.Field( + name: str = proto.Field( proto.STRING, number=1, ) diff --git a/owlbot.py b/owlbot.py new file mode 100644 index 0000000..ce738f0 --- /dev/null +++ b/owlbot.py @@ -0,0 +1,56 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +from pathlib import Path +import shutil + +import synthtool as s +import synthtool.gcp as gcp +from synthtool.languages import python + +# ---------------------------------------------------------------------------- +# Copy the generated client from the owl-bot staging directory +# ---------------------------------------------------------------------------- + +clean_up_generated_samples = True + +# Load the default version defined in .repo-metadata.json. +default_version = json.load(open(".repo-metadata.json", "rt")).get( + "default_version" +) + +for library in s.get_staging_dirs(default_version): + if clean_up_generated_samples: + shutil.rmtree("samples/generated_samples", ignore_errors=True) + clean_up_generated_samples = False + s.move([library], excludes=["**/gapic_version.py"]) +s.remove_staging_dirs() + +# ---------------------------------------------------------------------------- +# Add templated files +# ---------------------------------------------------------------------------- + +templated_files = gcp.CommonTemplates().py_library( + cov_level=100, + microgenerator=True, + versions=gcp.common.detect_versions(path="./google", default_first=True), +) +s.move(templated_files, excludes=[".coveragerc", ".github/release-please.yml"]) + +python.py_samples(skip_readmes=True) + +# run format session for all directories which have a noxfile +for noxfile in Path(".").glob("**/noxfile.py"): + s.shell.run(["nox", "-s", "format"], cwd=noxfile.parent, hide_output=False) diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..a595ebd --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "packages": { + ".": { + "release-type": "python", + "extra-files": [ + "google/cloud/notebooks/gapic_version.py", + "google/cloud/notebooks_v1/gapic_version.py", + "google/cloud/notebooks_v1beta1/gapic_version.py", + { + "type": "json", + "path": "samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1beta1.json", + "jsonpath": "$.clientLibrary.version" + }, + { + "type": "json", + "path": "samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1.json", + "jsonpath": "$.clientLibrary.version" + } + ] + } + }, + "release-type": "python", + "plugins": [ + { + "type": "sentence-case" + } + ], + "initial-version": "0.1.0" +} diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_create_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_create_runtime_async.py index e65865e..2ed8514 100644 --- a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_create_runtime_async.py +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_create_runtime_async.py @@ -49,7 +49,7 @@ async def sample_create_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_delete_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_delete_runtime_async.py index 3f4bcdf..f921e61 100644 --- a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_delete_runtime_async.py +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_delete_runtime_async.py @@ -48,7 +48,7 @@ async def sample_delete_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_diagnose_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_diagnose_runtime_async.py new file mode 100644 index 0000000..e87fcf5 --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_diagnose_runtime_async.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DiagnoseRuntime +# 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-notebooks + + +# [START notebooks_v1_generated_ManagedNotebookService_DiagnoseRuntime_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 notebooks_v1 + + +async def sample_diagnose_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceAsyncClient() + + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" + + request = notebooks_v1.DiagnoseRuntimeRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_runtime(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_ManagedNotebookService_DiagnoseRuntime_async] diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_diagnose_runtime_sync.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_diagnose_runtime_sync.py new file mode 100644 index 0000000..e55f5e8 --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_diagnose_runtime_sync.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DiagnoseRuntime +# 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-notebooks + + +# [START notebooks_v1_generated_ManagedNotebookService_DiagnoseRuntime_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 notebooks_v1 + + +def sample_diagnose_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceClient() + + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" + + request = notebooks_v1.DiagnoseRuntimeRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_runtime(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_ManagedNotebookService_DiagnoseRuntime_sync] diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_report_runtime_event_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_report_runtime_event_async.py index e93b83c..b072b5a 100644 --- a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_report_runtime_event_async.py +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_report_runtime_event_async.py @@ -49,7 +49,7 @@ async def sample_report_runtime_event(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_reset_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_reset_runtime_async.py index 3705202..53bfec2 100644 --- a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_reset_runtime_async.py +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_reset_runtime_async.py @@ -48,7 +48,7 @@ async def sample_reset_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_start_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_start_runtime_async.py index 3c457bc..d774562 100644 --- a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_start_runtime_async.py +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_start_runtime_async.py @@ -48,7 +48,7 @@ async def sample_start_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py index 404baea..1550b9a 100644 --- a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py @@ -48,7 +48,7 @@ async def sample_stop_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py index 7fc07df..0287bf8 100644 --- a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py @@ -48,7 +48,7 @@ async def sample_switch_runtime(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_update_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_update_runtime_async.py new file mode 100644 index 0000000..15c36f3 --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_update_runtime_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 UpdateRuntime +# 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-notebooks + + +# [START notebooks_v1_generated_ManagedNotebookService_UpdateRuntime_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 notebooks_v1 + + +async def sample_update_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceAsyncClient() + + # Initialize request argument(s) + request = notebooks_v1.UpdateRuntimeRequest( + ) + + # Make the request + operation = client.update_runtime(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_ManagedNotebookService_UpdateRuntime_async] diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_update_runtime_sync.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_update_runtime_sync.py new file mode 100644 index 0000000..579b661 --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_update_runtime_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 UpdateRuntime +# 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-notebooks + + +# [START notebooks_v1_generated_ManagedNotebookService_UpdateRuntime_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 notebooks_v1 + + +def sample_update_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceClient() + + # Initialize request argument(s) + request = notebooks_v1.UpdateRuntimeRequest( + ) + + # Make the request + operation = client.update_runtime(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_ManagedNotebookService_UpdateRuntime_sync] diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_upgrade_runtime_async.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_upgrade_runtime_async.py new file mode 100644 index 0000000..632ff90 --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_upgrade_runtime_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 UpgradeRuntime +# 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-notebooks + + +# [START notebooks_v1_generated_ManagedNotebookService_UpgradeRuntime_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 notebooks_v1 + + +async def sample_upgrade_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceAsyncClient() + + # Initialize request argument(s) + request = notebooks_v1.UpgradeRuntimeRequest( + name="name_value", + ) + + # Make the request + operation = client.upgrade_runtime(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_ManagedNotebookService_UpgradeRuntime_async] diff --git a/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_upgrade_runtime_sync.py b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_upgrade_runtime_sync.py new file mode 100644 index 0000000..c3a205c --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_managed_notebook_service_upgrade_runtime_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 UpgradeRuntime +# 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-notebooks + + +# [START notebooks_v1_generated_ManagedNotebookService_UpgradeRuntime_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 notebooks_v1 + + +def sample_upgrade_runtime(): + # Create a client + client = notebooks_v1.ManagedNotebookServiceClient() + + # Initialize request argument(s) + request = notebooks_v1.UpgradeRuntimeRequest( + name="name_value", + ) + + # Make the request + operation = client.upgrade_runtime(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_ManagedNotebookService_UpgradeRuntime_sync] diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_environment_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_environment_async.py index 85be6a2..3d26215 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_environment_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_environment_async.py @@ -54,7 +54,7 @@ async def sample_create_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_execution_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_execution_async.py index 018957c..58b2828 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_execution_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_execution_async.py @@ -49,7 +49,7 @@ async def sample_create_execution(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_instance_async.py index ba40b48..58f5bb3 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_instance_async.py @@ -55,7 +55,7 @@ async def sample_create_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_schedule_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_schedule_async.py index f7511e6..06c21e3 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_create_schedule_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_create_schedule_async.py @@ -49,7 +49,7 @@ async def sample_create_schedule(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_environment_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_environment_async.py index 075e0d4..341390b 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_environment_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_environment_async.py @@ -48,7 +48,7 @@ async def sample_delete_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_execution_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_execution_async.py index b558c8e..21d2209 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_execution_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_execution_async.py @@ -48,7 +48,7 @@ async def sample_delete_execution(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_instance_async.py index 0565fc5..0aeac29 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_instance_async.py @@ -48,7 +48,7 @@ async def sample_delete_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_schedule_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_schedule_async.py index 10ab29f..ee16486 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_schedule_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_delete_schedule_async.py @@ -48,7 +48,7 @@ async def sample_delete_schedule(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_diagnose_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_diagnose_instance_async.py new file mode 100644 index 0000000..2dfce0a --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_diagnose_instance_async.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DiagnoseInstance +# 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-notebooks + + +# [START notebooks_v1_generated_NotebookService_DiagnoseInstance_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 notebooks_v1 + + +async def sample_diagnose_instance(): + # Create a client + client = notebooks_v1.NotebookServiceAsyncClient() + + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" + + request = notebooks_v1.DiagnoseInstanceRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_instance(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_NotebookService_DiagnoseInstance_async] diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_diagnose_instance_sync.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_diagnose_instance_sync.py new file mode 100644 index 0000000..d76197b --- /dev/null +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_diagnose_instance_sync.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DiagnoseInstance +# 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-notebooks + + +# [START notebooks_v1_generated_NotebookService_DiagnoseInstance_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 notebooks_v1 + + +def sample_diagnose_instance(): + # Create a client + client = notebooks_v1.NotebookServiceClient() + + # Initialize request argument(s) + diagnostic_config = notebooks_v1.DiagnosticConfig() + diagnostic_config.gcs_bucket = "gcs_bucket_value" + + request = notebooks_v1.DiagnoseInstanceRequest( + name="name_value", + diagnostic_config=diagnostic_config, + ) + + # Make the request + operation = client.diagnose_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END notebooks_v1_generated_NotebookService_DiagnoseInstance_sync] diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_register_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_register_instance_async.py index c638b8d..401cc50 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_register_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_register_instance_async.py @@ -49,7 +49,7 @@ async def sample_register_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_report_instance_info_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_report_instance_info_async.py index d5818cc..11e07dd 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_report_instance_info_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_report_instance_info_async.py @@ -49,7 +49,7 @@ async def sample_report_instance_info(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_reset_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_reset_instance_async.py index 5ea78ae..eebb0f3 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_reset_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_reset_instance_async.py @@ -48,7 +48,7 @@ async def sample_reset_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_rollback_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_rollback_instance_async.py index 980bb5d..9467bbe 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_rollback_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_rollback_instance_async.py @@ -49,7 +49,7 @@ async def sample_rollback_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_accelerator_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_accelerator_async.py index 449ec7b..029b839 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_accelerator_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_accelerator_async.py @@ -50,7 +50,7 @@ async def sample_set_instance_accelerator(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_labels_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_labels_async.py index 6a454af..443aef7 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_labels_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_labels_async.py @@ -48,7 +48,7 @@ async def sample_set_instance_labels(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_machine_type_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_machine_type_async.py index eeccfa0..c42bf7c 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_machine_type_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_set_instance_machine_type_async.py @@ -49,7 +49,7 @@ async def sample_set_instance_machine_type(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_start_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_start_instance_async.py index c8ca50d..132aa7e 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_start_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_start_instance_async.py @@ -48,7 +48,7 @@ async def sample_start_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_stop_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_stop_instance_async.py index ff68ab1..38d1a18 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_stop_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_stop_instance_async.py @@ -48,7 +48,7 @@ async def sample_stop_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_trigger_schedule_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_trigger_schedule_async.py index d573481..fbd0d6d 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_trigger_schedule_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_trigger_schedule_async.py @@ -48,7 +48,7 @@ async def sample_trigger_schedule(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_update_instance_config_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_update_instance_config_async.py index 731e2ab..d742189 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_update_instance_config_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_update_instance_config_async.py @@ -48,7 +48,7 @@ async def sample_update_instance_config(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_update_shielded_instance_config_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_update_shielded_instance_config_async.py index 6fc5952..02e08e8 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_update_shielded_instance_config_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_update_shielded_instance_config_async.py @@ -48,7 +48,7 @@ async def sample_update_shielded_instance_config(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_async.py index 72965cc..c887bcc 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_async.py @@ -48,7 +48,7 @@ async def sample_upgrade_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_internal_async.py b/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_internal_async.py index e64ff80..2166966 100644 --- a/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_internal_async.py +++ b/samples/generated_samples/notebooks_v1_generated_notebook_service_upgrade_instance_internal_async.py @@ -49,7 +49,7 @@ async def sample_upgrade_instance_internal(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_environment_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_environment_async.py index 3f6d712..0e5bb5f 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_environment_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_environment_async.py @@ -54,7 +54,7 @@ async def sample_create_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_instance_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_instance_async.py index d90bd00..1c751b0 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_instance_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_create_instance_async.py @@ -55,7 +55,7 @@ async def sample_create_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_environment_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_environment_async.py index 1bfb942..5c07fa3 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_environment_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_environment_async.py @@ -48,7 +48,7 @@ async def sample_delete_environment(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_instance_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_instance_async.py index df7f53f..37e3f2d 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_instance_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_delete_instance_async.py @@ -48,7 +48,7 @@ async def sample_delete_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_register_instance_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_register_instance_async.py index 573fdd4..22da333 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_register_instance_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_register_instance_async.py @@ -49,7 +49,7 @@ async def sample_register_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_report_instance_info_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_report_instance_info_async.py index 0963793..0318ce7 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_report_instance_info_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_report_instance_info_async.py @@ -49,7 +49,7 @@ async def sample_report_instance_info(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_reset_instance_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_reset_instance_async.py index 6417a40..ddcc16e 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_reset_instance_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_reset_instance_async.py @@ -48,7 +48,7 @@ async def sample_reset_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_accelerator_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_accelerator_async.py index 7f70437..8f348f5 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_accelerator_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_accelerator_async.py @@ -50,7 +50,7 @@ async def sample_set_instance_accelerator(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_labels_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_labels_async.py index c733b23..e44e36e 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_labels_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_labels_async.py @@ -48,7 +48,7 @@ async def sample_set_instance_labels(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_machine_type_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_machine_type_async.py index 931dbb4..8d84ba5 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_machine_type_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_set_instance_machine_type_async.py @@ -49,7 +49,7 @@ async def sample_set_instance_machine_type(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_start_instance_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_start_instance_async.py index e2a652b..0d1aded 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_start_instance_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_start_instance_async.py @@ -48,7 +48,7 @@ async def sample_start_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_stop_instance_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_stop_instance_async.py index f3ee80f..46a8d60 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_stop_instance_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_stop_instance_async.py @@ -48,7 +48,7 @@ async def sample_stop_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_async.py index f78f73e..385ab00 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_async.py @@ -48,7 +48,7 @@ async def sample_upgrade_instance(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_internal_async.py b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_internal_async.py index 438e0bf..104247d 100644 --- a/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_internal_async.py +++ b/samples/generated_samples/notebooks_v1beta1_generated_notebook_service_upgrade_instance_internal_async.py @@ -49,7 +49,7 @@ async def sample_upgrade_instance_internal(): print("Waiting for operation to complete...") - response = await operation.result() + response = (await operation).result() # Handle the response print(response) diff --git a/samples/generated_samples/snippet_metadata_notebooks_v1.json b/samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1.json similarity index 91% rename from samples/generated_samples/snippet_metadata_notebooks_v1.json rename to samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1.json index 9519b30..1e5dcb8 100644 --- a/samples/generated_samples/snippet_metadata_notebooks_v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1.json @@ -7,7 +7,8 @@ } ], "language": "PYTHON", - "name": "google-cloud-notebooks" + "name": "google-cloud-notebooks", + "version": "0.1.0" }, "snippets": [ { @@ -348,6 +349,175 @@ ], "title": "notebooks_v1_generated_managed_notebook_service_delete_runtime_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient", + "shortName": "ManagedNotebookServiceAsyncClient" + }, + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.diagnose_runtime", + "method": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.DiagnoseRuntime", + "service": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", + "shortName": "ManagedNotebookService" + }, + "shortName": "DiagnoseRuntime" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.DiagnoseRuntimeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "diagnostic_config", + "type": "google.cloud.notebooks_v1.types.DiagnosticConfig" + }, + { + "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": "diagnose_runtime" + }, + "description": "Sample for DiagnoseRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_diagnose_runtime_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_DiagnoseRuntime_async", + "segments": [ + { + "end": 59, + "start": 27, + "type": "FULL" + }, + { + "end": 59, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 56, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 60, + "start": 57, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_managed_notebook_service_diagnose_runtime_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient", + "shortName": "ManagedNotebookServiceClient" + }, + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.diagnose_runtime", + "method": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.DiagnoseRuntime", + "service": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", + "shortName": "ManagedNotebookService" + }, + "shortName": "DiagnoseRuntime" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.DiagnoseRuntimeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "diagnostic_config", + "type": "google.cloud.notebooks_v1.types.DiagnosticConfig" + }, + { + "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": "diagnose_runtime" + }, + "description": "Sample for DiagnoseRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_diagnose_runtime_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_DiagnoseRuntime_sync", + "segments": [ + { + "end": 59, + "start": 27, + "type": "FULL" + }, + { + "end": 59, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 56, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 60, + "start": 57, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_managed_notebook_service_diagnose_runtime_sync.py" + }, { "canonical": true, "clientMethod": { @@ -1126,7 +1296,329 @@ "file": "notebooks_v1_generated_managed_notebook_service_reset_runtime_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "notebooks_v1_generated_ManagedNotebookService_ResetRuntime_sync", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_ResetRuntime_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_managed_notebook_service_reset_runtime_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient", + "shortName": "ManagedNotebookServiceAsyncClient" + }, + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.start_runtime", + "method": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StartRuntime", + "service": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", + "shortName": "ManagedNotebookService" + }, + "shortName": "StartRuntime" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.StartRuntimeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "start_runtime" + }, + "description": "Sample for StartRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_start_runtime_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_StartRuntime_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_managed_notebook_service_start_runtime_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient", + "shortName": "ManagedNotebookServiceClient" + }, + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.start_runtime", + "method": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StartRuntime", + "service": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", + "shortName": "ManagedNotebookService" + }, + "shortName": "StartRuntime" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.StartRuntimeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "start_runtime" + }, + "description": "Sample for StartRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_start_runtime_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_StartRuntime_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_managed_notebook_service_start_runtime_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient", + "shortName": "ManagedNotebookServiceAsyncClient" + }, + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.stop_runtime", + "method": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StopRuntime", + "service": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", + "shortName": "ManagedNotebookService" + }, + "shortName": "StopRuntime" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.StopRuntimeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "stop_runtime" + }, + "description": "Sample for StopRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_StopRuntime_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient", + "shortName": "ManagedNotebookServiceClient" + }, + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.stop_runtime", + "method": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StopRuntime", + "service": { + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", + "shortName": "ManagedNotebookService" + }, + "shortName": "StopRuntime" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.StopRuntimeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "stop_runtime" + }, + "description": "Sample for StopRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_stop_runtime_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_StopRuntime_sync", "segments": [ { "end": 55, @@ -1159,7 +1651,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "notebooks_v1_generated_managed_notebook_service_reset_runtime_sync.py" + "title": "notebooks_v1_generated_managed_notebook_service_stop_runtime_sync.py" }, { "canonical": true, @@ -1169,19 +1661,19 @@ "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient", "shortName": "ManagedNotebookServiceAsyncClient" }, - "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.start_runtime", + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.switch_runtime", "method": { - "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StartRuntime", + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.SwitchRuntime", "service": { "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", "shortName": "ManagedNotebookService" }, - "shortName": "StartRuntime" + "shortName": "SwitchRuntime" }, "parameters": [ { "name": "request", - "type": "google.cloud.notebooks_v1.types.StartRuntimeRequest" + "type": "google.cloud.notebooks_v1.types.SwitchRuntimeRequest" }, { "name": "name", @@ -1201,13 +1693,13 @@ } ], "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "start_runtime" + "shortName": "switch_runtime" }, - "description": "Sample for StartRuntime", - "file": "notebooks_v1_generated_managed_notebook_service_start_runtime_async.py", + "description": "Sample for SwitchRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "notebooks_v1_generated_ManagedNotebookService_StartRuntime_async", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_SwitchRuntime_async", "segments": [ { "end": 55, @@ -1240,7 +1732,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "notebooks_v1_generated_managed_notebook_service_start_runtime_async.py" + "title": "notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py" }, { "canonical": true, @@ -1249,19 +1741,19 @@ "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient", "shortName": "ManagedNotebookServiceClient" }, - "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.start_runtime", + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.switch_runtime", "method": { - "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StartRuntime", + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.SwitchRuntime", "service": { "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", "shortName": "ManagedNotebookService" }, - "shortName": "StartRuntime" + "shortName": "SwitchRuntime" }, "parameters": [ { "name": "request", - "type": "google.cloud.notebooks_v1.types.StartRuntimeRequest" + "type": "google.cloud.notebooks_v1.types.SwitchRuntimeRequest" }, { "name": "name", @@ -1281,13 +1773,13 @@ } ], "resultType": "google.api_core.operation.Operation", - "shortName": "start_runtime" + "shortName": "switch_runtime" }, - "description": "Sample for StartRuntime", - "file": "notebooks_v1_generated_managed_notebook_service_start_runtime_sync.py", + "description": "Sample for SwitchRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_switch_runtime_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "notebooks_v1_generated_ManagedNotebookService_StartRuntime_sync", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_SwitchRuntime_sync", "segments": [ { "end": 55, @@ -1320,7 +1812,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "notebooks_v1_generated_managed_notebook_service_start_runtime_sync.py" + "title": "notebooks_v1_generated_managed_notebook_service_switch_runtime_sync.py" }, { "canonical": true, @@ -1330,23 +1822,27 @@ "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient", "shortName": "ManagedNotebookServiceAsyncClient" }, - "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.stop_runtime", + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.update_runtime", "method": { - "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StopRuntime", + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.UpdateRuntime", "service": { "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", "shortName": "ManagedNotebookService" }, - "shortName": "StopRuntime" + "shortName": "UpdateRuntime" }, "parameters": [ { "name": "request", - "type": "google.cloud.notebooks_v1.types.StopRuntimeRequest" + "type": "google.cloud.notebooks_v1.types.UpdateRuntimeRequest" }, { - "name": "name", - "type": "str" + "name": "runtime", + "type": "google.cloud.notebooks_v1.types.Runtime" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" }, { "name": "retry", @@ -1362,21 +1858,21 @@ } ], "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "stop_runtime" + "shortName": "update_runtime" }, - "description": "Sample for StopRuntime", - "file": "notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py", + "description": "Sample for UpdateRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_update_runtime_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "notebooks_v1_generated_ManagedNotebookService_StopRuntime_async", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_UpdateRuntime_async", "segments": [ { - "end": 55, + "end": 54, "start": 27, "type": "FULL" }, { - "end": 55, + "end": 54, "start": 27, "type": "SHORT" }, @@ -1386,22 +1882,22 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 45, + "end": 44, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 52, - "start": 46, + "end": 51, + "start": 45, "type": "REQUEST_EXECUTION" }, { - "end": 56, - "start": 53, + "end": 55, + "start": 52, "type": "RESPONSE_HANDLING" } ], - "title": "notebooks_v1_generated_managed_notebook_service_stop_runtime_async.py" + "title": "notebooks_v1_generated_managed_notebook_service_update_runtime_async.py" }, { "canonical": true, @@ -1410,23 +1906,27 @@ "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient", "shortName": "ManagedNotebookServiceClient" }, - "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.stop_runtime", + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.update_runtime", "method": { - "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.StopRuntime", + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.UpdateRuntime", "service": { "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", "shortName": "ManagedNotebookService" }, - "shortName": "StopRuntime" + "shortName": "UpdateRuntime" }, "parameters": [ { "name": "request", - "type": "google.cloud.notebooks_v1.types.StopRuntimeRequest" + "type": "google.cloud.notebooks_v1.types.UpdateRuntimeRequest" }, { - "name": "name", - "type": "str" + "name": "runtime", + "type": "google.cloud.notebooks_v1.types.Runtime" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" }, { "name": "retry", @@ -1442,21 +1942,21 @@ } ], "resultType": "google.api_core.operation.Operation", - "shortName": "stop_runtime" + "shortName": "update_runtime" }, - "description": "Sample for StopRuntime", - "file": "notebooks_v1_generated_managed_notebook_service_stop_runtime_sync.py", + "description": "Sample for UpdateRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_update_runtime_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "notebooks_v1_generated_ManagedNotebookService_StopRuntime_sync", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_UpdateRuntime_sync", "segments": [ { - "end": 55, + "end": 54, "start": 27, "type": "FULL" }, { - "end": 55, + "end": 54, "start": 27, "type": "SHORT" }, @@ -1466,22 +1966,22 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 45, + "end": 44, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 52, - "start": 46, + "end": 51, + "start": 45, "type": "REQUEST_EXECUTION" }, { - "end": 56, - "start": 53, + "end": 55, + "start": 52, "type": "RESPONSE_HANDLING" } ], - "title": "notebooks_v1_generated_managed_notebook_service_stop_runtime_sync.py" + "title": "notebooks_v1_generated_managed_notebook_service_update_runtime_sync.py" }, { "canonical": true, @@ -1491,19 +1991,19 @@ "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient", "shortName": "ManagedNotebookServiceAsyncClient" }, - "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.switch_runtime", + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceAsyncClient.upgrade_runtime", "method": { - "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.SwitchRuntime", + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.UpgradeRuntime", "service": { "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", "shortName": "ManagedNotebookService" }, - "shortName": "SwitchRuntime" + "shortName": "UpgradeRuntime" }, "parameters": [ { "name": "request", - "type": "google.cloud.notebooks_v1.types.SwitchRuntimeRequest" + "type": "google.cloud.notebooks_v1.types.UpgradeRuntimeRequest" }, { "name": "name", @@ -1523,13 +2023,13 @@ } ], "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "switch_runtime" + "shortName": "upgrade_runtime" }, - "description": "Sample for SwitchRuntime", - "file": "notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py", + "description": "Sample for UpgradeRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_upgrade_runtime_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "notebooks_v1_generated_ManagedNotebookService_SwitchRuntime_async", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_UpgradeRuntime_async", "segments": [ { "end": 55, @@ -1562,7 +2062,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "notebooks_v1_generated_managed_notebook_service_switch_runtime_async.py" + "title": "notebooks_v1_generated_managed_notebook_service_upgrade_runtime_async.py" }, { "canonical": true, @@ -1571,19 +2071,19 @@ "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient", "shortName": "ManagedNotebookServiceClient" }, - "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.switch_runtime", + "fullName": "google.cloud.notebooks_v1.ManagedNotebookServiceClient.upgrade_runtime", "method": { - "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.SwitchRuntime", + "fullName": "google.cloud.notebooks.v1.ManagedNotebookService.UpgradeRuntime", "service": { "fullName": "google.cloud.notebooks.v1.ManagedNotebookService", "shortName": "ManagedNotebookService" }, - "shortName": "SwitchRuntime" + "shortName": "UpgradeRuntime" }, "parameters": [ { "name": "request", - "type": "google.cloud.notebooks_v1.types.SwitchRuntimeRequest" + "type": "google.cloud.notebooks_v1.types.UpgradeRuntimeRequest" }, { "name": "name", @@ -1603,13 +2103,13 @@ } ], "resultType": "google.api_core.operation.Operation", - "shortName": "switch_runtime" + "shortName": "upgrade_runtime" }, - "description": "Sample for SwitchRuntime", - "file": "notebooks_v1_generated_managed_notebook_service_switch_runtime_sync.py", + "description": "Sample for UpgradeRuntime", + "file": "notebooks_v1_generated_managed_notebook_service_upgrade_runtime_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "notebooks_v1_generated_ManagedNotebookService_SwitchRuntime_sync", + "regionTag": "notebooks_v1_generated_ManagedNotebookService_UpgradeRuntime_sync", "segments": [ { "end": 55, @@ -1642,7 +2142,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "notebooks_v1_generated_managed_notebook_service_switch_runtime_sync.py" + "title": "notebooks_v1_generated_managed_notebook_service_upgrade_runtime_sync.py" }, { "canonical": true, @@ -2996,6 +3496,175 @@ ], "title": "notebooks_v1_generated_notebook_service_delete_schedule_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.notebooks_v1.NotebookServiceAsyncClient", + "shortName": "NotebookServiceAsyncClient" + }, + "fullName": "google.cloud.notebooks_v1.NotebookServiceAsyncClient.diagnose_instance", + "method": { + "fullName": "google.cloud.notebooks.v1.NotebookService.DiagnoseInstance", + "service": { + "fullName": "google.cloud.notebooks.v1.NotebookService", + "shortName": "NotebookService" + }, + "shortName": "DiagnoseInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.DiagnoseInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "diagnostic_config", + "type": "google.cloud.notebooks_v1.types.DiagnosticConfig" + }, + { + "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": "diagnose_instance" + }, + "description": "Sample for DiagnoseInstance", + "file": "notebooks_v1_generated_notebook_service_diagnose_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_NotebookService_DiagnoseInstance_async", + "segments": [ + { + "end": 59, + "start": 27, + "type": "FULL" + }, + { + "end": 59, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 56, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 60, + "start": 57, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_notebook_service_diagnose_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.notebooks_v1.NotebookServiceClient", + "shortName": "NotebookServiceClient" + }, + "fullName": "google.cloud.notebooks_v1.NotebookServiceClient.diagnose_instance", + "method": { + "fullName": "google.cloud.notebooks.v1.NotebookService.DiagnoseInstance", + "service": { + "fullName": "google.cloud.notebooks.v1.NotebookService", + "shortName": "NotebookService" + }, + "shortName": "DiagnoseInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.notebooks_v1.types.DiagnoseInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "diagnostic_config", + "type": "google.cloud.notebooks_v1.types.DiagnosticConfig" + }, + { + "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": "diagnose_instance" + }, + "description": "Sample for DiagnoseInstance", + "file": "notebooks_v1_generated_notebook_service_diagnose_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "notebooks_v1_generated_NotebookService_DiagnoseInstance_sync", + "segments": [ + { + "end": 59, + "start": 27, + "type": "FULL" + }, + { + "end": 59, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 56, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 60, + "start": 57, + "type": "RESPONSE_HANDLING" + } + ], + "title": "notebooks_v1_generated_notebook_service_diagnose_instance_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/samples/generated_samples/snippet_metadata_notebooks_v1beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1beta1.json similarity index 99% rename from samples/generated_samples/snippet_metadata_notebooks_v1beta1.json rename to samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1beta1.json index 09d1297..7bc3178 100644 --- a/samples/generated_samples/snippet_metadata_notebooks_v1beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.notebooks.v1beta1.json @@ -7,7 +7,8 @@ } ], "language": "PYTHON", - "name": "google-cloud-notebooks" + "name": "google-cloud-notebooks", + "version": "0.1.0" }, "snippets": [ { diff --git a/scripts/fixup_notebooks_v1_keywords.py b/scripts/fixup_notebooks_v1_keywords.py index 23711ef..d1ef982 100644 --- a/scripts/fixup_notebooks_v1_keywords.py +++ b/scripts/fixup_notebooks_v1_keywords.py @@ -49,6 +49,8 @@ class notebooksCallTransformer(cst.CSTTransformer): 'delete_instance': ('name', ), 'delete_runtime': ('name', 'request_id', ), 'delete_schedule': ('name', ), + 'diagnose_instance': ('name', 'diagnostic_config', ), + 'diagnose_runtime': ('name', 'diagnostic_config', ), 'get_environment': ('name', ), 'get_execution': ('name', ), 'get_instance': ('name', ), @@ -79,9 +81,11 @@ class notebooksCallTransformer(cst.CSTTransformer): 'trigger_schedule': ('name', ), 'update_instance_config': ('name', 'config', ), 'update_instance_metadata_items': ('name', 'items', ), + 'update_runtime': ('runtime', 'update_mask', 'request_id', ), 'update_shielded_instance_config': ('name', 'shielded_instance_config', ), 'upgrade_instance': ('name', 'type_', ), 'upgrade_instance_internal': ('name', 'vm_id', 'type_', ), + 'upgrade_runtime': ('name', 'request_id', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: diff --git a/setup.py b/setup.py index 3a5e3ab..6de8c5e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- - -# Copyright 2020 Google LLC +# 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. @@ -14,13 +13,35 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import io import os import setuptools # type: ignore -version = "1.4.4" +package_root = os.path.abspath(os.path.dirname(__file__)) + +name = "google-cloud-notebooks" + + +description = "Google Cloud Notebooks API client library" + +version = {} +with open(os.path.join(package_root, "google/cloud/notebooks/gapic_version.py")) as fp: + exec(fp.read(), version) +version = version["__version__"] + +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" + +dependencies = [ + "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "proto-plus >= 1.22.0, <2.0.0dev", + "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "grpc-google-iam-v1 >= 0.12.4, < 1.0.0dev", +] +url = "https://github.com/googleapis/python-notebooks" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -28,34 +49,43 @@ with io.open(readme_filename, encoding="utf-8") as readme_file: readme = readme_file.read() +packages = [ + package + for package in setuptools.PEP420PackageFinder.find() + if package.startswith("google") +] + +namespaces = ["google"] +if "google.cloud" in packages: + namespaces.append("google.cloud") + setuptools.setup( - name="google-cloud-notebooks", + name=name, version=version, + description=description, long_description=readme, author="Google LLC", author_email="googleapis-packages@google.com", license="Apache 2.0", - url="https://github.com/googleapis/python-notebooks", - packages=setuptools.PEP420PackageFinder.find(), - namespace_packages=("google", "google.cloud"), - platforms="Posix; MacOS X; Windows", - include_package_data=True, - install_requires=( - "google-api-core[grpc] >= 1.32.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*", - "proto-plus >= 1.22.0, <2.0.0dev", - "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", - ), - python_requires=">=3.7", + url=url, classifiers=[ - "Development Status :: 5 - Production/Stable", + release_status, "Intended Audience :: Developers", - "Operating System :: OS Independent", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Operating System :: OS Independent", "Topic :: Internet", - "Topic :: Software Development :: Libraries :: Python Modules", ], + platforms="Posix; MacOS X; Windows", + packages=packages, + python_requires=">=3.7", + namespace_packages=namespaces, + install_requires=dependencies, + include_package_data=True, zip_safe=False, ) diff --git a/testing/constraints-3.10.txt b/testing/constraints-3.10.txt index e69de29..ad3f0fa 100644 --- a/testing/constraints-3.10.txt +++ b/testing/constraints-3.10.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/testing/constraints-3.11.txt b/testing/constraints-3.11.txt index e69de29..ad3f0fa 100644 --- a/testing/constraints-3.11.txt +++ b/testing/constraints-3.11.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt index 5dcaa6f..2beecf9 100644 --- a/testing/constraints-3.7.txt +++ b/testing/constraints-3.7.txt @@ -1,10 +1,10 @@ # This constraints file is used to check that lower bounds # are correct in setup.py -# List *all* library dependencies and extras in this file. +# List all library dependencies and extras in this file. # Pin the version to the lower bound. -# -# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", -# Then this file should have foo==1.14.0 -google-api-core==1.32.0 +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.34.0 proto-plus==1.22.0 protobuf==3.19.5 +grpc-google-iam-v1==0.12.4 diff --git a/testing/constraints-3.8.txt b/testing/constraints-3.8.txt index e69de29..ad3f0fa 100644 --- a/testing/constraints-3.8.txt +++ b/testing/constraints-3.8.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/testing/constraints-3.9.txt b/testing/constraints-3.9.txt index e69de29..ad3f0fa 100644 --- a/testing/constraints-3.9.txt +++ b/testing/constraints-3.9.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/tests/unit/gapic/notebooks_v1/test_managed_notebook_service.py b/tests/unit/gapic/notebooks_v1/test_managed_notebook_service.py index 378f3da..91c5207 100644 --- a/tests/unit/gapic/notebooks_v1/test_managed_notebook_service.py +++ b/tests/unit/gapic/notebooks_v1/test_managed_notebook_service.py @@ -39,8 +39,14 @@ import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore import grpc from grpc.experimental import aio @@ -54,6 +60,7 @@ pagers, transports, ) +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import environment, event, managed_service from google.cloud.notebooks_v1.types import runtime from google.cloud.notebooks_v1.types import runtime as gcn_runtime @@ -1626,6 +1633,242 @@ async def test_create_runtime_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + managed_service.UpdateRuntimeRequest, + dict, + ], +) +def test_update_runtime(request_type, transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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_runtime), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_runtime(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.UpdateRuntimeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_runtime_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 = ManagedNotebookServiceClient( + 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_runtime), "__call__") as call: + client.update_runtime() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.UpdateRuntimeRequest() + + +@pytest.mark.asyncio +async def test_update_runtime_async( + transport: str = "grpc_asyncio", request_type=managed_service.UpdateRuntimeRequest +): + client = ManagedNotebookServiceAsyncClient( + 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_runtime), "__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_runtime(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.UpdateRuntimeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_runtime_async_from_dict(): + await test_update_runtime_async(request_type=dict) + + +def test_update_runtime_field_headers(): + client = ManagedNotebookServiceClient( + 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 = managed_service.UpdateRuntimeRequest() + + request.runtime.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_runtime), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_runtime(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", + "runtime.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_runtime_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = managed_service.UpdateRuntimeRequest() + + request.runtime.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_runtime), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_runtime(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", + "runtime.name=name_value", + ) in kw["metadata"] + + +def test_update_runtime_flattened(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_runtime), "__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_runtime( + runtime=gcn_runtime.Runtime(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].runtime + mock_val = gcn_runtime.Runtime(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_runtime_flattened_error(): + client = ManagedNotebookServiceClient( + 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_runtime( + managed_service.UpdateRuntimeRequest(), + runtime=gcn_runtime.Runtime(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_runtime_flattened_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_runtime), "__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_runtime( + runtime=gcn_runtime.Runtime(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].runtime + mock_val = gcn_runtime.Runtime(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_runtime_flattened_error_async(): + client = ManagedNotebookServiceAsyncClient( + 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_runtime( + managed_service.UpdateRuntimeRequest(), + runtime=gcn_runtime.Runtime(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + @pytest.mark.parametrize( "request_type", [ @@ -2759,11 +3002,11 @@ async def test_reset_runtime_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - managed_service.ReportRuntimeEventRequest, + managed_service.UpgradeRuntimeRequest, dict, ], ) -def test_report_runtime_event(request_type, transport: str = "grpc"): +def test_upgrade_runtime(request_type, transport: str = "grpc"): client = ManagedNotebookServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2774,23 +3017,21 @@ def test_report_runtime_event(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.report_runtime_event), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_runtime), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.report_runtime_event(request) + response = client.upgrade_runtime(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_service.ReportRuntimeEventRequest() + assert args[0] == managed_service.UpgradeRuntimeRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_report_runtime_event_empty_call(): +def test_upgrade_runtime_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 = ManagedNotebookServiceClient( @@ -2799,19 +3040,16 @@ def test_report_runtime_event_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.report_runtime_event), "__call__" - ) as call: - client.report_runtime_event() + with mock.patch.object(type(client.transport.upgrade_runtime), "__call__") as call: + client.upgrade_runtime() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == managed_service.ReportRuntimeEventRequest() + assert args[0] == managed_service.UpgradeRuntimeRequest() @pytest.mark.asyncio -async def test_report_runtime_event_async( - transport: str = "grpc_asyncio", - request_type=managed_service.ReportRuntimeEventRequest, +async def test_upgrade_runtime_async( + transport: str = "grpc_asyncio", request_type=managed_service.UpgradeRuntimeRequest ): client = ManagedNotebookServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2823,46 +3061,42 @@ async def test_report_runtime_event_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.report_runtime_event), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_runtime), "__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.report_runtime_event(request) + response = await client.upgrade_runtime(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == managed_service.ReportRuntimeEventRequest() + assert args[0] == managed_service.UpgradeRuntimeRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_report_runtime_event_async_from_dict(): - await test_report_runtime_event_async(request_type=dict) +async def test_upgrade_runtime_async_from_dict(): + await test_upgrade_runtime_async(request_type=dict) -def test_report_runtime_event_field_headers(): +def test_upgrade_runtime_field_headers(): client = ManagedNotebookServiceClient( 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 = managed_service.ReportRuntimeEventRequest() + request = managed_service.UpgradeRuntimeRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.report_runtime_event), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_runtime), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.report_runtime_event(request) + client.upgrade_runtime(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2878,25 +3112,23 @@ def test_report_runtime_event_field_headers(): @pytest.mark.asyncio -async def test_report_runtime_event_field_headers_async(): +async def test_upgrade_runtime_field_headers_async(): client = ManagedNotebookServiceAsyncClient( 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 = managed_service.ReportRuntimeEventRequest() + request = managed_service.UpgradeRuntimeRequest() request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.report_runtime_event), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_runtime), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.report_runtime_event(request) + await client.upgrade_runtime(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2911,20 +3143,18 @@ async def test_report_runtime_event_field_headers_async(): ) in kw["metadata"] -def test_report_runtime_event_flattened(): +def test_upgrade_runtime_flattened(): client = ManagedNotebookServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.report_runtime_event), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_runtime), "__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.report_runtime_event( + client.upgrade_runtime( name="name_value", ) @@ -2937,7 +3167,7 @@ def test_report_runtime_event_flattened(): assert arg == mock_val -def test_report_runtime_event_flattened_error(): +def test_upgrade_runtime_flattened_error(): client = ManagedNotebookServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2945,22 +3175,20 @@ def test_report_runtime_event_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.report_runtime_event( - managed_service.ReportRuntimeEventRequest(), + client.upgrade_runtime( + managed_service.UpgradeRuntimeRequest(), name="name_value", ) @pytest.mark.asyncio -async def test_report_runtime_event_flattened_async(): +async def test_upgrade_runtime_flattened_async(): client = ManagedNotebookServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.report_runtime_event), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_runtime), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2969,7 +3197,7 @@ async def test_report_runtime_event_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.report_runtime_event( + response = await client.upgrade_runtime( name="name_value", ) @@ -2983,7 +3211,7 @@ async def test_report_runtime_event_flattened_async(): @pytest.mark.asyncio -async def test_report_runtime_event_flattened_error_async(): +async def test_upgrade_runtime_flattened_error_async(): client = ManagedNotebookServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2991,8 +3219,8 @@ async def test_report_runtime_event_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.report_runtime_event( - managed_service.ReportRuntimeEventRequest(), + await client.upgrade_runtime( + managed_service.UpgradeRuntimeRequest(), name="name_value", ) @@ -3000,11 +3228,11 @@ async def test_report_runtime_event_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - managed_service.RefreshRuntimeTokenInternalRequest, + managed_service.ReportRuntimeEventRequest, dict, ], ) -def test_refresh_runtime_token_internal(request_type, transport: str = "grpc"): +def test_report_runtime_event(request_type, transport: str = "grpc"): client = ManagedNotebookServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3016,22 +3244,263 @@ def test_refresh_runtime_token_internal(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.refresh_runtime_token_internal), "__call__" + type(client.transport.report_runtime_event), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = managed_service.RefreshRuntimeTokenInternalResponse( - access_token="access_token_value", - ) - response = client.refresh_runtime_token_internal(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.report_runtime_event(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == managed_service.RefreshRuntimeTokenInternalRequest() + assert args[0] == managed_service.ReportRuntimeEventRequest() # Establish that the response is the type that we expect. - assert isinstance(response, managed_service.RefreshRuntimeTokenInternalResponse) - assert response.access_token == "access_token_value" + assert isinstance(response, future.Future) + + +def test_report_runtime_event_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 = ManagedNotebookServiceClient( + 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.report_runtime_event), "__call__" + ) as call: + client.report_runtime_event() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.ReportRuntimeEventRequest() + + +@pytest.mark.asyncio +async def test_report_runtime_event_async( + transport: str = "grpc_asyncio", + request_type=managed_service.ReportRuntimeEventRequest, +): + client = ManagedNotebookServiceAsyncClient( + 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.report_runtime_event), "__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.report_runtime_event(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.ReportRuntimeEventRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_report_runtime_event_async_from_dict(): + await test_report_runtime_event_async(request_type=dict) + + +def test_report_runtime_event_field_headers(): + client = ManagedNotebookServiceClient( + 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 = managed_service.ReportRuntimeEventRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.report_runtime_event), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.report_runtime_event(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_report_runtime_event_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = managed_service.ReportRuntimeEventRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.report_runtime_event), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.report_runtime_event(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_report_runtime_event_flattened(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.report_runtime_event), "__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.report_runtime_event( + 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_report_runtime_event_flattened_error(): + client = ManagedNotebookServiceClient( + 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.report_runtime_event( + managed_service.ReportRuntimeEventRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_report_runtime_event_flattened_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.report_runtime_event), "__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.report_runtime_event( + 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_report_runtime_event_flattened_error_async(): + client = ManagedNotebookServiceAsyncClient( + 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.report_runtime_event( + managed_service.ReportRuntimeEventRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + managed_service.RefreshRuntimeTokenInternalRequest, + dict, + ], +) +def test_refresh_runtime_token_internal(request_type, transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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.refresh_runtime_token_internal), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = managed_service.RefreshRuntimeTokenInternalResponse( + access_token="access_token_value", + ) + response = client.refresh_runtime_token_internal(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.RefreshRuntimeTokenInternalRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, managed_service.RefreshRuntimeTokenInternalResponse) + assert response.access_token == "access_token_value" def test_refresh_runtime_token_internal_empty_call(): @@ -3254,12 +3723,256 @@ async def test_refresh_runtime_token_internal_flattened_error_async(): ) -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ManagedNotebookServiceGrpcTransport( +@pytest.mark.parametrize( + "request_type", + [ + managed_service.DiagnoseRuntimeRequest, + dict, + ], +) +def test_diagnose_runtime(request_type, transport: str = "grpc"): + client = ManagedNotebookServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): + + # 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.diagnose_runtime), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.diagnose_runtime(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.DiagnoseRuntimeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_diagnose_runtime_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 = ManagedNotebookServiceClient( + 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.diagnose_runtime), "__call__") as call: + client.diagnose_runtime() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.DiagnoseRuntimeRequest() + + +@pytest.mark.asyncio +async def test_diagnose_runtime_async( + transport: str = "grpc_asyncio", request_type=managed_service.DiagnoseRuntimeRequest +): + client = ManagedNotebookServiceAsyncClient( + 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.diagnose_runtime), "__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.diagnose_runtime(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == managed_service.DiagnoseRuntimeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_diagnose_runtime_async_from_dict(): + await test_diagnose_runtime_async(request_type=dict) + + +def test_diagnose_runtime_field_headers(): + client = ManagedNotebookServiceClient( + 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 = managed_service.DiagnoseRuntimeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.diagnose_runtime), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.diagnose_runtime(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_diagnose_runtime_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = managed_service.DiagnoseRuntimeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.diagnose_runtime), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.diagnose_runtime(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_diagnose_runtime_flattened(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.diagnose_runtime), "__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.diagnose_runtime( + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_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 + arg = args[0].diagnostic_config + mock_val = gcn_diagnostic_config.DiagnosticConfig(gcs_bucket="gcs_bucket_value") + assert arg == mock_val + + +def test_diagnose_runtime_flattened_error(): + client = ManagedNotebookServiceClient( + 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.diagnose_runtime( + managed_service.DiagnoseRuntimeRequest(), + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_value" + ), + ) + + +@pytest.mark.asyncio +async def test_diagnose_runtime_flattened_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.diagnose_runtime), "__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.diagnose_runtime( + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_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 + arg = args[0].diagnostic_config + mock_val = gcn_diagnostic_config.DiagnosticConfig(gcs_bucket="gcs_bucket_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_diagnose_runtime_flattened_error_async(): + client = ManagedNotebookServiceAsyncClient( + 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.diagnose_runtime( + managed_service.DiagnoseRuntimeRequest(), + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_value" + ), + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ManagedNotebookServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): client = ManagedNotebookServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3394,13 +4107,25 @@ def test_managed_notebook_service_base_transport(): "list_runtimes", "get_runtime", "create_runtime", + "update_runtime", "delete_runtime", "start_runtime", "stop_runtime", "switch_runtime", "reset_runtime", + "upgrade_runtime", "report_runtime_event", "refresh_runtime_token_internal", + "diagnose_runtime", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): @@ -3955,6 +4680,1372 @@ async def test_transport_close_async(): close.assert_called_once() +def test_delete_operation(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(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 response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation_async(transport: str = "grpc"): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(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 response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(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=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(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 response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(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 response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(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=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(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 response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation_async(transport: str = "grpc"): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(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 response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(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=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations_async(transport: str = "grpc"): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = ManagedNotebookServiceClient( + 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 = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(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 response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations_async(transport: str = "grpc"): + client = ManagedNotebookServiceAsyncClient( + 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 = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(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 response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = ManagedNotebookServiceClient( + 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 = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(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=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(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 response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = ManagedNotebookServiceAsyncClient( + 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 = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(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 response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = ManagedNotebookServiceClient( + 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 = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(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=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(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=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = ManagedNotebookServiceAsyncClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = ManagedNotebookServiceClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = ManagedNotebookServiceAsyncClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = ManagedNotebookServiceClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = ManagedNotebookServiceClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(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 response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = ManagedNotebookServiceAsyncClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(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 response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = ManagedNotebookServiceClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = ManagedNotebookServiceAsyncClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = ManagedNotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = ManagedNotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + def test_transport_close(): transports = { "grpc": "_grpc_channel", diff --git a/tests/unit/gapic/notebooks_v1/test_notebook_service.py b/tests/unit/gapic/notebooks_v1/test_notebook_service.py index afa3217..a3382ce 100644 --- a/tests/unit/gapic/notebooks_v1/test_notebook_service.py +++ b/tests/unit/gapic/notebooks_v1/test_notebook_service.py @@ -39,8 +39,13 @@ import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account +from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore import grpc from grpc.experimental import aio @@ -54,6 +59,7 @@ pagers, transports, ) +from google.cloud.notebooks_v1.types import diagnostic_config as gcn_diagnostic_config from google.cloud.notebooks_v1.types import environment from google.cloud.notebooks_v1.types import environment as gcn_environment from google.cloud.notebooks_v1.types import execution @@ -4321,6 +4327,264 @@ async def test_rollback_instance_field_headers_async(): ) in kw["metadata"] +@pytest.mark.parametrize( + "request_type", + [ + service.DiagnoseInstanceRequest, + dict, + ], +) +def test_diagnose_instance(request_type, transport: str = "grpc"): + client = NotebookServiceClient( + 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.diagnose_instance), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.diagnose_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == service.DiagnoseInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_diagnose_instance_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 = NotebookServiceClient( + 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.diagnose_instance), "__call__" + ) as call: + client.diagnose_instance() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.DiagnoseInstanceRequest() + + +@pytest.mark.asyncio +async def test_diagnose_instance_async( + transport: str = "grpc_asyncio", request_type=service.DiagnoseInstanceRequest +): + client = NotebookServiceAsyncClient( + 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.diagnose_instance), "__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.diagnose_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == service.DiagnoseInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_diagnose_instance_async_from_dict(): + await test_diagnose_instance_async(request_type=dict) + + +def test_diagnose_instance_field_headers(): + client = NotebookServiceClient( + 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 = service.DiagnoseInstanceRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.diagnose_instance), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.diagnose_instance(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_diagnose_instance_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = service.DiagnoseInstanceRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.diagnose_instance), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.diagnose_instance(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_diagnose_instance_flattened(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.diagnose_instance), "__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.diagnose_instance( + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_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 + arg = args[0].diagnostic_config + mock_val = gcn_diagnostic_config.DiagnosticConfig(gcs_bucket="gcs_bucket_value") + assert arg == mock_val + + +def test_diagnose_instance_flattened_error(): + client = NotebookServiceClient( + 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.diagnose_instance( + service.DiagnoseInstanceRequest(), + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_value" + ), + ) + + +@pytest.mark.asyncio +async def test_diagnose_instance_flattened_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.diagnose_instance), "__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.diagnose_instance( + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_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 + arg = args[0].diagnostic_config + mock_val = gcn_diagnostic_config.DiagnosticConfig(gcs_bucket="gcs_bucket_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_diagnose_instance_flattened_error_async(): + client = NotebookServiceAsyncClient( + 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.diagnose_instance( + service.DiagnoseInstanceRequest(), + name="name_value", + diagnostic_config=gcn_diagnostic_config.DiagnosticConfig( + gcs_bucket="gcs_bucket_value" + ), + ) + + @pytest.mark.parametrize( "request_type", [ @@ -8278,6 +8542,7 @@ def test_notebook_service_base_transport(): "get_instance_health", "upgrade_instance", "rollback_instance", + "diagnose_instance", "upgrade_instance_internal", "list_environments", "get_environment", @@ -8292,6 +8557,15 @@ def test_notebook_service_base_transport(): "get_execution", "delete_execution", "create_execution", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): @@ -8942,6 +9216,1370 @@ async def test_transport_close_async(): close.assert_called_once() +def test_delete_operation(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(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 response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(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 response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(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=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(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 response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(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 response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(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=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(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 response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(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 response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(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=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(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 response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(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 response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = NotebookServiceClient( + 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 = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(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=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(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 response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(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 response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = NotebookServiceClient(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 = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(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=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(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=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = NotebookServiceClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = NotebookServiceClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(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 response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(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 response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = NotebookServiceClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + def test_transport_close(): transports = { "grpc": "_grpc_channel", diff --git a/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py b/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py index 4bba5cc..ef45f9b 100644 --- a/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py +++ b/tests/unit/gapic/notebooks_v1beta1/test_notebook_service.py @@ -39,8 +39,13 @@ import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account +from google.protobuf import empty_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore import grpc from grpc.experimental import aio @@ -1088,6 +1093,8 @@ def test_get_instance(request_type, transport: str = "grpc"): no_proxy_access=True, network="network_value", subnet="subnet_value", + nic_type=instance.Instance.NicType.VIRTIO_NET, + can_ip_forward=True, vm_image=environment.VmImage(project="project_value"), ) response = client.get_instance(request) @@ -1119,6 +1126,8 @@ def test_get_instance(request_type, transport: str = "grpc"): assert response.no_proxy_access is True assert response.network == "network_value" assert response.subnet == "subnet_value" + assert response.nic_type == instance.Instance.NicType.VIRTIO_NET + assert response.can_ip_forward is True def test_get_instance_empty_call(): @@ -1175,6 +1184,8 @@ async def test_get_instance_async( no_proxy_access=True, network="network_value", subnet="subnet_value", + nic_type=instance.Instance.NicType.VIRTIO_NET, + can_ip_forward=True, ) ) response = await client.get_instance(request) @@ -1206,6 +1217,8 @@ async def test_get_instance_async( assert response.no_proxy_access is True assert response.network == "network_value" assert response.subnet == "subnet_value" + assert response.nic_type == instance.Instance.NicType.VIRTIO_NET + assert response.can_ip_forward is True @pytest.mark.asyncio @@ -2788,6 +2801,7 @@ def test_is_instance_upgradeable(request_type, transport: str = "grpc"): upgradeable=True, upgrade_version="upgrade_version_value", upgrade_info="upgrade_info_value", + upgrade_image="upgrade_image_value", ) response = client.is_instance_upgradeable(request) @@ -2801,6 +2815,7 @@ def test_is_instance_upgradeable(request_type, transport: str = "grpc"): assert response.upgradeable is True assert response.upgrade_version == "upgrade_version_value" assert response.upgrade_info == "upgrade_info_value" + assert response.upgrade_image == "upgrade_image_value" def test_is_instance_upgradeable_empty_call(): @@ -2844,6 +2859,7 @@ async def test_is_instance_upgradeable_async( upgradeable=True, upgrade_version="upgrade_version_value", upgrade_info="upgrade_info_value", + upgrade_image="upgrade_image_value", ) ) response = await client.is_instance_upgradeable(request) @@ -2858,6 +2874,7 @@ async def test_is_instance_upgradeable_async( assert response.upgradeable is True assert response.upgrade_version == "upgrade_version_value" assert response.upgrade_info == "upgrade_info_value" + assert response.upgrade_image == "upgrade_image_value" @pytest.mark.asyncio @@ -4215,6 +4232,15 @@ def test_notebook_service_base_transport(): "get_environment", "create_environment", "delete_environment", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): @@ -4785,6 +4811,1370 @@ async def test_transport_close_async(): close.assert_called_once() +def test_delete_operation(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(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 response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(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 response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(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=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(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 response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(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 response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(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=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(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 response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(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 response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(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=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = NotebookServiceClient( + 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 = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(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 response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations_async(transport: str = "grpc"): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(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 response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = NotebookServiceClient( + 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 = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(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=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(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=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(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 response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(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 response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = NotebookServiceClient(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 = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(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=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(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=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = NotebookServiceClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(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 response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = NotebookServiceClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = NotebookServiceClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(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 response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(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 response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = NotebookServiceClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(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", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = NotebookServiceAsyncClient( + 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 = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(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", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = NotebookServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = NotebookServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + def test_transport_close(): transports = { "grpc": "_grpc_channel",