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,475 @@
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
+ """Parent client for calling the Google Cloud Bigtable API.
16
+
17
+ This is the base from which all interactions with the API occur.
18
+
19
+ In the hierarchy of API concepts
20
+
21
+ * a :class:`~google.cloud.bigtable.client.Client` owns an
22
+ :class:`~google.cloud.bigtable.instance.Instance`
23
+ * an :class:`~google.cloud.bigtable.instance.Instance` owns a
24
+ :class:`~google.cloud.bigtable.table.Table`
25
+ * a :class:`~google.cloud.bigtable.table.Table` owns a
26
+ :class:`~.column_family.ColumnFamily`
27
+ * a :class:`~google.cloud.bigtable.table.Table` owns a
28
+ :class:`~google.cloud.bigtable.row.Row` (and all the cells in the row)
29
+ """
30
+ import os
31
+ import warnings
32
+ import grpc # type: ignore
33
+
34
+ from google.api_core.gapic_v1 import client_info as client_info_lib
35
+ from google.auth.credentials import AnonymousCredentials # type: ignore
36
+
37
+ from google.cloud import bigtable_v2
38
+ from google.cloud import bigtable_admin_v2
39
+ from google.cloud.bigtable_v2.services.bigtable.transports import BigtableGrpcTransport
40
+ from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin.transports import (
41
+ BigtableInstanceAdminGrpcTransport,
42
+ )
43
+ from google.cloud.bigtable_admin_v2.services.bigtable_table_admin.transports import (
44
+ BigtableTableAdminGrpcTransport,
45
+ )
46
+
47
+ from google.cloud import bigtable
48
+ from google.cloud.bigtable.instance import Instance
49
+ from google.cloud.bigtable.cluster import Cluster
50
+
51
+ from google.cloud.client import ClientWithProject # type: ignore
52
+
53
+ from google.cloud.bigtable_admin_v2.types import instance
54
+ from google.cloud.bigtable.cluster import _CLUSTER_NAME_RE
55
+ from google.cloud.environment_vars import BIGTABLE_EMULATOR # type: ignore
56
+
57
+
58
+ INSTANCE_TYPE_PRODUCTION = instance.Instance.Type.PRODUCTION
59
+ INSTANCE_TYPE_DEVELOPMENT = instance.Instance.Type.DEVELOPMENT
60
+ INSTANCE_TYPE_UNSPECIFIED = instance.Instance.Type.TYPE_UNSPECIFIED
61
+ SPANNER_ADMIN_SCOPE = "https://www.googleapis.com/auth/spanner.admin"
62
+ ADMIN_SCOPE = "https://www.googleapis.com/auth/bigtable.admin"
63
+ """Scope for interacting with the Cluster Admin and Table Admin APIs."""
64
+ DATA_SCOPE = "https://www.googleapis.com/auth/bigtable.data"
65
+ """Scope for reading and writing table data."""
66
+ READ_ONLY_SCOPE = "https://www.googleapis.com/auth/bigtable.data.readonly"
67
+ """Scope for reading table data."""
68
+
69
+ _DEFAULT_BIGTABLE_EMULATOR_CLIENT = "google-cloud-bigtable-emulator"
70
+ _GRPC_CHANNEL_OPTIONS = (
71
+ ("grpc.max_send_message_length", -1),
72
+ ("grpc.max_receive_message_length", -1),
73
+ ("grpc.keepalive_time_ms", 30000),
74
+ ("grpc.keepalive_timeout_ms", 10000),
75
+ )
76
+
77
+
78
+ def _create_gapic_client(client_class, client_options=None, transport=None):
79
+ def inner(self):
80
+ return client_class(
81
+ credentials=None,
82
+ client_info=self._client_info,
83
+ client_options=client_options,
84
+ transport=transport,
85
+ )
86
+
87
+ return inner
88
+
89
+
90
+ class Client(ClientWithProject):
91
+ """Client for interacting with Google Cloud Bigtable API.
92
+
93
+ .. note::
94
+
95
+ Since the Cloud Bigtable API requires the gRPC transport, no
96
+ ``_http`` argument is accepted by this class.
97
+
98
+ :type project: :class:`str` or :func:`unicode <unicode>`
99
+ :param project: (Optional) The ID of the project which owns the
100
+ instances, tables and data. If not provided, will
101
+ attempt to determine from the environment.
102
+
103
+ :type credentials: :class:`~google.auth.credentials.Credentials`
104
+ :param credentials: (Optional) The OAuth2 Credentials to use for this
105
+ client. If not passed, falls back to the default
106
+ inferred from the environment.
107
+
108
+ :type read_only: bool
109
+ :param read_only: (Optional) Boolean indicating if the data scope should be
110
+ for reading only (or for writing as well). Defaults to
111
+ :data:`False`.
112
+
113
+ :type admin: bool
114
+ :param admin: (Optional) Boolean indicating if the client will be used to
115
+ interact with the Instance Admin or Table Admin APIs. This
116
+ requires the :const:`ADMIN_SCOPE`. Defaults to :data:`False`.
117
+
118
+ :type: client_info: :class:`google.api_core.gapic_v1.client_info.ClientInfo`
119
+ :param client_info:
120
+ The client info used to send a user-agent string along with API
121
+ requests. If ``None``, then default info will be used. Generally,
122
+ you only need to set this if you're developing your own library
123
+ or partner tool.
124
+
125
+ :type client_options: :class:`~google.api_core.client_options.ClientOptions`
126
+ or :class:`dict`
127
+ :param client_options: (Optional) Client options used to set user options
128
+ on the client. API Endpoint should be set through client_options.
129
+
130
+ :type admin_client_options:
131
+ :class:`~google.api_core.client_options.ClientOptions` or :class:`dict`
132
+ :param admin_client_options: (Optional) Client options used to set user
133
+ options on the client. API Endpoint for admin operations should be set
134
+ through admin_client_options.
135
+
136
+ :type channel: :instance: grpc.Channel
137
+ :param channel (grpc.Channel): (Optional) DEPRECATED:
138
+ A ``Channel`` instance through which to make calls.
139
+ This argument is mutually exclusive with ``credentials``;
140
+ providing both will raise an exception. No longer used.
141
+
142
+ :raises: :class:`ValueError <exceptions.ValueError>` if both ``read_only``
143
+ and ``admin`` are :data:`True`
144
+ """
145
+
146
+ _table_data_client = None
147
+ _table_admin_client = None
148
+ _instance_admin_client = None
149
+
150
+ def __init__(
151
+ self,
152
+ project=None,
153
+ credentials=None,
154
+ read_only=False,
155
+ admin=False,
156
+ client_info=None,
157
+ client_options=None,
158
+ admin_client_options=None,
159
+ channel=None,
160
+ ):
161
+ if client_info is None:
162
+ client_info = client_info_lib.ClientInfo(
163
+ client_library_version=bigtable.__version__,
164
+ )
165
+ if read_only and admin:
166
+ raise ValueError(
167
+ "A read-only client cannot also perform" "administrative actions."
168
+ )
169
+
170
+ # NOTE: We set the scopes **before** calling the parent constructor.
171
+ # It **may** use those scopes in ``with_scopes_if_required``.
172
+ self._read_only = bool(read_only)
173
+ self._admin = bool(admin)
174
+ self._client_info = client_info
175
+ self._emulator_host = os.getenv(BIGTABLE_EMULATOR)
176
+
177
+ if self._emulator_host is not None:
178
+ if credentials is None:
179
+ credentials = AnonymousCredentials()
180
+ if project is None:
181
+ project = _DEFAULT_BIGTABLE_EMULATOR_CLIENT
182
+
183
+ if channel is not None:
184
+ warnings.warn(
185
+ "'channel' is deprecated and no longer used.",
186
+ DeprecationWarning,
187
+ stacklevel=2,
188
+ )
189
+
190
+ self._client_options = client_options
191
+ self._admin_client_options = admin_client_options
192
+ self._channel = channel
193
+ self.SCOPE = self._get_scopes()
194
+ super(Client, self).__init__(
195
+ project=project,
196
+ credentials=credentials,
197
+ client_options=client_options,
198
+ )
199
+
200
+ def _get_scopes(self):
201
+ """Get the scopes corresponding to admin / read-only state.
202
+
203
+ Returns:
204
+ Tuple[str, ...]: The tuple of scopes.
205
+ """
206
+ if self._read_only:
207
+ scopes = (READ_ONLY_SCOPE,)
208
+ else:
209
+ scopes = (DATA_SCOPE,)
210
+
211
+ if self._admin:
212
+ scopes += (ADMIN_SCOPE,)
213
+
214
+ return scopes
215
+
216
+ def _emulator_channel(self, transport, options):
217
+ """Create a channel for use with the Bigtable emulator.
218
+
219
+ Insecure channels are used for the emulator as secure channels
220
+ cannot be used to communicate on some environments.
221
+ https://github.com/googleapis/python-firestore/issues/359
222
+
223
+ Returns:
224
+ grpc.Channel or grpc.aio.Channel
225
+ """
226
+ # Note: this code also exists in the firestore client.
227
+ if "GrpcAsyncIOTransport" in str(transport.__name__):
228
+ channel_fn = grpc.aio.insecure_channel
229
+ else:
230
+ channel_fn = grpc.insecure_channel
231
+ return channel_fn(self._emulator_host, options=options)
232
+
233
+ def _create_gapic_client_channel(self, client_class, grpc_transport):
234
+ if self._emulator_host is not None:
235
+ api_endpoint = self._emulator_host
236
+ elif self._client_options and self._client_options.api_endpoint:
237
+ api_endpoint = self._client_options.api_endpoint
238
+ else:
239
+ api_endpoint = client_class.DEFAULT_ENDPOINT
240
+
241
+ if self._emulator_host is not None:
242
+ channel = self._emulator_channel(
243
+ transport=grpc_transport,
244
+ options=_GRPC_CHANNEL_OPTIONS,
245
+ )
246
+ else:
247
+ channel = grpc_transport.create_channel(
248
+ host=api_endpoint,
249
+ credentials=self._credentials,
250
+ options=_GRPC_CHANNEL_OPTIONS,
251
+ )
252
+ return grpc_transport(channel=channel, host=api_endpoint)
253
+
254
+ @property
255
+ def project_path(self):
256
+ """Project name to be used with Instance Admin API.
257
+
258
+ .. note::
259
+
260
+ This property will not change if ``project`` does not, but the
261
+ return value is not cached.
262
+
263
+ For example:
264
+
265
+ .. literalinclude:: snippets.py
266
+ :start-after: [START bigtable_api_project_path]
267
+ :end-before: [END bigtable_api_project_path]
268
+ :dedent: 4
269
+
270
+ The project name is of the form
271
+
272
+ ``"projects/{project}"``
273
+
274
+ :rtype: str
275
+ :returns: Return a fully-qualified project string.
276
+ """
277
+ return self.instance_admin_client.common_project_path(self.project)
278
+
279
+ @property
280
+ def table_data_client(self):
281
+ """Getter for the gRPC stub used for the Table Admin API.
282
+
283
+ For example:
284
+
285
+ .. literalinclude:: snippets.py
286
+ :start-after: [START bigtable_api_table_data_client]
287
+ :end-before: [END bigtable_api_table_data_client]
288
+ :dedent: 4
289
+
290
+ :rtype: :class:`.bigtable_v2.BigtableClient`
291
+ :returns: A BigtableClient object.
292
+ """
293
+ if self._table_data_client is None:
294
+ transport = self._create_gapic_client_channel(
295
+ bigtable_v2.BigtableClient,
296
+ BigtableGrpcTransport,
297
+ )
298
+ klass = _create_gapic_client(
299
+ bigtable_v2.BigtableClient,
300
+ client_options=self._client_options,
301
+ transport=transport,
302
+ )
303
+ self._table_data_client = klass(self)
304
+ return self._table_data_client
305
+
306
+ @property
307
+ def table_admin_client(self):
308
+ """Getter for the gRPC stub used for the Table Admin API.
309
+
310
+ For example:
311
+
312
+ .. literalinclude:: snippets.py
313
+ :start-after: [START bigtable_api_table_admin_client]
314
+ :end-before: [END bigtable_api_table_admin_client]
315
+ :dedent: 4
316
+
317
+ :rtype: :class:`.bigtable_admin_pb2.BigtableTableAdmin`
318
+ :returns: A BigtableTableAdmin instance.
319
+ :raises: :class:`ValueError <exceptions.ValueError>` if the current
320
+ client is not an admin client or if it has not been
321
+ :meth:`start`-ed.
322
+ """
323
+ if self._table_admin_client is None:
324
+ if not self._admin:
325
+ raise ValueError("Client is not an admin client.")
326
+
327
+ transport = self._create_gapic_client_channel(
328
+ bigtable_admin_v2.BigtableTableAdminClient,
329
+ BigtableTableAdminGrpcTransport,
330
+ )
331
+ klass = _create_gapic_client(
332
+ bigtable_admin_v2.BigtableTableAdminClient,
333
+ client_options=self._admin_client_options,
334
+ transport=transport,
335
+ )
336
+ self._table_admin_client = klass(self)
337
+ return self._table_admin_client
338
+
339
+ @property
340
+ def instance_admin_client(self):
341
+ """Getter for the gRPC stub used for the Table Admin API.
342
+
343
+ For example:
344
+
345
+ .. literalinclude:: snippets.py
346
+ :start-after: [START bigtable_api_instance_admin_client]
347
+ :end-before: [END bigtable_api_instance_admin_client]
348
+ :dedent: 4
349
+
350
+ :rtype: :class:`.bigtable_admin_pb2.BigtableInstanceAdmin`
351
+ :returns: A BigtableInstanceAdmin instance.
352
+ :raises: :class:`ValueError <exceptions.ValueError>` if the current
353
+ client is not an admin client or if it has not been
354
+ :meth:`start`-ed.
355
+ """
356
+ if self._instance_admin_client is None:
357
+ if not self._admin:
358
+ raise ValueError("Client is not an admin client.")
359
+
360
+ transport = self._create_gapic_client_channel(
361
+ bigtable_admin_v2.BigtableInstanceAdminClient,
362
+ BigtableInstanceAdminGrpcTransport,
363
+ )
364
+ klass = _create_gapic_client(
365
+ bigtable_admin_v2.BigtableInstanceAdminClient,
366
+ client_options=self._admin_client_options,
367
+ transport=transport,
368
+ )
369
+ self._instance_admin_client = klass(self)
370
+ return self._instance_admin_client
371
+
372
+ def instance(self, instance_id, display_name=None, instance_type=None, labels=None):
373
+ """Factory to create a instance associated with this client.
374
+
375
+ For example:
376
+
377
+ .. literalinclude:: snippets.py
378
+ :start-after: [START bigtable_api_create_prod_instance]
379
+ :end-before: [END bigtable_api_create_prod_instance]
380
+ :dedent: 4
381
+
382
+ :type instance_id: str
383
+ :param instance_id: The ID of the instance.
384
+
385
+ :type display_name: str
386
+ :param display_name: (Optional) The display name for the instance in
387
+ the Cloud Console UI. (Must be between 4 and 30
388
+ characters.) If this value is not set in the
389
+ constructor, will fall back to the instance ID.
390
+
391
+ :type instance_type: int
392
+ :param instance_type: (Optional) The type of the instance.
393
+ Possible values are represented
394
+ by the following constants:
395
+ :data:`google.cloud.bigtable.instance.InstanceType.PRODUCTION`.
396
+ :data:`google.cloud.bigtable.instance.InstanceType.DEVELOPMENT`,
397
+ Defaults to
398
+ :data:`google.cloud.bigtable.instance.InstanceType.UNSPECIFIED`.
399
+
400
+ :type labels: dict
401
+ :param labels: (Optional) Labels are a flexible and lightweight
402
+ mechanism for organizing cloud resources into groups
403
+ that reflect a customer's organizational needs and
404
+ deployment strategies. They can be used to filter
405
+ resources and aggregate metrics. Label keys must be
406
+ between 1 and 63 characters long. Maximum 64 labels can
407
+ be associated with a given resource. Label values must
408
+ be between 0 and 63 characters long. Keys and values
409
+ must both be under 128 bytes.
410
+
411
+ :rtype: :class:`~google.cloud.bigtable.instance.Instance`
412
+ :returns: an instance owned by this client.
413
+ """
414
+ return Instance(
415
+ instance_id,
416
+ self,
417
+ display_name=display_name,
418
+ instance_type=instance_type,
419
+ labels=labels,
420
+ )
421
+
422
+ def list_instances(self):
423
+ """List instances owned by the project.
424
+
425
+ For example:
426
+
427
+ .. literalinclude:: snippets.py
428
+ :start-after: [START bigtable_api_list_instances]
429
+ :end-before: [END bigtable_api_list_instances]
430
+ :dedent: 4
431
+
432
+ :rtype: tuple
433
+ :returns:
434
+ (instances, failed_locations), where 'instances' is list of
435
+ :class:`google.cloud.bigtable.instance.Instance`, and
436
+ 'failed_locations' is a list of locations which could not
437
+ be resolved.
438
+ """
439
+ resp = self.instance_admin_client.list_instances(
440
+ request={"parent": self.project_path}
441
+ )
442
+ instances = [Instance.from_pb(instance, self) for instance in resp.instances]
443
+ return instances, resp.failed_locations
444
+
445
+ def list_clusters(self):
446
+ """List the clusters in the project.
447
+
448
+ For example:
449
+
450
+ .. literalinclude:: snippets.py
451
+ :start-after: [START bigtable_api_list_clusters_in_project]
452
+ :end-before: [END bigtable_api_list_clusters_in_project]
453
+ :dedent: 4
454
+
455
+ :rtype: tuple
456
+ :returns:
457
+ (clusters, failed_locations), where 'clusters' is list of
458
+ :class:`google.cloud.bigtable.instance.Cluster`, and
459
+ 'failed_locations' is a list of strings representing
460
+ locations which could not be resolved.
461
+ """
462
+ resp = self.instance_admin_client.list_clusters(
463
+ request={
464
+ "parent": self.instance_admin_client.instance_path(self.project, "-")
465
+ }
466
+ )
467
+ clusters = []
468
+ instances = {}
469
+ for cluster in resp.clusters:
470
+ match_cluster_name = _CLUSTER_NAME_RE.match(cluster.name)
471
+ instance_id = match_cluster_name.group("instance")
472
+ if instance_id not in instances:
473
+ instances[instance_id] = self.instance(instance_id)
474
+ clusters.append(Cluster.from_pb(cluster, instances[instance_id]))
475
+ return clusters, resp.failed_locations