Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit e55220b

Browse files
authored
feat: add ConnectMode and upgrade_instance (#5)
* synthtool * docs: update sample for update_instance * fix: reduce coverage percent
1 parent e402711 commit e55220b

17 files changed

+783
-207
lines changed

google/cloud/redis_v1/gapic/cloud_redis_client.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,10 @@ def update_instance(
557557
>>> paths_element_2 = 'memory_size_gb'
558558
>>> paths = [paths_element, paths_element_2]
559559
>>> update_mask = {'paths': paths}
560-
>>> display_name = ' instance.memory_size_gb=4'
561-
>>> instance = {'display_name': display_name}
560+
>>> display_name = 'UpdatedDisplayName'
561+
>>> name = 'projects/<project-name>/locations/<location>/instances/<instance>'
562+
>>> memory_size_gb = 4
563+
>>> instance = {'display_name': display_name, 'name': name, 'memory_size_gb': memory_size_gb}
562564
>>>
563565
>>> response = client.update_instance(update_mask, instance)
564566
>>>

google/cloud/redis_v1/gapic/enums.py

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
class FailoverInstanceRequest(object):
2323
class DataProtectionMode(enum.IntEnum):
2424
"""
25+
Specifies different modes of operation in relation to the data retention.
26+
2527
Attributes:
2628
DATA_PROTECTION_MODE_UNSPECIFIED (int): Defaults to LIMITED\_DATA\_LOSS if a data protection mode is not
2729
specified.
@@ -38,6 +40,21 @@ class DataProtectionMode(enum.IntEnum):
3840

3941

4042
class Instance(object):
43+
class ConnectMode(enum.IntEnum):
44+
"""
45+
Available connection modes.
46+
47+
Attributes:
48+
CONNECT_MODE_UNSPECIFIED (int): Not set.
49+
DIRECT_PEERING (int): Connect via directly peering with memorystore redis hosted service.
50+
PRIVATE_SERVICE_ACCESS (int): Connect with google via private service access and share connection
51+
across google managed services.
52+
"""
53+
54+
CONNECT_MODE_UNSPECIFIED = 0
55+
DIRECT_PEERING = 1
56+
PRIVATE_SERVICE_ACCESS = 2
57+
4158
class State(enum.IntEnum):
4259
"""
4360
Represents the different states of a Redis instance.

google/cloud/redis_v1/proto/cloud_redis.proto

+37-18
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ service CloudRedis {
5353
// location (region) or all locations.
5454
//
5555
// The location should have the following format:
56+
//
5657
// * `projects/{project_id}/locations/{location_id}`
5758
//
5859
// If `location_id` is specified as `-` (wildcard), then all regions
@@ -230,15 +231,28 @@ message Instance {
230231
STANDARD_HA = 3;
231232
}
232233

234+
// Available connection modes.
235+
enum ConnectMode {
236+
// Not set.
237+
CONNECT_MODE_UNSPECIFIED = 0;
238+
239+
// Connect via directly peering with memorystore redis hosted service.
240+
DIRECT_PEERING = 1;
241+
242+
// Connect with google via private service access and share connection
243+
// across google managed services.
244+
PRIVATE_SERVICE_ACCESS = 2;
245+
}
246+
233247
// Required. Unique name of the resource in this scope including project and
234248
// location using the form:
235249
// `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
236250
//
237251
// Note: Redis instances are managed and addressed at regional level so
238252
// location_id here refers to a GCP region; however, users may choose which
239253
// specific zone (or collection of zones for cross-zone instances) an instance
240-
// should be provisioned in. Refer to [location_id] and
241-
// [alternative_location_id] fields for more details.
254+
// should be provisioned in. Refer to [location_id][google.cloud.redis.v1.Instance.location_id] and
255+
// [alternative_location_id][google.cloud.redis.v1.Instance.alternative_location_id] fields for more details.
242256
string name = 1 [(google.api.field_behavior) = REQUIRED];
243257

244258
// An arbitrary and optional user-provided name for the instance.
@@ -250,19 +264,18 @@ message Instance {
250264
// Optional. The zone where the instance will be provisioned. If not provided,
251265
// the service will choose a zone for the instance. For STANDARD_HA tier,
252266
// instances will be created across two zones for protection against zonal
253-
// failures. If [alternative_location_id] is also provided, it must be
254-
// different from [location_id].
267+
// failures. If [alternative_location_id][google.cloud.redis.v1.Instance.alternative_location_id] is also provided, it must be
268+
// different from [location_id][google.cloud.redis.v1.Instance.location_id].
255269
string location_id = 4 [(google.api.field_behavior) = OPTIONAL];
256270

257271
// Optional. Only applicable to STANDARD_HA tier which protects the instance
258272
// against zonal failures by provisioning it across two zones. If provided, it
259-
// must be a different zone from the one provided in [location_id].
273+
// must be a different zone from the one provided in [location_id][google.cloud.redis.v1.Instance.location_id].
260274
string alternative_location_id = 5 [(google.api.field_behavior) = OPTIONAL];
261275

262276
// Optional. The version of Redis software.
263-
// If not provided, latest supported version will be used. Updating the
264-
// version will perform an upgrade/downgrade to the new version. Currently,
265-
// the supported values are:
277+
// If not provided, latest supported version will be used. Currently, the
278+
// supported values are:
266279
//
267280
// * `REDIS_4_0` for Redis 4.0 compatibility (default)
268281
// * `REDIS_3_2` for Redis 3.2 compatibility
@@ -282,9 +295,9 @@ message Instance {
282295
int32 port = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
283296

284297
// Output only. The current zone where the Redis endpoint is placed. For Basic
285-
// Tier instances, this will always be the same as the [location_id]
298+
// Tier instances, this will always be the same as the [location_id][google.cloud.redis.v1.Instance.location_id]
286299
// provided by the user at creation time. For Standard Tier instances,
287-
// this can be either [location_id] or [alternative_location_id] and can
300+
// 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
288301
// change after a failover event.
289302
string current_location_id = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
290303

@@ -332,6 +345,11 @@ message Instance {
332345
// for a given instance so should be checked before each import/export
333346
// operation.
334347
string persistence_iam_identity = 21 [(google.api.field_behavior) = OUTPUT_ONLY];
348+
349+
// Optional. The connect mode of Redis instance.
350+
// If not provided, default one will be used.
351+
// Current default: DIRECT_PEERING.
352+
ConnectMode connect_mode = 22 [(google.api.field_behavior) = OPTIONAL];
335353
}
336354

337355
// Request for [ListInstances][google.cloud.redis.v1.CloudRedis.ListInstances].
@@ -351,12 +369,12 @@ message ListInstancesRequest {
351369
// If not specified, a default value of 1000 will be used by the service.
352370
// Regardless of the page_size value, the response may include a partial list
353371
// and a caller should only rely on response's
354-
// [next_page_token][CloudRedis.ListInstancesResponse.next_page_token]
372+
// [`next_page_token`][google.cloud.redis.v1.ListInstancesResponse.next_page_token]
355373
// to determine if there are more instances left to be queried.
356374
int32 page_size = 2;
357375

358-
// The next_page_token value returned from a previous List request,
359-
// if any.
376+
// The `next_page_token` value returned from a previous
377+
// [ListInstances][google.cloud.redis.v1.CloudRedis.ListInstances] request, if any.
360378
string page_token = 3;
361379
}
362380

@@ -368,10 +386,10 @@ message ListInstancesResponse {
368386
// If the `location_id` in the parent field of the request is "-", all regions
369387
// available to the project are queried, and the results aggregated.
370388
// If in such an aggregated query a location is unavailable, a dummy Redis
371-
// entry is included in the response with the "name" field set to a value of
372-
// the form projects/{project_id}/locations/{location_id}/instances/- and the
373-
// "status" field set to ERROR and "status_message" field set to "location not
374-
// available for ListInstances".
389+
// entry is included in the response with the `name` field set to a value of
390+
// the form `projects/{project_id}/locations/{location_id}/instances/`- and
391+
// the `status` field set to ERROR and `status_message` field set to "location
392+
// not available for ListInstances".
375393
repeated Instance instances = 1;
376394

377395
// Token to retrieve the next page of results, or empty if there are no more
@@ -425,7 +443,7 @@ message CreateInstanceRequest {
425443
message UpdateInstanceRequest {
426444
// Required. Mask of fields to update. At least one path must be supplied in
427445
// this field. The elements of the repeated paths field may only include these
428-
// fields from [Instance][CloudRedis.Instance]:
446+
// fields from [Instance][google.cloud.redis.v1.Instance]:
429447
//
430448
// * `displayName`
431449
// * `labels`
@@ -506,6 +524,7 @@ message ExportInstanceRequest {
506524

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

google/cloud/redis_v1/proto/cloud_redis_pb2.py

+137-75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

google/cloud/redis_v1/proto/cloud_redis_pb2_grpc.py

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def ListInstances(self, request, context):
9898
location (region) or all locations.
9999
100100
The location should have the following format:
101+
101102
* `projects/{project_id}/locations/{location_id}`
102103
103104
If `location_id` is specified as `-` (wildcard), then all regions

google/cloud/redis_v1beta1/gapic/cloud_redis_client.py

+96-1
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,9 @@ def update_instance(
559559
>>> paths = [paths_element, paths_element_2]
560560
>>> update_mask = {'paths': paths}
561561
>>> display_name = 'UpdatedDisplayName'
562+
>>> name = 'projects/<project-name>/locations/<location>/instances/<instance>'
562563
>>> memory_size_gb = 4
563-
>>> instance = {'display_name': display_name, 'memory_size_gb': memory_size_gb}
564+
>>> instance = {'display_name': display_name, 'name': name, 'memory_size_gb': memory_size_gb}
564565
>>>
565566
>>> response = client.update_instance(update_mask, instance)
566567
>>>
@@ -1031,3 +1032,97 @@ def delete_instance(
10311032
empty_pb2.Empty,
10321033
metadata_type=any_pb2.Any,
10331034
)
1035+
1036+
def upgrade_instance(
1037+
self,
1038+
name,
1039+
redis_version,
1040+
retry=google.api_core.gapic_v1.method.DEFAULT,
1041+
timeout=google.api_core.gapic_v1.method.DEFAULT,
1042+
metadata=None,
1043+
):
1044+
"""
1045+
Upgrades Redis instance to the newer Redis version specified in the
1046+
request.
1047+
1048+
Example:
1049+
>>> from google.cloud import redis_v1beta1
1050+
>>>
1051+
>>> client = redis_v1beta1.CloudRedisClient()
1052+
>>>
1053+
>>> name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]')
1054+
>>>
1055+
>>> # TODO: Initialize `redis_version`:
1056+
>>> redis_version = ''
1057+
>>>
1058+
>>> response = client.upgrade_instance(name, redis_version)
1059+
>>>
1060+
>>> def callback(operation_future):
1061+
... # Handle result.
1062+
... result = operation_future.result()
1063+
>>>
1064+
>>> response.add_done_callback(callback)
1065+
>>>
1066+
>>> # Handle metadata.
1067+
>>> metadata = response.metadata()
1068+
1069+
Args:
1070+
name (str): Required. Redis instance resource name using the form:
1071+
``projects/{project_id}/locations/{location_id}/instances/{instance_id}``
1072+
where ``location_id`` refers to a GCP region.
1073+
redis_version (str): Required. Specifies the target version of Redis software to upgrade to.
1074+
retry (Optional[google.api_core.retry.Retry]): A retry object used
1075+
to retry requests. If ``None`` is specified, requests will
1076+
be retried using a default configuration.
1077+
timeout (Optional[float]): The amount of time, in seconds, to wait
1078+
for the request to complete. Note that if ``retry`` is
1079+
specified, the timeout applies to each individual attempt.
1080+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
1081+
that is provided to the method.
1082+
1083+
Returns:
1084+
A :class:`~google.cloud.redis_v1beta1.types._OperationFuture` instance.
1085+
1086+
Raises:
1087+
google.api_core.exceptions.GoogleAPICallError: If the request
1088+
failed for any reason.
1089+
google.api_core.exceptions.RetryError: If the request failed due
1090+
to a retryable error and retry attempts failed.
1091+
ValueError: If the parameters are invalid.
1092+
"""
1093+
# Wrap the transport method to add retry and timeout logic.
1094+
if "upgrade_instance" not in self._inner_api_calls:
1095+
self._inner_api_calls[
1096+
"upgrade_instance"
1097+
] = google.api_core.gapic_v1.method.wrap_method(
1098+
self.transport.upgrade_instance,
1099+
default_retry=self._method_configs["UpgradeInstance"].retry,
1100+
default_timeout=self._method_configs["UpgradeInstance"].timeout,
1101+
client_info=self._client_info,
1102+
)
1103+
1104+
request = cloud_redis_pb2.UpgradeInstanceRequest(
1105+
name=name, redis_version=redis_version
1106+
)
1107+
if metadata is None:
1108+
metadata = []
1109+
metadata = list(metadata)
1110+
try:
1111+
routing_header = [("name", name)]
1112+
except AttributeError:
1113+
pass
1114+
else:
1115+
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
1116+
routing_header
1117+
)
1118+
metadata.append(routing_metadata)
1119+
1120+
operation = self._inner_api_calls["upgrade_instance"](
1121+
request, retry=retry, timeout=timeout, metadata=metadata
1122+
)
1123+
return google.api_core.operation.from_gapic(
1124+
operation,
1125+
self.transport._operations_client,
1126+
cloud_redis_pb2.Instance,
1127+
metadata_type=any_pb2.Any,
1128+
)

google/cloud/redis_v1beta1/gapic/cloud_redis_client_config.py

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
"retry_codes_name": "non_idempotent",
5858
"retry_params_name": "default",
5959
},
60+
"UpgradeInstance": {
61+
"timeout_millis": 60000,
62+
"retry_codes_name": "non_idempotent",
63+
"retry_params_name": "default",
64+
},
6065
},
6166
}
6267
}

google/cloud/redis_v1beta1/gapic/enums.py

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
class FailoverInstanceRequest(object):
2323
class DataProtectionMode(enum.IntEnum):
2424
"""
25+
Specifies different modes of operation in relation to the data retention.
26+
2527
Attributes:
2628
DATA_PROTECTION_MODE_UNSPECIFIED (int): Defaults to LIMITED\_DATA\_LOSS if a data protection mode is not
2729
specified.
@@ -38,6 +40,21 @@ class DataProtectionMode(enum.IntEnum):
3840

3941

4042
class Instance(object):
43+
class ConnectMode(enum.IntEnum):
44+
"""
45+
Available connection modes.
46+
47+
Attributes:
48+
CONNECT_MODE_UNSPECIFIED (int): Not set.
49+
DIRECT_PEERING (int): Connect via directly peering with memorystore redis hosted service.
50+
PRIVATE_SERVICE_ACCESS (int): Connect with google via private service access and share connection
51+
across google managed services.
52+
"""
53+
54+
CONNECT_MODE_UNSPECIFIED = 0
55+
DIRECT_PEERING = 1
56+
PRIVATE_SERVICE_ACCESS = 2
57+
4158
class State(enum.IntEnum):
4259
"""
4360
Represents the different states of a Redis instance.

google/cloud/redis_v1beta1/gapic/transports/cloud_redis_grpc_transport.py

+14
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,17 @@ def delete_instance(self):
254254
deserialized response object.
255255
"""
256256
return self._stubs["cloud_redis_stub"].DeleteInstance
257+
258+
@property
259+
def upgrade_instance(self):
260+
"""Return the gRPC stub for :meth:`CloudRedisClient.upgrade_instance`.
261+
262+
Upgrades Redis instance to the newer Redis version specified in the
263+
request.
264+
265+
Returns:
266+
Callable: A callable which accepts the appropriate
267+
deserialized request object and returns a
268+
deserialized response object.
269+
"""
270+
return self._stubs["cloud_redis_stub"].UpgradeInstance

0 commit comments

Comments
 (0)