diff --git a/redis/README.rst b/redis/README.rst index f85e808485df..9d9e6d58c056 100644 --- a/redis/README.rst +++ b/redis/README.rst @@ -24,7 +24,7 @@ In order to use this library, you first need to go through the following steps: .. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project .. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Enable the Google Cloud Memorystore for Redis API.: https://cloud.google.com/memorystore/ +.. _Enable the Google Cloud Memorystore for Redis API.: https://console.cloud.google.com/apis/library/redis.googleapis.com .. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html Installation @@ -72,5 +72,5 @@ Next Steps - View this `repository’s main README`_ to see the full list of Cloud APIs that we cover. -.. _Google Cloud Memorystore for Redis API Product documentation: https://cloud.google.com/redis -.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst +.. _Google Cloud Memorystore for Redis API Product documentation: https://cloud.google.com/memorystore/ +.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst \ No newline at end of file diff --git a/redis/docs/gapic/v1/api.rst b/redis/docs/gapic/v1/api.rst new file mode 100644 index 000000000000..50ad1f8a5f64 --- /dev/null +++ b/redis/docs/gapic/v1/api.rst @@ -0,0 +1,6 @@ +Client for Google Cloud Memorystore for Redis API +================================================= + +.. automodule:: google.cloud.redis_v1 + :members: + :inherited-members: \ No newline at end of file diff --git a/redis/docs/gapic/v1/types.rst b/redis/docs/gapic/v1/types.rst new file mode 100644 index 000000000000..ba92173ded8e --- /dev/null +++ b/redis/docs/gapic/v1/types.rst @@ -0,0 +1,5 @@ +Types for Google Cloud Memorystore for Redis API Client +======================================================= + +.. automodule:: google.cloud.redis_v1.types + :members: \ No newline at end of file diff --git a/redis/docs/index.rst b/redis/docs/index.rst index fb897092cacb..1fe54ebac9a6 100644 --- a/redis/docs/index.rst +++ b/redis/docs/index.rst @@ -5,5 +5,7 @@ Api Reference .. toctree:: :maxdepth: 2 + gapic/v1/api + gapic/v1/types gapic/v1beta1/api gapic/v1beta1/types diff --git a/redis/google/__init__.py b/redis/google/__init__.py index 7a9e5a0ef198..f65701dd143f 100644 --- a/redis/google/__init__.py +++ b/redis/google/__init__.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/redis/google/cloud/__init__.py b/redis/google/cloud/__init__.py index 7a9e5a0ef198..f65701dd143f 100644 --- a/redis/google/cloud/__init__.py +++ b/redis/google/cloud/__init__.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/redis/google/cloud/redis.py b/redis/google/cloud/redis.py index 50cd6bfc1425..8d88b66280a3 100644 --- a/redis/google/cloud/redis.py +++ b/redis/google/cloud/redis.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +16,9 @@ from __future__ import absolute_import -from google.cloud.redis_v1beta1 import CloudRedisClient -from google.cloud.redis_v1beta1 import enums -from google.cloud.redis_v1beta1 import types +from google.cloud.redis_v1 import CloudRedisClient +from google.cloud.redis_v1 import enums +from google.cloud.redis_v1 import types __all__ = ( 'enums', diff --git a/redis/google/cloud/redis_v1/__init__.py b/redis/google/cloud/redis_v1/__init__.py new file mode 100644 index 000000000000..9be2b9e1ff0f --- /dev/null +++ b/redis/google/cloud/redis_v1/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 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 +# +# https://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 __future__ import absolute_import + +from google.cloud.redis_v1 import types +from google.cloud.redis_v1.gapic import cloud_redis_client +from google.cloud.redis_v1.gapic import enums + + +class CloudRedisClient(cloud_redis_client.CloudRedisClient): + __doc__ = cloud_redis_client.CloudRedisClient.__doc__ + enums = enums + + +__all__ = ( + 'enums', + 'types', + 'CloudRedisClient', +) diff --git a/redis/google/cloud/redis_v1/gapic/__init__.py b/redis/google/cloud/redis_v1/gapic/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/redis/google/cloud/redis_v1/gapic/cloud_redis_client.py b/redis/google/cloud/redis_v1/gapic/cloud_redis_client.py new file mode 100644 index 000000000000..6b2393a81d22 --- /dev/null +++ b/redis/google/cloud/redis_v1/gapic/cloud_redis_client.py @@ -0,0 +1,610 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 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 +# +# https://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. +"""Accesses the google.cloud.redis.v1 CloudRedis API.""" + +import functools +import pkg_resources +import warnings + +from google.oauth2 import service_account +import google.api_core.gapic_v1.client_info +import google.api_core.gapic_v1.config +import google.api_core.gapic_v1.method +import google.api_core.grpc_helpers +import google.api_core.operation +import google.api_core.operations_v1 +import google.api_core.page_iterator +import google.api_core.path_template +import grpc + +from google.cloud.redis_v1.gapic import cloud_redis_client_config +from google.cloud.redis_v1.gapic import enums +from google.cloud.redis_v1.gapic.transports import cloud_redis_grpc_transport +from google.cloud.redis_v1.proto import cloud_redis_pb2 +from google.cloud.redis_v1.proto import cloud_redis_pb2_grpc +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 +from google.protobuf import field_mask_pb2 + +_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution( + 'google-cloud-redis', ).version + + +class CloudRedisClient(object): + """ + Configures and manages Cloud Memorystore for Redis instances + + Google Cloud Memorystore for Redis v1 + + The ``redis.googleapis.com`` service implements the Google Cloud Memorystore + for Redis API and defines the following resource model for managing Redis + instances: + * The service works with a collection of cloud projects, named: ``/projects/*`` + * Each project has a collection of available locations, named: ``/locations/*`` + * Each location has a collection of Redis instances, named: ``/instances/*`` + * As such, Redis instances are resources of the form: + + ``/projects/{project_id}/locations/{location_id}/instances/{instance_id}`` + + Note that location_id must be refering to a GCP ``region``; for example: + * ``projects/redpepper-1290/locations/us-central1/instances/my-redis`` + """ + + SERVICE_ADDRESS = 'redis.googleapis.com:443' + """The default address of the service.""" + + # The name of the interface for this client. This is the key used to + # find the method configuration in the client_config dictionary. + _INTERFACE_NAME = 'google.cloud.redis.v1.CloudRedis' + + @classmethod + def from_service_account_file(cls, filename, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudRedisClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs['credentials'] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @classmethod + def location_path(cls, project, location): + """Return a fully-qualified location string.""" + return google.api_core.path_template.expand( + 'projects/{project}/locations/{location}', + project=project, + location=location, + ) + + @classmethod + def instance_path(cls, project, location, instance): + """Return a fully-qualified instance string.""" + return google.api_core.path_template.expand( + 'projects/{project}/locations/{location}/instances/{instance}', + project=project, + location=location, + instance=instance, + ) + + def __init__(self, + transport=None, + channel=None, + credentials=None, + client_config=cloud_redis_client_config.config, + client_info=None): + """Constructor. + + Args: + transport (Union[~.CloudRedisGrpcTransport, + Callable[[~.Credentials, type], ~.CloudRedisGrpcTransport]): A transport + instance, responsible for actually making the API calls. + The default transport uses the gRPC protocol. + This argument may also be a callable which returns a + transport instance. Callables will be sent the credentials + as the first argument and the default transport class as + the second argument. + channel (grpc.Channel): DEPRECATED. A ``Channel`` instance + through which to make calls. This argument is mutually exclusive + with ``credentials``; providing both will raise an exception. + credentials (google.auth.credentials.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is mutually exclusive with providing a + transport instance to ``transport``; doing so will raise + an exception. + client_config (dict): DEPRECATED. A dictionary of call options for + each method. If not specified, the default configuration is used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + """ + # Raise deprecation warnings for things we want to go away. + if client_config: + warnings.warn('The `client_config` argument is deprecated.', + PendingDeprecationWarning) + if channel: + warnings.warn( + 'The `channel` argument is deprecated; use ' + '`transport` instead.', PendingDeprecationWarning) + + # Instantiate the transport. + # The transport is responsible for handling serialization and + # deserialization and actually sending data to the service. + if transport: + if callable(transport): + self.transport = transport( + credentials=credentials, + default_class=cloud_redis_grpc_transport. + CloudRedisGrpcTransport, + ) + else: + if credentials: + raise ValueError( + 'Received both a transport instance and ' + 'credentials; these are mutually exclusive.') + self.transport = transport + else: + self.transport = cloud_redis_grpc_transport.CloudRedisGrpcTransport( + address=self.SERVICE_ADDRESS, + channel=channel, + credentials=credentials, + ) + + if client_info is None: + client_info = ( + google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO) + client_info.gapic_version = _GAPIC_LIBRARY_VERSION + self._client_info = client_info + + # Parse out the default settings for retry and timeout for each RPC + # from the client configuration. + # (Ordinarily, these are the defaults specified in the `*_config.py` + # file next to this one.) + self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( + client_config['interfaces'][self._INTERFACE_NAME], ) + + # Save a dictionary of cached API call functions. + # These are the actual callables which invoke the proper + # transport methods, wrapped with `wrap_method` to add retry, + # timeout, and the like. + self._inner_api_calls = {} + + # Service calls + def list_instances(self, + parent, + page_size=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): + """ + Lists all Redis instances owned by a project in either the specified + location (region) or all locations. + + The location should have the following format: + * ``projects/{project_id}/locations/{location_id}`` + + If ``location_id`` is specified as ``-`` (wildcard), then all regions + available to the project are queried, and the results are aggregated. + + Example: + >>> from google.cloud import redis_v1 + >>> + >>> client = redis_v1.CloudRedisClient() + >>> + >>> parent = client.location_path('[PROJECT]', '[LOCATION]') + >>> + >>> # Iterate over all results + >>> for element in client.list_instances(parent): + ... # process element + ... pass + >>> + >>> + >>> # Alternatively: + >>> + >>> # Iterate over results one page at a time + >>> for page in client.list_instances(parent, options=CallOptions(page_token=INITIAL_PAGE)): + ... for element in page: + ... # process element + ... pass + + Args: + parent (str): Required. The resource name of the instance location using the form ``projects/{project_id}/locations/{location_id}`` + where ``location_id`` refers to a GCP region + page_size (int): The maximum number of resources contained in the + underlying API response. If page streaming is performed per- + resource, this parameter does not affect the return value. If page + streaming is performed per-page, this determines the maximum number + of resources in a page. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. + + Returns: + A :class:`~google.gax.PageIterator` instance. By default, this + is an iterable of :class:`~google.cloud.redis_v1.types.Instance` instances. + This object can also be configured to iterate over the pages + of the response through the `options` parameter. + + Raises: + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. + """ + # Wrap the transport method to add retry and timeout logic. + if 'list_instances' not in self._inner_api_calls: + self._inner_api_calls[ + 'list_instances'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.list_instances, + default_retry=self._method_configs['ListInstances'].retry, + default_timeout=self._method_configs['ListInstances'] + .timeout, + client_info=self._client_info, + ) + + request = cloud_redis_pb2.ListInstancesRequest( + parent=parent, + page_size=page_size, + ) + iterator = google.api_core.page_iterator.GRPCIterator( + client=None, + method=functools.partial( + self._inner_api_calls['list_instances'], + retry=retry, + timeout=timeout, + metadata=metadata), + request=request, + items_field='instances', + request_token_field='page_token', + response_token_field='next_page_token', + ) + return iterator + + def get_instance(self, + name, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): + """ + Gets the details of a specific Redis instance. + + Example: + >>> from google.cloud import redis_v1 + >>> + >>> client = redis_v1.CloudRedisClient() + >>> + >>> name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + >>> + >>> response = client.get_instance(name) + + Args: + name (str): Required. Redis instance resource name using the form ``projects/{project_id}/locations/{location_id}/instances/{instance_id}``` + where ``location_id`` refers to a GCP region + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. + + Returns: + A :class:`~google.cloud.redis_v1.types.Instance` instance. + + Raises: + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. + """ + # Wrap the transport method to add retry and timeout logic. + if 'get_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'get_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.get_instance, + default_retry=self._method_configs['GetInstance'].retry, + default_timeout=self._method_configs['GetInstance'] + .timeout, + client_info=self._client_info, + ) + + request = cloud_redis_pb2.GetInstanceRequest(name=name, ) + return self._inner_api_calls['get_instance']( + request, retry=retry, timeout=timeout, metadata=metadata) + + def create_instance(self, + parent, + instance_id, + instance, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): + """ + Creates a Redis instance based on the specified tier and memory size. + + By default, the instance is accessible from the project's + `default network `_. + + The creation is executed asynchronously and callers may check the returned + operation to track its progress. Once the operation is completed the Redis + instance will be fully functional. Completed longrunning.Operation will + contain the new instance object in the response field. + + The returned operation is automatically deleted after a few hours, so there + is no need to call DeleteOperation. + + Example: + >>> from google.cloud import redis_v1 + >>> from google.cloud.redis_v1 import enums + >>> + >>> client = redis_v1.CloudRedisClient() + >>> + >>> parent = client.location_path('[PROJECT]', '[LOCATION]') + >>> instance_id = 'test_instance' + >>> tier = enums.Instance.Tier.BASIC + >>> memory_size_gb = 1 + >>> instance = {'tier': tier, 'memory_size_gb': memory_size_gb} + >>> + >>> response = client.create_instance(parent, instance_id, instance) + >>> + >>> def callback(operation_future): + ... # Handle result. + ... result = operation_future.result() + >>> + >>> response.add_done_callback(callback) + >>> + >>> # Handle metadata. + >>> metadata = response.metadata() + + Args: + parent (str): Required. The resource name of the instance location using the form ``projects/{project_id}/locations/{location_id}`` + where ``location_id`` refers to a GCP region + instance_id (str): Required. The logical name of the Redis instance in the customer project + with the following restrictions: + * Must contain only lowercase letters, numbers, and hyphens. + * Must start with a letter. + * Must be between 1-40 characters. + * Must end with a number or a letter. + * Must be unique within the customer project / location + instance (Union[dict, ~google.cloud.redis_v1.types.Instance]): Required. A Redis [Instance] resource + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.redis_v1.types.Instance` + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. + + Returns: + A :class:`~google.cloud.redis_v1.types._OperationFuture` instance. + + Raises: + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. + """ + # Wrap the transport method to add retry and timeout logic. + if 'create_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'create_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.create_instance, + default_retry=self._method_configs['CreateInstance'].retry, + default_timeout=self._method_configs['CreateInstance'] + .timeout, + client_info=self._client_info, + ) + + request = cloud_redis_pb2.CreateInstanceRequest( + parent=parent, + instance_id=instance_id, + instance=instance, + ) + operation = self._inner_api_calls['create_instance']( + request, retry=retry, timeout=timeout, metadata=metadata) + return google.api_core.operation.from_gapic( + operation, + self.transport._operations_client, + cloud_redis_pb2.Instance, + metadata_type=cloud_redis_pb2.OperationMetadata, + ) + + def update_instance(self, + update_mask, + instance, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): + """ + Updates the metadata and configuration of a specific Redis instance. + + Completed longrunning.Operation will contain the new instance object + in the response field. The returned operation is automatically deleted + after a few hours, so there is no need to call DeleteOperation. + + Example: + >>> from google.cloud import redis_v1 + >>> + >>> client = redis_v1.CloudRedisClient() + >>> + >>> paths_element = 'display_name' + >>> paths_element_2 = 'memory_size_gb' + >>> paths = [paths_element, paths_element_2] + >>> update_mask = {'paths': paths} + >>> display_name = 'UpdatedDisplayName' + >>> memory_size_gb = 4 + >>> instance = {'display_name': display_name, 'memory_size_gb': memory_size_gb} + >>> + >>> response = client.update_instance(update_mask, instance) + >>> + >>> def callback(operation_future): + ... # Handle result. + ... result = operation_future.result() + >>> + >>> response.add_done_callback(callback) + >>> + >>> # Handle metadata. + >>> metadata = response.metadata() + + Args: + update_mask (Union[dict, ~google.cloud.redis_v1.types.FieldMask]): Required. Mask of fields to update. At least one path must be supplied in + this field. The elements of the repeated paths field may only include these + fields from ``Instance``: ``displayName``, ``labels``, ``memorySizeGb``, and ``redisConfig``. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.redis_v1.types.FieldMask` + instance (Union[dict, ~google.cloud.redis_v1.types.Instance]): Required. Update description. + Only fields specified in update_mask are updated. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.redis_v1.types.Instance` + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. + + Returns: + A :class:`~google.cloud.redis_v1.types._OperationFuture` instance. + + Raises: + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. + """ + # Wrap the transport method to add retry and timeout logic. + if 'update_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'update_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.update_instance, + default_retry=self._method_configs['UpdateInstance'].retry, + default_timeout=self._method_configs['UpdateInstance'] + .timeout, + client_info=self._client_info, + ) + + request = cloud_redis_pb2.UpdateInstanceRequest( + update_mask=update_mask, + instance=instance, + ) + operation = self._inner_api_calls['update_instance']( + request, retry=retry, timeout=timeout, metadata=metadata) + return google.api_core.operation.from_gapic( + operation, + self.transport._operations_client, + cloud_redis_pb2.Instance, + metadata_type=cloud_redis_pb2.OperationMetadata, + ) + + def delete_instance(self, + name, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): + """ + Deletes a specific Redis instance. Instance stops serving and data is + deleted. + + Example: + >>> from google.cloud import redis_v1 + >>> + >>> client = redis_v1.CloudRedisClient() + >>> + >>> name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + >>> + >>> response = client.delete_instance(name) + >>> + >>> def callback(operation_future): + ... # Handle result. + ... result = operation_future.result() + >>> + >>> response.add_done_callback(callback) + >>> + >>> # Handle metadata. + >>> metadata = response.metadata() + + Args: + name (str): Required. Redis instance resource name using the form ``projects/{project_id}/locations/{location_id}/instances/{instance_id}``` + where ``location_id`` refers to a GCP region + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. + + Returns: + A :class:`~google.cloud.redis_v1.types._OperationFuture` instance. + + Raises: + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. + """ + # Wrap the transport method to add retry and timeout logic. + if 'delete_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'delete_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.delete_instance, + default_retry=self._method_configs['DeleteInstance'].retry, + default_timeout=self._method_configs['DeleteInstance'] + .timeout, + client_info=self._client_info, + ) + + request = cloud_redis_pb2.DeleteInstanceRequest(name=name, ) + operation = self._inner_api_calls['delete_instance']( + request, retry=retry, timeout=timeout, metadata=metadata) + return google.api_core.operation.from_gapic( + operation, + self.transport._operations_client, + empty_pb2.Empty, + metadata_type=cloud_redis_pb2.OperationMetadata, + ) diff --git a/redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py b/redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py new file mode 100644 index 000000000000..ccf11e0a797d --- /dev/null +++ b/redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py @@ -0,0 +1,48 @@ +config = { + "interfaces": { + "google.cloud.redis.v1.CloudRedis": { + "retry_codes": { + "idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], + "non_idempotent": [] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 20000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 20000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "ListInstances": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "GetInstance": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "CreateInstance": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "UpdateInstance": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "DeleteInstance": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/redis/google/cloud/redis_v1/gapic/enums.py b/redis/google/cloud/redis_v1/gapic/enums.py new file mode 100644 index 000000000000..6edc8d81ca31 --- /dev/null +++ b/redis/google/cloud/redis_v1/gapic/enums.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 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 +# +# https://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. +"""Wrappers for protocol buffer enum types.""" + +import enum + + +class Instance(object): + class State(enum.IntEnum): + """ + Represents the different states of a Redis instance. + + Attributes: + STATE_UNSPECIFIED (int): Not set. + CREATING (int): Redis instance is being created. + READY (int): Redis instance has been created and is fully usable. + UPDATING (int): Redis instance configuration is being updated. Certain kinds of updates + may cause the instance to become unusable while the update is in + progress. + DELETING (int): Redis instance is being deleted. + REPAIRING (int): Redis instance is being repaired and may be unusable. Details can be + found in the ``status_message`` field. + MAINTENANCE (int): Maintenance is being performed on this Redis instance. + """ + STATE_UNSPECIFIED = 0 + CREATING = 1 + READY = 2 + UPDATING = 3 + DELETING = 4 + REPAIRING = 5 + MAINTENANCE = 6 + + class Tier(enum.IntEnum): + """ + Available service tiers to choose from + + Attributes: + TIER_UNSPECIFIED (int): Not set. + BASIC (int): BASIC tier: standalone instance + STANDARD_HA (int): STANDARD_HA tier: highly available primary/replica instances + """ + TIER_UNSPECIFIED = 0 + BASIC = 1 + STANDARD_HA = 3 diff --git a/redis/google/cloud/redis_v1/gapic/transports/__init__.py b/redis/google/cloud/redis_v1/gapic/transports/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py b/redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py new file mode 100644 index 000000000000..d1354b0e8c68 --- /dev/null +++ b/redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py @@ -0,0 +1,187 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 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 +# +# https://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 google.api_core.grpc_helpers +import google.api_core.operations_v1 + +from google.cloud.redis_v1.proto import cloud_redis_pb2_grpc + + +class CloudRedisGrpcTransport(object): + """gRPC transport class providing stubs for + google.cloud.redis.v1 CloudRedis API. + + The transport provides access to the raw gRPC stubs, + which can be used to take advantage of advanced + features of gRPC. + """ + # The scopes needed to make gRPC calls to all of the methods defined + # in this service. + _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + + def __init__(self, + channel=None, + credentials=None, + address='redis.googleapis.com:443'): + """Instantiate the transport class. + + Args: + channel (grpc.Channel): A ``Channel`` instance through + which to make calls. This argument is mutually exclusive + with ``credentials``; providing both will raise an exception. + credentials (google.auth.credentials.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If none + are specified, the client will attempt to ascertain the + credentials from the environment. + address (str): The address where the service is hosted. + """ + # If both `channel` and `credentials` are specified, raise an + # exception (channels come with credentials baked in already). + if channel is not None and credentials is not None: + raise ValueError( + 'The `channel` and `credentials` arguments are mutually ' + 'exclusive.', ) + + # Create the channel. + if channel is None: + channel = self.create_channel( + address=address, + credentials=credentials, + ) + + # gRPC uses objects called "stubs" that are bound to the + # channel and provide a basic method for each RPC. + self._stubs = { + 'cloud_redis_stub': cloud_redis_pb2_grpc.CloudRedisStub(channel), + } + + # Because this API includes a method that returns a + # long-running operation (proto: google.longrunning.Operation), + # instantiate an LRO client. + self._operations_client = google.api_core.operations_v1.OperationsClient( + channel) + + @classmethod + def create_channel(cls, + address='redis.googleapis.com:443', + credentials=None): + """Create and return a gRPC channel object. + + Args: + address (str): The host for the channel to use. + credentials (~.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + + Returns: + grpc.Channel: A gRPC channel object. + """ + return google.api_core.grpc_helpers.create_channel( + address, + credentials=credentials, + scopes=cls._OAUTH_SCOPES, + ) + + @property + def list_instances(self): + """Return the gRPC stub for {$apiMethod.name}. + + Lists all Redis instances owned by a project in either the specified + location (region) or all locations. + + The location should have the following format: + * ``projects/{project_id}/locations/{location_id}`` + + If ``location_id`` is specified as ``-`` (wildcard), then all regions + available to the project are queried, and the results are aggregated. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].ListInstances + + @property + def get_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Gets the details of a specific Redis instance. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].GetInstance + + @property + def create_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Creates a Redis instance based on the specified tier and memory size. + + By default, the instance is accessible from the project's + `default network `_. + + The creation is executed asynchronously and callers may check the returned + operation to track its progress. Once the operation is completed the Redis + instance will be fully functional. Completed longrunning.Operation will + contain the new instance object in the response field. + + The returned operation is automatically deleted after a few hours, so there + is no need to call DeleteOperation. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].CreateInstance + + @property + def update_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Updates the metadata and configuration of a specific Redis instance. + + Completed longrunning.Operation will contain the new instance object + in the response field. The returned operation is automatically deleted + after a few hours, so there is no need to call DeleteOperation. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].UpdateInstance + + @property + def delete_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Deletes a specific Redis instance. Instance stops serving and data is + deleted. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].DeleteInstance diff --git a/redis/google/cloud/redis_v1/proto/__init__.py b/redis/google/cloud/redis_v1/proto/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/redis/google/cloud/redis_v1/proto/cloud_redis_pb2.py b/redis/google/cloud/redis_v1/proto/cloud_redis_pb2.py new file mode 100644 index 000000000000..59eae8b2a03c --- /dev/null +++ b/redis/google/cloud/redis_v1/proto/cloud_redis_pb2.py @@ -0,0 +1,1119 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/redis_v1/proto/cloud_redis.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.longrunning import operations_pb2 as google_dot_longrunning_dot_operations__pb2 +from google.protobuf import field_mask_pb2 as google_dot_protobuf_dot_field__mask__pb2 +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/redis_v1/proto/cloud_redis.proto', + package='google.cloud.redis.v1', + syntax='proto3', + serialized_pb=_b('\n-google/cloud/redis_v1/proto/cloud_redis.proto\x12\x15google.cloud.redis.v1\x1a\x1cgoogle/api/annotations.proto\x1a#google/longrunning/operations.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xd0\x06\n\x08Instance\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x14\n\x0c\x64isplay_name\x18\x02 \x01(\t\x12;\n\x06labels\x18\x03 \x03(\x0b\x32+.google.cloud.redis.v1.Instance.LabelsEntry\x12\x13\n\x0blocation_id\x18\x04 \x01(\t\x12\x1f\n\x17\x61lternative_location_id\x18\x05 \x01(\t\x12\x15\n\rredis_version\x18\x07 \x01(\t\x12\x19\n\x11reserved_ip_range\x18\t \x01(\t\x12\x0c\n\x04host\x18\n \x01(\t\x12\x0c\n\x04port\x18\x0b \x01(\x05\x12\x1b\n\x13\x63urrent_location_id\x18\x0c \x01(\t\x12/\n\x0b\x63reate_time\x18\r \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x34\n\x05state\x18\x0e \x01(\x0e\x32%.google.cloud.redis.v1.Instance.State\x12\x16\n\x0estatus_message\x18\x0f \x01(\t\x12H\n\rredis_configs\x18\x10 \x03(\x0b\x32\x31.google.cloud.redis.v1.Instance.RedisConfigsEntry\x12\x32\n\x04tier\x18\x11 \x01(\x0e\x32$.google.cloud.redis.v1.Instance.Tier\x12\x16\n\x0ememory_size_gb\x18\x12 \x01(\x05\x12\x1a\n\x12\x61uthorized_network\x18\x14 \x01(\t\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x33\n\x11RedisConfigsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"s\n\x05State\x12\x15\n\x11STATE_UNSPECIFIED\x10\x00\x12\x0c\n\x08\x43REATING\x10\x01\x12\t\n\x05READY\x10\x02\x12\x0c\n\x08UPDATING\x10\x03\x12\x0c\n\x08\x44\x45LETING\x10\x04\x12\r\n\tREPAIRING\x10\x05\x12\x0f\n\x0bMAINTENANCE\x10\x06\"8\n\x04Tier\x12\x14\n\x10TIER_UNSPECIFIED\x10\x00\x12\t\n\x05\x42\x41SIC\x10\x01\x12\x0f\n\x0bSTANDARD_HA\x10\x03\"M\n\x14ListInstancesRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t\"d\n\x15ListInstancesResponse\x12\x32\n\tinstances\x18\x01 \x03(\x0b\x32\x1f.google.cloud.redis.v1.Instance\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t\"\"\n\x12GetInstanceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"o\n\x15\x43reateInstanceRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x13\n\x0binstance_id\x18\x02 \x01(\t\x12\x31\n\x08instance\x18\x03 \x01(\x0b\x32\x1f.google.cloud.redis.v1.Instance\"{\n\x15UpdateInstanceRequest\x12/\n\x0bupdate_mask\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.FieldMask\x12\x31\n\x08instance\x18\x02 \x01(\x0b\x32\x1f.google.cloud.redis.v1.Instance\"%\n\x15\x44\x65leteInstanceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\xd6\x01\n\x11OperationMetadata\x12/\n\x0b\x63reate_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12,\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x0e\n\x06target\x18\x03 \x01(\t\x12\x0c\n\x04verb\x18\x04 \x01(\t\x12\x15\n\rstatus_detail\x18\x05 \x01(\t\x12\x18\n\x10\x63\x61ncel_requested\x18\x06 \x01(\x08\x12\x13\n\x0b\x61pi_version\x18\x07 \x01(\t\"\xc4\x01\n\x10LocationMetadata\x12T\n\x0f\x61vailable_zones\x18\x01 \x03(\x0b\x32;.google.cloud.redis.v1.LocationMetadata.AvailableZonesEntry\x1aZ\n\x13\x41vailableZonesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x32\n\x05value\x18\x02 \x01(\x0b\x32#.google.cloud.redis.v1.ZoneMetadata:\x02\x38\x01\"\x0e\n\x0cZoneMetadata2\xa5\x06\n\nCloudRedis\x12\xa1\x01\n\rListInstances\x12+.google.cloud.redis.v1.ListInstancesRequest\x1a,.google.cloud.redis.v1.ListInstancesResponse\"5\x82\xd3\xe4\x93\x02/\x12-/v1/{parent=projects/*/locations/*}/instances\x12\x90\x01\n\x0bGetInstance\x12).google.cloud.redis.v1.GetInstanceRequest\x1a\x1f.google.cloud.redis.v1.Instance\"5\x82\xd3\xe4\x93\x02/\x12-/v1/{name=projects/*/locations/*/instances/*}\x12\x9e\x01\n\x0e\x43reateInstance\x12,.google.cloud.redis.v1.CreateInstanceRequest\x1a\x1d.google.longrunning.Operation\"?\x82\xd3\xe4\x93\x02\x39\"-/v1/{parent=projects/*/locations/*}/instances:\x08instance\x12\xa7\x01\n\x0eUpdateInstance\x12,.google.cloud.redis.v1.UpdateInstanceRequest\x1a\x1d.google.longrunning.Operation\"H\x82\xd3\xe4\x93\x02\x42\x32\x36/v1/{instance.name=projects/*/locations/*/instances/*}:\x08instance\x12\x94\x01\n\x0e\x44\x65leteInstance\x12,.google.cloud.redis.v1.DeleteInstanceRequest\x1a\x1d.google.longrunning.Operation\"5\x82\xd3\xe4\x93\x02/*-/v1/{name=projects/*/locations/*/instances/*}Bs\n\x19\x63om.google.cloud.redis.v1B\x18\x43loudRedisServiceV1ProtoP\x01Z:google.golang.org/genproto/googleapis/cloud/redis/v1;redisb\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_longrunning_dot_operations__pb2.DESCRIPTOR,google_dot_protobuf_dot_field__mask__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,]) + + + +_INSTANCE_STATE = _descriptor.EnumDescriptor( + name='State', + full_name='google.cloud.redis.v1.Instance.State', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='STATE_UNSPECIFIED', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='CREATING', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='READY', index=2, number=2, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='UPDATING', index=3, number=3, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DELETING', index=4, number=4, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='REPAIRING', index=5, number=5, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='MAINTENANCE', index=6, number=6, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=882, + serialized_end=997, +) +_sym_db.RegisterEnumDescriptor(_INSTANCE_STATE) + +_INSTANCE_TIER = _descriptor.EnumDescriptor( + name='Tier', + full_name='google.cloud.redis.v1.Instance.Tier', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='TIER_UNSPECIFIED', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='BASIC', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='STANDARD_HA', index=2, number=3, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=999, + serialized_end=1055, +) +_sym_db.RegisterEnumDescriptor(_INSTANCE_TIER) + + +_INSTANCE_LABELSENTRY = _descriptor.Descriptor( + name='LabelsEntry', + full_name='google.cloud.redis.v1.Instance.LabelsEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='google.cloud.redis.v1.Instance.LabelsEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='google.cloud.redis.v1.Instance.LabelsEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=782, + serialized_end=827, +) + +_INSTANCE_REDISCONFIGSENTRY = _descriptor.Descriptor( + name='RedisConfigsEntry', + full_name='google.cloud.redis.v1.Instance.RedisConfigsEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='google.cloud.redis.v1.Instance.RedisConfigsEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='google.cloud.redis.v1.Instance.RedisConfigsEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=829, + serialized_end=880, +) + +_INSTANCE = _descriptor.Descriptor( + name='Instance', + full_name='google.cloud.redis.v1.Instance', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='google.cloud.redis.v1.Instance.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='display_name', full_name='google.cloud.redis.v1.Instance.display_name', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='labels', full_name='google.cloud.redis.v1.Instance.labels', index=2, + number=3, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='location_id', full_name='google.cloud.redis.v1.Instance.location_id', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='alternative_location_id', full_name='google.cloud.redis.v1.Instance.alternative_location_id', index=4, + number=5, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='redis_version', full_name='google.cloud.redis.v1.Instance.redis_version', index=5, + number=7, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='reserved_ip_range', full_name='google.cloud.redis.v1.Instance.reserved_ip_range', index=6, + number=9, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='host', full_name='google.cloud.redis.v1.Instance.host', index=7, + number=10, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='port', full_name='google.cloud.redis.v1.Instance.port', index=8, + number=11, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='current_location_id', full_name='google.cloud.redis.v1.Instance.current_location_id', index=9, + number=12, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='create_time', full_name='google.cloud.redis.v1.Instance.create_time', index=10, + number=13, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='state', full_name='google.cloud.redis.v1.Instance.state', index=11, + number=14, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='status_message', full_name='google.cloud.redis.v1.Instance.status_message', index=12, + number=15, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='redis_configs', full_name='google.cloud.redis.v1.Instance.redis_configs', index=13, + number=16, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='tier', full_name='google.cloud.redis.v1.Instance.tier', index=14, + number=17, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='memory_size_gb', full_name='google.cloud.redis.v1.Instance.memory_size_gb', index=15, + number=18, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='authorized_network', full_name='google.cloud.redis.v1.Instance.authorized_network', index=16, + number=20, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[_INSTANCE_LABELSENTRY, _INSTANCE_REDISCONFIGSENTRY, ], + enum_types=[ + _INSTANCE_STATE, + _INSTANCE_TIER, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=207, + serialized_end=1055, +) + + +_LISTINSTANCESREQUEST = _descriptor.Descriptor( + name='ListInstancesRequest', + full_name='google.cloud.redis.v1.ListInstancesRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='parent', full_name='google.cloud.redis.v1.ListInstancesRequest.parent', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='page_size', full_name='google.cloud.redis.v1.ListInstancesRequest.page_size', index=1, + number=2, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='page_token', full_name='google.cloud.redis.v1.ListInstancesRequest.page_token', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1057, + serialized_end=1134, +) + + +_LISTINSTANCESRESPONSE = _descriptor.Descriptor( + name='ListInstancesResponse', + full_name='google.cloud.redis.v1.ListInstancesResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='instances', full_name='google.cloud.redis.v1.ListInstancesResponse.instances', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='next_page_token', full_name='google.cloud.redis.v1.ListInstancesResponse.next_page_token', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1136, + serialized_end=1236, +) + + +_GETINSTANCEREQUEST = _descriptor.Descriptor( + name='GetInstanceRequest', + full_name='google.cloud.redis.v1.GetInstanceRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='google.cloud.redis.v1.GetInstanceRequest.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1238, + serialized_end=1272, +) + + +_CREATEINSTANCEREQUEST = _descriptor.Descriptor( + name='CreateInstanceRequest', + full_name='google.cloud.redis.v1.CreateInstanceRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='parent', full_name='google.cloud.redis.v1.CreateInstanceRequest.parent', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='instance_id', full_name='google.cloud.redis.v1.CreateInstanceRequest.instance_id', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='instance', full_name='google.cloud.redis.v1.CreateInstanceRequest.instance', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1274, + serialized_end=1385, +) + + +_UPDATEINSTANCEREQUEST = _descriptor.Descriptor( + name='UpdateInstanceRequest', + full_name='google.cloud.redis.v1.UpdateInstanceRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='update_mask', full_name='google.cloud.redis.v1.UpdateInstanceRequest.update_mask', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='instance', full_name='google.cloud.redis.v1.UpdateInstanceRequest.instance', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1387, + serialized_end=1510, +) + + +_DELETEINSTANCEREQUEST = _descriptor.Descriptor( + name='DeleteInstanceRequest', + full_name='google.cloud.redis.v1.DeleteInstanceRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='google.cloud.redis.v1.DeleteInstanceRequest.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1512, + serialized_end=1549, +) + + +_OPERATIONMETADATA = _descriptor.Descriptor( + name='OperationMetadata', + full_name='google.cloud.redis.v1.OperationMetadata', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='create_time', full_name='google.cloud.redis.v1.OperationMetadata.create_time', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='end_time', full_name='google.cloud.redis.v1.OperationMetadata.end_time', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='target', full_name='google.cloud.redis.v1.OperationMetadata.target', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='verb', full_name='google.cloud.redis.v1.OperationMetadata.verb', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='status_detail', full_name='google.cloud.redis.v1.OperationMetadata.status_detail', index=4, + number=5, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='cancel_requested', full_name='google.cloud.redis.v1.OperationMetadata.cancel_requested', index=5, + number=6, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='api_version', full_name='google.cloud.redis.v1.OperationMetadata.api_version', index=6, + number=7, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1552, + serialized_end=1766, +) + + +_LOCATIONMETADATA_AVAILABLEZONESENTRY = _descriptor.Descriptor( + name='AvailableZonesEntry', + full_name='google.cloud.redis.v1.LocationMetadata.AvailableZonesEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='google.cloud.redis.v1.LocationMetadata.AvailableZonesEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='google.cloud.redis.v1.LocationMetadata.AvailableZonesEntry.value', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1875, + serialized_end=1965, +) + +_LOCATIONMETADATA = _descriptor.Descriptor( + name='LocationMetadata', + full_name='google.cloud.redis.v1.LocationMetadata', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='available_zones', full_name='google.cloud.redis.v1.LocationMetadata.available_zones', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[_LOCATIONMETADATA_AVAILABLEZONESENTRY, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1769, + serialized_end=1965, +) + + +_ZONEMETADATA = _descriptor.Descriptor( + name='ZoneMetadata', + full_name='google.cloud.redis.v1.ZoneMetadata', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1967, + serialized_end=1981, +) + +_INSTANCE_LABELSENTRY.containing_type = _INSTANCE +_INSTANCE_REDISCONFIGSENTRY.containing_type = _INSTANCE +_INSTANCE.fields_by_name['labels'].message_type = _INSTANCE_LABELSENTRY +_INSTANCE.fields_by_name['create_time'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +_INSTANCE.fields_by_name['state'].enum_type = _INSTANCE_STATE +_INSTANCE.fields_by_name['redis_configs'].message_type = _INSTANCE_REDISCONFIGSENTRY +_INSTANCE.fields_by_name['tier'].enum_type = _INSTANCE_TIER +_INSTANCE_STATE.containing_type = _INSTANCE +_INSTANCE_TIER.containing_type = _INSTANCE +_LISTINSTANCESRESPONSE.fields_by_name['instances'].message_type = _INSTANCE +_CREATEINSTANCEREQUEST.fields_by_name['instance'].message_type = _INSTANCE +_UPDATEINSTANCEREQUEST.fields_by_name['update_mask'].message_type = google_dot_protobuf_dot_field__mask__pb2._FIELDMASK +_UPDATEINSTANCEREQUEST.fields_by_name['instance'].message_type = _INSTANCE +_OPERATIONMETADATA.fields_by_name['create_time'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +_OPERATIONMETADATA.fields_by_name['end_time'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +_LOCATIONMETADATA_AVAILABLEZONESENTRY.fields_by_name['value'].message_type = _ZONEMETADATA +_LOCATIONMETADATA_AVAILABLEZONESENTRY.containing_type = _LOCATIONMETADATA +_LOCATIONMETADATA.fields_by_name['available_zones'].message_type = _LOCATIONMETADATA_AVAILABLEZONESENTRY +DESCRIPTOR.message_types_by_name['Instance'] = _INSTANCE +DESCRIPTOR.message_types_by_name['ListInstancesRequest'] = _LISTINSTANCESREQUEST +DESCRIPTOR.message_types_by_name['ListInstancesResponse'] = _LISTINSTANCESRESPONSE +DESCRIPTOR.message_types_by_name['GetInstanceRequest'] = _GETINSTANCEREQUEST +DESCRIPTOR.message_types_by_name['CreateInstanceRequest'] = _CREATEINSTANCEREQUEST +DESCRIPTOR.message_types_by_name['UpdateInstanceRequest'] = _UPDATEINSTANCEREQUEST +DESCRIPTOR.message_types_by_name['DeleteInstanceRequest'] = _DELETEINSTANCEREQUEST +DESCRIPTOR.message_types_by_name['OperationMetadata'] = _OPERATIONMETADATA +DESCRIPTOR.message_types_by_name['LocationMetadata'] = _LOCATIONMETADATA +DESCRIPTOR.message_types_by_name['ZoneMetadata'] = _ZONEMETADATA +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +Instance = _reflection.GeneratedProtocolMessageType('Instance', (_message.Message,), dict( + + LabelsEntry = _reflection.GeneratedProtocolMessageType('LabelsEntry', (_message.Message,), dict( + DESCRIPTOR = _INSTANCE_LABELSENTRY, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.Instance.LabelsEntry) + )) + , + + RedisConfigsEntry = _reflection.GeneratedProtocolMessageType('RedisConfigsEntry', (_message.Message,), dict( + DESCRIPTOR = _INSTANCE_REDISCONFIGSENTRY, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.Instance.RedisConfigsEntry) + )) + , + DESCRIPTOR = _INSTANCE, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """A Google Cloud Redis instance. + + + Attributes: + name: + Required. Unique name of the resource in this scope including + project and location using the form: ``projects/{project_id}/l + ocations/{location_id}/instances/{instance_id}`` Note: Redis + instances are managed and addressed at regional level so + location\_id here refers to a GCP region; however, users may + choose which specific zone (or collection of zones for cross- + zone instances) an instance should be provisioned in. Refer to + [location\_id] and [alternative\_location\_id] fields for more + details. + display_name: + An arbitrary and optional user-provided name for the instance. + labels: + Resource labels to represent user provided metadata + location_id: + Optional. The zone where the instance will be provisioned. If + not provided, the service will choose a zone for the instance. + For STANDARD\_HA tier, instances will be created across two + zones for protection against zonal failures. If + [alternative\_location\_id] is also provided, it must be + different from [location\_id]. + alternative_location_id: + Optional. Only applicable to STANDARD\_HA tier which protects + the instance against zonal failures by provisioning it across + two zones. If provided, it must be a different zone from the + one provided in [location\_id]. + redis_version: + Optional. The version of Redis software. If not provided, + latest supported version will be used. Updating the version + will perform an upgrade/downgrade to the new version. + Currently, the supported values are ``REDIS_3_2`` for Redis + 3.2. + reserved_ip_range: + Optional. The CIDR range of internal addresses that are + reserved for this instance. If not provided, the service will + choose an unused /29 block, for example, 10.0.0.0/29 or + 192.168.0.0/29. Ranges must be unique and non-overlapping with + existing subnets in an authorized network. + host: + Output only. Hostname or IP address of the exposed Redis + endpoint used by clients to connect to the service. + port: + Output only. The port number of the exposed Redis endpoint. + current_location_id: + Output only. The current zone where the Redis endpoint is + placed. For Basic Tier instances, this will always be the same + as the [location\_id] provided by the user at creation time. + For Standard Tier instances, this can be either [location\_id] + or [alternative\_location\_id] and can change after a failover + event. + create_time: + Output only. The time the instance was created. + state: + Output only. The current state of this instance. + status_message: + Output only. Additional information about the current status + of this instance, if available. + redis_configs: + Optional. Redis configuration parameters, according to + http://redis.io/topics/config. Currently, the only supported + parameters are: - maxmemory-policy - notify-keyspace-events + tier: + Required. The service tier of the instance. + memory_size_gb: + Required. Redis memory size in GiB. + authorized_network: + Optional. The full name of the Google Compute Engine `network + `__ to which + the instance is connected. If left unspecified, the + ``default`` network will be used. + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.Instance) + )) +_sym_db.RegisterMessage(Instance) +_sym_db.RegisterMessage(Instance.LabelsEntry) +_sym_db.RegisterMessage(Instance.RedisConfigsEntry) + +ListInstancesRequest = _reflection.GeneratedProtocolMessageType('ListInstancesRequest', (_message.Message,), dict( + DESCRIPTOR = _LISTINSTANCESREQUEST, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Request for + [ListInstances][google.cloud.redis.v1.CloudRedis.ListInstances]. + + + Attributes: + parent: + Required. The resource name of the instance location using the + form: ``projects/{project_id}/locations/{location_id}`` where + ``location_id`` refers to a GCP region + page_size: + The maximum number of items to return. If not specified, a + default value of 1000 will be used by the service. Regardless + of the page\_size value, the response may include a partial + list and a caller should only rely on response's [next\_page\_ + token][CloudRedis.ListInstancesResponse.next\_page\_token] to + determine if there are more instances left to be queried. + page_token: + The next\_page\_token value returned from a previous List + request, if any. + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.ListInstancesRequest) + )) +_sym_db.RegisterMessage(ListInstancesRequest) + +ListInstancesResponse = _reflection.GeneratedProtocolMessageType('ListInstancesResponse', (_message.Message,), dict( + DESCRIPTOR = _LISTINSTANCESRESPONSE, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Response for + [ListInstances][google.cloud.redis.v1.CloudRedis.ListInstances]. + + + Attributes: + instances: + A list of Redis instances in the project in the specified + location, or across all locations. If the ``location_id`` in + the parent field of the request is "-", all regions available + to the project are queried, and the results aggregated. If in + such an aggregated query a location is unavailable, a dummy + Redis entry is included in the response with the "name" field + set to a value of the form + projects/{project\_id}/locations/{location\_id}/instances/- + and the "status" field set to ERROR and "status\_message" + field set to "location not available for ListInstances". + next_page_token: + Token to retrieve the next page of results, or empty if there + are no more results in the list. + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.ListInstancesResponse) + )) +_sym_db.RegisterMessage(ListInstancesResponse) + +GetInstanceRequest = _reflection.GeneratedProtocolMessageType('GetInstanceRequest', (_message.Message,), dict( + DESCRIPTOR = _GETINSTANCEREQUEST, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Request for [GetInstance][google.cloud.redis.v1.CloudRedis.GetInstance]. + + + Attributes: + name: + Required. Redis instance resource name using the form: ``proje + cts/{project_id}/locations/{location_id}/instances/{instance_i + d}`` where ``location_id`` refers to a GCP region + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.GetInstanceRequest) + )) +_sym_db.RegisterMessage(GetInstanceRequest) + +CreateInstanceRequest = _reflection.GeneratedProtocolMessageType('CreateInstanceRequest', (_message.Message,), dict( + DESCRIPTOR = _CREATEINSTANCEREQUEST, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Request for + [CreateInstance][google.cloud.redis.v1.CloudRedis.CreateInstance]. + + + Attributes: + parent: + Required. The resource name of the instance location using the + form: ``projects/{project_id}/locations/{location_id}`` where + ``location_id`` refers to a GCP region + instance_id: + Required. The logical name of the Redis instance in the + customer project with the following restrictions: - Must + contain only lowercase letters, numbers, and hyphens. - Must + start with a letter. - Must be between 1-40 characters. - + Must end with a number or a letter. - Must be unique within + the customer project / location + instance: + Required. A Redis [Instance] resource + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.CreateInstanceRequest) + )) +_sym_db.RegisterMessage(CreateInstanceRequest) + +UpdateInstanceRequest = _reflection.GeneratedProtocolMessageType('UpdateInstanceRequest', (_message.Message,), dict( + DESCRIPTOR = _UPDATEINSTANCEREQUEST, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Request for + [UpdateInstance][google.cloud.redis.v1.CloudRedis.UpdateInstance]. + + + Attributes: + update_mask: + Required. Mask of fields to update. At least one path must be + supplied in this field. The elements of the repeated paths + field may only include these fields from + [Instance][CloudRedis.Instance]: - ``displayName`` - + ``labels`` - ``memorySizeGb`` - ``redisConfig`` + instance: + Required. Update description. Only fields specified in + update\_mask are updated. + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.UpdateInstanceRequest) + )) +_sym_db.RegisterMessage(UpdateInstanceRequest) + +DeleteInstanceRequest = _reflection.GeneratedProtocolMessageType('DeleteInstanceRequest', (_message.Message,), dict( + DESCRIPTOR = _DELETEINSTANCEREQUEST, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Request for + [DeleteInstance][google.cloud.redis.v1.CloudRedis.DeleteInstance]. + + + Attributes: + name: + Required. Redis instance resource name using the form: ``proje + cts/{project_id}/locations/{location_id}/instances/{instance_i + d}`` where ``location_id`` refers to a GCP region + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.DeleteInstanceRequest) + )) +_sym_db.RegisterMessage(DeleteInstanceRequest) + +OperationMetadata = _reflection.GeneratedProtocolMessageType('OperationMetadata', (_message.Message,), dict( + DESCRIPTOR = _OPERATIONMETADATA, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Represents the v1 metadata of the long-running operation. + + + Attributes: + create_time: + Creation timestamp. + end_time: + End timestamp. + target: + Operation target. + verb: + Operation verb. + status_detail: + Operation status details. + cancel_requested: + Specifies if cancellation was requested for the operaiton. + api_version: + API version. + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.OperationMetadata) + )) +_sym_db.RegisterMessage(OperationMetadata) + +LocationMetadata = _reflection.GeneratedProtocolMessageType('LocationMetadata', (_message.Message,), dict( + + AvailableZonesEntry = _reflection.GeneratedProtocolMessageType('AvailableZonesEntry', (_message.Message,), dict( + DESCRIPTOR = _LOCATIONMETADATA_AVAILABLEZONESENTRY, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.LocationMetadata.AvailableZonesEntry) + )) + , + DESCRIPTOR = _LOCATIONMETADATA, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """This location metadata represents additional configuration options for a + given location where a Redis instance may be created. All fields are + output only. It is returned as content of the + ``google.cloud.location.Location.metadata`` field. + + + Attributes: + available_zones: + Output only. The set of available zones in the location. The + map is keyed by the lowercase ID of each zone, as defined by + GCE. These keys can be specified in ``location_id`` or + ``alternative_location_id`` fields when creating a Redis + instance. + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.LocationMetadata) + )) +_sym_db.RegisterMessage(LocationMetadata) +_sym_db.RegisterMessage(LocationMetadata.AvailableZonesEntry) + +ZoneMetadata = _reflection.GeneratedProtocolMessageType('ZoneMetadata', (_message.Message,), dict( + DESCRIPTOR = _ZONEMETADATA, + __module__ = 'google.cloud.redis_v1.proto.cloud_redis_pb2' + , + __doc__ = """Defines specific information for a particular zone. Currently empty and + reserved for future use only. + """, + # @@protoc_insertion_point(class_scope:google.cloud.redis.v1.ZoneMetadata) + )) +_sym_db.RegisterMessage(ZoneMetadata) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\031com.google.cloud.redis.v1B\030CloudRedisServiceV1ProtoP\001Z:google.golang.org/genproto/googleapis/cloud/redis/v1;redis')) +_INSTANCE_LABELSENTRY.has_options = True +_INSTANCE_LABELSENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) +_INSTANCE_REDISCONFIGSENTRY.has_options = True +_INSTANCE_REDISCONFIGSENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) +_LOCATIONMETADATA_AVAILABLEZONESENTRY.has_options = True +_LOCATIONMETADATA_AVAILABLEZONESENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) + +_CLOUDREDIS = _descriptor.ServiceDescriptor( + name='CloudRedis', + full_name='google.cloud.redis.v1.CloudRedis', + file=DESCRIPTOR, + index=0, + options=None, + serialized_start=1984, + serialized_end=2789, + methods=[ + _descriptor.MethodDescriptor( + name='ListInstances', + full_name='google.cloud.redis.v1.CloudRedis.ListInstances', + index=0, + containing_service=None, + input_type=_LISTINSTANCESREQUEST, + output_type=_LISTINSTANCESRESPONSE, + options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002/\022-/v1/{parent=projects/*/locations/*}/instances')), + ), + _descriptor.MethodDescriptor( + name='GetInstance', + full_name='google.cloud.redis.v1.CloudRedis.GetInstance', + index=1, + containing_service=None, + input_type=_GETINSTANCEREQUEST, + output_type=_INSTANCE, + options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002/\022-/v1/{name=projects/*/locations/*/instances/*}')), + ), + _descriptor.MethodDescriptor( + name='CreateInstance', + full_name='google.cloud.redis.v1.CloudRedis.CreateInstance', + index=2, + containing_service=None, + input_type=_CREATEINSTANCEREQUEST, + output_type=google_dot_longrunning_dot_operations__pb2._OPERATION, + options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\0029\"-/v1/{parent=projects/*/locations/*}/instances:\010instance')), + ), + _descriptor.MethodDescriptor( + name='UpdateInstance', + full_name='google.cloud.redis.v1.CloudRedis.UpdateInstance', + index=3, + containing_service=None, + input_type=_UPDATEINSTANCEREQUEST, + output_type=google_dot_longrunning_dot_operations__pb2._OPERATION, + options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002B26/v1/{instance.name=projects/*/locations/*/instances/*}:\010instance')), + ), + _descriptor.MethodDescriptor( + name='DeleteInstance', + full_name='google.cloud.redis.v1.CloudRedis.DeleteInstance', + index=4, + containing_service=None, + input_type=_DELETEINSTANCEREQUEST, + output_type=google_dot_longrunning_dot_operations__pb2._OPERATION, + options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002/*-/v1/{name=projects/*/locations/*/instances/*}')), + ), +]) +_sym_db.RegisterServiceDescriptor(_CLOUDREDIS) + +DESCRIPTOR.services_by_name['CloudRedis'] = _CLOUDREDIS + +# @@protoc_insertion_point(module_scope) diff --git a/redis/google/cloud/redis_v1/proto/cloud_redis_pb2_grpc.py b/redis/google/cloud/redis_v1/proto/cloud_redis_pb2_grpc.py new file mode 100644 index 000000000000..ad325a717831 --- /dev/null +++ b/redis/google/cloud/redis_v1/proto/cloud_redis_pb2_grpc.py @@ -0,0 +1,166 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + +from google.cloud.redis_v1.proto import cloud_redis_pb2 as google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2 +from google.longrunning import operations_pb2 as google_dot_longrunning_dot_operations__pb2 + + +class CloudRedisStub(object): + """Configures and manages Cloud Memorystore for Redis instances + + Google Cloud Memorystore for Redis v1 + + The `redis.googleapis.com` service implements the Google Cloud Memorystore + for Redis API and defines the following resource model for managing Redis + instances: + * The service works with a collection of cloud projects, named: `/projects/*` + * Each project has a collection of available locations, named: `/locations/*` + * Each location has a collection of Redis instances, named: `/instances/*` + * As such, Redis instances are resources of the form: + `/projects/{project_id}/locations/{location_id}/instances/{instance_id}` + + Note that location_id must be refering to a GCP `region`; for example: + * `projects/redpepper-1290/locations/us-central1/instances/my-redis` + """ + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.ListInstances = channel.unary_unary( + '/google.cloud.redis.v1.CloudRedis/ListInstances', + request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ListInstancesRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ListInstancesResponse.FromString, + ) + self.GetInstance = channel.unary_unary( + '/google.cloud.redis.v1.CloudRedis/GetInstance', + request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.GetInstanceRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.Instance.FromString, + ) + self.CreateInstance = channel.unary_unary( + '/google.cloud.redis.v1.CloudRedis/CreateInstance', + request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.CreateInstanceRequest.SerializeToString, + response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString, + ) + self.UpdateInstance = channel.unary_unary( + '/google.cloud.redis.v1.CloudRedis/UpdateInstance', + request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.UpdateInstanceRequest.SerializeToString, + response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString, + ) + self.DeleteInstance = channel.unary_unary( + '/google.cloud.redis.v1.CloudRedis/DeleteInstance', + request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.DeleteInstanceRequest.SerializeToString, + response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString, + ) + + +class CloudRedisServicer(object): + """Configures and manages Cloud Memorystore for Redis instances + + Google Cloud Memorystore for Redis v1 + + The `redis.googleapis.com` service implements the Google Cloud Memorystore + for Redis API and defines the following resource model for managing Redis + instances: + * The service works with a collection of cloud projects, named: `/projects/*` + * Each project has a collection of available locations, named: `/locations/*` + * Each location has a collection of Redis instances, named: `/instances/*` + * As such, Redis instances are resources of the form: + `/projects/{project_id}/locations/{location_id}/instances/{instance_id}` + + Note that location_id must be refering to a GCP `region`; for example: + * `projects/redpepper-1290/locations/us-central1/instances/my-redis` + """ + + def ListInstances(self, request, context): + """Lists all Redis instances owned by a project in either the specified + location (region) or all locations. + + The location should have the following format: + * `projects/{project_id}/locations/{location_id}` + + If `location_id` is specified as `-` (wildcard), then all regions + available to the project are queried, and the results are aggregated. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetInstance(self, request, context): + """Gets the details of a specific Redis instance. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def CreateInstance(self, request, context): + """Creates a Redis instance based on the specified tier and memory size. + + By default, the instance is accessible from the project's + [default network](/compute/docs/networks-and-firewalls#networks). + + The creation is executed asynchronously and callers may check the returned + operation to track its progress. Once the operation is completed the Redis + instance will be fully functional. Completed longrunning.Operation will + contain the new instance object in the response field. + + The returned operation is automatically deleted after a few hours, so there + is no need to call DeleteOperation. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def UpdateInstance(self, request, context): + """Updates the metadata and configuration of a specific Redis instance. + + Completed longrunning.Operation will contain the new instance object + in the response field. The returned operation is automatically deleted + after a few hours, so there is no need to call DeleteOperation. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def DeleteInstance(self, request, context): + """Deletes a specific Redis instance. Instance stops serving and data is + deleted. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_CloudRedisServicer_to_server(servicer, server): + rpc_method_handlers = { + 'ListInstances': grpc.unary_unary_rpc_method_handler( + servicer.ListInstances, + request_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ListInstancesRequest.FromString, + response_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ListInstancesResponse.SerializeToString, + ), + 'GetInstance': grpc.unary_unary_rpc_method_handler( + servicer.GetInstance, + request_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.GetInstanceRequest.FromString, + response_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.Instance.SerializeToString, + ), + 'CreateInstance': grpc.unary_unary_rpc_method_handler( + servicer.CreateInstance, + request_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.CreateInstanceRequest.FromString, + response_serializer=google_dot_longrunning_dot_operations__pb2.Operation.SerializeToString, + ), + 'UpdateInstance': grpc.unary_unary_rpc_method_handler( + servicer.UpdateInstance, + request_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.UpdateInstanceRequest.FromString, + response_serializer=google_dot_longrunning_dot_operations__pb2.Operation.SerializeToString, + ), + 'DeleteInstance': grpc.unary_unary_rpc_method_handler( + servicer.DeleteInstance, + request_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.DeleteInstanceRequest.FromString, + response_serializer=google_dot_longrunning_dot_operations__pb2.Operation.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'google.cloud.redis.v1.CloudRedis', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) diff --git a/redis/google/cloud/redis_v1/types.py b/redis/google/cloud/redis_v1/types.py new file mode 100644 index 000000000000..2b3d570a6614 --- /dev/null +++ b/redis/google/cloud/redis_v1/types.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 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 +# +# https://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 __future__ import absolute_import +import sys + +from google.api_core.protobuf_helpers import get_messages + +from google.api import http_pb2 +from google.cloud.redis_v1.proto import cloud_redis_pb2 +from google.longrunning import operations_pb2 +from google.protobuf import any_pb2 +from google.protobuf import descriptor_pb2 +from google.protobuf import empty_pb2 +from google.protobuf import field_mask_pb2 +from google.protobuf import timestamp_pb2 +from google.rpc import status_pb2 + +_shared_modules = [ + http_pb2, + operations_pb2, + any_pb2, + descriptor_pb2, + empty_pb2, + field_mask_pb2, + timestamp_pb2, + status_pb2, +] + +_local_modules = [ + cloud_redis_pb2, +] + +names = [] + +for module in _shared_modules: + for name, message in get_messages(module).items(): + setattr(sys.modules[__name__], name, message) + names.append(name) +for module in _local_modules: + for name, message in get_messages(module).items(): + message.__module__ = 'google.cloud.redis_v1.types' + setattr(sys.modules[__name__], name, message) + names.append(name) + +__all__ = tuple(sorted(names)) diff --git a/redis/google/cloud/redis_v1beta1/__init__.py b/redis/google/cloud/redis_v1beta1/__init__.py index 1b6e08085d52..cbac83c2d838 100644 --- a/redis/google/cloud/redis_v1beta1/__init__.py +++ b/redis/google/cloud/redis_v1beta1/__init__.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py b/redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py index d66da2ec8637..6d448c1f4370 100644 --- a/redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py +++ b/redis/google/cloud/redis_v1beta1/gapic/cloud_redis_client.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +17,9 @@ import functools import pkg_resources +import warnings +from google.oauth2 import service_account import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config import google.api_core.gapic_v1.method @@ -24,9 +28,11 @@ import google.api_core.operations_v1 import google.api_core.page_iterator import google.api_core.path_template +import grpc from google.cloud.redis_v1beta1.gapic import cloud_redis_client_config from google.cloud.redis_v1beta1.gapic import enums +from google.cloud.redis_v1beta1.gapic.transports import cloud_redis_grpc_transport from google.cloud.redis_v1beta1.proto import cloud_redis_pb2 from google.cloud.redis_v1beta1.proto import cloud_redis_pb2_grpc from google.longrunning import operations_pb2 @@ -51,7 +57,7 @@ class CloudRedisClient(object): * Each project has a collection of available locations, named: ``/locations/*`` * Each location has a collection of Redis instances, named: ``/instances/*`` * As such, Redis instances are resources of the form: - + ``/projects/{project_id}/locations/{location_id}/instances/{instance_id}`` Note that location_id must be refering to a GCP ``region``; for example: @@ -61,14 +67,31 @@ class CloudRedisClient(object): SERVICE_ADDRESS = 'redis.googleapis.com:443' """The default address of the service.""" - # The scopes needed to make gRPC calls to all of the methods defined in - # this service - _DEFAULT_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) - - # The name of the interface for this client. This is the key used to find - # method configuration in the client_config dictionary. + # The name of the interface for this client. This is the key used to + # find the method configuration in the client_config dictionary. _INTERFACE_NAME = 'google.cloud.redis.v1beta1.CloudRedis' + @classmethod + def from_service_account_file(cls, filename, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudRedisClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs['credentials'] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + @classmethod def location_path(cls, project, location): """Return a fully-qualified location string.""" @@ -89,6 +112,7 @@ def instance_path(cls, project, location, instance): ) def __init__(self, + transport=None, channel=None, credentials=None, client_config=cloud_redis_client_config.config, @@ -96,91 +120,83 @@ def __init__(self, """Constructor. Args: - channel (grpc.Channel): A ``Channel`` instance through - which to make calls. This argument is mutually exclusive + transport (Union[~.CloudRedisGrpcTransport, + Callable[[~.Credentials, type], ~.CloudRedisGrpcTransport]): A transport + instance, responsible for actually making the API calls. + The default transport uses the gRPC protocol. + This argument may also be a callable which returns a + transport instance. Callables will be sent the credentials + as the first argument and the default transport class as + the second argument. + channel (grpc.Channel): DEPRECATED. A ``Channel`` instance + through which to make calls. This argument is mutually exclusive with ``credentials``; providing both will raise an exception. credentials (google.auth.credentials.Credentials): The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. - client_config (dict): A dictionary of call options for each - method. If not specified, the default configuration is used. + This argument is mutually exclusive with providing a + transport instance to ``transport``; doing so will raise + an exception. + client_config (dict): DEPRECATED. A dictionary of call options for + each method. If not specified, the default configuration is used. client_info (google.api_core.gapic_v1.client_info.ClientInfo): The client info used to send a user-agent string along with API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. """ - # If both `channel` and `credentials` are specified, raise an - # exception (channels come with credentials baked in already). - if channel is not None and credentials is not None: - raise ValueError( - 'The `channel` and `credentials` arguments to {} are mutually ' - 'exclusive.'.format(self.__class__.__name__), ) - - # Create the channel. - if channel is None: - channel = google.api_core.grpc_helpers.create_channel( - self.SERVICE_ADDRESS, + # Raise deprecation warnings for things we want to go away. + if client_config: + warnings.warn('The `client_config` argument is deprecated.', + PendingDeprecationWarning) + if channel: + warnings.warn( + 'The `channel` argument is deprecated; use ' + '`transport` instead.', PendingDeprecationWarning) + + # Instantiate the transport. + # The transport is responsible for handling serialization and + # deserialization and actually sending data to the service. + if transport: + if callable(transport): + self.transport = transport( + credentials=credentials, + default_class=cloud_redis_grpc_transport. + CloudRedisGrpcTransport, + ) + else: + if credentials: + raise ValueError( + 'Received both a transport instance and ' + 'credentials; these are mutually exclusive.') + self.transport = transport + else: + self.transport = cloud_redis_grpc_transport.CloudRedisGrpcTransport( + address=self.SERVICE_ADDRESS, + channel=channel, credentials=credentials, - scopes=self._DEFAULT_SCOPES, ) - # Create the gRPC stubs. - self.cloud_redis_stub = (cloud_redis_pb2_grpc.CloudRedisStub(channel)) - - # Operations client for methods that return long-running operations - # futures. - self.operations_client = ( - google.api_core.operations_v1.OperationsClient(channel)) - if client_info is None: client_info = ( google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO) client_info.gapic_version = _GAPIC_LIBRARY_VERSION + self._client_info = client_info # Parse out the default settings for retry and timeout for each RPC # from the client configuration. # (Ordinarily, these are the defaults specified in the `*_config.py` # file next to this one.) - method_configs = google.api_core.gapic_v1.config.parse_method_configs( + self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( client_config['interfaces'][self._INTERFACE_NAME], ) - # Write the "inner API call" methods to the class. - # These are wrapped versions of the gRPC stub methods, with retry and - # timeout configuration applied, called by the public methods on - # this class. - self._list_instances = google.api_core.gapic_v1.method.wrap_method( - self.cloud_redis_stub.ListInstances, - default_retry=method_configs['ListInstances'].retry, - default_timeout=method_configs['ListInstances'].timeout, - client_info=client_info, - ) - self._get_instance = google.api_core.gapic_v1.method.wrap_method( - self.cloud_redis_stub.GetInstance, - default_retry=method_configs['GetInstance'].retry, - default_timeout=method_configs['GetInstance'].timeout, - client_info=client_info, - ) - self._create_instance = google.api_core.gapic_v1.method.wrap_method( - self.cloud_redis_stub.CreateInstance, - default_retry=method_configs['CreateInstance'].retry, - default_timeout=method_configs['CreateInstance'].timeout, - client_info=client_info, - ) - self._update_instance = google.api_core.gapic_v1.method.wrap_method( - self.cloud_redis_stub.UpdateInstance, - default_retry=method_configs['UpdateInstance'].retry, - default_timeout=method_configs['UpdateInstance'].timeout, - client_info=client_info, - ) - self._delete_instance = google.api_core.gapic_v1.method.wrap_method( - self.cloud_redis_stub.DeleteInstance, - default_retry=method_configs['DeleteInstance'].retry, - default_timeout=method_configs['DeleteInstance'].timeout, - client_info=client_info, - ) + # Save a dictionary of cached API call functions. + # These are the actual callables which invoke the proper + # transport methods, wrapped with `wrap_method` to add retry, + # timeout, and the like. + self._inner_api_calls = {} # Service calls def list_instances(self, @@ -206,21 +222,22 @@ def list_instances(self, >>> >>> parent = client.location_path('[PROJECT]', '[LOCATION]') >>> - >>> >>> # Iterate over all results >>> for element in client.list_instances(parent): ... # process element ... pass >>> - >>> # Or iterate over results one page at a time + >>> + >>> # Alternatively: + >>> + >>> # Iterate over results one page at a time >>> for page in client.list_instances(parent, options=CallOptions(page_token=INITIAL_PAGE)): ... for element in page: ... # process element ... pass Args: - parent (str): Required. The resource name of the instance location using the form: - `projects/{project_id}/locations/{location_id}` + parent (str): Required. The resource name of the instance location using the form ``projects/{project_id}/locations/{location_id}`` where ``location_id`` refers to a GCP region page_size (int): The maximum number of resources contained in the underlying API response. If page streaming is performed per- @@ -249,9 +266,17 @@ def list_instances(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'list_instances' not in self._inner_api_calls: + self._inner_api_calls[ + 'list_instances'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.list_instances, + default_retry=self._method_configs['ListInstances'].retry, + default_timeout=self._method_configs['ListInstances'] + .timeout, + client_info=self._client_info, + ) + request = cloud_redis_pb2.ListInstancesRequest( parent=parent, page_size=page_size, @@ -259,7 +284,7 @@ def list_instances(self, iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( - self._list_instances, + self._inner_api_calls['list_instances'], retry=retry, timeout=timeout, metadata=metadata), @@ -288,8 +313,7 @@ def get_instance(self, >>> response = client.get_instance(name) Args: - name (str): Required. Redis instance resource name using the form: - `projects/{project_id}/locations/{location_id}/instances/{instance_id}` + name (str): Required. Redis instance resource name using the form ``projects/{project_id}/locations/{location_id}/instances/{instance_id}``` where ``location_id`` refers to a GCP region retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will not @@ -310,11 +334,19 @@ def get_instance(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'get_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'get_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.get_instance, + default_retry=self._method_configs['GetInstance'].retry, + default_timeout=self._method_configs['GetInstance'] + .timeout, + client_info=self._client_info, + ) + request = cloud_redis_pb2.GetInstanceRequest(name=name, ) - return self._get_instance( + return self._inner_api_calls['get_instance']( request, retry=retry, timeout=timeout, metadata=metadata) def create_instance(self, @@ -362,11 +394,10 @@ def create_instance(self, >>> metadata = response.metadata() Args: - parent (str): Required. The resource name of the instance location using the form: - `projects/{project_id}/locations/{location_id}` where ``location_id`` refers to a GCP region - instance_id (str): Required. The logical name of the Redis instance in the customer project + parent (str): Required. The resource name of the instance location using the form ``projects/{project_id}/locations/{location_id}`` + where ``location_id`` refers to a GCP region + instance_id (str): Required. The logical name of the Redis instance in the customer project with the following restrictions: - * Must contain only lowercase letters, numbers, and hyphens. * Must start with a letter. * Must be between 1-40 characters. @@ -394,19 +425,27 @@ def create_instance(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'create_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'create_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.create_instance, + default_retry=self._method_configs['CreateInstance'].retry, + default_timeout=self._method_configs['CreateInstance'] + .timeout, + client_info=self._client_info, + ) + request = cloud_redis_pb2.CreateInstanceRequest( parent=parent, instance_id=instance_id, instance=instance, ) - operation = self._create_instance( + operation = self._inner_api_calls['create_instance']( request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, - self.operations_client, + self.transport._operations_client, cloud_redis_pb2.Instance, metadata_type=any_pb2.Any, ) @@ -481,18 +520,26 @@ def update_instance(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'update_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'update_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.update_instance, + default_retry=self._method_configs['UpdateInstance'].retry, + default_timeout=self._method_configs['UpdateInstance'] + .timeout, + client_info=self._client_info, + ) + request = cloud_redis_pb2.UpdateInstanceRequest( update_mask=update_mask, instance=instance, ) - operation = self._update_instance( + operation = self._inner_api_calls['update_instance']( request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, - self.operations_client, + self.transport._operations_client, cloud_redis_pb2.Instance, metadata_type=any_pb2.Any, ) @@ -525,10 +572,9 @@ def delete_instance(self, >>> metadata = response.metadata() Args: - name (str): Required. Redis instance resource name using the form: - `projects/{project_id}/locations/{location_id}/instances/{instance_id}` + name (str): Required. Redis instance resource name using the form ``projects/{project_id}/locations/{location_id}/instances/{instance_id}``` where ``location_id`` refers to a GCP region - retry (Optional[google.api_core.retry.Retry]): A retry object used + retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will not be retried. timeout (Optional[float]): The amount of time, in seconds, to wait @@ -547,15 +593,23 @@ def delete_instance(self, to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ - if metadata is None: - metadata = [] - metadata = list(metadata) + # Wrap the transport method to add retry and timeout logic. + if 'delete_instance' not in self._inner_api_calls: + self._inner_api_calls[ + 'delete_instance'] = google.api_core.gapic_v1.method.wrap_method( + self.transport.delete_instance, + default_retry=self._method_configs['DeleteInstance'].retry, + default_timeout=self._method_configs['DeleteInstance'] + .timeout, + client_info=self._client_info, + ) + request = cloud_redis_pb2.DeleteInstanceRequest(name=name, ) - operation = self._delete_instance( + operation = self._inner_api_calls['delete_instance']( request, retry=retry, timeout=timeout, metadata=metadata) return google.api_core.operation.from_gapic( operation, - self.operations_client, + self.transport._operations_client, empty_pb2.Empty, metadata_type=any_pb2.Any, ) diff --git a/redis/google/cloud/redis_v1beta1/gapic/enums.py b/redis/google/cloud/redis_v1beta1/gapic/enums.py index c245a013f02e..6edc8d81ca31 100644 --- a/redis/google/cloud/redis_v1beta1/gapic/enums.py +++ b/redis/google/cloud/redis_v1beta1/gapic/enums.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,9 +15,11 @@ # limitations under the License. """Wrappers for protocol buffer enum types.""" +import enum + class Instance(object): - class State(object): + class State(enum.IntEnum): """ Represents the different states of a Redis instance. @@ -39,7 +43,7 @@ class State(object): REPAIRING = 5 MAINTENANCE = 6 - class Tier(object): + class Tier(enum.IntEnum): """ Available service tiers to choose from diff --git a/redis/google/cloud/redis_v1beta1/gapic/transports/__init__.py b/redis/google/cloud/redis_v1beta1/gapic/transports/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/redis/google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py b/redis/google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py new file mode 100644 index 000000000000..9666c73560ca --- /dev/null +++ b/redis/google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py @@ -0,0 +1,187 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 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 +# +# https://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 google.api_core.grpc_helpers +import google.api_core.operations_v1 + +from google.cloud.redis_v1beta1.proto import cloud_redis_pb2_grpc + + +class CloudRedisGrpcTransport(object): + """gRPC transport class providing stubs for + google.cloud.redis.v1beta1 CloudRedis API. + + The transport provides access to the raw gRPC stubs, + which can be used to take advantage of advanced + features of gRPC. + """ + # The scopes needed to make gRPC calls to all of the methods defined + # in this service. + _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + + def __init__(self, + channel=None, + credentials=None, + address='redis.googleapis.com:443'): + """Instantiate the transport class. + + Args: + channel (grpc.Channel): A ``Channel`` instance through + which to make calls. This argument is mutually exclusive + with ``credentials``; providing both will raise an exception. + credentials (google.auth.credentials.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If none + are specified, the client will attempt to ascertain the + credentials from the environment. + address (str): The address where the service is hosted. + """ + # If both `channel` and `credentials` are specified, raise an + # exception (channels come with credentials baked in already). + if channel is not None and credentials is not None: + raise ValueError( + 'The `channel` and `credentials` arguments are mutually ' + 'exclusive.', ) + + # Create the channel. + if channel is None: + channel = self.create_channel( + address=address, + credentials=credentials, + ) + + # gRPC uses objects called "stubs" that are bound to the + # channel and provide a basic method for each RPC. + self._stubs = { + 'cloud_redis_stub': cloud_redis_pb2_grpc.CloudRedisStub(channel), + } + + # Because this API includes a method that returns a + # long-running operation (proto: google.longrunning.Operation), + # instantiate an LRO client. + self._operations_client = google.api_core.operations_v1.OperationsClient( + channel) + + @classmethod + def create_channel(cls, + address='redis.googleapis.com:443', + credentials=None): + """Create and return a gRPC channel object. + + Args: + address (str): The host for the channel to use. + credentials (~.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + + Returns: + grpc.Channel: A gRPC channel object. + """ + return google.api_core.grpc_helpers.create_channel( + address, + credentials=credentials, + scopes=cls._OAUTH_SCOPES, + ) + + @property + def list_instances(self): + """Return the gRPC stub for {$apiMethod.name}. + + Lists all Redis instances owned by a project in either the specified + location (region) or all locations. + + The location should have the following format: + * ``projects/{project_id}/locations/{location_id}`` + + If ``location_id`` is specified as ``-`` (wildcard), then all regions + available to the project are queried, and the results are aggregated. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].ListInstances + + @property + def get_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Gets the details of a specific Redis instance. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].GetInstance + + @property + def create_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Creates a Redis instance based on the specified tier and memory size. + + By default, the instance is peered to the project's + `default network `_. + + The creation is executed asynchronously and callers may check the returned + operation to track its progress. Once the operation is completed the Redis + instance will be fully functional. Completed longrunning.Operation will + contain the new instance object in the response field. + + The returned operation is automatically deleted after a few hours, so there + is no need to call DeleteOperation. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].CreateInstance + + @property + def update_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Updates the metadata and configuration of a specific Redis instance. + + Completed longrunning.Operation will contain the new instance object + in the response field. The returned operation is automatically deleted + after a few hours, so there is no need to call DeleteOperation. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].UpdateInstance + + @property + def delete_instance(self): + """Return the gRPC stub for {$apiMethod.name}. + + Deletes a specific Redis instance. Instance stops serving and data is + deleted. + + Returns: + Callable: A callable which accepts the appropriate + deserialized request object and returns a + deserialized response object. + """ + return self._stubs['cloud_redis_stub'].DeleteInstance diff --git a/redis/google/cloud/redis_v1beta1/types.py b/redis/google/cloud/redis_v1beta1/types.py index c854d1fb68d4..d9af4f1dfc0d 100644 --- a/redis/google/cloud/redis_v1beta1/types.py +++ b/redis/google/cloud/redis_v1beta1/types.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +17,10 @@ from __future__ import absolute_import import sys +from google.api_core.protobuf_helpers import get_messages + from google.api import http_pb2 +from google.cloud.redis_v1beta1.proto import cloud_redis_pb2 from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 @@ -24,9 +29,6 @@ from google.protobuf import timestamp_pb2 from google.rpc import status_pb2 -from google.api_core.protobuf_helpers import get_messages -from google.cloud.redis_v1beta1.proto import cloud_redis_pb2 - _shared_modules = [ http_pb2, operations_pb2, @@ -48,7 +50,6 @@ for name, message in get_messages(module).items(): setattr(sys.modules[__name__], name, message) names.append(name) - for module in _local_modules: for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.redis_v1beta1.types' diff --git a/redis/nox.py b/redis/nox.py index 1b99982e76da..964788384a5c 100644 --- a/redis/nox.py +++ b/redis/nox.py @@ -57,7 +57,7 @@ def default(session): @nox.session -@nox.parametrize('py', ['2.7', '3.5', '3.6']) +@nox.parametrize('py', ['2.7', '3.5', '3.6', '3.7']) def unit(session, py): """Run the unit test suite.""" diff --git a/redis/setup.py b/redis/setup.py index c760bf9ccaac..909c71f26fff 100644 --- a/redis/setup.py +++ b/redis/setup.py @@ -21,7 +21,7 @@ # Package metadata. name = 'google-cloud-redis' -description = 'Cloud Redis API client library' +description = 'Google Cloud Memorystore for Redis API client library' version = '0.1.0' # Should be one of: # 'Development Status :: 3 - Alpha' @@ -30,6 +30,7 @@ release_status = 'Development Status :: 3 - Alpha' dependencies = [ 'google-api-core[grpc] >= 0.1.0, < 0.2.0dev', + 'enum34; python_version < "3.4"', ] extras = { } diff --git a/redis/synth.py b/redis/synth.py new file mode 100644 index 000000000000..21c92a28c279 --- /dev/null +++ b/redis/synth.py @@ -0,0 +1,124 @@ +# Copyright 2018 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. + +"""This script is used to synthesize generated parts of this library.""" + +import synthtool as s +import synthtool.gcp as gcp +import logging + +logging.basicConfig(level=logging.DEBUG) + +gapic = gcp.GAPICGenerator() +common = gcp.CommonTemplates() +excludes = [ + 'setup.py', + 'nox.py', + 'docs/conf.py', + 'docs/index.rst', +] + +for version in ['v1beta1', 'v1']: + library = gapic.py_library( + 'redis', version, + config_path=f'artman_redis_{version}.yaml') + + s.copy(library, excludes=excludes) + + +# Fix docstrings +s.replace( + 'google/cloud/**/cloud_redis_client.py', + r'resources of the form:\n ``', + r'resources of the form:\n\n ``',) + +s.replace( + 'google/cloud/**/cloud_redis_client.py', + r""" + parent \(str\): Required. The resource name of the instance location using the form: + :: + + `projects/{project_id}/locations/{location_id}` + where ``location_id`` refers to a GCP region""", + + r""" + parent (str): Required. The resource name of the instance location using the form ``projects/{project_id}/locations/{location_id}`` + where ``location_id`` refers to a GCP region""",) + + +s.replace( + 'google/cloud/**/cloud_redis_client.py', + r""" + with the following restrictions: + + \* Must contain only lowercase letters, numbers, and hyphens\.""", + r""" + with the following restrictions: + * Must contain only lowercase letters, numbers, and hyphens.""") + +s.replace( + 'google/cloud/**/cloud_redis_client.py', + r""" + name \(str\): Required. Redis instance resource name using the form: + :: + + `projects/{project_id}/locations/{location_id}/instances/{instance_id}` + where ``location_id`` refers to a GCP region""", + r""" + name (str): Required. Redis instance resource name using the form ``projects/{project_id}/locations/{location_id}/instances/{instance_id}``` + where ``location_id`` refers to a GCP region""") + +s.replace( + 'google/cloud/**/cloud_redis_client.py', + r""" + fields from ``Instance``: + + \* ``displayName`` + \* ``labels`` + \* ``memorySizeGb`` + \* ``redisConfig``""", + + r""" + fields from ``Instance``: ``displayName``, ``labels``, ``memorySizeGb``, and ``redisConfig``.""",) + +# Set Release Status +release_status = 'Development Status :: 3 - Alpha' +s.replace('setup.py', + '(release_status = )(.*)$', + f"\\1'{release_status}'") + +# Fix the enable API link +s.replace( + 'README.rst', + r'.. _Enable the Google Cloud Memorystore for Redis API.: https://cloud.google.com/redis', + '.. _Enable the Google Cloud Memorystore for Redis API.: https://console.cloud.google.com/apis/' + 'library/redis.googleapis.com') + +# Fix link to product page +s.replace( + 'README.rst', + r'https://cloud.google.com/redis', + 'https://cloud.google.com/memorystore/') + +# Fix link to Client Library Documentation +s.replace( + 'README.rst', + r'https://googlecloudplatform.github.io/google-cloud-python/stable/redis/usage.html', + 'https://googlecloudplatform.github.io/google-cloud-python/latest/redis/index.html') + +# Fix link to Auth instructions +s.replace( + 'README.rst', + r'https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html', + 'https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html') diff --git a/redis/tests/unit/gapic/v1/test_cloud_redis_client_v1.py b/redis/tests/unit/gapic/v1/test_cloud_redis_client_v1.py new file mode 100644 index 000000000000..2da9ecd56390 --- /dev/null +++ b/redis/tests/unit/gapic/v1/test_cloud_redis_client_v1.py @@ -0,0 +1,369 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2018 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 +# +# https://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. +"""Unit tests.""" + +import pytest + +from google.rpc import status_pb2 + +from google.cloud import redis_v1 +from google.cloud.redis_v1 import enums +from google.cloud.redis_v1.proto import cloud_redis_pb2 +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 +from google.protobuf import field_mask_pb2 + + +class MultiCallableStub(object): + """Stub for the grpc.UnaryUnaryMultiCallable interface.""" + + def __init__(self, method, channel_stub): + self.method = method + self.channel_stub = channel_stub + + def __call__(self, request, timeout=None, metadata=None, credentials=None): + self.channel_stub.requests.append((self.method, request)) + + response = None + if self.channel_stub.responses: + response = self.channel_stub.responses.pop() + + if isinstance(response, Exception): + raise response + + if response: + return response + + +class ChannelStub(object): + """Stub for the grpc.Channel interface.""" + + def __init__(self, responses=[]): + self.responses = responses + self.requests = [] + + def unary_unary(self, + method, + request_serializer=None, + response_deserializer=None): + return MultiCallableStub(method, self) + + +class CustomException(Exception): + pass + + +class TestCloudRedisClient(object): + def test_list_instances(self): + # Setup Expected Response + next_page_token = '' + instances_element = {} + instances = [instances_element] + expected_response = { + 'next_page_token': next_page_token, + 'instances': instances + } + expected_response = cloud_redis_pb2.ListInstancesResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + parent = client.location_path('[PROJECT]', '[LOCATION]') + + paged_list_response = client.list_instances(parent) + resources = list(paged_list_response) + assert len(resources) == 1 + + assert expected_response.instances[0] == resources[0] + + assert len(channel.requests) == 1 + expected_request = cloud_redis_pb2.ListInstancesRequest(parent=parent) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_list_instances_exception(self): + channel = ChannelStub(responses=[CustomException()]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup request + parent = client.location_path('[PROJECT]', '[LOCATION]') + + paged_list_response = client.list_instances(parent) + with pytest.raises(CustomException): + list(paged_list_response) + + def test_get_instance(self): + # Setup Expected Response + name_2 = 'name2-1052831874' + display_name = 'displayName1615086568' + location_id = 'locationId552319461' + alternative_location_id = 'alternativeLocationId-718920621' + redis_version = 'redisVersion-685310444' + reserved_ip_range = 'reservedIpRange-1082940580' + host = 'host3208616' + port = 3446913 + current_location_id = 'currentLocationId1312712735' + status_message = 'statusMessage-239442758' + memory_size_gb = 34199707 + authorized_network = 'authorizedNetwork-1733809270' + expected_response = { + 'name': name_2, + 'display_name': display_name, + 'location_id': location_id, + 'alternative_location_id': alternative_location_id, + 'redis_version': redis_version, + 'reserved_ip_range': reserved_ip_range, + 'host': host, + 'port': port, + 'current_location_id': current_location_id, + 'status_message': status_message, + 'memory_size_gb': memory_size_gb, + 'authorized_network': authorized_network + } + expected_response = cloud_redis_pb2.Instance(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + + response = client.get_instance(name) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = cloud_redis_pb2.GetInstanceRequest(name=name) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_get_instance_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup request + name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + + with pytest.raises(CustomException): + client.get_instance(name) + + def test_create_instance(self): + # Setup Expected Response + name = 'name3373707' + display_name = 'displayName1615086568' + location_id = 'locationId552319461' + alternative_location_id = 'alternativeLocationId-718920621' + redis_version = 'redisVersion-685310444' + reserved_ip_range = 'reservedIpRange-1082940580' + host = 'host3208616' + port = 3446913 + current_location_id = 'currentLocationId1312712735' + status_message = 'statusMessage-239442758' + memory_size_gb_2 = 1493816946 + authorized_network = 'authorizedNetwork-1733809270' + expected_response = { + 'name': name, + 'display_name': display_name, + 'location_id': location_id, + 'alternative_location_id': alternative_location_id, + 'redis_version': redis_version, + 'reserved_ip_range': reserved_ip_range, + 'host': host, + 'port': port, + 'current_location_id': current_location_id, + 'status_message': status_message, + 'memory_size_gb': memory_size_gb_2, + 'authorized_network': authorized_network + } + expected_response = cloud_redis_pb2.Instance(**expected_response) + operation = operations_pb2.Operation( + name='operations/test_create_instance', done=True) + operation.response.Pack(expected_response) + + # Mock the API response + channel = ChannelStub(responses=[operation]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + parent = client.location_path('[PROJECT]', '[LOCATION]') + instance_id = 'test_instance' + tier = enums.Instance.Tier.BASIC + memory_size_gb = 1 + instance = {'tier': tier, 'memory_size_gb': memory_size_gb} + + response = client.create_instance(parent, instance_id, instance) + result = response.result() + assert expected_response == result + + assert len(channel.requests) == 1 + expected_request = cloud_redis_pb2.CreateInstanceRequest( + parent=parent, instance_id=instance_id, instance=instance) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_create_instance_exception(self): + # Setup Response + error = status_pb2.Status() + operation = operations_pb2.Operation( + name='operations/test_create_instance_exception', done=True) + operation.error.CopyFrom(error) + + # Mock the API response + channel = ChannelStub(responses=[operation]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + parent = client.location_path('[PROJECT]', '[LOCATION]') + instance_id = 'test_instance' + tier = enums.Instance.Tier.BASIC + memory_size_gb = 1 + instance = {'tier': tier, 'memory_size_gb': memory_size_gb} + + response = client.create_instance(parent, instance_id, instance) + exception = response.exception() + assert exception.errors[0] == error + + def test_update_instance(self): + # Setup Expected Response + name = 'name3373707' + display_name_2 = 'displayName21615000987' + location_id = 'locationId552319461' + alternative_location_id = 'alternativeLocationId-718920621' + redis_version = 'redisVersion-685310444' + reserved_ip_range = 'reservedIpRange-1082940580' + host = 'host3208616' + port = 3446913 + current_location_id = 'currentLocationId1312712735' + status_message = 'statusMessage-239442758' + memory_size_gb_2 = 1493816946 + authorized_network = 'authorizedNetwork-1733809270' + expected_response = { + 'name': name, + 'display_name': display_name_2, + 'location_id': location_id, + 'alternative_location_id': alternative_location_id, + 'redis_version': redis_version, + 'reserved_ip_range': reserved_ip_range, + 'host': host, + 'port': port, + 'current_location_id': current_location_id, + 'status_message': status_message, + 'memory_size_gb': memory_size_gb_2, + 'authorized_network': authorized_network + } + expected_response = cloud_redis_pb2.Instance(**expected_response) + operation = operations_pb2.Operation( + name='operations/test_update_instance', done=True) + operation.response.Pack(expected_response) + + # Mock the API response + channel = ChannelStub(responses=[operation]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + paths_element = 'display_name' + paths_element_2 = 'memory_size_gb' + paths = [paths_element, paths_element_2] + update_mask = {'paths': paths} + display_name = 'UpdatedDisplayName' + memory_size_gb = 4 + instance = { + 'display_name': display_name, + 'memory_size_gb': memory_size_gb + } + + response = client.update_instance(update_mask, instance) + result = response.result() + assert expected_response == result + + assert len(channel.requests) == 1 + expected_request = cloud_redis_pb2.UpdateInstanceRequest( + update_mask=update_mask, instance=instance) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_update_instance_exception(self): + # Setup Response + error = status_pb2.Status() + operation = operations_pb2.Operation( + name='operations/test_update_instance_exception', done=True) + operation.error.CopyFrom(error) + + # Mock the API response + channel = ChannelStub(responses=[operation]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + paths_element = 'display_name' + paths_element_2 = 'memory_size_gb' + paths = [paths_element, paths_element_2] + update_mask = {'paths': paths} + display_name = 'UpdatedDisplayName' + memory_size_gb = 4 + instance = { + 'display_name': display_name, + 'memory_size_gb': memory_size_gb + } + + response = client.update_instance(update_mask, instance) + exception = response.exception() + assert exception.errors[0] == error + + def test_delete_instance(self): + # Setup Expected Response + expected_response = {} + expected_response = empty_pb2.Empty(**expected_response) + operation = operations_pb2.Operation( + name='operations/test_delete_instance', done=True) + operation.response.Pack(expected_response) + + # Mock the API response + channel = ChannelStub(responses=[operation]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + + response = client.delete_instance(name) + result = response.result() + assert expected_response == result + + assert len(channel.requests) == 1 + expected_request = cloud_redis_pb2.DeleteInstanceRequest(name=name) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_delete_instance_exception(self): + # Setup Response + error = status_pb2.Status() + operation = operations_pb2.Operation( + name='operations/test_delete_instance_exception', done=True) + operation.error.CopyFrom(error) + + # Mock the API response + channel = ChannelStub(responses=[operation]) + client = redis_v1.CloudRedisClient(channel=channel) + + # Setup Request + name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]') + + response = client.delete_instance(name) + exception = response.exception() + assert exception.errors[0] == error diff --git a/redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py b/redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py index 72e615802dee..f038f2fb3cc9 100644 --- a/redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py +++ b/redis/tests/unit/gapic/v1beta1/test_cloud_redis_client_v1beta1.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License");