google-cloud-bigtable 2.30.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. google/cloud/bigtable/__init__.py +25 -0
  2. google/cloud/bigtable/app_profile.py +377 -0
  3. google/cloud/bigtable/backup.py +490 -0
  4. google/cloud/bigtable/batcher.py +414 -0
  5. google/cloud/bigtable/client.py +475 -0
  6. google/cloud/bigtable/cluster.py +541 -0
  7. google/cloud/bigtable/column_family.py +362 -0
  8. google/cloud/bigtable/data/__init__.py +103 -0
  9. google/cloud/bigtable/data/_async/__init__.py +25 -0
  10. google/cloud/bigtable/data/_async/_mutate_rows.py +226 -0
  11. google/cloud/bigtable/data/_async/_read_rows.py +363 -0
  12. google/cloud/bigtable/data/_async/client.py +1522 -0
  13. google/cloud/bigtable/data/_async/mutations_batcher.py +534 -0
  14. google/cloud/bigtable/data/_cross_sync/__init__.py +20 -0
  15. google/cloud/bigtable/data/_cross_sync/_decorators.py +441 -0
  16. google/cloud/bigtable/data/_cross_sync/_mapping_meta.py +64 -0
  17. google/cloud/bigtable/data/_cross_sync/cross_sync.py +334 -0
  18. google/cloud/bigtable/data/_helpers.py +249 -0
  19. google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py +182 -0
  20. google/cloud/bigtable/data/_sync_autogen/_read_rows.py +304 -0
  21. google/cloud/bigtable/data/_sync_autogen/client.py +1293 -0
  22. google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py +449 -0
  23. google/cloud/bigtable/data/exceptions.py +340 -0
  24. google/cloud/bigtable/data/execute_query/__init__.py +43 -0
  25. google/cloud/bigtable/data/execute_query/_async/__init__.py +13 -0
  26. google/cloud/bigtable/data/execute_query/_async/execute_query_iterator.py +291 -0
  27. google/cloud/bigtable/data/execute_query/_byte_cursor.py +123 -0
  28. google/cloud/bigtable/data/execute_query/_checksum.py +43 -0
  29. google/cloud/bigtable/data/execute_query/_parameters_formatting.py +155 -0
  30. google/cloud/bigtable/data/execute_query/_query_result_parsing_utils.py +134 -0
  31. google/cloud/bigtable/data/execute_query/_reader.py +122 -0
  32. google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py +239 -0
  33. google/cloud/bigtable/data/execute_query/metadata.py +399 -0
  34. google/cloud/bigtable/data/execute_query/values.py +123 -0
  35. google/cloud/bigtable/data/mutations.py +380 -0
  36. google/cloud/bigtable/data/read_modify_write_rules.py +112 -0
  37. google/cloud/bigtable/data/read_rows_query.py +536 -0
  38. google/cloud/bigtable/data/row.py +535 -0
  39. google/cloud/bigtable/data/row_filters.py +968 -0
  40. google/cloud/bigtable/encryption_info.py +64 -0
  41. google/cloud/bigtable/enums.py +223 -0
  42. google/cloud/bigtable/error.py +64 -0
  43. google/cloud/bigtable/gapic_version.py +16 -0
  44. google/cloud/bigtable/helpers.py +31 -0
  45. google/cloud/bigtable/instance.py +789 -0
  46. google/cloud/bigtable/policy.py +255 -0
  47. google/cloud/bigtable/row.py +1267 -0
  48. google/cloud/bigtable/row_data.py +380 -0
  49. google/cloud/bigtable/row_filters.py +838 -0
  50. google/cloud/bigtable/row_merger.py +250 -0
  51. google/cloud/bigtable/row_set.py +213 -0
  52. google/cloud/bigtable/table.py +1409 -0
  53. google/cloud/bigtable_admin/__init__.py +410 -0
  54. google/cloud/bigtable_admin/gapic_version.py +16 -0
  55. google/cloud/bigtable_admin/py.typed +2 -0
  56. google/cloud/bigtable_admin_v2/__init__.py +250 -0
  57. google/cloud/bigtable_admin_v2/gapic_metadata.json +962 -0
  58. google/cloud/bigtable_admin_v2/gapic_version.py +16 -0
  59. google/cloud/bigtable_admin_v2/py.typed +2 -0
  60. google/cloud/bigtable_admin_v2/services/__init__.py +15 -0
  61. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/__init__.py +22 -0
  62. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py +3465 -0
  63. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py +3944 -0
  64. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py +681 -0
  65. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/__init__.py +40 -0
  66. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py +751 -0
  67. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py +1249 -0
  68. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py +1579 -0
  69. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py +6820 -0
  70. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py +1746 -0
  71. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/__init__.py +22 -0
  72. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py +3472 -0
  73. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py +3949 -0
  74. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py +669 -0
  75. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/__init__.py +40 -0
  76. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py +708 -0
  77. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py +1257 -0
  78. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py +1549 -0
  79. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py +6609 -0
  80. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py +1714 -0
  81. google/cloud/bigtable_admin_v2/types/__init__.py +248 -0
  82. google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py +1364 -0
  83. google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py +1715 -0
  84. google/cloud/bigtable_admin_v2/types/common.py +81 -0
  85. google/cloud/bigtable_admin_v2/types/instance.py +819 -0
  86. google/cloud/bigtable_admin_v2/types/table.py +1028 -0
  87. google/cloud/bigtable_admin_v2/types/types.py +776 -0
  88. google/cloud/bigtable_v2/__init__.py +136 -0
  89. google/cloud/bigtable_v2/gapic_metadata.json +193 -0
  90. google/cloud/bigtable_v2/gapic_version.py +16 -0
  91. google/cloud/bigtable_v2/py.typed +2 -0
  92. google/cloud/bigtable_v2/services/__init__.py +15 -0
  93. google/cloud/bigtable_v2/services/bigtable/__init__.py +22 -0
  94. google/cloud/bigtable_v2/services/bigtable/async_client.py +1741 -0
  95. google/cloud/bigtable_v2/services/bigtable/client.py +2194 -0
  96. google/cloud/bigtable_v2/services/bigtable/transports/__init__.py +38 -0
  97. google/cloud/bigtable_v2/services/bigtable/transports/base.py +343 -0
  98. google/cloud/bigtable_v2/services/bigtable/transports/grpc.py +660 -0
  99. google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py +762 -0
  100. google/cloud/bigtable_v2/services/bigtable/transports/rest.py +2489 -0
  101. google/cloud/bigtable_v2/services/bigtable/transports/rest_base.py +711 -0
  102. google/cloud/bigtable_v2/types/__init__.py +138 -0
  103. google/cloud/bigtable_v2/types/bigtable.py +1531 -0
  104. google/cloud/bigtable_v2/types/data.py +1612 -0
  105. google/cloud/bigtable_v2/types/feature_flags.py +119 -0
  106. google/cloud/bigtable_v2/types/request_stats.py +171 -0
  107. google/cloud/bigtable_v2/types/response_params.py +64 -0
  108. google/cloud/bigtable_v2/types/types.py +579 -0
  109. google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_admin_v2_keywords.py +233 -0
  110. google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_v2_keywords.py +186 -0
  111. google_cloud_bigtable-2.30.0.dist-info/LICENSE +202 -0
  112. google_cloud_bigtable-2.30.0.dist-info/METADATA +154 -0
  113. google_cloud_bigtable-2.30.0.dist-info/RECORD +115 -0
  114. google_cloud_bigtable-2.30.0.dist-info/WHEEL +5 -0
  115. google_cloud_bigtable-2.30.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,541 @@
