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,789 @@
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 Instance."""
16
+
17
+ import re
18
+
19
+ from google.cloud.bigtable.app_profile import AppProfile
20
+ from google.cloud.bigtable.cluster import Cluster
21
+ from google.cloud.bigtable.table import Table
22
+
23
+ from google.protobuf import field_mask_pb2
24
+
25
+ from google.cloud.bigtable_admin_v2.types import instance
26
+
27
+ from google.iam.v1 import options_pb2 # type: ignore
28
+
29
+ from google.api_core.exceptions import NotFound
30
+
31
+ from google.cloud.bigtable.policy import Policy
32
+
33
+ import warnings
34
+
35
+
36
+ _INSTANCE_NAME_RE = re.compile(
37
+ r"^projects/(?P<project>[^/]+)/" r"instances/(?P<instance_id>[a-z][-a-z0-9]*)$"
38
+ )
39
+
40
+ _INSTANCE_CREATE_WARNING = """
41
+ Use of `instance.create({0}, {1}, {2})` will be deprecated.
42
+ Please replace with
43
+ `cluster = instance.cluster({0}, {1}, {2})`
44
+ `instance.create(clusters=[cluster])`."""
45
+
46
+
47
+ class Instance(object):
48
+ """Representation of a Google Cloud Bigtable Instance.
49
+
50
+ We can use an :class:`Instance` to:
51
+
52
+ * :meth:`reload` itself
53
+ * :meth:`create` itself
54
+ * :meth:`update` itself
55
+ * :meth:`delete` itself
56
+
57
+ .. note::
58
+
59
+ For now, we leave out the ``default_storage_type`` (an enum)
60
+ which if not sent will end up as :data:`.data_v2_pb2.STORAGE_SSD`.
61
+
62
+ :type instance_id: str
63
+ :param instance_id: The ID of the instance.
64
+
65
+ :type client: :class:`Client <google.cloud.bigtable.client.Client>`
66
+ :param client: The client that owns the instance. Provides
67
+ authorization and a project ID.
68
+
69
+ :type display_name: str
70
+ :param display_name: (Optional) The display name for the instance in the
71
+ Cloud Console UI. (Must be between 4 and 30
72
+ characters.) If this value is not set in the
73
+ constructor, will fall back to the instance ID.
74
+
75
+ :type instance_type: int
76
+ :param instance_type: (Optional) The type of the instance.
77
+ Possible values are represented
78
+ by the following constants:
79
+ :data:`google.cloud.bigtable.enums.Instance.Type.PRODUCTION`.
80
+ :data:`google.cloud.bigtable.enums.Instance.Type.DEVELOPMENT`,
81
+ Defaults to
82
+ :data:`google.cloud.bigtable.enums.Instance.Type.UNSPECIFIED`.
83
+
84
+ :type labels: dict
85
+ :param labels: (Optional) Labels are a flexible and lightweight
86
+ mechanism for organizing cloud resources into groups
87
+ that reflect a customer's organizational needs and
88
+ deployment strategies. They can be used to filter
89
+ resources and aggregate metrics. Label keys must be
90
+ between 1 and 63 characters long. Maximum 64 labels can
91
+ be associated with a given resource. Label values must
92
+ be between 0 and 63 characters long. Keys and values
93
+ must both be under 128 bytes.
94
+
95
+ :type _state: int
96
+ :param _state: (`OutputOnly`)
97
+ The current state of the instance.
98
+ Possible values are represented by the following constants:
99
+ :data:`google.cloud.bigtable.enums.Instance.State.STATE_NOT_KNOWN`.
100
+ :data:`google.cloud.bigtable.enums.Instance.State.READY`.
101
+ :data:`google.cloud.bigtable.enums.Instance.State.CREATING`.
102
+ """
103
+
104
+ def __init__(
105
+ self,
106
+ instance_id,
107
+ client,
108
+ display_name=None,
109
+ instance_type=None,
110
+ labels=None,
111
+ _state=None,
112
+ ):
113
+ self.instance_id = instance_id
114
+ self._client = client
115
+ self.display_name = display_name or instance_id
116
+ self.type_ = instance_type
117
+ self.labels = labels
118
+ self._state = _state
119
+
120
+ def _update_from_pb(self, instance_pb):
121
+ """Refresh self from the server-provided protobuf.
122
+ Helper for :meth:`from_pb` and :meth:`reload`.
123
+ """
124
+ if not instance_pb.display_name: # Simple field (string)
125
+ raise ValueError("Instance protobuf does not contain display_name")
126
+ self.display_name = instance_pb.display_name
127
+ self.type_ = instance_pb.type_
128
+ self.labels = dict(instance_pb.labels)
129
+ self._state = instance_pb.state
130
+
131
+ @classmethod
132
+ def from_pb(cls, instance_pb, client):
133
+ """Creates an instance instance from a protobuf.
134
+
135
+ For example:
136
+
137
+ .. literalinclude:: snippets.py
138
+ :start-after: [START bigtable_api_instance_from_pb]
139
+ :end-before: [END bigtable_api_instance_from_pb]
140
+ :dedent: 4
141
+
142
+ :type instance_pb: :class:`instance.Instance`
143
+ :param instance_pb: An instance protobuf object.
144
+
145
+ :type client: :class:`Client <google.cloud.bigtable.client.Client>`
146
+ :param client: The client that owns the instance.
147
+
148
+ :rtype: :class:`Instance`
149
+ :returns: The instance parsed from the protobuf response.
150
+ :raises: :class:`ValueError <exceptions.ValueError>` if the instance
151
+ name does not match
152
+ ``projects/{project}/instances/{instance_id}``
153
+ or if the parsed project ID does not match the project ID
154
+ on the client.
155
+ """
156
+ match = _INSTANCE_NAME_RE.match(instance_pb.name)
157
+ if match is None:
158
+ raise ValueError(
159
+ "Instance protobuf name was not in the " "expected format.",
160
+ instance_pb.name,
161
+ )
162
+ if match.group("project") != client.project:
163
+ raise ValueError(
164
+ "Project ID on instance does not match the " "project ID on the client"
165
+ )
166
+ instance_id = match.group("instance_id")
167
+
168
+ result = cls(instance_id, client)
169
+ result._update_from_pb(instance_pb)
170
+ return result
171
+
172
+ @property
173
+ def name(self):
174
+ """Instance name used in requests.
175
+
176
+ .. note::
177
+ This property will not change if ``instance_id`` does not,
178
+ but the return value is not cached.
179
+
180
+ For example:
181
+
182
+ .. literalinclude:: snippets.py
183
+ :start-after: [START bigtable_api_instance_name]
184
+ :end-before: [END bigtable_api_instance_name]
185
+ :dedent: 4
186
+
187
+ The instance name is of the form
188
+
189
+ ``"projects/{project}/instances/{instance_id}"``
190
+
191
+ :rtype: str
192
+ :returns: Return a fully-qualified instance string.
193
+ """
194
+ return self._client.instance_admin_client.instance_path(
195
+ project=self._client.project, instance=self.instance_id
196
+ )
197
+
198
+ @property
199
+ def state(self):
200
+ """google.cloud.bigtable.enums.Instance.State: state of Instance.
201
+
202
+ For example:
203
+
204
+ .. literalinclude:: snippets.py
205
+ :start-after: [START bigtable_api_instance_state]
206
+ :end-before: [END bigtable_api_instance_state]
207
+ :dedent: 4
208
+
209
+ """
210
+ return self._state
211
+
212
+ def __eq__(self, other):
213
+ if not isinstance(other, self.__class__):
214
+ return NotImplemented
215
+ # NOTE: This does not compare the configuration values, such as
216
+ # the display_name. Instead, it only compares
217
+ # identifying values instance ID and client. This is
218
+ # intentional, since the same instance can be in different states
219
+ # if not synchronized. Instances with similar instance
220
+ # settings but different clients can't be used in the same way.
221
+ return other.instance_id == self.instance_id and other._client == self._client
222
+
223
+ def __ne__(self, other):
224
+ return not self == other
225
+
226
+ def create(
227
+ self,
228
+ location_id=None,
229
+ serve_nodes=None,
230
+ default_storage_type=None,
231
+ clusters=None,
232
+ min_serve_nodes=None,
233
+ max_serve_nodes=None,
234
+ cpu_utilization_percent=None,
235
+ ):
236
+ """Create this instance.
237
+
238
+ For example:
239
+
240
+ .. literalinclude:: snippets.py
241
+ :start-after: [START bigtable_api_create_prod_instance]
242
+ :end-before: [END bigtable_api_create_prod_instance]
243
+ :dedent: 4
244
+
245
+ .. note::
246
+
247
+ Uses the ``project`` and ``instance_id`` on the current
248
+ :class:`Instance` in addition to the ``display_name``.
249
+ To change them before creating, reset the values via
250
+
251
+ .. code:: python
252
+
253
+ instance.display_name = 'New display name'
254
+ instance.instance_id = 'i-changed-my-mind'
255
+
256
+ before calling :meth:`create`.
257
+
258
+ :type location_id: str
259
+ :param location_id: (Creation Only) The location where nodes and
260
+ storage of the cluster owned by this instance
261
+ reside. For best performance, clients should be
262
+ located as close as possible to cluster's location.
263
+ For list of supported locations refer to
264
+ https://cloud.google.com/bigtable/docs/locations
265
+
266
+
267
+ :type serve_nodes: int
268
+ :param serve_nodes: (Optional) The number of nodes in the instance's
269
+ cluster; used to set up the instance's cluster.
270
+
271
+ :type default_storage_type: int
272
+ :param default_storage_type: (Optional) The storage media type for
273
+ persisting Bigtable data.
274
+ Possible values are represented
275
+ by the following constants:
276
+ :data:`google.cloud.bigtable.enums.StorageType.SSD`.
277
+ :data:`google.cloud.bigtable.enums.StorageType.HDD`,
278
+ Defaults to
279
+ :data:`google.cloud.bigtable.enums.StorageType.UNSPECIFIED`.
280
+
281
+ :type clusters: class:`~[~google.cloud.bigtable.cluster.Cluster]`
282
+ :param clusters: List of clusters to be created.
283
+
284
+ :rtype: :class:`~google.api_core.operation.Operation`
285
+ :returns: The long-running operation corresponding to the create
286
+ operation.
287
+
288
+ :raises: :class:`ValueError <exceptions.ValueError>` if both
289
+ ``clusters`` and one of ``location_id``, ``serve_nodes``
290
+ and ``default_storage_type`` are set.
291
+ """
292
+
293
+ if clusters is None:
294
+ warnings.warn(
295
+ _INSTANCE_CREATE_WARNING.format(
296
+ "location_id", "serve_nodes", "default_storage_type"
297
+ ),
298
+ DeprecationWarning,
299
+ stacklevel=2,
300
+ )
301
+
302
+ cluster_id = "{}-cluster".format(self.instance_id)
303
+
304
+ clusters = [
305
+ self.cluster(
306
+ cluster_id,
307
+ location_id=location_id,
308
+ serve_nodes=serve_nodes,
309
+ default_storage_type=default_storage_type,
310
+ min_serve_nodes=None,
311
+ max_serve_nodes=None,
312
+ cpu_utilization_percent=None,
313
+ )
314
+ ]
315
+ elif (
316
+ location_id is not None
317
+ or serve_nodes is not None
318
+ or default_storage_type is not None
319
+ or min_serve_nodes is not None
320
+ or max_serve_nodes is not None
321
+ or cpu_utilization_percent is not None
322
+ ):
323
+ raise ValueError(
324
+ "clusters and one of location_id, serve_nodes, \
325
+ default_storage_type can not be set \
326
+ simultaneously."
327
+ )
328
+
329
+ instance_pb = instance.Instance(
330
+ display_name=self.display_name, type_=self.type_, labels=self.labels
331
+ )
332
+
333
+ parent = self._client.project_path
334
+
335
+ return self._client.instance_admin_client.create_instance(
336
+ request={
337
+ "parent": parent,
338
+ "instance_id": self.instance_id,
339
+ "instance": instance_pb,
340
+ "clusters": {c.cluster_id: c._to_pb() for c in clusters},
341
+ }
342
+ )
343
+
344
+ def exists(self):
345
+ """Check whether the instance already exists.
346
+
347
+ For example:
348
+
349
+ .. literalinclude:: snippets.py
350
+ :start-after: [START bigtable_api_check_instance_exists]
351
+ :end-before: [END bigtable_api_check_instance_exists]
352
+ :dedent: 4
353
+
354
+ :rtype: bool
355
+ :returns: True if the table exists, else False.
356
+ """
357
+ try:
358
+ self._client.instance_admin_client.get_instance(request={"name": self.name})
359
+ return True
360
+ # NOTE: There could be other exceptions that are returned to the user.
361
+ except NotFound:
362
+ return False
363
+
364
+ def reload(self):
365
+ """Reload the metadata for this instance.
366
+
367
+ For example:
368
+
369
+ .. literalinclude:: snippets.py
370
+ :start-after: [START bigtable_api_reload_instance]
371
+ :end-before: [END bigtable_api_reload_instance]
372
+ :dedent: 4
373
+ """
374
+ instance_pb = self._client.instance_admin_client.get_instance(
375
+ request={"name": self.name}
376
+ )
377
+
378
+ # NOTE: _update_from_pb does not check that the project and
379
+ # instance ID on the response match the request.
380
+ self._update_from_pb(instance_pb)
381
+
382
+ def update(self):
383
+ """Updates an instance within a project.
384
+
385
+ For example:
386
+
387
+ .. literalinclude:: snippets.py
388
+ :start-after: [START bigtable_api_update_instance]
389
+ :end-before: [END bigtable_api_update_instance]
390
+ :dedent: 4
391
+
392
+ .. note::
393
+
394
+ Updates any or all of the following values:
395
+ ``display_name``
396
+ ``type``
397
+ ``labels``
398
+ To change a value before
399
+ updating, assign that values via
400
+
401
+ .. code:: python
402
+
403
+ instance.display_name = 'New display name'
404
+
405
+ before calling :meth:`update`.
406
+
407
+ :rtype: :class:`~google.api_core.operation.Operation`
408
+ :returns: The long-running operation corresponding to the update
409
+ operation.
410
+ """
411
+ update_mask_pb = field_mask_pb2.FieldMask()
412
+ if self.display_name is not None:
413
+ update_mask_pb.paths.append("display_name")
414
+ if self.type_ is not None:
415
+ update_mask_pb.paths.append("type")
416
+ if self.labels is not None:
417
+ update_mask_pb.paths.append("labels")
418
+ instance_pb = instance.Instance(
419
+ name=self.name,
420
+ display_name=self.display_name,
421
+ type_=self.type_,
422
+ labels=self.labels,
423
+ )
424
+
425
+ return self._client.instance_admin_client.partial_update_instance(
426
+ request={"instance": instance_pb, "update_mask": update_mask_pb}
427
+ )
428
+
429
+ def delete(self):
430
+ """Delete this instance.
431
+
432
+ For example:
433
+
434
+ .. literalinclude:: snippets.py
435
+ :start-after: [START bigtable_api_delete_instance]
436
+ :end-before: [END bigtable_api_delete_instance]
437
+ :dedent: 4
438
+
439
+ Marks an instance and all of its tables for permanent deletion
440
+ in 7 days.
441
+
442
+ Immediately upon completion of the request:
443
+
444
+ * Billing will cease for all of the instance's reserved resources.
445
+ * The instance's ``delete_time`` field will be set 7 days in
446
+ the future.
447
+
448
+ Soon afterward:
449
+
450
+ * All tables within the instance will become unavailable.
451
+
452
+ At the instance's ``delete_time``:
453
+
454
+ * The instance and **all of its tables** will immediately and
455
+ irrevocably disappear from the API, and their data will be
456
+ permanently deleted.
457
+ """
458
+ self._client.instance_admin_client.delete_instance(request={"name": self.name})
459
+
460
+ def get_iam_policy(self, requested_policy_version=None):
461
+ """Gets the access control policy for an instance resource.
462
+
463
+ For example:
464
+
465
+ .. literalinclude:: snippets.py
466
+ :start-after: [START bigtable_api_get_iam_policy]
467
+ :end-before: [END bigtable_api_get_iam_policy]
468
+ :dedent: 4
469
+
470
+ :type requested_policy_version: int or ``NoneType``
471
+ :param requested_policy_version: Optional. The version of IAM policies to request.
472
+ If a policy with a condition is requested without
473
+ setting this, the server will return an error.
474
+ This must be set to a value of 3 to retrieve IAM
475
+ policies containing conditions. This is to prevent
476
+ client code that isn't aware of IAM conditions from
477
+ interpreting and modifying policies incorrectly.
478
+ The service might return a policy with version lower
479
+ than the one that was requested, based on the
480
+ feature syntax in the policy fetched.
481
+
482
+ :rtype: :class:`google.cloud.bigtable.policy.Policy`
483
+ :returns: The current IAM policy of this instance
484
+ """
485
+ args = {"resource": self.name}
486
+ if requested_policy_version is not None:
487
+ args["options_"] = options_pb2.GetPolicyOptions(
488
+ requested_policy_version=requested_policy_version
489
+ )
490
+
491
+ instance_admin_client = self._client.instance_admin_client
492
+
493
+ resp = instance_admin_client.get_iam_policy(request=args)
494
+ return Policy.from_pb(resp)
495
+
496
+ def set_iam_policy(self, policy):
497
+ """Sets the access control policy on an instance resource. Replaces any
498
+ existing policy.
499
+
500
+ For more information about policy, please see documentation of
501
+ class `google.cloud.bigtable.policy.Policy`
502
+
503
+ For example:
504
+
505
+ .. literalinclude:: snippets.py
506
+ :start-after: [START bigtable_api_set_iam_policy]
507
+ :end-before: [END bigtable_api_set_iam_policy]
508
+ :dedent: 4
509
+
510
+ :type policy: :class:`google.cloud.bigtable.policy.Policy`
511
+ :param policy: A new IAM policy to replace the current IAM policy
512
+ of this instance
513
+
514
+ :rtype: :class:`google.cloud.bigtable.policy.Policy`
515
+ :returns: The current IAM policy of this instance.
516
+ """
517
+ instance_admin_client = self._client.instance_admin_client
518
+ resp = instance_admin_client.set_iam_policy(
519
+ request={"resource": self.name, "policy": policy.to_pb()}
520
+ )
521
+ return Policy.from_pb(resp)
522
+
523
+ def test_iam_permissions(self, permissions):
524
+ """Returns permissions that the caller has on the specified instance
525
+ resource.
526
+
527
+ For example:
528
+
529
+ .. literalinclude:: snippets.py
530
+ :start-after: [START bigtable_api_test_iam_permissions]
531
+ :end-before: [END bigtable_api_test_iam_permissions]
532
+ :dedent: 4
533
+
534
+ :type permissions: list
535
+ :param permissions: The set of permissions to check for
536
+ the ``resource``. Permissions with wildcards (such as '*'
537
+ or 'storage.*') are not allowed. For more information see
538
+ `IAM Overview
539
+ <https://cloud.google.com/iam/docs/overview#permissions>`_.
540
+ `Bigtable Permissions
541
+ <https://cloud.google.com/bigtable/docs/access-control>`_.
542
+
543
+ :rtype: list
544
+ :returns: A List(string) of permissions allowed on the instance
545
+ """
546
+ instance_admin_client = self._client.instance_admin_client
547
+ resp = instance_admin_client.test_iam_permissions(
548
+ request={"resource": self.name, "permissions": permissions}
549
+ )
550
+ return list(resp.permissions)
551
+
552
+ def cluster(
553
+ self,
554
+ cluster_id,
555
+ location_id=None,
556
+ serve_nodes=None,
557
+ default_storage_type=None,
558
+ kms_key_name=None,
559
+ min_serve_nodes=None,
560
+ max_serve_nodes=None,
561
+ cpu_utilization_percent=None,
562
+ ):
563
+ """Factory to create a cluster associated with this instance.
564
+
565
+ For example:
566
+
567
+ .. literalinclude:: snippets.py
568
+ :start-after: [START bigtable_api_create_cluster]
569
+ :end-before: [END bigtable_api_create_cluster]
570
+ :dedent: 4
571
+
572
+ :type cluster_id: str
573
+ :param cluster_id: The ID of the cluster.
574
+
575
+ :type location_id: str
576
+ :param location_id: (Creation Only) The location where this cluster's
577
+ nodes and storage reside. For best performance,
578
+ clients should be located as close as possible to
579
+ this cluster.
580
+ For list of supported locations refer to
581
+ https://cloud.google.com/bigtable/docs/locations
582
+
583
+ :type serve_nodes: int
584
+ :param serve_nodes: (Optional) The number of nodes in the cluster.
585
+
586
+ :type default_storage_type: int
587
+ :param default_storage_type: (Optional) The type of storage
588
+ Possible values are represented by the
589
+ following constants:
590
+ :data:`google.cloud.bigtable.enums.StorageType.SSD`.
591
+ :data:`google.cloud.bigtable.enums.StorageType.HDD`,
592
+ Defaults to
593
+ :data:`google.cloud.bigtable.enums.StorageType.UNSPECIFIED`.
594
+
595
+ :rtype: :class:`~google.cloud.bigtable.instance.Cluster`
596
+ :returns: a cluster owned by this instance.
597
+
598
+ :type kms_key_name: str
599
+ :param kms_key_name: (Optional, Creation Only) The name of the KMS customer
600
+ managed encryption key (CMEK) to use for at-rest encryption
601
+ of data in this cluster. If omitted, Google's default
602
+ encryption will be used. If specified, the requirements for
603
+ this key are:
604
+
605
+ 1) The Cloud Bigtable service account associated with the
606
+ project that contains the cluster must be granted the
607
+ ``cloudkms.cryptoKeyEncrypterDecrypter`` role on the
608
+ CMEK.
609
+ 2) Only regional keys can be used and the region of the
610
+ CMEK key must match the region of the cluster.
611
+ 3) All clusters within an instance must use the same CMEK
612
+ key.
613
+ """
614
+ return Cluster(
615
+ cluster_id,
616
+ self,
617
+ location_id=location_id,
618
+ serve_nodes=serve_nodes,
619
+ default_storage_type=default_storage_type,
620
+ kms_key_name=kms_key_name,
621
+ min_serve_nodes=min_serve_nodes,
622
+ max_serve_nodes=max_serve_nodes,
623
+ cpu_utilization_percent=cpu_utilization_percent,
624
+ )
625
+
626
+ def list_clusters(self):
627
+ """List the clusters in this instance.
628
+
629
+ For example:
630
+
631
+ .. literalinclude:: snippets.py
632
+ :start-after: [START bigtable_api_list_clusters_on_instance]
633
+ :end-before: [END bigtable_api_list_clusters_on_instance]
634
+ :dedent: 4
635
+
636
+ :rtype: tuple
637
+ :returns:
638
+ (clusters, failed_locations), where 'clusters' is list of
639
+ :class:`google.cloud.bigtable.instance.Cluster`, and
640
+ 'failed_locations' is a list of locations which could not
641
+ be resolved.
642
+ """
643
+ resp = self._client.instance_admin_client.list_clusters(
644
+ request={"parent": self.name}
645
+ )
646
+ clusters = [Cluster.from_pb(cluster, self) for cluster in resp.clusters]
647
+ return clusters, resp.failed_locations
648
+
649
+ def table(self, table_id, mutation_timeout=None, app_profile_id=None):
650
+ """Factory to create a table associated with this instance.
651
+
652
+ For example:
653
+
654
+ .. literalinclude:: snippets.py
655
+ :start-after: [START bigtable_api_create_table]
656
+ :end-before: [END bigtable_api_create_table]
657
+ :dedent: 4
658
+
659
+ :type table_id: str
660
+ :param table_id: The ID of the table.
661
+
662
+ :type mutation_timeout: int
663
+ :param mutation_timeout: (Optional) The overriding mutation timeout.
664
+
665
+ :type app_profile_id: str
666
+ :param app_profile_id: (Optional) The unique name of the AppProfile.
667
+
668
+ :rtype: :class:`Table <google.cloud.bigtable.table.Table>`
669
+ :returns: The table owned by this instance.
670
+ """
671
+ return Table(
672
+ table_id,
673
+ self,
674
+ app_profile_id=app_profile_id,
675
+ mutation_timeout=mutation_timeout,
676
+ )
677
+
678
+ def list_tables(self):
679
+ """List the tables in this instance.
680
+
681
+ For example:
682
+
683
+ .. literalinclude:: snippets.py
684
+ :start-after: [START bigtable_api_list_tables]
685
+ :end-before: [END bigtable_api_list_tables]
686
+ :dedent: 4
687
+
688
+ :rtype: list of :class:`Table <google.cloud.bigtable.table.Table>`
689
+ :returns: The list of tables owned by the instance.
690
+ :raises: :class:`ValueError <exceptions.ValueError>` if one of the
691
+ returned tables has a name that is not of the expected format.
692
+ """
693
+ table_list_pb = self._client.table_admin_client.list_tables(
694
+ request={"parent": self.name}
695
+ )
696
+
697
+ result = []
698
+ for table_pb in table_list_pb.tables:
699
+ table_prefix = self.name + "/tables/"
700
+ if not table_pb.name.startswith(table_prefix):
701
+ raise ValueError(
702
+ "Table name {} not of expected format".format(table_pb.name)
703
+ )
704
+ table_id = table_pb.name[len(table_prefix) :]
705
+ result.append(self.table(table_id))
706
+
707
+ return result
708
+
709
+ def app_profile(
710
+ self,
711
+ app_profile_id,
712
+ routing_policy_type=None,
713
+ description=None,
714
+ cluster_id=None,
715
+ multi_cluster_ids=None,
716
+ allow_transactional_writes=None,
717
+ ):
718
+ """Factory to create AppProfile associated with this instance.
719
+
720
+ For example:
721
+
722
+ .. literalinclude:: snippets.py
723
+ :start-after: [START bigtable_api_create_app_profile]
724
+ :end-before: [END bigtable_api_create_app_profile]
725
+ :dedent: 4
726
+
727
+ :type app_profile_id: str
728
+ :param app_profile_id: The ID of the AppProfile. Must be of the form
729
+ ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``.
730
+
731
+ :type: routing_policy_type: int
732
+ :param: routing_policy_type: The type of the routing policy.
733
+ Possible values are represented
734
+ by the following constants:
735
+ :data:`google.cloud.bigtable.enums.RoutingPolicyType.ANY`
736
+ :data:`google.cloud.bigtable.enums.RoutingPolicyType.SINGLE`
737
+
738
+ :type: description: str
739
+ :param: description: (Optional) Long form description of the use
740
+ case for this AppProfile.
741
+
742
+ :type: cluster_id: str
743
+ :param: cluster_id: (Optional) Unique cluster_id which is only required
744
+ when routing_policy_type is
745
+ ROUTING_POLICY_TYPE_SINGLE.
746
+
747
+ :type: multi_cluster_ids: list
748
+ :param: multi_cluster_ids: (Optional) The set of clusters to route to.
749
+ The order is ignored; clusters will be tried in order of distance.
750
+ If left empty, all clusters are eligible.
751
+
752
+ :type: allow_transactional_writes: bool
753
+ :param: allow_transactional_writes: (Optional) If true, allow
754
+ transactional writes for
755
+ ROUTING_POLICY_TYPE_SINGLE.
756
+
757
+ :rtype: :class:`~google.cloud.bigtable.app_profile.AppProfile>`
758
+ :returns: AppProfile for this instance.
759
+ """
760
+ return AppProfile(
761
+ app_profile_id,
762
+ self,
763
+ routing_policy_type=routing_policy_type,
764
+ description=description,
765
+ cluster_id=cluster_id,
766
+ multi_cluster_ids=multi_cluster_ids,
767
+ allow_transactional_writes=allow_transactional_writes,
768
+ )
769
+
770
+ def list_app_profiles(self):
771
+ """Lists information about AppProfiles in an instance.
772
+
773
+ For example:
774
+
775
+ .. literalinclude:: snippets.py
776
+ :start-after: [START bigtable_api_list_app_profiles]
777
+ :end-before: [END bigtable_api_list_app_profiles]
778
+ :dedent: 4
779
+
780
+ :rtype: :list:[`~google.cloud.bigtable.app_profile.AppProfile`]
781
+ :returns: A :list:[`~google.cloud.bigtable.app_profile.AppProfile`].
782
+ By default, this is a list of
783
+ :class:`~google.cloud.bigtable.app_profile.AppProfile`
784
+ instances.
785
+ """
786
+ resp = self._client.instance_admin_client.list_app_profiles(
787
+ request={"parent": self.name}
788
+ )
789
+ return [AppProfile.from_pb(app_profile, self) for app_profile in resp]