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,490 @@
1
+ # Copyright 2020 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
+ """A user-friendly wrapper for a Google Cloud Bigtable Backup."""
16
+
17
+ import re
18
+
19
+ from google.cloud._helpers import _datetime_to_pb_timestamp # type: ignore
20
+ from google.cloud.bigtable_admin_v2 import BigtableTableAdminClient
21
+ from google.cloud.bigtable_admin_v2.types import table
22
+ from google.cloud.bigtable.encryption_info import EncryptionInfo
23
+ from google.cloud.bigtable.policy import Policy
24
+ from google.cloud.exceptions import NotFound # type: ignore
25
+ from google.protobuf import field_mask_pb2
26
+
27
+ _BACKUP_NAME_RE = re.compile(
28
+ r"^projects/(?P<project>[^/]+)/"
29
+ r"instances/(?P<instance_id>[a-z][-a-z0-9]*)/"
30
+ r"clusters/(?P<cluster_id>[a-z][-a-z0-9]*)/"
31
+ r"backups/(?P<backup_id>[_a-zA-Z0-9][-_.a-zA-Z0-9]*)$"
32
+ )
33
+
34
+ _TABLE_NAME_RE = re.compile(
35
+ r"^projects/(?P<project>[^/]+)/"
36
+ r"instances/(?P<instance_id>[a-z][-a-z0-9]*)/"
37
+ r"tables/(?P<table_id>[_a-zA-Z0-9][-_.a-zA-Z0-9]*)$"
38
+ )
39
+
40
+
41
+ class Backup(object):
42
+ """Representation of a Google Cloud Bigtable Backup.
43
+
44
+ A :class: `Backup` can be used to:
45
+
46
+ * :meth:`create` the backup
47
+ * :meth:`update` the backup
48
+ * :meth:`delete` the backup
49
+
50
+ :type backup_id: str
51
+ :param backup_id: The ID of the backup.
52
+
53
+ :type instance: :class:`~google.cloud.bigtable.instance.Instance`
54
+ :param instance: The Instance that owns this Backup.
55
+
56
+ :type cluster_id: str
57
+ :param cluster_id: (Optional) The ID of the Cluster that contains this Backup.
58
+ Required for calling 'delete', 'exists' etc. methods.
59
+
60
+ :type table_id: str
61
+ :param table_id: (Optional) The ID of the Table that the Backup is for.
62
+ Required if the 'create' method will be called.
63
+
64
+ :type expire_time: :class:`datetime.datetime`
65
+ :param expire_time: (Optional) The expiration time after which the Backup
66
+ will be automatically deleted. Required if the `create`
67
+ method will be called.
68
+ """
69
+
70
+ def __init__(
71
+ self,
72
+ backup_id,
73
+ instance,
74
+ cluster_id=None,
75
+ table_id=None,
76
+ expire_time=None,
77
+ encryption_info=None,
78
+ ):
79
+ self.backup_id = backup_id
80
+ self._instance = instance
81
+ self._cluster = cluster_id
82
+ self.table_id = table_id
83
+ self._expire_time = expire_time
84
+ self._encryption_info = encryption_info
85
+
86
+ self._parent = None
87
+ self._source_table = None
88
+ self._start_time = None
89
+ self._end_time = None
90
+ self._size_bytes = None
91
+ self._state = None
92
+
93
+ @property
94
+ def name(self):
95
+ """Backup name used in requests.
96
+
97
+ The Backup name is of the form
98
+
99
+ ``"projects/../instances/../clusters/../backups/{backup_id}"``
100
+
101
+ :rtype: str
102
+ :returns: The Backup name.
103
+
104
+ :raises: ValueError: If the 'cluster' has not been set.
105
+ """
106
+ if not self._cluster:
107
+ raise ValueError('"cluster" parameter must be set')
108
+
109
+ return BigtableTableAdminClient.backup_path(
110
+ project=self._instance._client.project,
111
+ instance=self._instance.instance_id,
112
+ cluster=self._cluster,
113
+ backup=self.backup_id,
114
+ )
115
+
116
+ @property
117
+ def cluster(self):
118
+ """The ID of the [parent] cluster used in requests.
119
+
120
+ :rtype: str
121
+ :returns: The ID of the cluster containing the Backup.
122
+ """
123
+ return self._cluster
124
+
125
+ @cluster.setter
126
+ def cluster(self, cluster_id):
127
+ self._cluster = cluster_id
128
+
129
+ @property
130
+ def parent(self):
131
+ """Name of the parent cluster used in requests.
132
+
133
+ .. note::
134
+ This property will return None if ``cluster`` is not set.
135
+
136
+ The parent name is of the form
137
+
138
+ ``"projects/{project}/instances/{instance_id}/clusters/{cluster}"``
139
+
140
+ :rtype: str
141
+ :returns: A full path to the parent cluster.
142
+ """
143
+ if not self._parent and self._cluster:
144
+ self._parent = BigtableTableAdminClient.cluster_path(
145
+ project=self._instance._client.project,
146
+ instance=self._instance.instance_id,
147
+ cluster=self._cluster,
148
+ )
149
+ return self._parent
150
+
151
+ @property
152
+ def source_table(self):
153
+ """The full name of the Table from which this Backup is created.
154
+
155
+ .. note::
156
+ This property will return None if ``table_id`` is not set.
157
+
158
+ The table name is of the form
159
+
160
+ ``"projects/../instances/../tables/{source_table}"``
161
+
162
+ :rtype: str
163
+ :returns: The Table name.
164
+ """
165
+ if not self._source_table and self.table_id:
166
+ self._source_table = BigtableTableAdminClient.table_path(
167
+ project=self._instance._client.project,
168
+ instance=self._instance.instance_id,
169
+ table=self.table_id,
170
+ )
171
+ return self._source_table
172
+
173
+ @property
174
+ def expire_time(self):
175
+ """Expiration time used in the creation requests.
176
+
177
+ :rtype: :class:`datetime.datetime`
178
+ :returns: A 'datetime' object representing the expiration time of
179
+ this Backup.
180
+ """
181
+ return self._expire_time
182
+
183
+ @expire_time.setter
184
+ def expire_time(self, new_expire_time):
185
+ self._expire_time = new_expire_time
186
+
187
+ @property
188
+ def encryption_info(self):
189
+ """Encryption info for this Backup.
190
+
191
+ :rtype: :class:`google.cloud.bigtable.encryption.EncryptionInfo`
192
+ :returns: The encryption information for this backup.
193
+ """
194
+ return self._encryption_info
195
+
196
+ @property
197
+ def start_time(self):
198
+ """The time this Backup was started.
199
+
200
+ :rtype: :class:`datetime.datetime`
201
+ :returns: A 'datetime' object representing the time when the creation
202
+ of this Backup had started.
203
+ """
204
+ return self._start_time
205
+
206
+ @property
207
+ def end_time(self):
208
+ """The time this Backup was finished.
209
+
210
+ :rtype: :class:`datetime.datetime`
211
+ :returns: A 'datetime' object representing the time when the creation
212
+ of this Backup was finished.
213
+ """
214
+ return self._end_time
215
+
216
+ @property
217
+ def size_bytes(self):
218
+ """The size of this Backup, in bytes.
219
+
220
+ :rtype: int
221
+ :returns: The size of this Backup, in bytes.
222
+ """
223
+ return self._size_bytes
224
+
225
+ @property
226
+ def state(self):
227
+ """The current state of this Backup.
228
+
229
+ :rtype: :class:`~google.cloud.bigtable_admin_v2.gapic.enums.Backup.State`
230
+ :returns: The current state of this Backup.
231
+ """
232
+ return self._state
233
+
234
+ @classmethod
235
+ def from_pb(cls, backup_pb, instance):
236
+ """Creates a Backup instance from a protobuf message.
237
+
238
+ :type backup_pb: :class:`table.Backup`
239
+ :param backup_pb: A Backup protobuf object.
240
+
241
+ :type instance: :class:`Instance <google.cloud.bigtable.instance.Instance>`
242
+ :param instance: The Instance that owns the Backup.
243
+
244
+ :rtype: :class:`~google.cloud.bigtable.backup.Backup`
245
+ :returns: The backup parsed from the protobuf response.
246
+ :raises: ValueError: If the backup name does not match the expected
247
+ format or the parsed project ID does not match the
248
+ project ID on the Instance's client, or if the
249
+ parsed instance ID does not match the Instance ID.
250
+ """
251
+ match = _BACKUP_NAME_RE.match(backup_pb.name)
252
+ if match is None:
253
+ raise ValueError(
254
+ "Backup protobuf name was not in the expected format.", backup_pb.name
255
+ )
256
+ if match.group("project") != instance._client.project:
257
+ raise ValueError(
258
+ "Project ID of the Backup does not match the Project ID "
259
+ "of the instance's client"
260
+ )
261
+
262
+ instance_id = match.group("instance_id")
263
+ if instance_id != instance.instance_id:
264
+ raise ValueError(
265
+ "Instance ID of the Backup does not match the Instance ID "
266
+ "of the instance"
267
+ )
268
+ backup_id = match.group("backup_id")
269
+ cluster_id = match.group("cluster_id")
270
+
271
+ match = _TABLE_NAME_RE.match(backup_pb.source_table)
272
+ table_id = match.group("table_id") if match else None
273
+
274
+ expire_time = backup_pb._pb.expire_time
275
+ encryption_info = EncryptionInfo._from_pb(backup_pb.encryption_info)
276
+
277
+ backup = cls(
278
+ backup_id,
279
+ instance,
280
+ cluster_id=cluster_id,
281
+ table_id=table_id,
282
+ expire_time=expire_time,
283
+ encryption_info=encryption_info,
284
+ )
285
+ backup._start_time = backup_pb._pb.start_time
286
+ backup._end_time = backup_pb._pb.end_time
287
+ backup._size_bytes = backup_pb._pb.size_bytes
288
+ backup._state = backup_pb._pb.state
289
+
290
+ return backup
291
+
292
+ def __eq__(self, other):
293
+ if not isinstance(other, self.__class__):
294
+ return NotImplemented
295
+ return other.backup_id == self.backup_id and other._instance == self._instance
296
+
297
+ def __ne__(self, other):
298
+ return not self == other
299
+
300
+ def create(self, cluster_id=None):
301
+ """Creates this backup within its instance.
302
+
303
+ :type cluster_id: str
304
+ :param cluster_id: (Optional) The ID of the Cluster for the newly
305
+ created Backup.
306
+
307
+ :rtype: :class:`~google.api_core.operation.Operation`
308
+ :returns: :class:`~google.cloud.bigtable_admin_v2.types._OperationFuture`
309
+ instance, to be used to poll the status of the 'create' request
310
+ :raises Conflict: if the Backup already exists
311
+ :raises NotFound: if the Instance owning the Backup does not exist
312
+ :raises BadRequest: if the `table` or `expire_time` values are invalid,
313
+ or `expire_time` is not set
314
+ """
315
+ if not self._expire_time:
316
+ raise ValueError('"expire_time" parameter must be set')
317
+ # TODO: Consider implementing a method that sets a default value of
318
+ # `expire_time`, e.g. 1 week from the creation of the Backup.
319
+ if not self.table_id:
320
+ raise ValueError('"table" parameter must be set')
321
+
322
+ if cluster_id:
323
+ self._cluster = cluster_id
324
+
325
+ if not self._cluster:
326
+ raise ValueError('"cluster" parameter must be set')
327
+
328
+ backup = table.Backup(
329
+ source_table=self.source_table,
330
+ expire_time=_datetime_to_pb_timestamp(self.expire_time),
331
+ )
332
+
333
+ api = self._instance._client.table_admin_client
334
+ return api.create_backup(
335
+ request={
336
+ "parent": self.parent,
337
+ "backup_id": self.backup_id,
338
+ "backup": backup,
339
+ }
340
+ )
341
+
342
+ def get(self):
343
+ """Retrieves metadata of a pending or completed Backup.
344
+
345
+ :returns: An instance of
346
+ :class:`~google.cloud.bigtable_admin_v2.types.Backup`
347
+
348
+ :raises google.api_core.exceptions.GoogleAPICallError: If the request
349
+ failed for any reason.
350
+ :raises google.api_core.exceptions.RetryError: If the request failed
351
+ due to a retryable error and retry attempts failed.
352
+ :raises ValueError: If the parameters are invalid.
353
+ """
354
+ api = self._instance._client.table_admin_client
355
+ try:
356
+ return api.get_backup(request={"name": self.name})
357
+ except NotFound:
358
+ return None
359
+
360
+ def reload(self):
361
+ """Refreshes the stored backup properties."""
362
+ backup = self.get()
363
+ self._source_table = backup.source_table
364
+ self._expire_time = backup._pb.expire_time
365
+ self._start_time = backup._pb.start_time
366
+ self._end_time = backup._pb.end_time
367
+ self._size_bytes = backup._pb.size_bytes
368
+ self._state = backup._pb.state
369
+
370
+ def exists(self):
371
+ """Tests whether this Backup exists.
372
+
373
+ :rtype: bool
374
+ :returns: True if the Backup exists, else False.
375
+ """
376
+ return self.get() is not None
377
+
378
+ def update_expire_time(self, new_expire_time):
379
+ """Update the expire time of this Backup.
380
+
381
+ :type new_expire_time: :class:`datetime.datetime`
382
+ :param new_expire_time: the new expiration time timestamp
383
+ """
384
+ backup_update = table.Backup(
385
+ name=self.name,
386
+ expire_time=_datetime_to_pb_timestamp(new_expire_time),
387
+ )
388
+ update_mask = field_mask_pb2.FieldMask(paths=["expire_time"])
389
+ api = self._instance._client.table_admin_client
390
+ api.update_backup(request={"backup": backup_update, "update_mask": update_mask})
391
+ self._expire_time = new_expire_time
392
+
393
+ def delete(self):
394
+ """Delete this Backup."""
395
+ self._instance._client.table_admin_client.delete_backup(
396
+ request={"name": self.name}
397
+ )
398
+
399
+ def restore(self, table_id, instance_id=None):
400
+ """Creates a new Table by restoring from this Backup. The new Table
401
+ can be created in the same Instance as the Instance containing the
402
+ Backup, or another Instance whose ID can be specified in the arguments.
403
+ The returned Table ``long-running operation`` can be used to track the
404
+ progress of the operation and to cancel it. The ``response`` type is
405
+ ``Table``, if successful.
406
+
407
+ :type table_id: str
408
+ :param table_id: The ID of the Table to create and restore to.
409
+ This Table must not already exist.
410
+
411
+ :type instance_id: str
412
+ :param instance_id: (Optional) The ID of the Instance to restore the
413
+ backup into, if different from the current one.
414
+
415
+ :rtype: :class:`~google.cloud.bigtable_admin_v2.types._OperationFuture`
416
+ :returns: A future to be used to poll the status of the 'restore'
417
+ request.
418
+
419
+ :raises: google.api_core.exceptions.AlreadyExists: If the table
420
+ already exists.
421
+ :raises: google.api_core.exceptions.GoogleAPICallError: If the request
422
+ failed for any reason.
423
+ :raises: google.api_core.exceptions.RetryError: If the request failed
424
+ due to a retryable error and retry attempts failed.
425
+ :raises: ValueError: If the parameters are invalid.
426
+ """
427
+ api = self._instance._client.table_admin_client
428
+ if instance_id:
429
+ parent = BigtableTableAdminClient.instance_path(
430
+ project=self._instance._client.project,
431
+ instance=instance_id,
432
+ )
433
+ else:
434
+ parent = self._instance.name
435
+
436
+ return api.restore_table(
437
+ request={"parent": parent, "table_id": table_id, "backup": self.name}
438
+ )
439
+
440
+ def get_iam_policy(self):
441
+ """Gets the IAM access control policy for this backup.
442
+
443
+ :rtype: :class:`google.cloud.bigtable.policy.Policy`
444
+ :returns: The current IAM policy of this backup.
445
+ """
446
+ table_api = self._instance._client.table_admin_client
447
+ response = table_api.get_iam_policy(request={"resource": self.name})
448
+ return Policy.from_pb(response)
449
+
450
+ def set_iam_policy(self, policy):
451
+ """Sets the IAM access control policy for this backup. Replaces any
452
+ existing policy.
453
+
454
+ For more information about policy, please see documentation of
455
+ class `google.cloud.bigtable.policy.Policy`
456
+
457
+ :type policy: :class:`google.cloud.bigtable.policy.Policy`
458
+ :param policy: A new IAM policy to replace the current IAM policy
459
+ of this backup.
460
+
461
+ :rtype: :class:`google.cloud.bigtable.policy.Policy`
462
+ :returns: The current IAM policy of this backup.
463
+ """
464
+ table_api = self._instance._client.table_admin_client
465
+ response = table_api.set_iam_policy(
466
+ request={"resource": self.name, "policy": policy.to_pb()}
467
+ )
468
+ return Policy.from_pb(response)
469
+
470
+ def test_iam_permissions(self, permissions):
471
+ """Tests whether the caller has the given permissions for this backup.
472
+ Returns the permissions that the caller has.
473
+
474
+ :type permissions: list
475
+ :param permissions: The set of permissions to check for
476
+ the ``resource``. Permissions with wildcards (such as '*'
477
+ or 'storage.*') are not allowed. For more information see
478
+ `IAM Overview
479
+ <https://cloud.google.com/iam/docs/overview#permissions>`_.
480
+ `Bigtable Permissions
481
+ <https://cloud.google.com/bigtable/docs/access-control>`_.
482
+
483
+ :rtype: list
484
+ :returns: A List(string) of permissions allowed on the backup.
485
+ """
486
+ table_api = self._instance._client.table_admin_client
487
+ response = table_api.test_iam_permissions(
488
+ request={"resource": self.name, "permissions": permissions}
489
+ )
490
+ return list(response.permissions)