1
+ # Copyright 2015 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """User friendly container for Google Cloud Bigtable Cluster."""
16
+
17
+
18
+ import re
19
+ from google.cloud.bigtable_admin_v2.types import instance
20
+ from google.api_core.exceptions import NotFound
21
+ from google.protobuf import field_mask_pb2
22
+
23
+
24
+ _CLUSTER_NAME_RE = re.compile(
25
+ r"^projects/(?P<project>[^/]+)/"
26
+ r"instances/(?P<instance>[^/]+)/clusters/"
27
+ r"(?P<cluster_id>[a-z][-a-z0-9]*)$"
28
+ )
29
+
30
+
31
+ class Cluster(object):
32
+ """Representation of a Google Cloud Bigtable Cluster.
33
+
34
+ We can use a :class:`Cluster` to:
35
+
36
+ * :meth:`reload` itself
37
+ * :meth:`create` itself
38
+ * :meth:`update` itself
39
+ * :meth:`delete` itself
40
+ * :meth:`disable_autoscaling` itself
41
+
42
+ :type cluster_id: str
43
+ :param cluster_id: The ID of the cluster.
44
+
45
+ :type instance: :class:`~google.cloud.bigtable.instance.Instance`
46
+ :param instance: The instance where the cluster resides.
47
+
48
+ :type location_id: str
49
+ :param location_id: (Creation Only) The location where this cluster's
50
+ nodes and storage reside . For best performance,
51
+ clients should be located as close as possible to
52
+ this cluster.
53
+ For list of supported locations refer to
54
+ https://cloud.google.com/bigtable/docs/locations
55
+
56
+ :type serve_nodes: int
57
+ :param serve_nodes: (Optional) The number of nodes in the cluster for manual scaling. If any of the
58
+ autoscaling configuration are specified, then the autoscaling
59
+ configuration will take precedent.
60
+
61
+ :type default_storage_type: int
62
+ :param default_storage_type: (Optional) The type of storage
63
+ Possible values are represented by the
64
+ following constants:
65
+ :data:`google.cloud.bigtable.enums.StorageType.SSD`.
66
+ :data:`google.cloud.bigtable.enums.StorageType.HDD`,
67
+ Defaults to
68
+ :data:`google.cloud.bigtable.enums.StorageType.UNSPECIFIED`.
69
+
70
+ :type kms_key_name: str
71
+ :param kms_key_name: (Optional, Creation Only) The name of the KMS customer managed
72
+ encryption key (CMEK) to use for at-rest encryption of data in
73
+ this cluster. If omitted, Google's default encryption will be
74
+ used. If specified, the requirements for this key are:
75
+
76
+ 1) The Cloud Bigtable service account associated with the
77
+ project that contains the cluster must be granted the
78
+ ``cloudkms.cryptoKeyEncrypterDecrypter`` role on the CMEK.
79
+ 2) Only regional keys can be used and the region of the CMEK
80
+ key must match the region of the cluster.
81
+ 3) All clusters within an instance must use the same CMEK key.
82
+
83
+ :type _state: int
84
+ :param _state: (`OutputOnly`)
85
+ The current state of the cluster.
86
+ Possible values are represented by the following constants:
87
+ :data:`google.cloud.bigtable.enums.Cluster.State.NOT_KNOWN`.
88
+ :data:`google.cloud.bigtable.enums.Cluster.State.READY`.
89
+ :data:`google.cloud.bigtable.enums.Cluster.State.CREATING`.
90
+ :data:`google.cloud.bigtable.enums.Cluster.State.RESIZING`.
91
+ :data:`google.cloud.bigtable.enums.Cluster.State.DISABLED`.
92
+
93
+ :type min_serve_nodes: int
94
+ :param min_serve_nodes: (Optional) The minimum number of nodes to be set in the cluster for autoscaling.
95
+ Must be 1 or greater.
96
+ If specified, this configuration takes precedence over
97
+ ``serve_nodes``.
98
+ If specified, then
99
+ ``max_serve_nodes`` and ``cpu_utilization_percent`` must be
100
+ specified too.
101
+
102
+ :type max_serve_nodes: int
103
+ :param max_serve_nodes: (Optional) The maximum number of nodes to be set in the cluster for autoscaling.
104
+ If specified, this configuration
105
+ takes precedence over ``serve_nodes``. If specified, then
106
+ ``min_serve_nodes`` and ``cpu_utilization_percent`` must be
107
+ specified too.
108
+
109
+ :param cpu_utilization_percent: (Optional) The CPU utilization target for the cluster's workload for autoscaling.
110
+ If specified, this configuration takes precedence over ``serve_nodes``. If specified, then
111
+ ``min_serve_nodes`` and ``max_serve_nodes`` must be
112
+ specified too.
113
+ """
114
+
115
+ def __init__(
116
+ self,
117
+ cluster_id,
118
+ instance,
119
+ location_id=None,
120
+ serve_nodes=None,
121
+ default_storage_type=None,
122
+ kms_key_name=None,
123
+ _state=None,
124
+ min_serve_nodes=None,
125
+ max_serve_nodes=None,
126
+ cpu_utilization_percent=None,
127
+ ):
128
+ self.cluster_id = cluster_id
129
+ self._instance = instance
130
+ self.location_id = location_id
131
+ self.serve_nodes = serve_nodes
132
+ self.default_storage_type = default_storage_type
133
+ self._kms_key_name = kms_key_name
134
+ self._state = _state
135
+ self.min_serve_nodes = min_serve_nodes
136
+ self.max_serve_nodes = max_serve_nodes
137
+ self.cpu_utilization_percent = cpu_utilization_percent
138
+
139
+ @classmethod
140
+ def from_pb(cls, cluster_pb, instance):
141
+ """Creates a cluster instance from a protobuf.
142
+
143
+ For example:
144
+
145
+ .. literalinclude:: snippets.py
146
+ :start-after: [START bigtable_api_cluster_from_pb]
147
+ :end-before: [END bigtable_api_cluster_from_pb]
148
+ :dedent: 4
149
+
150
+ :type cluster_pb: :class:`instance.Cluster`
151
+ :param cluster_pb: An instance protobuf object.
152
+
153
+ :type instance: :class:`google.cloud.bigtable.instance.Instance`
154
+ :param instance: The instance that owns the cluster.
155
+
156
+ :rtype: :class:`Cluster`
157
+ :returns: The Cluster parsed from the protobuf response.
158
+ :raises: :class:`ValueError <exceptions.ValueError>` if the cluster
159
+ name does not match
160
+ ``projects/{project}/instances/{instance_id}/clusters/{cluster_id}``
161
+ or if the parsed instance ID does not match the istance ID
162
+ on the client.
163
+ or if the parsed project ID does not match the project ID
164
+ on the client.
165
+ """
166
+ match_cluster_name = _CLUSTER_NAME_RE.match(cluster_pb.name)
167
+ if match_cluster_name is None:
168
+ raise ValueError(
169
+ "Cluster protobuf name was not in the " "expected format.",
170
+ cluster_pb.name,
171
+ )
172
+ if match_cluster_name.group("instance") != instance.instance_id:
173
+ raise ValueError(
174
+ "Instance ID on cluster does not match the " "instance ID on the client"
175
+ )
176
+ if match_cluster_name.group("project") != instance._client.project:
177
+ raise ValueError(
178
+ "Project ID on cluster does not match the " "project ID on the client"
179
+ )
180
+ cluster_id = match_cluster_name.group("cluster_id")
181
+
182
+ result = cls(cluster_id, instance)
183
+ result._update_from_pb(cluster_pb)
184
+ return result
185
+
186
+ def _update_from_pb(self, cluster_pb):
187
+ """Refresh self from the server-provided protobuf.
188
+ Helper for :meth:`from_pb` and :meth:`reload`.
189
+ """
190
+
191
+ self.location_id = cluster_pb.location.split("/")[-1]
192
+ self.serve_nodes = cluster_pb.serve_nodes
193
+
194
+ self.min_serve_nodes = (
195
+ cluster_pb.cluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodes
196
+ )
197
+ self.max_serve_nodes = (
198
+ cluster_pb.cluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodes
199
+ )
200
+ self.cpu_utilization_percent = (
201
+ cluster_pb.cluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percent
202
+ )
203
+
204
+ self.default_storage_type = cluster_pb.default_storage_type
205
+ if cluster_pb.encryption_config:
206
+ self._kms_key_name = cluster_pb.encryption_config.kms_key_name
207
+ else:
208
+ self._kms_key_name = None
209
+ self._state = cluster_pb.state
210
+
211
+ @property
212
+ def name(self):
213
+ """Cluster name used in requests.
214
+
215
+ .. note::
216
+ This property will not change if ``_instance`` and ``cluster_id``
217
+ do not, but the return value is not cached.
218
+
219
+ For example:
220
+
221
+ .. literalinclude:: snippets.py
222
+ :start-after: [START bigtable_api_cluster_name]
223
+ :end-before: [END bigtable_api_cluster_name]
224
+ :dedent: 4
225
+
226
+ The cluster name is of the form
227
+
228
+ ``"projects/{project}/instances/{instance}/clusters/{cluster_id}"``
229
+
230
+ :rtype: str
231
+ :returns: The cluster name.
232
+ """
233
+ return self._instance._client.instance_admin_client.cluster_path(
234
+ self._instance._client.project, self._instance.instance_id, self.cluster_id
235
+ )
236
+
237
+ @property
238
+ def state(self):
239
+ """google.cloud.bigtable.enums.Cluster.State: state of cluster.
240
+
241
+ For example:
242
+
243
+ .. literalinclude:: snippets.py
244
+ :start-after: [START bigtable_api_cluster_state]
245
+ :end-before: [END bigtable_api_cluster_state]
246
+ :dedent: 4
247
+
248
+ """
249
+ return self._state
250
+
251
+ @property
252
+ def kms_key_name(self):
253
+ """str: Customer managed encryption key for the cluster."""
254
+ return self._kms_key_name
255
+
256
+ def _validate_scaling_config(self):
257
+ """Validate auto/manual scaling configuration before creating or updating."""
258
+
259
+ if (
260
+ not self.serve_nodes
261
+ and not self.min_serve_nodes
262
+ and not self.max_serve_nodes
263
+ and not self.cpu_utilization_percent
264
+ ):
265
+ raise ValueError(
266
+ "Must specify either serve_nodes or all of the autoscaling configurations (min_serve_nodes, max_serve_nodes, and cpu_utilization_percent)."
267
+ )
268
+ if self.serve_nodes and (
269
+ self.max_serve_nodes or self.min_serve_nodes or self.cpu_utilization_percent
270
+ ):
271
+ raise ValueError(
272
+ "Cannot specify both serve_nodes and autoscaling configurations (min_serve_nodes, max_serve_nodes, and cpu_utilization_percent)."
273
+ )
274
+ if (
275
+ (
276
+ self.min_serve_nodes
277
+ and (not self.max_serve_nodes or not self.cpu_utilization_percent)
278
+ )
279
+ or (
280
+ self.max_serve_nodes
281
+ and (not self.min_serve_nodes or not self.cpu_utilization_percent)
282
+ )
283
+ or (
284
+ self.cpu_utilization_percent
285
+ and (not self.min_serve_nodes or not self.max_serve_nodes)
286
+ )
287
+ ):
288
+ raise ValueError(
289
+ "All of autoscaling configurations must be specified at the same time (min_serve_nodes, max_serve_nodes, and cpu_utilization_percent)."
290
+ )
291
+
292
+ def __eq__(self, other):
293
+ if not isinstance(other, self.__class__):
294
+ return NotImplemented
295
+ # NOTE: This does not compare the configuration values, such as
296
+ # the serve_nodes. Instead, it only compares
297
+ # identifying values instance, cluster ID and client. This is
298
+ # intentional, since the same cluster can be in different states
299
+ # if not synchronized. Clusters with similar instance/cluster
300
+ # settings but different clients can't be used in the same way.
301
+ return other.cluster_id == self.cluster_id and other._instance == self._instance
302
+
303
+ def __ne__(self, other):
304
+ return not self == other
305
+
306
+ def reload(self):
307
+ """Reload the metadata for this cluster.
308
+
309
+ For example:
310
+
311
+ .. literalinclude:: snippets.py
312
+ :start-after: [START bigtable_api_reload_cluster]
313
+ :end-before: [END bigtable_api_reload_cluster]
314
+ :dedent: 4
315
+ """
316
+ cluster_pb = self._instance._client.instance_admin_client.get_cluster(
317
+ request={"name": self.name}
318
+ )
319
+
320
+ # NOTE: _update_from_pb does not check that the project and
321
+ # cluster ID on the response match the request.
322
+ self._update_from_pb(cluster_pb)
323
+
324
+ def exists(self):
325
+ """Check whether the cluster already exists.
326
+
327
+ For example:
328
+
329
+ .. literalinclude:: snippets.py
330
+ :start-after: [START bigtable_api_check_cluster_exists]
331
+ :end-before: [END bigtable_api_check_cluster_exists]
332
+ :dedent: 4
333
+
334
+ :rtype: bool
335
+ :returns: True if the table exists, else False.
336
+ """
337
+ client = self._instance._client
338
+ try:
339
+ client.instance_admin_client.get_cluster(request={"name": self.name})
340
+ return True
341
+ # NOTE: There could be other exceptions that are returned to the user.
342
+ except NotFound:
343
+ return False
344
+
345
+ def create(self):
346
+ """Create this cluster.
347
+
348
+ For example:
349
+
350
+ .. literalinclude:: snippets.py
351
+ :start-after: [START bigtable_api_create_cluster]
352
+ :end-before: [END bigtable_api_create_cluster]
353
+ :dedent: 4
354
+
355
+ .. note::
356
+
357
+ Uses the ``project``, ``instance`` and ``cluster_id`` on the
358
+ current :class:`Cluster` in addition to the ``serve_nodes``.
359
+ To change them before creating, reset the values via
360
+
361
+ .. code:: python
362
+
363
+ cluster.serve_nodes = 8
364
+ cluster.cluster_id = 'i-changed-my-mind'
365
+
366
+ before calling :meth:`create`.
367
+
368
+ :rtype: :class:`~google.api_core.operation.Operation`
369
+ :returns: The long-running operation corresponding to the
370
+ create operation.
371
+
372
+ :raises: :class:`ValueError <exceptions.ValueError>` if the both ``serve_nodes`` and autoscaling configurations
373
+ are set at the same time or if none of the ``serve_nodes`` or autoscaling configurations are set
374
+ or if the autoscaling configurations are only partially set.
375
+
376
+ """
377
+
378
+ self._validate_scaling_config()
379
+
380
+ client = self._instance._client
381
+ cluster_pb = self._to_pb()
382
+
383
+ return client.instance_admin_client.create_cluster(
384
+ request={
385
+ "parent": self._instance.name,
386
+ "cluster_id": self.cluster_id,
387
+ "cluster": cluster_pb,
388
+ }
389
+ )
390
+
391
+ def update(self):
392
+ """Update this cluster.
393
+
394
+ For example:
395
+
396
+ .. literalinclude:: snippets.py
397
+ :start-after: [START bigtable_api_update_cluster]
398
+ :end-before: [END bigtable_api_update_cluster]
399
+ :dedent: 4
400
+
401
+ .. note::
402
+
403
+ Updates the ``serve_nodes``. If you'd like to
404
+ change them before updating, reset the values via
405
+
406
+ .. code:: python
407
+
408
+ cluster.serve_nodes = 8
409
+
410
+ before calling :meth:`update`.
411
+
412
+ If autoscaling is already enabled, manual scaling will be silently ignored.
413
+ To disable autoscaling and enable manual scaling, use the :meth:`disable_autoscaling` instead.
414
+
415
+ :rtype: :class:`Operation`
416
+ :returns: The long-running operation corresponding to the
417
+ update operation.
418
+
419
+ """
420
+
421
+ client = self._instance._client
422
+
423
+ update_mask_pb = field_mask_pb2.FieldMask()
424
+
425
+ if self.serve_nodes:
426
+ update_mask_pb.paths.append("serve_nodes")
427
+
428
+ if self.min_serve_nodes:
429
+ update_mask_pb.paths.append(
430
+ "cluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodes"
431
+ )
432
+ if self.max_serve_nodes:
433
+ update_mask_pb.paths.append(
434
+ "cluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodes"
435
+ )
436
+ if self.cpu_utilization_percent:
437
+ update_mask_pb.paths.append(
438
+ "cluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percent"
439
+ )
440
+
441
+ cluster_pb = self._to_pb()
442
+ cluster_pb.name = self.name
443
+
444
+ return client.instance_admin_client.partial_update_cluster(
445
+ request={"cluster": cluster_pb, "update_mask": update_mask_pb}
446
+ )
447
+
448
+ def disable_autoscaling(self, serve_nodes):
449
+ """
450
+ Disable autoscaling by specifying the number of nodes.
451
+
452
+ For example:
453
+
454
+ .. literalinclude:: snippets.py
455
+ :start-after: [START bigtable_api_cluster_disable_autoscaling]
456
+ :end-before: [END bigtable_api_cluster_disable_autoscaling]
457
+ :dedent: 4
458
+
459
+ :type serve_nodes: int
460
+ :param serve_nodes: The number of nodes in the cluster.
461
+ """
462
+
463
+ client = self._instance._client
464
+
465
+ update_mask_pb = field_mask_pb2.FieldMask()
466
+
467
+ self.serve_nodes = serve_nodes
468
+ self.min_serve_nodes = 0
469
+ self.max_serve_nodes = 0
470
+ self.cpu_utilization_percent = 0
471
+
472
+ update_mask_pb.paths.append("serve_nodes")
473
+ update_mask_pb.paths.append("cluster_config.cluster_autoscaling_config")
474
+ cluster_pb = self._to_pb()
475
+ cluster_pb.name = self.name
476
+
477
+ return client.instance_admin_client.partial_update_cluster(
478
+ request={"cluster": cluster_pb, "update_mask": update_mask_pb}
479
+ )
480
+
481
+ def delete(self):
482
+ """Delete this cluster.
483
+
484
+ For example:
485
+
486
+ .. literalinclude:: snippets.py
487
+ :start-after: [START bigtable_api_delete_cluster]
488
+ :end-before: [END bigtable_api_delete_cluster]
489
+ :dedent: 4
490
+
491
+ Marks a cluster and all of its tables for permanent deletion in 7 days.
492
+
493
+ Immediately upon completion of the request:
494
+
495
+ * Billing will cease for all of the cluster's reserved resources.
496
+ * The cluster's ``delete_time`` field will be set 7 days in the future.
497
+
498
+ Soon afterward:
499
+
500
+ * All tables within the cluster will become unavailable.
501
+
502
+ At the cluster's ``delete_time``:
503
+
504
+ * The cluster and **all of its tables** will immediately and
505
+ irrevocably disappear from the API, and their data will be
506
+ permanently deleted.
507
+ """
508
+ client = self._instance._client
509
+ client.instance_admin_client.delete_cluster(request={"name": self.name})
510
+
511
+ def _to_pb(self):
512
+ """Create cluster proto buff message for API calls"""
513
+ client = self._instance._client
514
+ location = client.instance_admin_client.common_location_path(
515
+ client.project, self.location_id
516
+ )
517
+
518
+ cluster_pb = instance.Cluster(
519
+ location=location,
520
+ serve_nodes=self.serve_nodes,
521
+ default_storage_type=self.default_storage_type,
522
+ )
523
+ if self._kms_key_name:
524
+ cluster_pb.encryption_config = instance.Cluster.EncryptionConfig(
525
+ kms_key_name=self._kms_key_name,
526
+ )
527
+
528
+ if self.min_serve_nodes:
529
+ cluster_pb.cluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodes = (
530
+ self.min_serve_nodes
531
+ )
532
+ if self.max_serve_nodes:
533
+ cluster_pb.cluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodes = (
534
+ self.max_serve_nodes
535
+ )
536
+ if self.cpu_utilization_percent:
537
+ cluster_pb.cluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percent = (
538
+ self.cpu_utilization_percent
539
+ )
540
+
541
+ return cluster_pb