Skip to content

Commit

Permalink
feat: add ConnectMode and upgrade_instance (#5)
Browse files Browse the repository at this point in the history
* synthtool

* docs: update sample for update_instance

* fix: reduce coverage percent
  • Loading branch information
crwilcox authored Feb 12, 2020
1 parent fce8a98 commit efec3f7
Show file tree
Hide file tree
Showing 17 changed files with 783 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,10 @@ def update_instance(
>>> paths_element_2 = 'memory_size_gb'
>>> paths = [paths_element, paths_element_2]
>>> update_mask = {'paths': paths}
>>> display_name = ' instance.memory_size_gb=4'
>>> instance = {'display_name': display_name}
>>> display_name = 'UpdatedDisplayName'
>>> name = 'projects/<project-name>/locations/<location>/instances/<instance>'
>>> memory_size_gb = 4
>>> instance = {'display_name': display_name, 'name': name, 'memory_size_gb': memory_size_gb}
>>>
>>> response = client.update_instance(update_mask, instance)
>>>
Expand Down
17 changes: 17 additions & 0 deletions packages/google-cloud-redis/google/cloud/redis_v1/gapic/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
class FailoverInstanceRequest(object):
class DataProtectionMode(enum.IntEnum):
"""
Specifies different modes of operation in relation to the data retention.
Attributes:
DATA_PROTECTION_MODE_UNSPECIFIED (int): Defaults to LIMITED\_DATA\_LOSS if a data protection mode is not
specified.
Expand All @@ -38,6 +40,21 @@ class DataProtectionMode(enum.IntEnum):


class Instance(object):
class ConnectMode(enum.IntEnum):
"""
Available connection modes.
Attributes:
CONNECT_MODE_UNSPECIFIED (int): Not set.
DIRECT_PEERING (int): Connect via directly peering with memorystore redis hosted service.
PRIVATE_SERVICE_ACCESS (int): Connect with google via private service access and share connection
across google managed services.
"""

CONNECT_MODE_UNSPECIFIED = 0
DIRECT_PEERING = 1
PRIVATE_SERVICE_ACCESS = 2

class State(enum.IntEnum):
"""
Represents the different states of a Redis instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ service CloudRedis {
// 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
Expand Down Expand Up @@ -230,15 +231,28 @@ message Instance {
STANDARD_HA = 3;
}

// Available connection modes.
enum ConnectMode {
// Not set.
CONNECT_MODE_UNSPECIFIED = 0;

// Connect via directly peering with memorystore redis hosted service.
DIRECT_PEERING = 1;

// Connect with google via private service access and share connection
// across google managed services.
PRIVATE_SERVICE_ACCESS = 2;
}

// Required. Unique name of the resource in this scope including project and
// location using the form:
// `projects/{project_id}/locations/{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.
// should be provisioned in. Refer to [location_id][google.cloud.redis.v1.Instance.location_id] and
// [alternative_location_id][google.cloud.redis.v1.Instance.alternative_location_id] fields for more details.
string name = 1 [(google.api.field_behavior) = REQUIRED];

// An arbitrary and optional user-provided name for the instance.
Expand All @@ -250,19 +264,18 @@ message Instance {
// 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].
// failures. If [alternative_location_id][google.cloud.redis.v1.Instance.alternative_location_id] is also provided, it must be
// different from [location_id][google.cloud.redis.v1.Instance.location_id].
string location_id = 4 [(google.api.field_behavior) = OPTIONAL];

// 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].
// must be a different zone from the one provided in [location_id][google.cloud.redis.v1.Instance.location_id].
string alternative_location_id = 5 [(google.api.field_behavior) = OPTIONAL];

// 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:
// If not provided, latest supported version will be used. Currently, the
// supported values are:
//
// * `REDIS_4_0` for Redis 4.0 compatibility (default)
// * `REDIS_3_2` for Redis 3.2 compatibility
Expand All @@ -282,9 +295,9 @@ message Instance {
int32 port = 11 [(google.api.field_behavior) = OUTPUT_ONLY];

// 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]
// Tier instances, this will always be the same as the [location_id][google.cloud.redis.v1.Instance.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
// this can be either [location_id][google.cloud.redis.v1.Instance.location_id] or [alternative_location_id][google.cloud.redis.v1.Instance.alternative_location_id] and can
// change after a failover event.
string current_location_id = 12 [(google.api.field_behavior) = OUTPUT_ONLY];

Expand Down Expand Up @@ -332,6 +345,11 @@ message Instance {
// for a given instance so should be checked before each import/export
// operation.
string persistence_iam_identity = 21 [(google.api.field_behavior) = OUTPUT_ONLY];

// Optional. The connect mode of Redis instance.
// If not provided, default one will be used.
// Current default: DIRECT_PEERING.
ConnectMode connect_mode = 22 [(google.api.field_behavior) = OPTIONAL];
}

// Request for [ListInstances][google.cloud.redis.v1.CloudRedis.ListInstances].
Expand All @@ -351,12 +369,12 @@ message ListInstancesRequest {
// 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]
// [`next_page_token`][google.cloud.redis.v1.ListInstancesResponse.next_page_token]
// to determine if there are more instances left to be queried.
int32 page_size = 2;

// The next_page_token value returned from a previous List request,
// if any.
// The `next_page_token` value returned from a previous
// [ListInstances][google.cloud.redis.v1.CloudRedis.ListInstances] request, if any.
string page_token = 3;
}

Expand All @@ -368,10 +386,10 @@ message ListInstancesResponse {
// 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".
// 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".
repeated Instance instances = 1;

// Token to retrieve the next page of results, or empty if there are no more
Expand Down Expand Up @@ -425,7 +443,7 @@ message CreateInstanceRequest {
message UpdateInstanceRequest {
// 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]:
// fields from [Instance][google.cloud.redis.v1.Instance]:
//
// * `displayName`
// * `labels`
Expand Down Expand Up @@ -506,6 +524,7 @@ message ExportInstanceRequest {

// Request for [Failover][google.cloud.redis.v1.CloudRedis.FailoverInstance].
message FailoverInstanceRequest {
// Specifies different modes of operation in relation to the data retention.
enum DataProtectionMode {
// Defaults to LIMITED_DATA_LOSS if a data protection mode is not
// specified.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def ListInstances(self, request, context):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,9 @@ def update_instance(
>>> paths = [paths_element, paths_element_2]
>>> update_mask = {'paths': paths}
>>> display_name = 'UpdatedDisplayName'
>>> name = 'projects/<project-name>/locations/<location>/instances/<instance>'
>>> memory_size_gb = 4
>>> instance = {'display_name': display_name, 'memory_size_gb': memory_size_gb}
>>> instance = {'display_name': display_name, 'name': name, 'memory_size_gb': memory_size_gb}
>>>
>>> response = client.update_instance(update_mask, instance)
>>>
Expand Down Expand Up @@ -1031,3 +1032,97 @@ def delete_instance(
empty_pb2.Empty,
metadata_type=any_pb2.Any,
)

def upgrade_instance(
self,
name,
redis_version,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Upgrades Redis instance to the newer Redis version specified in the
request.
Example:
>>> from google.cloud import redis_v1beta1
>>>
>>> client = redis_v1beta1.CloudRedisClient()
>>>
>>> name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]')
>>>
>>> # TODO: Initialize `redis_version`:
>>> redis_version = ''
>>>
>>> response = client.upgrade_instance(name, redis_version)
>>>
>>> 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.
redis_version (str): Required. Specifies the target version of Redis software to upgrade to.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
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_v1beta1.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 "upgrade_instance" not in self._inner_api_calls:
self._inner_api_calls[
"upgrade_instance"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.upgrade_instance,
default_retry=self._method_configs["UpgradeInstance"].retry,
default_timeout=self._method_configs["UpgradeInstance"].timeout,
client_info=self._client_info,
)

request = cloud_redis_pb2.UpgradeInstanceRequest(
name=name, redis_version=redis_version
)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("name", name)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)

operation = self._inner_api_calls["upgrade_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=any_pb2.Any,
)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"UpgradeInstance": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
class FailoverInstanceRequest(object):
class DataProtectionMode(enum.IntEnum):
"""
Specifies different modes of operation in relation to the data retention.
Attributes:
DATA_PROTECTION_MODE_UNSPECIFIED (int): Defaults to LIMITED\_DATA\_LOSS if a data protection mode is not
specified.
Expand All @@ -38,6 +40,21 @@ class DataProtectionMode(enum.IntEnum):


class Instance(object):
class ConnectMode(enum.IntEnum):
"""
Available connection modes.
Attributes:
CONNECT_MODE_UNSPECIFIED (int): Not set.
DIRECT_PEERING (int): Connect via directly peering with memorystore redis hosted service.
PRIVATE_SERVICE_ACCESS (int): Connect with google via private service access and share connection
across google managed services.
"""

CONNECT_MODE_UNSPECIFIED = 0
DIRECT_PEERING = 1
PRIVATE_SERVICE_ACCESS = 2

class State(enum.IntEnum):
"""
Represents the different states of a Redis instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,17 @@ def delete_instance(self):
deserialized response object.
"""
return self._stubs["cloud_redis_stub"].DeleteInstance

@property
def upgrade_instance(self):
"""Return the gRPC stub for :meth:`CloudRedisClient.upgrade_instance`.
Upgrades Redis instance to the newer Redis version specified in the
request.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["cloud_redis_stub"].UpgradeInstance
Loading

0 comments on commit efec3f7

Please sign in to comment.