google-cloud-spanner 3.55.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 (119) hide show
  1. google/cloud/spanner.py +47 -0
  2. google/cloud/spanner_admin_database_v1/__init__.py +146 -0
  3. google/cloud/spanner_admin_database_v1/gapic_metadata.json +418 -0
  4. google/cloud/spanner_admin_database_v1/gapic_version.py +16 -0
  5. google/cloud/spanner_admin_database_v1/py.typed +2 -0
  6. google/cloud/spanner_admin_database_v1/services/__init__.py +15 -0
  7. google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +22 -0
  8. google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +4097 -0
  9. google/cloud/spanner_admin_database_v1/services/database_admin/client.py +4602 -0
  10. google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +989 -0
  11. google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +38 -0
  12. google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +820 -0
  13. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +1303 -0
  14. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +1688 -0
  15. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +6512 -0
  16. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest_base.py +1650 -0
  17. google/cloud/spanner_admin_database_v1/types/__init__.py +144 -0
  18. google/cloud/spanner_admin_database_v1/types/backup.py +1106 -0
  19. google/cloud/spanner_admin_database_v1/types/backup_schedule.py +369 -0
  20. google/cloud/spanner_admin_database_v1/types/common.py +180 -0
  21. google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +1303 -0
  22. google/cloud/spanner_admin_instance_v1/__init__.py +110 -0
  23. google/cloud/spanner_admin_instance_v1/gapic_metadata.json +343 -0
  24. google/cloud/spanner_admin_instance_v1/gapic_version.py +16 -0
  25. google/cloud/spanner_admin_instance_v1/py.typed +2 -0
  26. google/cloud/spanner_admin_instance_v1/services/__init__.py +15 -0
  27. google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +22 -0
  28. google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +3466 -0
  29. google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +3881 -0
  30. google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +856 -0
  31. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +38 -0
  32. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +545 -0
  33. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +1347 -0
  34. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +1539 -0
  35. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py +4834 -0
  36. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest_base.py +1198 -0
  37. google/cloud/spanner_admin_instance_v1/types/__init__.py +104 -0
  38. google/cloud/spanner_admin_instance_v1/types/common.py +99 -0
  39. google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +2375 -0
  40. google/cloud/spanner_dbapi/__init__.py +93 -0
  41. google/cloud/spanner_dbapi/_helpers.py +113 -0
  42. google/cloud/spanner_dbapi/batch_dml_executor.py +135 -0
  43. google/cloud/spanner_dbapi/checksum.py +80 -0
  44. google/cloud/spanner_dbapi/client_side_statement_executor.py +140 -0
  45. google/cloud/spanner_dbapi/client_side_statement_parser.py +106 -0
  46. google/cloud/spanner_dbapi/connection.py +818 -0
  47. google/cloud/spanner_dbapi/cursor.py +609 -0
  48. google/cloud/spanner_dbapi/exceptions.py +172 -0
  49. google/cloud/spanner_dbapi/parse_utils.py +392 -0
  50. google/cloud/spanner_dbapi/parsed_statement.py +63 -0
  51. google/cloud/spanner_dbapi/parser.py +258 -0
  52. google/cloud/spanner_dbapi/partition_helper.py +41 -0
  53. google/cloud/spanner_dbapi/transaction_helper.py +294 -0
  54. google/cloud/spanner_dbapi/types.py +106 -0
  55. google/cloud/spanner_dbapi/utils.py +147 -0
  56. google/cloud/spanner_dbapi/version.py +20 -0
  57. google/cloud/spanner_v1/__init__.py +154 -0
  58. google/cloud/spanner_v1/_helpers.py +751 -0
  59. google/cloud/spanner_v1/_opentelemetry_tracing.py +165 -0
  60. google/cloud/spanner_v1/backup.py +397 -0
  61. google/cloud/spanner_v1/batch.py +433 -0
  62. google/cloud/spanner_v1/client.py +538 -0
  63. google/cloud/spanner_v1/data_types.py +350 -0
  64. google/cloud/spanner_v1/database.py +1968 -0
  65. google/cloud/spanner_v1/database_sessions_manager.py +249 -0
  66. google/cloud/spanner_v1/gapic_metadata.json +268 -0
  67. google/cloud/spanner_v1/gapic_version.py +16 -0
  68. google/cloud/spanner_v1/instance.py +735 -0
  69. google/cloud/spanner_v1/keyset.py +193 -0
  70. google/cloud/spanner_v1/merged_result_set.py +146 -0
  71. google/cloud/spanner_v1/metrics/constants.py +71 -0
  72. google/cloud/spanner_v1/metrics/metrics_capture.py +75 -0
  73. google/cloud/spanner_v1/metrics/metrics_exporter.py +384 -0
  74. google/cloud/spanner_v1/metrics/metrics_interceptor.py +156 -0
  75. google/cloud/spanner_v1/metrics/metrics_tracer.py +588 -0
  76. google/cloud/spanner_v1/metrics/metrics_tracer_factory.py +328 -0
  77. google/cloud/spanner_v1/metrics/spanner_metrics_tracer_factory.py +172 -0
  78. google/cloud/spanner_v1/param_types.py +110 -0
  79. google/cloud/spanner_v1/pool.py +813 -0
  80. google/cloud/spanner_v1/py.typed +2 -0
  81. google/cloud/spanner_v1/request_id_header.py +64 -0
  82. google/cloud/spanner_v1/services/__init__.py +15 -0
  83. google/cloud/spanner_v1/services/spanner/__init__.py +22 -0
  84. google/cloud/spanner_v1/services/spanner/async_client.py +2205 -0
  85. google/cloud/spanner_v1/services/spanner/client.py +2624 -0
  86. google/cloud/spanner_v1/services/spanner/pagers.py +196 -0
  87. google/cloud/spanner_v1/services/spanner/transports/__init__.py +38 -0
  88. google/cloud/spanner_v1/services/spanner/transports/base.py +520 -0
  89. google/cloud/spanner_v1/services/spanner/transports/grpc.py +911 -0
  90. google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +1144 -0
  91. google/cloud/spanner_v1/services/spanner/transports/rest.py +3468 -0
  92. google/cloud/spanner_v1/services/spanner/transports/rest_base.py +981 -0
  93. google/cloud/spanner_v1/session.py +631 -0
  94. google/cloud/spanner_v1/session_options.py +133 -0
  95. google/cloud/spanner_v1/snapshot.py +1057 -0
  96. google/cloud/spanner_v1/streamed.py +402 -0
  97. google/cloud/spanner_v1/table.py +181 -0
  98. google/cloud/spanner_v1/testing/__init__.py +0 -0
  99. google/cloud/spanner_v1/testing/database_test.py +121 -0
  100. google/cloud/spanner_v1/testing/interceptors.py +118 -0
  101. google/cloud/spanner_v1/testing/mock_database_admin.py +38 -0
  102. google/cloud/spanner_v1/testing/mock_spanner.py +261 -0
  103. google/cloud/spanner_v1/testing/spanner_database_admin_pb2_grpc.py +1267 -0
  104. google/cloud/spanner_v1/testing/spanner_pb2_grpc.py +882 -0
  105. google/cloud/spanner_v1/transaction.py +747 -0
  106. google/cloud/spanner_v1/types/__init__.py +118 -0
  107. google/cloud/spanner_v1/types/commit_response.py +94 -0
  108. google/cloud/spanner_v1/types/keys.py +248 -0
  109. google/cloud/spanner_v1/types/mutation.py +201 -0
  110. google/cloud/spanner_v1/types/query_plan.py +220 -0
  111. google/cloud/spanner_v1/types/result_set.py +379 -0
  112. google/cloud/spanner_v1/types/spanner.py +1815 -0
  113. google/cloud/spanner_v1/types/transaction.py +818 -0
  114. google/cloud/spanner_v1/types/type.py +288 -0
  115. google_cloud_spanner-3.55.0.dist-info/LICENSE +202 -0
  116. google_cloud_spanner-3.55.0.dist-info/METADATA +318 -0
  117. google_cloud_spanner-3.55.0.dist-info/RECORD +119 -0
  118. google_cloud_spanner-3.55.0.dist-info/WHEEL +5 -0
  119. google_cloud_spanner-3.55.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,4602 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2025 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from collections import OrderedDict
17
+ from http import HTTPStatus
18
+ import json
19
+ import logging as std_logging
20
+ import os
21
+ import re
22
+ from typing import (
23
+ Dict,
24
+ Callable,
25
+ Mapping,
26
+ MutableMapping,
27
+ MutableSequence,
28
+ Optional,
29
+ Sequence,
30
+ Tuple,
31
+ Type,
32
+ Union,
33
+ cast,
34
+ )
35
+ import warnings
36
+
37
+ from google.cloud.spanner_admin_database_v1 import gapic_version as package_version
38
+
39
+ from google.api_core import client_options as client_options_lib
40
+ from google.api_core import exceptions as core_exceptions
41
+ from google.api_core import gapic_v1
42
+ from google.api_core import retry as retries
43
+ from google.auth import credentials as ga_credentials # type: ignore
44
+ from google.auth.transport import mtls # type: ignore
45
+ from google.auth.transport.grpc import SslCredentials # type: ignore
46
+ from google.auth.exceptions import MutualTLSChannelError # type: ignore
47
+ from google.oauth2 import service_account # type: ignore
48
+ import google.protobuf
49
+
50
+ try:
51
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
52
+ except AttributeError: # pragma: NO COVER
53
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
54
+
55
+ try:
56
+ from google.api_core import client_logging # type: ignore
57
+
58
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
59
+ except ImportError: # pragma: NO COVER
60
+ CLIENT_LOGGING_SUPPORTED = False
61
+
62
+ _LOGGER = std_logging.getLogger(__name__)
63
+
64
+ from google.api_core import operation # type: ignore
65
+ from google.api_core import operation_async # type: ignore
66
+ from google.cloud.spanner_admin_database_v1.services.database_admin import pagers
67
+ from google.cloud.spanner_admin_database_v1.types import backup
68
+ from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup
69
+ from google.cloud.spanner_admin_database_v1.types import backup_schedule
70
+ from google.cloud.spanner_admin_database_v1.types import (
71
+ backup_schedule as gsad_backup_schedule,
72
+ )
73
+ from google.cloud.spanner_admin_database_v1.types import common
74
+ from google.cloud.spanner_admin_database_v1.types import spanner_database_admin
75
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
76
+ from google.iam.v1 import policy_pb2 # type: ignore
77
+ from google.longrunning import operations_pb2 # type: ignore
78
+ from google.longrunning import operations_pb2 # type: ignore
79
+ from google.protobuf import duration_pb2 # type: ignore
80
+ from google.protobuf import empty_pb2 # type: ignore
81
+ from google.protobuf import field_mask_pb2 # type: ignore
82
+ from google.protobuf import timestamp_pb2 # type: ignore
83
+ from .transports.base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO
84
+ from .transports.grpc import DatabaseAdminGrpcTransport
85
+ from .transports.grpc_asyncio import DatabaseAdminGrpcAsyncIOTransport
86
+ from .transports.rest import DatabaseAdminRestTransport
87
+
88
+
89
+ class DatabaseAdminClientMeta(type):
90
+ """Metaclass for the DatabaseAdmin client.
91
+
92
+ This provides class-level methods for building and retrieving
93
+ support objects (e.g. transport) without polluting the client instance
94
+ objects.
95
+ """
96
+
97
+ _transport_registry = OrderedDict() # type: Dict[str, Type[DatabaseAdminTransport]]
98
+ _transport_registry["grpc"] = DatabaseAdminGrpcTransport
99
+ _transport_registry["grpc_asyncio"] = DatabaseAdminGrpcAsyncIOTransport
100
+ _transport_registry["rest"] = DatabaseAdminRestTransport
101
+
102
+ def get_transport_class(
103
+ cls,
104
+ label: Optional[str] = None,
105
+ ) -> Type[DatabaseAdminTransport]:
106
+ """Returns an appropriate transport class.
107
+
108
+ Args:
109
+ label: The name of the desired transport. If none is
110
+ provided, then the first transport in the registry is used.
111
+
112
+ Returns:
113
+ The transport class to use.
114
+ """
115
+ # If a specific transport is requested, return that one.
116
+ if label:
117
+ return cls._transport_registry[label]
118
+
119
+ # No transport is requested; return the default (that is, the first one
120
+ # in the dictionary).
121
+ return next(iter(cls._transport_registry.values()))
122
+
123
+
124
+ class DatabaseAdminClient(metaclass=DatabaseAdminClientMeta):
125
+ """Cloud Spanner Database Admin API
126
+
127
+ The Cloud Spanner Database Admin API can be used to:
128
+
129
+ - create, drop, and list databases
130
+ - update the schema of pre-existing databases
131
+ - create, delete, copy and list backups for a database
132
+ - restore a database from an existing backup
133
+ """
134
+
135
+ @staticmethod
136
+ def _get_default_mtls_endpoint(api_endpoint):
137
+ """Converts api endpoint to mTLS endpoint.
138
+
139
+ Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
140
+ "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
141
+ Args:
142
+ api_endpoint (Optional[str]): the api endpoint to convert.
143
+ Returns:
144
+ str: converted mTLS api endpoint.
145
+ """
146
+ if not api_endpoint:
147
+ return api_endpoint
148
+
149
+ mtls_endpoint_re = re.compile(
150
+ r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
151
+ )
152
+
153
+ m = mtls_endpoint_re.match(api_endpoint)
154
+ name, mtls, sandbox, googledomain = m.groups()
155
+ if mtls or not googledomain:
156
+ return api_endpoint
157
+
158
+ if sandbox:
159
+ return api_endpoint.replace(
160
+ "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
161
+ )
162
+
163
+ return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
164
+
165
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
166
+ DEFAULT_ENDPOINT = "spanner.googleapis.com"
167
+ DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
168
+ DEFAULT_ENDPOINT
169
+ )
170
+
171
+ _DEFAULT_ENDPOINT_TEMPLATE = "spanner.{UNIVERSE_DOMAIN}"
172
+ _DEFAULT_UNIVERSE = "googleapis.com"
173
+
174
+ @classmethod
175
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
176
+ """Creates an instance of this client using the provided credentials
177
+ info.
178
+
179
+ Args:
180
+ info (dict): The service account private key info.
181
+ args: Additional arguments to pass to the constructor.
182
+ kwargs: Additional arguments to pass to the constructor.
183
+
184
+ Returns:
185
+ DatabaseAdminClient: The constructed client.
186
+ """
187
+ credentials = service_account.Credentials.from_service_account_info(info)
188
+ kwargs["credentials"] = credentials
189
+ return cls(*args, **kwargs)
190
+
191
+ @classmethod
192
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
193
+ """Creates an instance of this client using the provided credentials
194
+ file.
195
+
196
+ Args:
197
+ filename (str): The path to the service account private key json
198
+ file.
199
+ args: Additional arguments to pass to the constructor.
200
+ kwargs: Additional arguments to pass to the constructor.
201
+
202
+ Returns:
203
+ DatabaseAdminClient: The constructed client.
204
+ """
205
+ credentials = service_account.Credentials.from_service_account_file(filename)
206
+ kwargs["credentials"] = credentials
207
+ return cls(*args, **kwargs)
208
+
209
+ from_service_account_json = from_service_account_file
210
+
211
+ @property
212
+ def transport(self) -> DatabaseAdminTransport:
213
+ """Returns the transport used by the client instance.
214
+
215
+ Returns:
216
+ DatabaseAdminTransport: The transport used by the client
217
+ instance.
218
+ """
219
+ return self._transport
220
+
221
+ @staticmethod
222
+ def backup_path(
223
+ project: str,
224
+ instance: str,
225
+ backup: str,
226
+ ) -> str:
227
+ """Returns a fully-qualified backup string."""
228
+ return "projects/{project}/instances/{instance}/backups/{backup}".format(
229
+ project=project,
230
+ instance=instance,
231
+ backup=backup,
232
+ )
233
+
234
+ @staticmethod
235
+ def parse_backup_path(path: str) -> Dict[str, str]:
236
+ """Parses a backup path into its component segments."""
237
+ m = re.match(
238
+ r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/backups/(?P<backup>.+?)$",
239
+ path,
240
+ )
241
+ return m.groupdict() if m else {}
242
+
243
+ @staticmethod
244
+ def backup_schedule_path(
245
+ project: str,
246
+ instance: str,
247
+ database: str,
248
+ schedule: str,
249
+ ) -> str:
250
+ """Returns a fully-qualified backup_schedule string."""
251
+ return "projects/{project}/instances/{instance}/databases/{database}/backupSchedules/{schedule}".format(
252
+ project=project,
253
+ instance=instance,
254
+ database=database,
255
+ schedule=schedule,
256
+ )
257
+
258
+ @staticmethod
259
+ def parse_backup_schedule_path(path: str) -> Dict[str, str]:
260
+ """Parses a backup_schedule path into its component segments."""
261
+ m = re.match(
262
+ r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/databases/(?P<database>.+?)/backupSchedules/(?P<schedule>.+?)$",
263
+ path,
264
+ )
265
+ return m.groupdict() if m else {}
266
+
267
+ @staticmethod
268
+ def crypto_key_path(
269
+ project: str,
270
+ location: str,
271
+ key_ring: str,
272
+ crypto_key: str,
273
+ ) -> str:
274
+ """Returns a fully-qualified crypto_key string."""
275
+ return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format(
276
+ project=project,
277
+ location=location,
278
+ key_ring=key_ring,
279
+ crypto_key=crypto_key,
280
+ )
281
+
282
+ @staticmethod
283
+ def parse_crypto_key_path(path: str) -> Dict[str, str]:
284
+ """Parses a crypto_key path into its component segments."""
285
+ m = re.match(
286
+ r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/keyRings/(?P<key_ring>.+?)/cryptoKeys/(?P<crypto_key>.+?)$",
287
+ path,
288
+ )
289
+ return m.groupdict() if m else {}
290
+
291
+ @staticmethod
292
+ def crypto_key_version_path(
293
+ project: str,
294
+ location: str,
295
+ key_ring: str,
296
+ crypto_key: str,
297
+ crypto_key_version: str,
298
+ ) -> str:
299
+ """Returns a fully-qualified crypto_key_version string."""
300
+ return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}".format(
301
+ project=project,
302
+ location=location,
303
+ key_ring=key_ring,
304
+ crypto_key=crypto_key,
305
+ crypto_key_version=crypto_key_version,
306
+ )
307
+
308
+ @staticmethod
309
+ def parse_crypto_key_version_path(path: str) -> Dict[str, str]:
310
+ """Parses a crypto_key_version path into its component segments."""
311
+ m = re.match(
312
+ r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/keyRings/(?P<key_ring>.+?)/cryptoKeys/(?P<crypto_key>.+?)/cryptoKeyVersions/(?P<crypto_key_version>.+?)$",
313
+ path,
314
+ )
315
+ return m.groupdict() if m else {}
316
+
317
+ @staticmethod
318
+ def database_path(
319
+ project: str,
320
+ instance: str,
321
+ database: str,
322
+ ) -> str:
323
+ """Returns a fully-qualified database string."""
324
+ return "projects/{project}/instances/{instance}/databases/{database}".format(
325
+ project=project,
326
+ instance=instance,
327
+ database=database,
328
+ )
329
+
330
+ @staticmethod
331
+ def parse_database_path(path: str) -> Dict[str, str]:
332
+ """Parses a database path into its component segments."""
333
+ m = re.match(
334
+ r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/databases/(?P<database>.+?)$",
335
+ path,
336
+ )
337
+ return m.groupdict() if m else {}
338
+
339
+ @staticmethod
340
+ def database_role_path(
341
+ project: str,
342
+ instance: str,
343
+ database: str,
344
+ role: str,
345
+ ) -> str:
346
+ """Returns a fully-qualified database_role string."""
347
+ return "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}".format(
348
+ project=project,
349
+ instance=instance,
350
+ database=database,
351
+ role=role,
352
+ )
353
+
354
+ @staticmethod
355
+ def parse_database_role_path(path: str) -> Dict[str, str]:
356
+ """Parses a database_role path into its component segments."""
357
+ m = re.match(
358
+ r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/databases/(?P<database>.+?)/databaseRoles/(?P<role>.+?)$",
359
+ path,
360
+ )
361
+ return m.groupdict() if m else {}
362
+
363
+ @staticmethod
364
+ def instance_path(
365
+ project: str,
366
+ instance: str,
367
+ ) -> str:
368
+ """Returns a fully-qualified instance string."""
369
+ return "projects/{project}/instances/{instance}".format(
370
+ project=project,
371
+ instance=instance,
372
+ )
373
+
374
+ @staticmethod
375
+ def parse_instance_path(path: str) -> Dict[str, str]:
376
+ """Parses a instance path into its component segments."""
377
+ m = re.match(r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)$", path)
378
+ return m.groupdict() if m else {}
379
+
380
+ @staticmethod
381
+ def instance_partition_path(
382
+ project: str,
383
+ instance: str,
384
+ instance_partition: str,
385
+ ) -> str:
386
+ """Returns a fully-qualified instance_partition string."""
387
+ return "projects/{project}/instances/{instance}/instancePartitions/{instance_partition}".format(
388
+ project=project,
389
+ instance=instance,
390
+ instance_partition=instance_partition,
391
+ )
392
+
393
+ @staticmethod
394
+ def parse_instance_partition_path(path: str) -> Dict[str, str]:
395
+ """Parses a instance_partition path into its component segments."""
396
+ m = re.match(
397
+ r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/instancePartitions/(?P<instance_partition>.+?)$",
398
+ path,
399
+ )
400
+ return m.groupdict() if m else {}
401
+
402
+ @staticmethod
403
+ def common_billing_account_path(
404
+ billing_account: str,
405
+ ) -> str:
406
+ """Returns a fully-qualified billing_account string."""
407
+ return "billingAccounts/{billing_account}".format(
408
+ billing_account=billing_account,
409
+ )
410
+
411
+ @staticmethod
412
+ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
413
+ """Parse a billing_account path into its component segments."""
414
+ m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
415
+ return m.groupdict() if m else {}
416
+
417
+ @staticmethod
418
+ def common_folder_path(
419
+ folder: str,
420
+ ) -> str:
421
+ """Returns a fully-qualified folder string."""
422
+ return "folders/{folder}".format(
423
+ folder=folder,
424
+ )
425
+
426
+ @staticmethod
427
+ def parse_common_folder_path(path: str) -> Dict[str, str]:
428
+ """Parse a folder path into its component segments."""
429
+ m = re.match(r"^folders/(?P<folder>.+?)$", path)
430
+ return m.groupdict() if m else {}
431
+
432
+ @staticmethod
433
+ def common_organization_path(
434
+ organization: str,
435
+ ) -> str:
436
+ """Returns a fully-qualified organization string."""
437
+ return "organizations/{organization}".format(
438
+ organization=organization,
439
+ )
440
+
441
+ @staticmethod
442
+ def parse_common_organization_path(path: str) -> Dict[str, str]:
443
+ """Parse a organization path into its component segments."""
444
+ m = re.match(r"^organizations/(?P<organization>.+?)$", path)
445
+ return m.groupdict() if m else {}
446
+
447
+ @staticmethod
448
+ def common_project_path(
449
+ project: str,
450
+ ) -> str:
451
+ """Returns a fully-qualified project string."""
452
+ return "projects/{project}".format(
453
+ project=project,
454
+ )
455
+
456
+ @staticmethod
457
+ def parse_common_project_path(path: str) -> Dict[str, str]:
458
+ """Parse a project path into its component segments."""
459
+ m = re.match(r"^projects/(?P<project>.+?)$", path)
460
+ return m.groupdict() if m else {}
461
+
462
+ @staticmethod
463
+ def common_location_path(
464
+ project: str,
465
+ location: str,
466
+ ) -> str:
467
+ """Returns a fully-qualified location string."""
468
+ return "projects/{project}/locations/{location}".format(
469
+ project=project,
470
+ location=location,
471
+ )
472
+
473
+ @staticmethod
474
+ def parse_common_location_path(path: str) -> Dict[str, str]:
475
+ """Parse a location path into its component segments."""
476
+ m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
477
+ return m.groupdict() if m else {}
478
+
479
+ @classmethod
480
+ def get_mtls_endpoint_and_cert_source(
481
+ cls, client_options: Optional[client_options_lib.ClientOptions] = None
482
+ ):
483
+ """Deprecated. Return the API endpoint and client cert source for mutual TLS.
484
+
485
+ The client cert source is determined in the following order:
486
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
487
+ client cert source is None.
488
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
489
+ default client cert source exists, use the default one; otherwise the client cert
490
+ source is None.
491
+
492
+ The API endpoint is determined in the following order:
493
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
494
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
495
+ default mTLS endpoint; if the environment variable is "never", use the default API
496
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
497
+ use the default API endpoint.
498
+
499
+ More details can be found at https://google.aip.dev/auth/4114.
500
+
501
+ Args:
502
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
503
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
504
+ in this method.
505
+
506
+ Returns:
507
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
508
+ client cert source to use.
509
+
510
+ Raises:
511
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
512
+ """
513
+
514
+ warnings.warn(
515
+ "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
516
+ DeprecationWarning,
517
+ )
518
+ if client_options is None:
519
+ client_options = client_options_lib.ClientOptions()
520
+ use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
521
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
522
+ if use_client_cert not in ("true", "false"):
523
+ raise ValueError(
524
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
525
+ )
526
+ if use_mtls_endpoint not in ("auto", "never", "always"):
527
+ raise MutualTLSChannelError(
528
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
529
+ )
530
+
531
+ # Figure out the client cert source to use.
532
+ client_cert_source = None
533
+ if use_client_cert == "true":
534
+ if client_options.client_cert_source:
535
+ client_cert_source = client_options.client_cert_source
536
+ elif mtls.has_default_client_cert_source():
537
+ client_cert_source = mtls.default_client_cert_source()
538
+
539
+ # Figure out which api endpoint to use.
540
+ if client_options.api_endpoint is not None:
541
+ api_endpoint = client_options.api_endpoint
542
+ elif use_mtls_endpoint == "always" or (
543
+ use_mtls_endpoint == "auto" and client_cert_source
544
+ ):
545
+ api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
546
+ else:
547
+ api_endpoint = cls.DEFAULT_ENDPOINT
548
+
549
+ return api_endpoint, client_cert_source
550
+
551
+ @staticmethod
552
+ def _read_environment_variables():
553
+ """Returns the environment variables used by the client.
554
+
555
+ Returns:
556
+ Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
557
+ GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
558
+
559
+ Raises:
560
+ ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
561
+ any of ["true", "false"].
562
+ google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
563
+ is not any of ["auto", "never", "always"].
564
+ """
565
+ use_client_cert = os.getenv(
566
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
567
+ ).lower()
568
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
569
+ universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
570
+ if use_client_cert not in ("true", "false"):
571
+ raise ValueError(
572
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
573
+ )
574
+ if use_mtls_endpoint not in ("auto", "never", "always"):
575
+ raise MutualTLSChannelError(
576
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
577
+ )
578
+ return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
579
+
580
+ @staticmethod
581
+ def _get_client_cert_source(provided_cert_source, use_cert_flag):
582
+ """Return the client cert source to be used by the client.
583
+
584
+ Args:
585
+ provided_cert_source (bytes): The client certificate source provided.
586
+ use_cert_flag (bool): A flag indicating whether to use the client certificate.
587
+
588
+ Returns:
589
+ bytes or None: The client cert source to be used by the client.
590
+ """
591
+ client_cert_source = None
592
+ if use_cert_flag:
593
+ if provided_cert_source:
594
+ client_cert_source = provided_cert_source
595
+ elif mtls.has_default_client_cert_source():
596
+ client_cert_source = mtls.default_client_cert_source()
597
+ return client_cert_source
598
+
599
+ @staticmethod
600
+ def _get_api_endpoint(
601
+ api_override, client_cert_source, universe_domain, use_mtls_endpoint
602
+ ):
603
+ """Return the API endpoint used by the client.
604
+
605
+ Args:
606
+ api_override (str): The API endpoint override. If specified, this is always
607
+ the return value of this function and the other arguments are not used.
608
+ client_cert_source (bytes): The client certificate source used by the client.
609
+ universe_domain (str): The universe domain used by the client.
610
+ use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
611
+ Possible values are "always", "auto", or "never".
612
+
613
+ Returns:
614
+ str: The API endpoint to be used by the client.
615
+ """
616
+ if api_override is not None:
617
+ api_endpoint = api_override
618
+ elif use_mtls_endpoint == "always" or (
619
+ use_mtls_endpoint == "auto" and client_cert_source
620
+ ):
621
+ _default_universe = DatabaseAdminClient._DEFAULT_UNIVERSE
622
+ if universe_domain != _default_universe:
623
+ raise MutualTLSChannelError(
624
+ f"mTLS is not supported in any universe other than {_default_universe}."
625
+ )
626
+ api_endpoint = DatabaseAdminClient.DEFAULT_MTLS_ENDPOINT
627
+ else:
628
+ api_endpoint = DatabaseAdminClient._DEFAULT_ENDPOINT_TEMPLATE.format(
629
+ UNIVERSE_DOMAIN=universe_domain
630
+ )
631
+ return api_endpoint
632
+
633
+ @staticmethod
634
+ def _get_universe_domain(
635
+ client_universe_domain: Optional[str], universe_domain_env: Optional[str]
636
+ ) -> str:
637
+ """Return the universe domain used by the client.
638
+
639
+ Args:
640
+ client_universe_domain (Optional[str]): The universe domain configured via the client options.
641
+ universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
642
+
643
+ Returns:
644
+ str: The universe domain to be used by the client.
645
+
646
+ Raises:
647
+ ValueError: If the universe domain is an empty string.
648
+ """
649
+ universe_domain = DatabaseAdminClient._DEFAULT_UNIVERSE
650
+ if client_universe_domain is not None:
651
+ universe_domain = client_universe_domain
652
+ elif universe_domain_env is not None:
653
+ universe_domain = universe_domain_env
654
+ if len(universe_domain.strip()) == 0:
655
+ raise ValueError("Universe Domain cannot be an empty string.")
656
+ return universe_domain
657
+
658
+ def _validate_universe_domain(self):
659
+ """Validates client's and credentials' universe domains are consistent.
660
+
661
+ Returns:
662
+ bool: True iff the configured universe domain is valid.
663
+
664
+ Raises:
665
+ ValueError: If the configured universe domain is not valid.
666
+ """
667
+
668
+ # NOTE (b/349488459): universe validation is disabled until further notice.
669
+ return True
670
+
671
+ def _add_cred_info_for_auth_errors(
672
+ self, error: core_exceptions.GoogleAPICallError
673
+ ) -> None:
674
+ """Adds credential info string to error details for 401/403/404 errors.
675
+
676
+ Args:
677
+ error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
678
+ """
679
+ if error.code not in [
680
+ HTTPStatus.UNAUTHORIZED,
681
+ HTTPStatus.FORBIDDEN,
682
+ HTTPStatus.NOT_FOUND,
683
+ ]:
684
+ return
685
+
686
+ cred = self._transport._credentials
687
+
688
+ # get_cred_info is only available in google-auth>=2.35.0
689
+ if not hasattr(cred, "get_cred_info"):
690
+ return
691
+
692
+ # ignore the type check since pypy test fails when get_cred_info
693
+ # is not available
694
+ cred_info = cred.get_cred_info() # type: ignore
695
+ if cred_info and hasattr(error._details, "append"):
696
+ error._details.append(json.dumps(cred_info))
697
+
698
+ @property
699
+ def api_endpoint(self):
700
+ """Return the API endpoint used by the client instance.
701
+
702
+ Returns:
703
+ str: The API endpoint used by the client instance.
704
+ """
705
+ return self._api_endpoint
706
+
707
+ @property
708
+ def universe_domain(self) -> str:
709
+ """Return the universe domain used by the client instance.
710
+
711
+ Returns:
712
+ str: The universe domain used by the client instance.
713
+ """
714
+ return self._universe_domain
715
+
716
+ def __init__(
717
+ self,
718
+ *,
719
+ credentials: Optional[ga_credentials.Credentials] = None,
720
+ transport: Optional[
721
+ Union[str, DatabaseAdminTransport, Callable[..., DatabaseAdminTransport]]
722
+ ] = None,
723
+ client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
724
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
725
+ ) -> None:
726
+ """Instantiates the database admin client.
727
+
728
+ Args:
729
+ credentials (Optional[google.auth.credentials.Credentials]): The
730
+ authorization credentials to attach to requests. These
731
+ credentials identify the application to the service; if none
732
+ are specified, the client will attempt to ascertain the
733
+ credentials from the environment.
734
+ transport (Optional[Union[str,DatabaseAdminTransport,Callable[..., DatabaseAdminTransport]]]):
735
+ The transport to use, or a Callable that constructs and returns a new transport.
736
+ If a Callable is given, it will be called with the same set of initialization
737
+ arguments as used in the DatabaseAdminTransport constructor.
738
+ If set to None, a transport is chosen automatically.
739
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
740
+ Custom options for the client.
741
+
742
+ 1. The ``api_endpoint`` property can be used to override the
743
+ default endpoint provided by the client when ``transport`` is
744
+ not explicitly provided. Only if this property is not set and
745
+ ``transport`` was not explicitly provided, the endpoint is
746
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
747
+ variable, which have one of the following values:
748
+ "always" (always use the default mTLS endpoint), "never" (always
749
+ use the default regular endpoint) and "auto" (auto-switch to the
750
+ default mTLS endpoint if client certificate is present; this is
751
+ the default value).
752
+
753
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
754
+ is "true", then the ``client_cert_source`` property can be used
755
+ to provide a client certificate for mTLS transport. If
756
+ not provided, the default SSL client certificate will be used if
757
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
758
+ set, no client certificate will be used.
759
+
760
+ 3. The ``universe_domain`` property can be used to override the
761
+ default "googleapis.com" universe. Note that the ``api_endpoint``
762
+ property still takes precedence; and ``universe_domain`` is
763
+ currently not supported for mTLS.
764
+
765
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
766
+ The client info used to send a user-agent string along with
767
+ API requests. If ``None``, then default info will be used.
768
+ Generally, you only need to set this if you're developing
769
+ your own client library.
770
+
771
+ Raises:
772
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
773
+ creation failed for any reason.
774
+ """
775
+ self._client_options = client_options
776
+ if isinstance(self._client_options, dict):
777
+ self._client_options = client_options_lib.from_dict(self._client_options)
778
+ if self._client_options is None:
779
+ self._client_options = client_options_lib.ClientOptions()
780
+ self._client_options = cast(
781
+ client_options_lib.ClientOptions, self._client_options
782
+ )
783
+
784
+ universe_domain_opt = getattr(self._client_options, "universe_domain", None)
785
+
786
+ (
787
+ self._use_client_cert,
788
+ self._use_mtls_endpoint,
789
+ self._universe_domain_env,
790
+ ) = DatabaseAdminClient._read_environment_variables()
791
+ self._client_cert_source = DatabaseAdminClient._get_client_cert_source(
792
+ self._client_options.client_cert_source, self._use_client_cert
793
+ )
794
+ self._universe_domain = DatabaseAdminClient._get_universe_domain(
795
+ universe_domain_opt, self._universe_domain_env
796
+ )
797
+ self._api_endpoint = None # updated below, depending on `transport`
798
+
799
+ # Initialize the universe domain validation.
800
+ self._is_universe_domain_valid = False
801
+
802
+ if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
803
+ # Setup logging.
804
+ client_logging.initialize_logging()
805
+
806
+ api_key_value = getattr(self._client_options, "api_key", None)
807
+ if api_key_value and credentials:
808
+ raise ValueError(
809
+ "client_options.api_key and credentials are mutually exclusive"
810
+ )
811
+
812
+ # Save or instantiate the transport.
813
+ # Ordinarily, we provide the transport, but allowing a custom transport
814
+ # instance provides an extensibility point for unusual situations.
815
+ transport_provided = isinstance(transport, DatabaseAdminTransport)
816
+ if transport_provided:
817
+ # transport is a DatabaseAdminTransport instance.
818
+ if credentials or self._client_options.credentials_file or api_key_value:
819
+ raise ValueError(
820
+ "When providing a transport instance, "
821
+ "provide its credentials directly."
822
+ )
823
+ if self._client_options.scopes:
824
+ raise ValueError(
825
+ "When providing a transport instance, provide its scopes "
826
+ "directly."
827
+ )
828
+ self._transport = cast(DatabaseAdminTransport, transport)
829
+ self._api_endpoint = self._transport.host
830
+
831
+ self._api_endpoint = (
832
+ self._api_endpoint
833
+ or DatabaseAdminClient._get_api_endpoint(
834
+ self._client_options.api_endpoint,
835
+ self._client_cert_source,
836
+ self._universe_domain,
837
+ self._use_mtls_endpoint,
838
+ )
839
+ )
840
+
841
+ if not transport_provided:
842
+ import google.auth._default # type: ignore
843
+
844
+ if api_key_value and hasattr(
845
+ google.auth._default, "get_api_key_credentials"
846
+ ):
847
+ credentials = google.auth._default.get_api_key_credentials(
848
+ api_key_value
849
+ )
850
+
851
+ transport_init: Union[
852
+ Type[DatabaseAdminTransport], Callable[..., DatabaseAdminTransport]
853
+ ] = (
854
+ DatabaseAdminClient.get_transport_class(transport)
855
+ if isinstance(transport, str) or transport is None
856
+ else cast(Callable[..., DatabaseAdminTransport], transport)
857
+ )
858
+ # initialize with the provided callable or the passed in class
859
+ self._transport = transport_init(
860
+ credentials=credentials,
861
+ credentials_file=self._client_options.credentials_file,
862
+ host=self._api_endpoint,
863
+ scopes=self._client_options.scopes,
864
+ client_cert_source_for_mtls=self._client_cert_source,
865
+ quota_project_id=self._client_options.quota_project_id,
866
+ client_info=client_info,
867
+ always_use_jwt_access=True,
868
+ api_audience=self._client_options.api_audience,
869
+ )
870
+
871
+ if "async" not in str(self._transport):
872
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
873
+ std_logging.DEBUG
874
+ ): # pragma: NO COVER
875
+ _LOGGER.debug(
876
+ "Created client `google.spanner.admin.database_v1.DatabaseAdminClient`.",
877
+ extra={
878
+ "serviceName": "google.spanner.admin.database.v1.DatabaseAdmin",
879
+ "universeDomain": getattr(
880
+ self._transport._credentials, "universe_domain", ""
881
+ ),
882
+ "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
883
+ "credentialsInfo": getattr(
884
+ self.transport._credentials, "get_cred_info", lambda: None
885
+ )(),
886
+ }
887
+ if hasattr(self._transport, "_credentials")
888
+ else {
889
+ "serviceName": "google.spanner.admin.database.v1.DatabaseAdmin",
890
+ "credentialsType": None,
891
+ },
892
+ )
893
+
894
+ def list_databases(
895
+ self,
896
+ request: Optional[
897
+ Union[spanner_database_admin.ListDatabasesRequest, dict]
898
+ ] = None,
899
+ *,
900
+ parent: Optional[str] = None,
901
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
902
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
903
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
904
+ ) -> pagers.ListDatabasesPager:
905
+ r"""Lists Cloud Spanner databases.
906
+
907
+ .. code-block:: python
908
+
909
+ # This snippet has been automatically generated and should be regarded as a
910
+ # code template only.
911
+ # It will require modifications to work:
912
+ # - It may require correct/in-range values for request initialization.
913
+ # - It may require specifying regional endpoints when creating the service
914
+ # client as shown in:
915
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
916
+ from google.cloud import spanner_admin_database_v1
917
+
918
+ def sample_list_databases():
919
+ # Create a client
920
+ client = spanner_admin_database_v1.DatabaseAdminClient()
921
+
922
+ # Initialize request argument(s)
923
+ request = spanner_admin_database_v1.ListDatabasesRequest(
924
+ parent="parent_value",
925
+ )
926
+
927
+ # Make the request
928
+ page_result = client.list_databases(request=request)
929
+
930
+ # Handle the response
931
+ for response in page_result:
932
+ print(response)
933
+
934
+ Args:
935
+ request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest, dict]):
936
+ The request object. The request for
937
+ [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases].
938
+ parent (str):
939
+ Required. The instance whose databases should be listed.
940
+ Values are of the form
941
+ ``projects/<project>/instances/<instance>``.
942
+
943
+ This corresponds to the ``parent`` field
944
+ on the ``request`` instance; if ``request`` is provided, this
945
+ should not be set.
946
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
947
+ should be retried.
948
+ timeout (float): The timeout for this request.
949
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
950
+ sent along with the request as metadata. Normally, each value must be of type `str`,
951
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
952
+ be of type `bytes`.
953
+
954
+ Returns:
955
+ google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesPager:
956
+ The response for
957
+ [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases].
958
+
959
+ Iterating over this object will yield results and
960
+ resolve additional pages automatically.
961
+
962
+ """
963
+ # Create or coerce a protobuf request object.
964
+ # - Quick check: If we got a request object, we should *not* have
965
+ # gotten any keyword arguments that map to the request.
966
+ flattened_params = [parent]
967
+ has_flattened_params = (
968
+ len([param for param in flattened_params if param is not None]) > 0
969
+ )
970
+ if request is not None and has_flattened_params:
971
+ raise ValueError(
972
+ "If the `request` argument is set, then none of "
973
+ "the individual field arguments should be set."
974
+ )
975
+
976
+ # - Use the request object if provided (there's no risk of modifying the input as
977
+ # there are no flattened fields), or create one.
978
+ if not isinstance(request, spanner_database_admin.ListDatabasesRequest):
979
+ request = spanner_database_admin.ListDatabasesRequest(request)
980
+ # If we have keyword arguments corresponding to fields on the
981
+ # request, apply these.
982
+ if parent is not None:
983
+ request.parent = parent
984
+
985
+ # Wrap the RPC method; this adds retry and timeout information,
986
+ # and friendly error handling.
987
+ rpc = self._transport._wrapped_methods[self._transport.list_databases]
988
+
989
+ # Certain fields should be provided within the metadata header;
990
+ # add these here.
991
+ metadata = tuple(metadata) + (
992
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
993
+ )
994
+
995
+ # Validate the universe domain.
996
+ self._validate_universe_domain()
997
+
998
+ # Send the request.
999
+ response = rpc(
1000
+ request,
1001
+ retry=retry,
1002
+ timeout=timeout,
1003
+ metadata=metadata,
1004
+ )
1005
+
1006
+ # This method is paged; wrap the response in a pager, which provides
1007
+ # an `__iter__` convenience method.
1008
+ response = pagers.ListDatabasesPager(
1009
+ method=rpc,
1010
+ request=request,
1011
+ response=response,
1012
+ retry=retry,
1013
+ timeout=timeout,
1014
+ metadata=metadata,
1015
+ )
1016
+
1017
+ # Done; return the response.
1018
+ return response
1019
+
1020
+ def create_database(
1021
+ self,
1022
+ request: Optional[
1023
+ Union[spanner_database_admin.CreateDatabaseRequest, dict]
1024
+ ] = None,
1025
+ *,
1026
+ parent: Optional[str] = None,
1027
+ create_statement: Optional[str] = None,
1028
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1029
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1030
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1031
+ ) -> operation.Operation:
1032
+ r"""Creates a new Cloud Spanner database and starts to prepare it
1033
+ for serving. The returned [long-running
1034
+ operation][google.longrunning.Operation] will have a name of the
1035
+ format ``<database_name>/operations/<operation_id>`` and can be
1036
+ used to track preparation of the database. The
1037
+ [metadata][google.longrunning.Operation.metadata] field type is
1038
+ [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata].
1039
+ The [response][google.longrunning.Operation.response] field type
1040
+ is [Database][google.spanner.admin.database.v1.Database], if
1041
+ successful.
1042
+
1043
+ .. code-block:: python
1044
+
1045
+ # This snippet has been automatically generated and should be regarded as a
1046
+ # code template only.
1047
+ # It will require modifications to work:
1048
+ # - It may require correct/in-range values for request initialization.
1049
+ # - It may require specifying regional endpoints when creating the service
1050
+ # client as shown in:
1051
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1052
+ from google.cloud import spanner_admin_database_v1
1053
+
1054
+ def sample_create_database():
1055
+ # Create a client
1056
+ client = spanner_admin_database_v1.DatabaseAdminClient()
1057
+
1058
+ # Initialize request argument(s)
1059
+ request = spanner_admin_database_v1.CreateDatabaseRequest(
1060
+ parent="parent_value",
1061
+ create_statement="create_statement_value",
1062
+ )
1063
+
1064
+ # Make the request
1065
+ operation = client.create_database(request=request)
1066
+
1067
+ print("Waiting for operation to complete...")
1068
+
1069
+ response = operation.result()
1070
+
1071
+ # Handle the response
1072
+ print(response)
1073
+
1074
+ Args:
1075
+ request (Union[google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest, dict]):
1076
+ The request object. The request for
1077
+ [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase].
1078
+ parent (str):
1079
+ Required. The name of the instance that will serve the
1080
+ new database. Values are of the form
1081
+ ``projects/<project>/instances/<instance>``.
1082
+
1083
+ This corresponds to the ``parent`` field
1084
+ on the ``request`` instance; if ``request`` is provided, this
1085
+ should not be set.
1086
+ create_statement (str):
1087
+ Required. A ``CREATE DATABASE`` statement, which
1088
+ specifies the ID of the new database. The database ID
1089
+ must conform to the regular expression
1090
+ ``[a-z][a-z0-9_\-]*[a-z0-9]`` and be between 2 and 30
1091
+ characters in length. If the database ID is a reserved
1092
+ word or if it contains a hyphen, the database ID must be
1093
+ enclosed in backticks (:literal:`\``).
1094
+
1095
+ This corresponds to the ``create_statement`` field
1096
+ on the ``request`` instance; if ``request`` is provided, this
1097
+ should not be set.
1098
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1099
+ should be retried.
1100
+ timeout (float): The timeout for this request.
1101
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1102
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1103
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1104
+ be of type `bytes`.
1105
+
1106
+ Returns:
1107
+ google.api_core.operation.Operation:
1108
+ An object representing a long-running operation.
1109
+
1110
+ The result type for the operation will be
1111
+ :class:`google.cloud.spanner_admin_database_v1.types.Database`
1112
+ A Cloud Spanner database.
1113
+
1114
+ """
1115
+ # Create or coerce a protobuf request object.
1116
+ # - Quick check: If we got a request object, we should *not* have
1117
+ # gotten any keyword arguments that map to the request.
1118
+ flattened_params = [parent, create_statement]
1119
+ has_flattened_params = (
1120
+ len([param for param in flattened_params if param is not None]) > 0
1121
+ )
1122
+ if request is not None and has_flattened_params:
1123
+ raise ValueError(
1124
+ "If the `request` argument is set, then none of "
1125
+ "the individual field arguments should be set."
1126
+ )
1127
+
1128
+ # - Use the request object if provided (there's no risk of modifying the input as
1129
+ # there are no flattened fields), or create one.
1130
+ if not isinstance(request, spanner_database_admin.CreateDatabaseRequest):
1131
+ request = spanner_database_admin.CreateDatabaseRequest(request)
1132
+ # If we have keyword arguments corresponding to fields on the
1133
+ # request, apply these.
1134
+ if parent is not None:
1135
+ request.parent = parent
1136
+ if create_statement is not None:
1137
+ request.create_statement = create_statement
1138
+
1139
+ # Wrap the RPC method; this adds retry and timeout information,
1140
+ # and friendly error handling.
1141
+ rpc = self._transport._wrapped_methods[self._transport.create_database]
1142
+
1143
+ # Certain fields should be provided within the metadata header;
1144
+ # add these here.
1145
+ metadata = tuple(metadata) + (
1146
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1147
+ )
1148
+
1149
+ # Validate the universe domain.
1150
+ self._validate_universe_domain()
1151
+
1152
+ # Send the request.
1153
+ response = rpc(
1154
+ request,
1155
+ retry=retry,
1156
+ timeout=timeout,
1157
+ metadata=metadata,
1158
+ )
1159
+
1160
+ # Wrap the response in an operation future.
1161
+ response = operation.from_gapic(
1162
+ response,
1163
+ self._transport.operations_client,
1164
+ spanner_database_admin.Database,
1165
+ metadata_type=spanner_database_admin.CreateDatabaseMetadata,
1166
+ )
1167
+
1168
+ # Done; return the response.
1169
+ return response
1170
+
1171
+ def get_database(
1172
+ self,
1173
+ request: Optional[
1174
+ Union[spanner_database_admin.GetDatabaseRequest, dict]
1175
+ ] = None,
1176
+ *,
1177
+ name: Optional[str] = None,
1178
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1179
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1180
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1181
+ ) -> spanner_database_admin.Database:
1182
+ r"""Gets the state of a Cloud Spanner database.
1183
+
1184
+ .. code-block:: python
1185
+
1186
+ # This snippet has been automatically generated and should be regarded as a
1187
+ # code template only.
1188
+ # It will require modifications to work:
1189
+ # - It may require correct/in-range values for request initialization.
1190
+ # - It may require specifying regional endpoints when creating the service
1191
+ # client as shown in:
1192
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1193
+ from google.cloud import spanner_admin_database_v1
1194
+
1195
+ def sample_get_database():
1196
+ # Create a client
1197
+ client = spanner_admin_database_v1.DatabaseAdminClient()
1198
+
1199
+ # Initialize request argument(s)
1200
+ request = spanner_admin_database_v1.GetDatabaseRequest(
1201
+ name="name_value",
1202
+ )
1203
+
1204
+ # Make the request
1205
+ response = client.get_database(request=request)
1206
+
1207
+ # Handle the response
1208
+ print(response)
1209
+
1210
+ Args:
1211
+ request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest, dict]):
1212
+ The request object. The request for
1213
+ [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase].
1214
+ name (str):
1215
+ Required. The name of the requested database. Values are
1216
+ of the form
1217
+ ``projects/<project>/instances/<instance>/databases/<database>``.
1218
+
1219
+ This corresponds to the ``name`` field
1220
+ on the ``request`` instance; if ``request`` is provided, this
1221
+ should not be set.
1222
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1223
+ should be retried.
1224
+ timeout (float): The timeout for this request.
1225
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1226
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1227
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1228
+ be of type `bytes`.
1229
+
1230
+ Returns:
1231
+ google.cloud.spanner_admin_database_v1.types.Database:
1232
+ A Cloud Spanner database.
1233
+ """
1234
+ # Create or coerce a protobuf request object.
1235
+ # - Quick check: If we got a request object, we should *not* have
1236
+ # gotten any keyword arguments that map to the request.
1237
+ flattened_params = [name]
1238
+ has_flattened_params = (
1239
+ len([param for param in flattened_params if param is not None]) > 0
1240
+ )
1241
+ if request is not None and has_flattened_params:
1242
+ raise ValueError(
1243
+ "If the `request` argument is set, then none of "
1244
+ "the individual field arguments should be set."
1245
+ )
1246
+
1247
+ # - Use the request object if provided (there's no risk of modifying the input as
1248
+ # there are no flattened fields), or create one.
1249
+ if not isinstance(request, spanner_database_admin.GetDatabaseRequest):
1250
+ request = spanner_database_admin.GetDatabaseRequest(request)
1251
+ # If we have keyword arguments corresponding to fields on the
1252
+ # request, apply these.
1253
+ if name is not None:
1254
+ request.name = name
1255
+
1256
+ # Wrap the RPC method; this adds retry and timeout information,
1257
+ # and friendly error handling.
1258
+ rpc = self._transport._wrapped_methods[self._transport.get_database]
1259
+
1260
+ # Certain fields should be provided within the metadata header;
1261
+ # add these here.
1262
+ metadata = tuple(metadata) + (
1263
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1264
+ )
1265
+
1266
+ # Validate the universe domain.
1267
+ self._validate_universe_domain()
1268
+
1269
+ # Send the request.
1270
+ response = rpc(
1271
+ request,
1272
+ retry=retry,
1273
+ timeout=timeout,
1274
+ metadata=metadata,
1275
+ )
1276
+
1277
+ # Done; return the response.
1278
+ return response
1279
+
1280
+ def update_database(
1281
+ self,
1282
+ request: Optional[
1283
+ Union[spanner_database_admin.UpdateDatabaseRequest, dict]
1284
+ ] = None,
1285
+ *,
1286
+ database: Optional[spanner_database_admin.Database] = None,
1287
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
1288
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1289
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1290
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1291
+ ) -> operation.Operation:
1292
+ r"""Updates a Cloud Spanner database. The returned [long-running
1293
+ operation][google.longrunning.Operation] can be used to track
1294
+ the progress of updating the database. If the named database
1295
+ does not exist, returns ``NOT_FOUND``.
1296
+
1297
+ While the operation is pending:
1298
+
1299
+ - The database's
1300
+ [reconciling][google.spanner.admin.database.v1.Database.reconciling]
1301
+ field is set to true.
1302
+ - Cancelling the operation is best-effort. If the cancellation
1303
+ succeeds, the operation metadata's
1304
+ [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time]
1305
+ is set, the updates are reverted, and the operation
1306
+ terminates with a ``CANCELLED`` status.
1307
+ - New UpdateDatabase requests will return a
1308
+ ``FAILED_PRECONDITION`` error until the pending operation is
1309
+ done (returns successfully or with error).
1310
+ - Reading the database via the API continues to give the
1311
+ pre-request values.
1312
+
1313
+ Upon completion of the returned operation:
1314
+
1315
+ - The new values are in effect and readable via the API.
1316
+ - The database's
1317
+ [reconciling][google.spanner.admin.database.v1.Database.reconciling]
1318
+ field becomes false.
1319
+
1320
+ The returned [long-running
1321
+ operation][google.longrunning.Operation] will have a name of the
1322
+ format
1323
+ ``projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>``
1324
+ and can be used to track the database modification. The
1325
+ [metadata][google.longrunning.Operation.metadata] field type is
1326
+ [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata].
1327
+ The [response][google.longrunning.Operation.response] field type
1328
+ is [Database][google.spanner.admin.database.v1.Database], if
1329
+ successful.
1330
+
1331
+ .. code-block:: python
1332
+
1333
+ # This snippet has been automatically generated and should be regarded as a
1334
+ # code template only.
1335
+ # It will require modifications to work:
1336
+ # - It may require correct/in-range values for request initialization.
1337
+ # - It may require specifying regional endpoints when creating the service
1338
+ # client as shown in:
1339
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1340
+ from google.cloud import spanner_admin_database_v1
1341
+
1342
+ def sample_update_database():
1343
+ # Create a client
1344
+ client = spanner_admin_database_v1.DatabaseAdminClient()
1345
+
1346
+ # Initialize request argument(s)
1347
+ database = spanner_admin_database_v1.Database()
1348
+ database.name = "name_value"
1349
+
1350
+ request = spanner_admin_database_v1.UpdateDatabaseRequest(
1351
+ database=database,
1352
+ )
1353
+
1354
+ # Make the request
1355
+ operation = client.update_database(request=request)
1356
+
1357
+ print("Waiting for operation to complete...")
1358
+
1359
+ response = operation.result()
1360
+
1361
+ # Handle the response
1362
+ print(response)
1363
+
1364
+ Args:
1365
+ request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]):
1366
+ The request object. The request for
1367
+ [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase].
1368
+ database (google.cloud.spanner_admin_database_v1.types.Database):
1369
+ Required. The database to update. The ``name`` field of
1370
+ the database is of the form
1371
+ ``projects/<project>/instances/<instance>/databases/<database>``.
1372
+
1373
+ This corresponds to the ``database`` field
1374
+ on the ``request`` instance; if ``request`` is provided, this
1375
+ should not be set.
1376
+ update_mask (google.protobuf.field_mask_pb2.FieldMask):
1377
+ Required. The list of fields to update. Currently, only
1378
+ ``enable_drop_protection`` field can be updated.
1379
+
1380
+ This corresponds to the ``update_mask`` field
1381
+ on the ``request`` instance; if ``request`` is provided, this
1382
+ should not be set.
1383
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1384
+ should be retried.
1385
+ timeout (float): The timeout for this request.
1386
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1387
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1388
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1389
+ be of type `bytes`.
1390
+
1391
+ Returns:
1392
+ google.api_core.operation.Operation:
1393
+ An object representing a long-running operation.
1394
+
1395
+ The result type for the operation will be
1396
+ :class:`google.cloud.spanner_admin_database_v1.types.Database`
1397
+ A Cloud Spanner database.
1398
+
1399
+ """
1400
+ # Create or coerce a protobuf request object.
1401
+ # - Quick check: If we got a request object, we should *not* have
1402
+ # gotten any keyword arguments that map to the request.
1403
+ flattened_params = [database, update_mask]
1404
+ has_flattened_params = (
1405
+ len([param for param in flattened_params if param is not None]) > 0
1406
+ )
1407
+ if request is not None and has_flattened_params:
1408
+ raise ValueError(
1409
+ "If the `request` argument is set, then none of "
1410
+ "the individual field arguments should be set."
1411
+ )
1412
+
1413
+ # - Use the request object if provided (there's no risk of modifying the input as
1414
+ # there are no flattened fields), or create one.
1415
+ if not isinstance(request, spanner_database_admin.UpdateDatabaseRequest):
1416
+ request = spanner_database_admin.UpdateDatabaseRequest(request)
1417
+ # If we have keyword arguments corresponding to fields on the
1418
+ # request, apply these.
1419
+ if database is not None:
1420
+ request.database = database
1421
+ if update_mask is not None:
1422
+ request.update_mask = update_mask
1423
+
1424
+ # Wrap the RPC method; this adds retry and timeout information,
1425
+ # and friendly error handling.
1426
+ rpc = self._transport._wrapped_methods[self._transport.update_database]
1427
+
1428
+ # Certain fields should be provided within the metadata header;
1429
+ # add these here.
1430
+ metadata = tuple(metadata) + (
1431
+ gapic_v1.routing_header.to_grpc_metadata(
1432
+ (("database.name", request.database.name),)
1433
+ ),
1434
+ )
1435
+
1436
+ # Validate the universe domain.
1437
+ self._validate_universe_domain()
1438
+
1439
+ # Send the request.
1440
+ response = rpc(
1441
+ request,
1442
+ retry=retry,
1443
+ timeout=timeout,
1444
+ metadata=metadata,
1445
+ )
1446
+
1447
+ # Wrap the response in an operation future.
1448
+ response = operation.from_gapic(
1449
+ response,
1450
+ self._transport.operations_client,
1451
+ spanner_database_admin.Database,
1452
+ metadata_type=spanner_database_admin.UpdateDatabaseMetadata,
1453
+ )
1454
+
1455
+ # Done; return the response.
1456
+ return response
1457
+
1458
+ def update_database_ddl(
1459
+ self,
1460
+ request: Optional[
1461
+ Union[spanner_database_admin.UpdateDatabaseDdlRequest, dict]
1462
+ ] = None,
1463
+ *,
1464
+ database: Optional[str] = None,
1465
+ statements: Optional[MutableSequence[str]] = None,
1466
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1467
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1468
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1469
+ ) -> operation.Operation:
1470
+ r"""Updates the schema of a Cloud Spanner database by
1471
+ creating/altering/dropping tables, columns, indexes, etc. The
1472
+ returned [long-running operation][google.longrunning.Operation]
1473
+ will have a name of the format
1474
+ ``<database_name>/operations/<operation_id>`` and can be used to
1475
+ track execution of the schema change(s). The
1476
+ [metadata][google.longrunning.Operation.metadata] field type is
1477
+ [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata].
1478
+ The operation has no response.
1479
+
1480
+ .. code-block:: python
1481
+
1482
+ # This snippet has been automatically generated and should be regarded as a
1483
+ # code template only.
1484
+ # It will require modifications to work:
1485
+ # - It may require correct/in-range values for request initialization.
1486
+ # - It may require specifying regional endpoints when creating the service
1487
+ # client as shown in:
1488
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1489
+ from google.cloud import spanner_admin_database_v1
1490
+
1491
+ def sample_update_database_ddl():
1492
+ # Create a client
1493
+ client = spanner_admin_database_v1.DatabaseAdminClient()
1494
+
1495
+ # Initialize request argument(s)
1496
+ request = spanner_admin_database_v1.UpdateDatabaseDdlRequest(
1497
+ database="database_value",
1498
+ statements=['statements_value1', 'statements_value2'],
1499
+ )
1500
+
1501
+ # Make the request
1502
+ operation = client.update_database_ddl(request=request)
1503
+
1504
+ print("Waiting for operation to complete...")
1505
+
1506
+ response = operation.result()
1507
+
1508
+ # Handle the response
1509
+ print(response)
1510
+
1511
+ Args:
1512
+ request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest, dict]):
1513
+ The request object. Enqueues the given DDL statements to be applied, in
1514
+ order but not necessarily all at once, to the database
1515
+ schema at some point (or points) in the future. The
1516
+ server checks that the statements are executable
1517
+ (syntactically valid, name tables that exist, etc.)
1518
+ before enqueueing them, but they may still fail upon
1519
+ later execution (e.g., if a statement from another batch
1520
+ of statements is applied first and it conflicts in some
1521
+ way, or if there is some data-related problem like a
1522
+ ``NULL`` value in a column to which ``NOT NULL`` would
1523
+ be added). If a statement fails, all subsequent
1524
+ statements in the batch are automatically cancelled.
1525
+
1526
+ Each batch of statements is assigned a name which can be
1527
+ used with the
1528
+ [Operations][google.longrunning.Operations] API to
1529
+ monitor progress. See the
1530
+ [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id]
1531
+ field for more details.
1532
+ database (str):
1533
+ Required. The database to update.
1534
+ This corresponds to the ``database`` field
1535
+ on the ``request`` instance; if ``request`` is provided, this
1536
+ should not be set.
1537
+ statements (MutableSequence[str]):
1538
+ Required. DDL statements to be
1539
+ applied to the database.
1540
+
1541
+ This corresponds to the ``statements`` field
1542
+ on the ``request`` instance; if ``request`` is provided, this
1543
+ should not be set.
1544
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1545
+ should be retried.
1546
+ timeout (float): The timeout for this request.
1547
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1548
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1549
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1550
+ be of type `bytes`.
1551
+
1552
+ Returns:
1553
+ google.api_core.operation.Operation:
1554
+ An object representing a long-running operation.
1555
+
1556
+ The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated
1557
+ empty messages in your APIs. A typical example is to
1558
+ use it as the request or the response type of an API
1559
+ method. For instance:
1560
+
1561
+ service Foo {
1562
+ rpc Bar(google.protobuf.Empty) returns
1563
+ (google.protobuf.Empty);
1564
+
1565
+ }
1566
+
1567
+ """
1568
+ # Create or coerce a protobuf request object.
1569
+ # - Quick check: If we got a request object, we should *not* have
1570
+ # gotten any keyword arguments that map to the request.
1571
+ flattened_params = [database, statements]
1572
+ has_flattened_params = (
1573
+ len([param for param in flattened_params if param is not None]) > 0
1574
+ )
1575
+ if request is not None and has_flattened_params:
1576
+ raise ValueError(
1577
+ "If the `request` argument is set, then none of "
1578
+ "the individual field arguments should be set."
1579
+ )
1580
+
1581
+ # - Use the request object if provided (there's no risk of modifying the input as
1582
+ # there are no flattened fields), or create one.
1583
+ if not isinstance(request, spanner_database_admin.UpdateDatabaseDdlRequest):
1584
+ request = spanner_database_admin.UpdateDatabaseDdlRequest(request)
1585
+ # If we have keyword arguments corresponding to fields on the
1586
+ # request, apply these.
1587
+ if database is not None:
1588
+ request.database = database
1589
+ if statements is not None:
1590
+ request.statements = statements
1591
+
1592
+ # Wrap the RPC method; this adds retry and timeout information,
1593
+ # and friendly error handling.
1594
+ rpc = self._transport._wrapped_methods[self._transport.update_database_ddl]
1595
+
1596
+ # Certain fields should be provided within the metadata header;
1597
+ # add these here.
1598
+ metadata = tuple(metadata) + (
1599
+ gapic_v1.routing_header.to_grpc_metadata((("database", request.database),)),
1600
+ )
1601
+
1602
+ # Validate the universe domain.
1603
+ self._validate_universe_domain()
1604
+
1605
+ # Send the request.
1606
+ response = rpc(
1607
+ request,
1608
+ retry=retry,
1609
+ timeout=timeout,
1610
+ metadata=metadata,
1611
+ )
1612
+
1613
+ # Wrap the response in an operation future.
1614
+ response = operation.from_gapic(
1615
+ response,
1616
+ self._transport.operations_client,
1617
+ empty_pb2.Empty,
1618
+ metadata_type=spanner_database_admin.UpdateDatabaseDdlMetadata,
1619
+ )
1620
+
1621
+ # Done; return the response.
1622
+ return response
1623
+
1624
+ def drop_database(
1625
+ self,
1626
+ request: Optional[
1627
+ Union[spanner_database_admin.DropDatabaseRequest, dict]
1628
+ ] = None,
1629
+ *,
1630
+ database: Optional[str] = None,
1631
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1632
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1633
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1634
+ ) -> None:
1635
+ r"""Drops (aka deletes) a Cloud Spanner database. Completed backups
1636
+ for the database will be retained according to their
1637
+ ``expire_time``. Note: Cloud Spanner might continue to accept
1638
+ requests for a few seconds after the database has been deleted.
1639
+
1640
+ .. code-block:: python
1641
+
1642
+ # This snippet has been automatically generated and should be regarded as a
1643
+ # code template only.
1644
+ # It will require modifications to work:
1645
+ # - It may require correct/in-range values for request initialization.
1646
+ # - It may require specifying regional endpoints when creating the service
1647
+ # client as shown in:
1648
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1649
+ from google.cloud import spanner_admin_database_v1
1650
+
1651
+ def sample_drop_database():
1652
+ # Create a client
1653
+ client = spanner_admin_database_v1.DatabaseAdminClient()
1654
+
1655
+ # Initialize request argument(s)
1656
+ request = spanner_admin_database_v1.DropDatabaseRequest(
1657
+ database="database_value",
1658
+ )
1659
+
1660
+ # Make the request
1661
+ client.drop_database(request=request)
1662
+
1663
+ Args:
1664
+ request (Union[google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest, dict]):
1665
+ The request object. The request for
1666
+ [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase].
1667
+ database (str):
1668
+ Required. The database to be dropped.
1669
+ This corresponds to the ``database`` field
1670
+ on the ``request`` instance; if ``request`` is provided, this
1671
+ should not be set.
1672
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1673
+ should be retried.
1674
+ timeout (float): The timeout for this request.
1675
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1676
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1677
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1678
+ be of type `bytes`.
1679
+ """
1680
+ # Create or coerce a protobuf request object.
1681
+ # - Quick check: If we got a request object, we should *not* have
1682
+ # gotten any keyword arguments that map to the request.
1683
+ flattened_params = [database]
1684
+ has_flattened_params = (
1685
+ len([param for param in flattened_params if param is not None]) > 0
1686
+ )
1687
+ if request is not None and has_flattened_params:
1688
+ raise ValueError(
1689
+ "If the `request` argument is set, then none of "
1690
+ "the individual field arguments should be set."
1691
+ )
1692
+
1693
+ # - Use the request object if provided (there's no risk of modifying the input as
1694
+ # there are no flattened fields), or create one.
1695
+ if not isinstance(request, spanner_database_admin.DropDatabaseRequest):
1696
+ request = spanner_database_admin.DropDatabaseRequest(request)
1697
+ # If we have keyword arguments corresponding to fields on the
1698
+ # request, apply these.
1699
+ if database is not None:
1700
+ request.database = database
1701
+
1702
+ # Wrap the RPC method; this adds retry and timeout information,
1703
+ # and friendly error handling.
1704
+ rpc = self._transport._wrapped_methods[self._transport.drop_database]
1705
+
1706
+ # Certain fields should be provided within the metadata header;
1707
+ # add these here.
1708
+ metadata = tuple(metadata) + (
1709
+ gapic_v1.routing_header.to_grpc_metadata((("database", request.database),)),
1710
+ )
1711
+
1712
+ # Validate the universe domain.
1713
+ self._validate_universe_domain()
1714
+
1715
+ # Send the request.
1716
+ rpc(
1717
+ request,
1718
+ retry=retry,
1719
+ timeout=timeout,
1720
+ metadata=metadata,
1721
+ )
1722
+
1723
+ def get_database_ddl(
1724
+ self,
1725
+ request: Optional[
1726
+ Union[spanner_database_admin.GetDatabaseDdlRequest, dict]
1727
+ ] = None,
1728
+ *,
1729
+ database: Optional[str] = None,
1730
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1731
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1732
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1733
+ ) -> spanner_database_admin.GetDatabaseDdlResponse:
1734
+ r"""Returns the schema of a Cloud Spanner database as a list of
1735
+ formatted DDL statements. This method does not show pending
1736
+ schema updates, those may be queried using the
1737
+ [Operations][google.longrunning.Operations] API.
1738
+
1739
+ .. code-block:: python
1740
+
1741
+ # This snippet has been automatically generated and should be regarded as a
1742
+ # code template only.
1743
+ # It will require modifications to work:
1744
+ # - It may require correct/in-range values for request initialization.
1745
+ # - It may require specifying regional endpoints when creating the service
1746
+ # client as shown in:
1747
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1748
+ from google.cloud import spanner_admin_database_v1
1749
+
1750
+ def sample_get_database_ddl():
1751
+ # Create a client
1752
+ client = spanner_admin_database_v1.DatabaseAdminClient()
1753
+
1754
+ # Initialize request argument(s)
1755
+ request = spanner_admin_database_v1.GetDatabaseDdlRequest(
1756
+ database="database_value",
1757
+ )
1758
+
1759
+ # Make the request
1760
+ response = client.get_database_ddl(request=request)
1761
+
1762
+ # Handle the response
1763
+ print(response)
1764
+
1765
+ Args:
1766
+ request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest, dict]):
1767
+ The request object. The request for
1768
+ [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl].
1769
+ database (str):
1770
+ Required. The database whose schema we wish to get.
1771
+ Values are of the form
1772
+ ``projects/<project>/instances/<instance>/databases/<database>``
1773
+
1774
+ This corresponds to the ``database`` field
1775
+ on the ``request`` instance; if ``request`` is provided, this
1776
+ should not be set.
1777
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1778
+ should be retried.
1779
+ timeout (float): The timeout for this request.
1780
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1781
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1782
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1783
+ be of type `bytes`.
1784
+
1785
+ Returns:
1786
+ google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse:
1787
+ The response for
1788
+ [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl].
1789
+
1790
+ """
1791
+ # Create or coerce a protobuf request object.
1792
+ # - Quick check: If we got a request object, we should *not* have
1793
+ # gotten any keyword arguments that map to the request.
1794
+ flattened_params = [database]
1795
+ has_flattened_params = (
1796
+ len([param for param in flattened_params if param is not None]) > 0
1797
+ )
1798
+ if request is not None and has_flattened_params:
1799
+ raise ValueError(
1800
+ "If the `request` argument is set, then none of "
1801
+ "the individual field arguments should be set."
1802
+ )
1803
+
1804
+ # - Use the request object if provided (there's no risk of modifying the input as
1805
+ # there are no flattened fields), or create one.
1806
+ if not isinstance(request, spanner_database_admin.GetDatabaseDdlRequest):
1807
+ request = spanner_database_admin.GetDatabaseDdlRequest(request)
1808
+ # If we have keyword arguments corresponding to fields on the
1809
+ # request, apply these.
1810
+ if database is not None:
1811
+ request.database = database
1812
+
1813
+ # Wrap the RPC method; this adds retry and timeout information,
1814
+ # and friendly error handling.
1815
+ rpc = self._transport._wrapped_methods[self._transport.get_database_ddl]
1816
+
1817
+ # Certain fields should be provided within the metadata header;
1818
+ # add these here.
1819
+ metadata = tuple(metadata) + (
1820
+ gapic_v1.routing_header.to_grpc_metadata((("database", request.database),)),
1821
+ )
1822
+
1823
+ # Validate the universe domain.
1824
+ self._validate_universe_domain()
1825
+
1826
+ # Send the request.
1827
+ response = rpc(
1828
+ request,
1829
+ retry=retry,
1830
+ timeout=timeout,
1831
+ metadata=metadata,
1832
+ )
1833
+
1834
+ # Done; return the response.
1835
+ return response
1836
+
1837
+ def set_iam_policy(
1838
+ self,
1839
+ request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None,
1840
+ *,
1841
+ resource: Optional[str] = None,
1842
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1843
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1844
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1845
+ ) -> policy_pb2.Policy:
1846
+ r"""Sets the access control policy on a database or backup resource.
1847
+ Replaces any existing policy.
1848
+
1849
+ Authorization requires ``spanner.databases.setIamPolicy``
1850
+ permission on
1851
+ [resource][google.iam.v1.SetIamPolicyRequest.resource]. For
1852
+ backups, authorization requires ``spanner.backups.setIamPolicy``
1853
+ permission on
1854
+ [resource][google.iam.v1.SetIamPolicyRequest.resource].
1855
+
1856
+ .. code-block:: python
1857
+
1858
+ # This snippet has been automatically generated and should be regarded as a
1859
+ # code template only.
1860
+ # It will require modifications to work:
1861
+ # - It may require correct/in-range values for request initialization.
1862
+ # - It may require specifying regional endpoints when creating the service
1863
+ # client as shown in:
1864
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1865
+ from google.cloud import spanner_admin_database_v1
1866
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
1867
+
1868
+ def sample_set_iam_policy():
1869
+ # Create a client
1870
+ client = spanner_admin_database_v1.DatabaseAdminClient()
1871
+
1872
+ # Initialize request argument(s)
1873
+ request = iam_policy_pb2.SetIamPolicyRequest(
1874
+ resource="resource_value",
1875
+ )
1876
+
1877
+ # Make the request
1878
+ response = client.set_iam_policy(request=request)
1879
+
1880
+ # Handle the response
1881
+ print(response)
1882
+
1883
+ Args:
1884
+ request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]):
1885
+ The request object. Request message for ``SetIamPolicy`` method.
1886
+ resource (str):
1887
+ REQUIRED: The resource for which the
1888
+ policy is being specified. See the
1889
+ operation documentation for the
1890
+ appropriate value for this field.
1891
+
1892
+ This corresponds to the ``resource`` field
1893
+ on the ``request`` instance; if ``request`` is provided, this
1894
+ should not be set.
1895
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1896
+ should be retried.
1897
+ timeout (float): The timeout for this request.
1898
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1899
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1900
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1901
+ be of type `bytes`.
1902
+
1903
+ Returns:
1904
+ google.iam.v1.policy_pb2.Policy:
1905
+ An Identity and Access Management (IAM) policy, which specifies access
1906
+ controls for Google Cloud resources.
1907
+
1908
+ A Policy is a collection of bindings. A binding binds
1909
+ one or more members, or principals, to a single role.
1910
+ Principals can be user accounts, service accounts,
1911
+ Google groups, and domains (such as G Suite). A role
1912
+ is a named list of permissions; each role can be an
1913
+ IAM predefined role or a user-created custom role.
1914
+
1915
+ For some types of Google Cloud resources, a binding
1916
+ can also specify a condition, which is a logical
1917
+ expression that allows access to a resource only if
1918
+ the expression evaluates to true. A condition can add
1919
+ constraints based on attributes of the request, the
1920
+ resource, or both. To learn which resources support
1921
+ conditions in their IAM policies, see the [IAM
1922
+ documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
1923
+
1924
+ **JSON example:**
1925
+
1926
+ :literal:`\` { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 }`\ \`
1927
+
1928
+ **YAML example:**
1929
+
1930
+ :literal:`\` bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3`\ \`
1931
+
1932
+ For a description of IAM and its features, see the
1933
+ [IAM
1934
+ documentation](\ https://cloud.google.com/iam/docs/).
1935
+
1936
+ """
1937
+ # Create or coerce a protobuf request object.
1938
+ # - Quick check: If we got a request object, we should *not* have
1939
+ # gotten any keyword arguments that map to the request.
1940
+ flattened_params = [resource]
1941
+ has_flattened_params = (
1942
+ len([param for param in flattened_params if param is not None]) > 0
1943
+ )
1944
+ if request is not None and has_flattened_params:
1945
+ raise ValueError(
1946
+ "If the `request` argument is set, then none of "
1947
+ "the individual field arguments should be set."
1948
+ )
1949
+
1950
+ if isinstance(request, dict):
1951
+ # - The request isn't a proto-plus wrapped type,
1952
+ # so it must be constructed via keyword expansion.
1953
+ request = iam_policy_pb2.SetIamPolicyRequest(**request)
1954
+ elif not request:
1955
+ # Null request, just make one.
1956
+ request = iam_policy_pb2.SetIamPolicyRequest()
1957
+ if resource is not None:
1958
+ request.resource = resource
1959
+
1960
+ # Wrap the RPC method; this adds retry and timeout information,
1961
+ # and friendly error handling.
1962
+ rpc = self._transport._wrapped_methods[self._transport.set_iam_policy]
1963
+
1964
+ # Certain fields should be provided within the metadata header;
1965
+ # add these here.
1966
+ metadata = tuple(metadata) + (
1967
+ gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1968
+ )
1969
+
1970
+ # Validate the universe domain.
1971
+ self._validate_universe_domain()
1972
+
1973
+ # Send the request.
1974
+ response = rpc(
1975
+ request,
1976
+ retry=retry,
1977
+ timeout=timeout,
1978
+ metadata=metadata,
1979
+ )
1980
+
1981
+ # Done; return the response.
1982
+ return response
1983
+
1984
+ def get_iam_policy(
1985
+ self,
1986
+ request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None,
1987
+ *,
1988
+ resource: Optional[str] = None,
1989
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1990
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1991
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1992
+ ) -> policy_pb2.Policy:
1993
+ r"""Gets the access control policy for a database or backup
1994
+ resource. Returns an empty policy if a database or backup exists
1995
+ but does not have a policy set.
1996
+
1997
+ Authorization requires ``spanner.databases.getIamPolicy``
1998
+ permission on
1999
+ [resource][google.iam.v1.GetIamPolicyRequest.resource]. For
2000
+ backups, authorization requires ``spanner.backups.getIamPolicy``
2001
+ permission on
2002
+ [resource][google.iam.v1.GetIamPolicyRequest.resource].
2003
+
2004
+ .. code-block:: python
2005
+
2006
+ # This snippet has been automatically generated and should be regarded as a
2007
+ # code template only.
2008
+ # It will require modifications to work:
2009
+ # - It may require correct/in-range values for request initialization.
2010
+ # - It may require specifying regional endpoints when creating the service
2011
+ # client as shown in:
2012
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2013
+ from google.cloud import spanner_admin_database_v1
2014
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
2015
+
2016
+ def sample_get_iam_policy():
2017
+ # Create a client
2018
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2019
+
2020
+ # Initialize request argument(s)
2021
+ request = iam_policy_pb2.GetIamPolicyRequest(
2022
+ resource="resource_value",
2023
+ )
2024
+
2025
+ # Make the request
2026
+ response = client.get_iam_policy(request=request)
2027
+
2028
+ # Handle the response
2029
+ print(response)
2030
+
2031
+ Args:
2032
+ request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]):
2033
+ The request object. Request message for ``GetIamPolicy`` method.
2034
+ resource (str):
2035
+ REQUIRED: The resource for which the
2036
+ policy is being requested. See the
2037
+ operation documentation for the
2038
+ appropriate value for this field.
2039
+
2040
+ This corresponds to the ``resource`` field
2041
+ on the ``request`` instance; if ``request`` is provided, this
2042
+ should not be set.
2043
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2044
+ should be retried.
2045
+ timeout (float): The timeout for this request.
2046
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2047
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2048
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2049
+ be of type `bytes`.
2050
+
2051
+ Returns:
2052
+ google.iam.v1.policy_pb2.Policy:
2053
+ An Identity and Access Management (IAM) policy, which specifies access
2054
+ controls for Google Cloud resources.
2055
+
2056
+ A Policy is a collection of bindings. A binding binds
2057
+ one or more members, or principals, to a single role.
2058
+ Principals can be user accounts, service accounts,
2059
+ Google groups, and domains (such as G Suite). A role
2060
+ is a named list of permissions; each role can be an
2061
+ IAM predefined role or a user-created custom role.
2062
+
2063
+ For some types of Google Cloud resources, a binding
2064
+ can also specify a condition, which is a logical
2065
+ expression that allows access to a resource only if
2066
+ the expression evaluates to true. A condition can add
2067
+ constraints based on attributes of the request, the
2068
+ resource, or both. To learn which resources support
2069
+ conditions in their IAM policies, see the [IAM
2070
+ documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
2071
+
2072
+ **JSON example:**
2073
+
2074
+ :literal:`\` { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 }`\ \`
2075
+
2076
+ **YAML example:**
2077
+
2078
+ :literal:`\` bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3`\ \`
2079
+
2080
+ For a description of IAM and its features, see the
2081
+ [IAM
2082
+ documentation](\ https://cloud.google.com/iam/docs/).
2083
+
2084
+ """
2085
+ # Create or coerce a protobuf request object.
2086
+ # - Quick check: If we got a request object, we should *not* have
2087
+ # gotten any keyword arguments that map to the request.
2088
+ flattened_params = [resource]
2089
+ has_flattened_params = (
2090
+ len([param for param in flattened_params if param is not None]) > 0
2091
+ )
2092
+ if request is not None and has_flattened_params:
2093
+ raise ValueError(
2094
+ "If the `request` argument is set, then none of "
2095
+ "the individual field arguments should be set."
2096
+ )
2097
+
2098
+ if isinstance(request, dict):
2099
+ # - The request isn't a proto-plus wrapped type,
2100
+ # so it must be constructed via keyword expansion.
2101
+ request = iam_policy_pb2.GetIamPolicyRequest(**request)
2102
+ elif not request:
2103
+ # Null request, just make one.
2104
+ request = iam_policy_pb2.GetIamPolicyRequest()
2105
+ if resource is not None:
2106
+ request.resource = resource
2107
+
2108
+ # Wrap the RPC method; this adds retry and timeout information,
2109
+ # and friendly error handling.
2110
+ rpc = self._transport._wrapped_methods[self._transport.get_iam_policy]
2111
+
2112
+ # Certain fields should be provided within the metadata header;
2113
+ # add these here.
2114
+ metadata = tuple(metadata) + (
2115
+ gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
2116
+ )
2117
+
2118
+ # Validate the universe domain.
2119
+ self._validate_universe_domain()
2120
+
2121
+ # Send the request.
2122
+ response = rpc(
2123
+ request,
2124
+ retry=retry,
2125
+ timeout=timeout,
2126
+ metadata=metadata,
2127
+ )
2128
+
2129
+ # Done; return the response.
2130
+ return response
2131
+
2132
+ def test_iam_permissions(
2133
+ self,
2134
+ request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None,
2135
+ *,
2136
+ resource: Optional[str] = None,
2137
+ permissions: Optional[MutableSequence[str]] = None,
2138
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2139
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2140
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2141
+ ) -> iam_policy_pb2.TestIamPermissionsResponse:
2142
+ r"""Returns permissions that the caller has on the specified
2143
+ database or backup resource.
2144
+
2145
+ Attempting this RPC on a non-existent Cloud Spanner database
2146
+ will result in a NOT_FOUND error if the user has
2147
+ ``spanner.databases.list`` permission on the containing Cloud
2148
+ Spanner instance. Otherwise returns an empty set of permissions.
2149
+ Calling this method on a backup that does not exist will result
2150
+ in a NOT_FOUND error if the user has ``spanner.backups.list``
2151
+ permission on the containing instance.
2152
+
2153
+ .. code-block:: python
2154
+
2155
+ # This snippet has been automatically generated and should be regarded as a
2156
+ # code template only.
2157
+ # It will require modifications to work:
2158
+ # - It may require correct/in-range values for request initialization.
2159
+ # - It may require specifying regional endpoints when creating the service
2160
+ # client as shown in:
2161
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2162
+ from google.cloud import spanner_admin_database_v1
2163
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
2164
+
2165
+ def sample_test_iam_permissions():
2166
+ # Create a client
2167
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2168
+
2169
+ # Initialize request argument(s)
2170
+ request = iam_policy_pb2.TestIamPermissionsRequest(
2171
+ resource="resource_value",
2172
+ permissions=['permissions_value1', 'permissions_value2'],
2173
+ )
2174
+
2175
+ # Make the request
2176
+ response = client.test_iam_permissions(request=request)
2177
+
2178
+ # Handle the response
2179
+ print(response)
2180
+
2181
+ Args:
2182
+ request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]):
2183
+ The request object. Request message for ``TestIamPermissions`` method.
2184
+ resource (str):
2185
+ REQUIRED: The resource for which the
2186
+ policy detail is being requested. See
2187
+ the operation documentation for the
2188
+ appropriate value for this field.
2189
+
2190
+ This corresponds to the ``resource`` field
2191
+ on the ``request`` instance; if ``request`` is provided, this
2192
+ should not be set.
2193
+ permissions (MutableSequence[str]):
2194
+ The set of permissions to check for the ``resource``.
2195
+ Permissions with wildcards (such as '*' or 'storage.*')
2196
+ are not allowed. For more information see `IAM
2197
+ Overview <https://cloud.google.com/iam/docs/overview#permissions>`__.
2198
+
2199
+ This corresponds to the ``permissions`` field
2200
+ on the ``request`` instance; if ``request`` is provided, this
2201
+ should not be set.
2202
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2203
+ should be retried.
2204
+ timeout (float): The timeout for this request.
2205
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2206
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2207
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2208
+ be of type `bytes`.
2209
+
2210
+ Returns:
2211
+ google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse:
2212
+ Response message for TestIamPermissions method.
2213
+ """
2214
+ # Create or coerce a protobuf request object.
2215
+ # - Quick check: If we got a request object, we should *not* have
2216
+ # gotten any keyword arguments that map to the request.
2217
+ flattened_params = [resource, permissions]
2218
+ has_flattened_params = (
2219
+ len([param for param in flattened_params if param is not None]) > 0
2220
+ )
2221
+ if request is not None and has_flattened_params:
2222
+ raise ValueError(
2223
+ "If the `request` argument is set, then none of "
2224
+ "the individual field arguments should be set."
2225
+ )
2226
+
2227
+ if isinstance(request, dict):
2228
+ # - The request isn't a proto-plus wrapped type,
2229
+ # so it must be constructed via keyword expansion.
2230
+ request = iam_policy_pb2.TestIamPermissionsRequest(**request)
2231
+ elif not request:
2232
+ # Null request, just make one.
2233
+ request = iam_policy_pb2.TestIamPermissionsRequest()
2234
+ if resource is not None:
2235
+ request.resource = resource
2236
+ if permissions:
2237
+ request.permissions.extend(permissions)
2238
+
2239
+ # Wrap the RPC method; this adds retry and timeout information,
2240
+ # and friendly error handling.
2241
+ rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions]
2242
+
2243
+ # Certain fields should be provided within the metadata header;
2244
+ # add these here.
2245
+ metadata = tuple(metadata) + (
2246
+ gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
2247
+ )
2248
+
2249
+ # Validate the universe domain.
2250
+ self._validate_universe_domain()
2251
+
2252
+ # Send the request.
2253
+ response = rpc(
2254
+ request,
2255
+ retry=retry,
2256
+ timeout=timeout,
2257
+ metadata=metadata,
2258
+ )
2259
+
2260
+ # Done; return the response.
2261
+ return response
2262
+
2263
+ def create_backup(
2264
+ self,
2265
+ request: Optional[Union[gsad_backup.CreateBackupRequest, dict]] = None,
2266
+ *,
2267
+ parent: Optional[str] = None,
2268
+ backup: Optional[gsad_backup.Backup] = None,
2269
+ backup_id: Optional[str] = None,
2270
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2271
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2272
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2273
+ ) -> operation.Operation:
2274
+ r"""Starts creating a new Cloud Spanner Backup. The returned backup
2275
+ [long-running operation][google.longrunning.Operation] will have
2276
+ a name of the format
2277
+ ``projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>``
2278
+ and can be used to track creation of the backup. The
2279
+ [metadata][google.longrunning.Operation.metadata] field type is
2280
+ [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata].
2281
+ The [response][google.longrunning.Operation.response] field type
2282
+ is [Backup][google.spanner.admin.database.v1.Backup], if
2283
+ successful. Cancelling the returned operation will stop the
2284
+ creation and delete the backup. There can be only one pending
2285
+ backup creation per database. Backup creation of different
2286
+ databases can run concurrently.
2287
+
2288
+ .. code-block:: python
2289
+
2290
+ # This snippet has been automatically generated and should be regarded as a
2291
+ # code template only.
2292
+ # It will require modifications to work:
2293
+ # - It may require correct/in-range values for request initialization.
2294
+ # - It may require specifying regional endpoints when creating the service
2295
+ # client as shown in:
2296
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2297
+ from google.cloud import spanner_admin_database_v1
2298
+
2299
+ def sample_create_backup():
2300
+ # Create a client
2301
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2302
+
2303
+ # Initialize request argument(s)
2304
+ request = spanner_admin_database_v1.CreateBackupRequest(
2305
+ parent="parent_value",
2306
+ backup_id="backup_id_value",
2307
+ )
2308
+
2309
+ # Make the request
2310
+ operation = client.create_backup(request=request)
2311
+
2312
+ print("Waiting for operation to complete...")
2313
+
2314
+ response = operation.result()
2315
+
2316
+ # Handle the response
2317
+ print(response)
2318
+
2319
+ Args:
2320
+ request (Union[google.cloud.spanner_admin_database_v1.types.CreateBackupRequest, dict]):
2321
+ The request object. The request for
2322
+ [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup].
2323
+ parent (str):
2324
+ Required. The name of the instance in which the backup
2325
+ will be created. This must be the same instance that
2326
+ contains the database the backup will be created from.
2327
+ The backup will be stored in the location(s) specified
2328
+ in the instance configuration of this instance. Values
2329
+ are of the form
2330
+ ``projects/<project>/instances/<instance>``.
2331
+
2332
+ This corresponds to the ``parent`` field
2333
+ on the ``request`` instance; if ``request`` is provided, this
2334
+ should not be set.
2335
+ backup (google.cloud.spanner_admin_database_v1.types.Backup):
2336
+ Required. The backup to create.
2337
+ This corresponds to the ``backup`` field
2338
+ on the ``request`` instance; if ``request`` is provided, this
2339
+ should not be set.
2340
+ backup_id (str):
2341
+ Required. The id of the backup to be created. The
2342
+ ``backup_id`` appended to ``parent`` forms the full
2343
+ backup name of the form
2344
+ ``projects/<project>/instances/<instance>/backups/<backup_id>``.
2345
+
2346
+ This corresponds to the ``backup_id`` field
2347
+ on the ``request`` instance; if ``request`` is provided, this
2348
+ should not be set.
2349
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2350
+ should be retried.
2351
+ timeout (float): The timeout for this request.
2352
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2353
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2354
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2355
+ be of type `bytes`.
2356
+
2357
+ Returns:
2358
+ google.api_core.operation.Operation:
2359
+ An object representing a long-running operation.
2360
+
2361
+ The result type for the operation will be
2362
+ :class:`google.cloud.spanner_admin_database_v1.types.Backup`
2363
+ A backup of a Cloud Spanner database.
2364
+
2365
+ """
2366
+ # Create or coerce a protobuf request object.
2367
+ # - Quick check: If we got a request object, we should *not* have
2368
+ # gotten any keyword arguments that map to the request.
2369
+ flattened_params = [parent, backup, backup_id]
2370
+ has_flattened_params = (
2371
+ len([param for param in flattened_params if param is not None]) > 0
2372
+ )
2373
+ if request is not None and has_flattened_params:
2374
+ raise ValueError(
2375
+ "If the `request` argument is set, then none of "
2376
+ "the individual field arguments should be set."
2377
+ )
2378
+
2379
+ # - Use the request object if provided (there's no risk of modifying the input as
2380
+ # there are no flattened fields), or create one.
2381
+ if not isinstance(request, gsad_backup.CreateBackupRequest):
2382
+ request = gsad_backup.CreateBackupRequest(request)
2383
+ # If we have keyword arguments corresponding to fields on the
2384
+ # request, apply these.
2385
+ if parent is not None:
2386
+ request.parent = parent
2387
+ if backup is not None:
2388
+ request.backup = backup
2389
+ if backup_id is not None:
2390
+ request.backup_id = backup_id
2391
+
2392
+ # Wrap the RPC method; this adds retry and timeout information,
2393
+ # and friendly error handling.
2394
+ rpc = self._transport._wrapped_methods[self._transport.create_backup]
2395
+
2396
+ # Certain fields should be provided within the metadata header;
2397
+ # add these here.
2398
+ metadata = tuple(metadata) + (
2399
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2400
+ )
2401
+
2402
+ # Validate the universe domain.
2403
+ self._validate_universe_domain()
2404
+
2405
+ # Send the request.
2406
+ response = rpc(
2407
+ request,
2408
+ retry=retry,
2409
+ timeout=timeout,
2410
+ metadata=metadata,
2411
+ )
2412
+
2413
+ # Wrap the response in an operation future.
2414
+ response = operation.from_gapic(
2415
+ response,
2416
+ self._transport.operations_client,
2417
+ gsad_backup.Backup,
2418
+ metadata_type=gsad_backup.CreateBackupMetadata,
2419
+ )
2420
+
2421
+ # Done; return the response.
2422
+ return response
2423
+
2424
+ def copy_backup(
2425
+ self,
2426
+ request: Optional[Union[backup.CopyBackupRequest, dict]] = None,
2427
+ *,
2428
+ parent: Optional[str] = None,
2429
+ backup_id: Optional[str] = None,
2430
+ source_backup: Optional[str] = None,
2431
+ expire_time: Optional[timestamp_pb2.Timestamp] = None,
2432
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2433
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2434
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2435
+ ) -> operation.Operation:
2436
+ r"""Starts copying a Cloud Spanner Backup. The returned backup
2437
+ [long-running operation][google.longrunning.Operation] will have
2438
+ a name of the format
2439
+ ``projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>``
2440
+ and can be used to track copying of the backup. The operation is
2441
+ associated with the destination backup. The
2442
+ [metadata][google.longrunning.Operation.metadata] field type is
2443
+ [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata].
2444
+ The [response][google.longrunning.Operation.response] field type
2445
+ is [Backup][google.spanner.admin.database.v1.Backup], if
2446
+ successful. Cancelling the returned operation will stop the
2447
+ copying and delete the destination backup. Concurrent CopyBackup
2448
+ requests can run on the same source backup.
2449
+
2450
+ .. code-block:: python
2451
+
2452
+ # This snippet has been automatically generated and should be regarded as a
2453
+ # code template only.
2454
+ # It will require modifications to work:
2455
+ # - It may require correct/in-range values for request initialization.
2456
+ # - It may require specifying regional endpoints when creating the service
2457
+ # client as shown in:
2458
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2459
+ from google.cloud import spanner_admin_database_v1
2460
+
2461
+ def sample_copy_backup():
2462
+ # Create a client
2463
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2464
+
2465
+ # Initialize request argument(s)
2466
+ request = spanner_admin_database_v1.CopyBackupRequest(
2467
+ parent="parent_value",
2468
+ backup_id="backup_id_value",
2469
+ source_backup="source_backup_value",
2470
+ )
2471
+
2472
+ # Make the request
2473
+ operation = client.copy_backup(request=request)
2474
+
2475
+ print("Waiting for operation to complete...")
2476
+
2477
+ response = operation.result()
2478
+
2479
+ # Handle the response
2480
+ print(response)
2481
+
2482
+ Args:
2483
+ request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]):
2484
+ The request object. The request for
2485
+ [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup].
2486
+ parent (str):
2487
+ Required. The name of the destination instance that will
2488
+ contain the backup copy. Values are of the form:
2489
+ ``projects/<project>/instances/<instance>``.
2490
+
2491
+ This corresponds to the ``parent`` field
2492
+ on the ``request`` instance; if ``request`` is provided, this
2493
+ should not be set.
2494
+ backup_id (str):
2495
+ Required. The id of the backup copy. The ``backup_id``
2496
+ appended to ``parent`` forms the full backup_uri of the
2497
+ form
2498
+ ``projects/<project>/instances/<instance>/backups/<backup>``.
2499
+
2500
+ This corresponds to the ``backup_id`` field
2501
+ on the ``request`` instance; if ``request`` is provided, this
2502
+ should not be set.
2503
+ source_backup (str):
2504
+ Required. The source backup to be copied. The source
2505
+ backup needs to be in READY state for it to be copied.
2506
+ Once CopyBackup is in progress, the source backup cannot
2507
+ be deleted or cleaned up on expiration until CopyBackup
2508
+ is finished. Values are of the form:
2509
+ ``projects/<project>/instances/<instance>/backups/<backup>``.
2510
+
2511
+ This corresponds to the ``source_backup`` field
2512
+ on the ``request`` instance; if ``request`` is provided, this
2513
+ should not be set.
2514
+ expire_time (google.protobuf.timestamp_pb2.Timestamp):
2515
+ Required. The expiration time of the backup in
2516
+ microsecond granularity. The expiration time must be at
2517
+ least 6 hours and at most 366 days from the
2518
+ ``create_time`` of the source backup. Once the
2519
+ ``expire_time`` has passed, the backup is eligible to be
2520
+ automatically deleted by Cloud Spanner to free the
2521
+ resources used by the backup.
2522
+
2523
+ This corresponds to the ``expire_time`` field
2524
+ on the ``request`` instance; if ``request`` is provided, this
2525
+ should not be set.
2526
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2527
+ should be retried.
2528
+ timeout (float): The timeout for this request.
2529
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2530
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2531
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2532
+ be of type `bytes`.
2533
+
2534
+ Returns:
2535
+ google.api_core.operation.Operation:
2536
+ An object representing a long-running operation.
2537
+
2538
+ The result type for the operation will be
2539
+ :class:`google.cloud.spanner_admin_database_v1.types.Backup`
2540
+ A backup of a Cloud Spanner database.
2541
+
2542
+ """
2543
+ # Create or coerce a protobuf request object.
2544
+ # - Quick check: If we got a request object, we should *not* have
2545
+ # gotten any keyword arguments that map to the request.
2546
+ flattened_params = [parent, backup_id, source_backup, expire_time]
2547
+ has_flattened_params = (
2548
+ len([param for param in flattened_params if param is not None]) > 0
2549
+ )
2550
+ if request is not None and has_flattened_params:
2551
+ raise ValueError(
2552
+ "If the `request` argument is set, then none of "
2553
+ "the individual field arguments should be set."
2554
+ )
2555
+
2556
+ # - Use the request object if provided (there's no risk of modifying the input as
2557
+ # there are no flattened fields), or create one.
2558
+ if not isinstance(request, backup.CopyBackupRequest):
2559
+ request = backup.CopyBackupRequest(request)
2560
+ # If we have keyword arguments corresponding to fields on the
2561
+ # request, apply these.
2562
+ if parent is not None:
2563
+ request.parent = parent
2564
+ if backup_id is not None:
2565
+ request.backup_id = backup_id
2566
+ if source_backup is not None:
2567
+ request.source_backup = source_backup
2568
+ if expire_time is not None:
2569
+ request.expire_time = expire_time
2570
+
2571
+ # Wrap the RPC method; this adds retry and timeout information,
2572
+ # and friendly error handling.
2573
+ rpc = self._transport._wrapped_methods[self._transport.copy_backup]
2574
+
2575
+ # Certain fields should be provided within the metadata header;
2576
+ # add these here.
2577
+ metadata = tuple(metadata) + (
2578
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2579
+ )
2580
+
2581
+ # Validate the universe domain.
2582
+ self._validate_universe_domain()
2583
+
2584
+ # Send the request.
2585
+ response = rpc(
2586
+ request,
2587
+ retry=retry,
2588
+ timeout=timeout,
2589
+ metadata=metadata,
2590
+ )
2591
+
2592
+ # Wrap the response in an operation future.
2593
+ response = operation.from_gapic(
2594
+ response,
2595
+ self._transport.operations_client,
2596
+ backup.Backup,
2597
+ metadata_type=backup.CopyBackupMetadata,
2598
+ )
2599
+
2600
+ # Done; return the response.
2601
+ return response
2602
+
2603
+ def get_backup(
2604
+ self,
2605
+ request: Optional[Union[backup.GetBackupRequest, dict]] = None,
2606
+ *,
2607
+ name: Optional[str] = None,
2608
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2609
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2610
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2611
+ ) -> backup.Backup:
2612
+ r"""Gets metadata on a pending or completed
2613
+ [Backup][google.spanner.admin.database.v1.Backup].
2614
+
2615
+ .. code-block:: python
2616
+
2617
+ # This snippet has been automatically generated and should be regarded as a
2618
+ # code template only.
2619
+ # It will require modifications to work:
2620
+ # - It may require correct/in-range values for request initialization.
2621
+ # - It may require specifying regional endpoints when creating the service
2622
+ # client as shown in:
2623
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2624
+ from google.cloud import spanner_admin_database_v1
2625
+
2626
+ def sample_get_backup():
2627
+ # Create a client
2628
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2629
+
2630
+ # Initialize request argument(s)
2631
+ request = spanner_admin_database_v1.GetBackupRequest(
2632
+ name="name_value",
2633
+ )
2634
+
2635
+ # Make the request
2636
+ response = client.get_backup(request=request)
2637
+
2638
+ # Handle the response
2639
+ print(response)
2640
+
2641
+ Args:
2642
+ request (Union[google.cloud.spanner_admin_database_v1.types.GetBackupRequest, dict]):
2643
+ The request object. The request for
2644
+ [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup].
2645
+ name (str):
2646
+ Required. Name of the backup. Values are of the form
2647
+ ``projects/<project>/instances/<instance>/backups/<backup>``.
2648
+
2649
+ This corresponds to the ``name`` field
2650
+ on the ``request`` instance; if ``request`` is provided, this
2651
+ should not be set.
2652
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2653
+ should be retried.
2654
+ timeout (float): The timeout for this request.
2655
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2656
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2657
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2658
+ be of type `bytes`.
2659
+
2660
+ Returns:
2661
+ google.cloud.spanner_admin_database_v1.types.Backup:
2662
+ A backup of a Cloud Spanner database.
2663
+ """
2664
+ # Create or coerce a protobuf request object.
2665
+ # - Quick check: If we got a request object, we should *not* have
2666
+ # gotten any keyword arguments that map to the request.
2667
+ flattened_params = [name]
2668
+ has_flattened_params = (
2669
+ len([param for param in flattened_params if param is not None]) > 0
2670
+ )
2671
+ if request is not None and has_flattened_params:
2672
+ raise ValueError(
2673
+ "If the `request` argument is set, then none of "
2674
+ "the individual field arguments should be set."
2675
+ )
2676
+
2677
+ # - Use the request object if provided (there's no risk of modifying the input as
2678
+ # there are no flattened fields), or create one.
2679
+ if not isinstance(request, backup.GetBackupRequest):
2680
+ request = backup.GetBackupRequest(request)
2681
+ # If we have keyword arguments corresponding to fields on the
2682
+ # request, apply these.
2683
+ if name is not None:
2684
+ request.name = name
2685
+
2686
+ # Wrap the RPC method; this adds retry and timeout information,
2687
+ # and friendly error handling.
2688
+ rpc = self._transport._wrapped_methods[self._transport.get_backup]
2689
+
2690
+ # Certain fields should be provided within the metadata header;
2691
+ # add these here.
2692
+ metadata = tuple(metadata) + (
2693
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2694
+ )
2695
+
2696
+ # Validate the universe domain.
2697
+ self._validate_universe_domain()
2698
+
2699
+ # Send the request.
2700
+ response = rpc(
2701
+ request,
2702
+ retry=retry,
2703
+ timeout=timeout,
2704
+ metadata=metadata,
2705
+ )
2706
+
2707
+ # Done; return the response.
2708
+ return response
2709
+
2710
+ def update_backup(
2711
+ self,
2712
+ request: Optional[Union[gsad_backup.UpdateBackupRequest, dict]] = None,
2713
+ *,
2714
+ backup: Optional[gsad_backup.Backup] = None,
2715
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
2716
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2717
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2718
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2719
+ ) -> gsad_backup.Backup:
2720
+ r"""Updates a pending or completed
2721
+ [Backup][google.spanner.admin.database.v1.Backup].
2722
+
2723
+ .. code-block:: python
2724
+
2725
+ # This snippet has been automatically generated and should be regarded as a
2726
+ # code template only.
2727
+ # It will require modifications to work:
2728
+ # - It may require correct/in-range values for request initialization.
2729
+ # - It may require specifying regional endpoints when creating the service
2730
+ # client as shown in:
2731
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2732
+ from google.cloud import spanner_admin_database_v1
2733
+
2734
+ def sample_update_backup():
2735
+ # Create a client
2736
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2737
+
2738
+ # Initialize request argument(s)
2739
+ request = spanner_admin_database_v1.UpdateBackupRequest(
2740
+ )
2741
+
2742
+ # Make the request
2743
+ response = client.update_backup(request=request)
2744
+
2745
+ # Handle the response
2746
+ print(response)
2747
+
2748
+ Args:
2749
+ request (Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest, dict]):
2750
+ The request object. The request for
2751
+ [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup].
2752
+ backup (google.cloud.spanner_admin_database_v1.types.Backup):
2753
+ Required. The backup to update. ``backup.name``, and the
2754
+ fields to be updated as specified by ``update_mask`` are
2755
+ required. Other fields are ignored. Update is only
2756
+ supported for the following fields:
2757
+
2758
+ - ``backup.expire_time``.
2759
+
2760
+ This corresponds to the ``backup`` field
2761
+ on the ``request`` instance; if ``request`` is provided, this
2762
+ should not be set.
2763
+ update_mask (google.protobuf.field_mask_pb2.FieldMask):
2764
+ Required. A mask specifying which fields (e.g.
2765
+ ``expire_time``) in the Backup resource should be
2766
+ updated. This mask is relative to the Backup resource,
2767
+ not to the request message. The field mask must always
2768
+ be specified; this prevents any future fields from being
2769
+ erased accidentally by clients that do not know about
2770
+ them.
2771
+
2772
+ This corresponds to the ``update_mask`` field
2773
+ on the ``request`` instance; if ``request`` is provided, this
2774
+ should not be set.
2775
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2776
+ should be retried.
2777
+ timeout (float): The timeout for this request.
2778
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2779
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2780
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2781
+ be of type `bytes`.
2782
+
2783
+ Returns:
2784
+ google.cloud.spanner_admin_database_v1.types.Backup:
2785
+ A backup of a Cloud Spanner database.
2786
+ """
2787
+ # Create or coerce a protobuf request object.
2788
+ # - Quick check: If we got a request object, we should *not* have
2789
+ # gotten any keyword arguments that map to the request.
2790
+ flattened_params = [backup, update_mask]
2791
+ has_flattened_params = (
2792
+ len([param for param in flattened_params if param is not None]) > 0
2793
+ )
2794
+ if request is not None and has_flattened_params:
2795
+ raise ValueError(
2796
+ "If the `request` argument is set, then none of "
2797
+ "the individual field arguments should be set."
2798
+ )
2799
+
2800
+ # - Use the request object if provided (there's no risk of modifying the input as
2801
+ # there are no flattened fields), or create one.
2802
+ if not isinstance(request, gsad_backup.UpdateBackupRequest):
2803
+ request = gsad_backup.UpdateBackupRequest(request)
2804
+ # If we have keyword arguments corresponding to fields on the
2805
+ # request, apply these.
2806
+ if backup is not None:
2807
+ request.backup = backup
2808
+ if update_mask is not None:
2809
+ request.update_mask = update_mask
2810
+
2811
+ # Wrap the RPC method; this adds retry and timeout information,
2812
+ # and friendly error handling.
2813
+ rpc = self._transport._wrapped_methods[self._transport.update_backup]
2814
+
2815
+ # Certain fields should be provided within the metadata header;
2816
+ # add these here.
2817
+ metadata = tuple(metadata) + (
2818
+ gapic_v1.routing_header.to_grpc_metadata(
2819
+ (("backup.name", request.backup.name),)
2820
+ ),
2821
+ )
2822
+
2823
+ # Validate the universe domain.
2824
+ self._validate_universe_domain()
2825
+
2826
+ # Send the request.
2827
+ response = rpc(
2828
+ request,
2829
+ retry=retry,
2830
+ timeout=timeout,
2831
+ metadata=metadata,
2832
+ )
2833
+
2834
+ # Done; return the response.
2835
+ return response
2836
+
2837
+ def delete_backup(
2838
+ self,
2839
+ request: Optional[Union[backup.DeleteBackupRequest, dict]] = None,
2840
+ *,
2841
+ name: Optional[str] = None,
2842
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2843
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2844
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2845
+ ) -> None:
2846
+ r"""Deletes a pending or completed
2847
+ [Backup][google.spanner.admin.database.v1.Backup].
2848
+
2849
+ .. code-block:: python
2850
+
2851
+ # This snippet has been automatically generated and should be regarded as a
2852
+ # code template only.
2853
+ # It will require modifications to work:
2854
+ # - It may require correct/in-range values for request initialization.
2855
+ # - It may require specifying regional endpoints when creating the service
2856
+ # client as shown in:
2857
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2858
+ from google.cloud import spanner_admin_database_v1
2859
+
2860
+ def sample_delete_backup():
2861
+ # Create a client
2862
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2863
+
2864
+ # Initialize request argument(s)
2865
+ request = spanner_admin_database_v1.DeleteBackupRequest(
2866
+ name="name_value",
2867
+ )
2868
+
2869
+ # Make the request
2870
+ client.delete_backup(request=request)
2871
+
2872
+ Args:
2873
+ request (Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest, dict]):
2874
+ The request object. The request for
2875
+ [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup].
2876
+ name (str):
2877
+ Required. Name of the backup to delete. Values are of
2878
+ the form
2879
+ ``projects/<project>/instances/<instance>/backups/<backup>``.
2880
+
2881
+ This corresponds to the ``name`` field
2882
+ on the ``request`` instance; if ``request`` is provided, this
2883
+ should not be set.
2884
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2885
+ should be retried.
2886
+ timeout (float): The timeout for this request.
2887
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2888
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2889
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2890
+ be of type `bytes`.
2891
+ """
2892
+ # Create or coerce a protobuf request object.
2893
+ # - Quick check: If we got a request object, we should *not* have
2894
+ # gotten any keyword arguments that map to the request.
2895
+ flattened_params = [name]
2896
+ has_flattened_params = (
2897
+ len([param for param in flattened_params if param is not None]) > 0
2898
+ )
2899
+ if request is not None and has_flattened_params:
2900
+ raise ValueError(
2901
+ "If the `request` argument is set, then none of "
2902
+ "the individual field arguments should be set."
2903
+ )
2904
+
2905
+ # - Use the request object if provided (there's no risk of modifying the input as
2906
+ # there are no flattened fields), or create one.
2907
+ if not isinstance(request, backup.DeleteBackupRequest):
2908
+ request = backup.DeleteBackupRequest(request)
2909
+ # If we have keyword arguments corresponding to fields on the
2910
+ # request, apply these.
2911
+ if name is not None:
2912
+ request.name = name
2913
+
2914
+ # Wrap the RPC method; this adds retry and timeout information,
2915
+ # and friendly error handling.
2916
+ rpc = self._transport._wrapped_methods[self._transport.delete_backup]
2917
+
2918
+ # Certain fields should be provided within the metadata header;
2919
+ # add these here.
2920
+ metadata = tuple(metadata) + (
2921
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2922
+ )
2923
+
2924
+ # Validate the universe domain.
2925
+ self._validate_universe_domain()
2926
+
2927
+ # Send the request.
2928
+ rpc(
2929
+ request,
2930
+ retry=retry,
2931
+ timeout=timeout,
2932
+ metadata=metadata,
2933
+ )
2934
+
2935
+ def list_backups(
2936
+ self,
2937
+ request: Optional[Union[backup.ListBackupsRequest, dict]] = None,
2938
+ *,
2939
+ parent: Optional[str] = None,
2940
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2941
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2942
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2943
+ ) -> pagers.ListBackupsPager:
2944
+ r"""Lists completed and pending backups. Backups returned are
2945
+ ordered by ``create_time`` in descending order, starting from
2946
+ the most recent ``create_time``.
2947
+
2948
+ .. code-block:: python
2949
+
2950
+ # This snippet has been automatically generated and should be regarded as a
2951
+ # code template only.
2952
+ # It will require modifications to work:
2953
+ # - It may require correct/in-range values for request initialization.
2954
+ # - It may require specifying regional endpoints when creating the service
2955
+ # client as shown in:
2956
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2957
+ from google.cloud import spanner_admin_database_v1
2958
+
2959
+ def sample_list_backups():
2960
+ # Create a client
2961
+ client = spanner_admin_database_v1.DatabaseAdminClient()
2962
+
2963
+ # Initialize request argument(s)
2964
+ request = spanner_admin_database_v1.ListBackupsRequest(
2965
+ parent="parent_value",
2966
+ )
2967
+
2968
+ # Make the request
2969
+ page_result = client.list_backups(request=request)
2970
+
2971
+ # Handle the response
2972
+ for response in page_result:
2973
+ print(response)
2974
+
2975
+ Args:
2976
+ request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupsRequest, dict]):
2977
+ The request object. The request for
2978
+ [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups].
2979
+ parent (str):
2980
+ Required. The instance to list backups from. Values are
2981
+ of the form ``projects/<project>/instances/<instance>``.
2982
+
2983
+ This corresponds to the ``parent`` field
2984
+ on the ``request`` instance; if ``request`` is provided, this
2985
+ should not be set.
2986
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2987
+ should be retried.
2988
+ timeout (float): The timeout for this request.
2989
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2990
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2991
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2992
+ be of type `bytes`.
2993
+
2994
+ Returns:
2995
+ google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsPager:
2996
+ The response for
2997
+ [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups].
2998
+
2999
+ Iterating over this object will yield results and
3000
+ resolve additional pages automatically.
3001
+
3002
+ """
3003
+ # Create or coerce a protobuf request object.
3004
+ # - Quick check: If we got a request object, we should *not* have
3005
+ # gotten any keyword arguments that map to the request.
3006
+ flattened_params = [parent]
3007
+ has_flattened_params = (
3008
+ len([param for param in flattened_params if param is not None]) > 0
3009
+ )
3010
+ if request is not None and has_flattened_params:
3011
+ raise ValueError(
3012
+ "If the `request` argument is set, then none of "
3013
+ "the individual field arguments should be set."
3014
+ )
3015
+
3016
+ # - Use the request object if provided (there's no risk of modifying the input as
3017
+ # there are no flattened fields), or create one.
3018
+ if not isinstance(request, backup.ListBackupsRequest):
3019
+ request = backup.ListBackupsRequest(request)
3020
+ # If we have keyword arguments corresponding to fields on the
3021
+ # request, apply these.
3022
+ if parent is not None:
3023
+ request.parent = parent
3024
+
3025
+ # Wrap the RPC method; this adds retry and timeout information,
3026
+ # and friendly error handling.
3027
+ rpc = self._transport._wrapped_methods[self._transport.list_backups]
3028
+
3029
+ # Certain fields should be provided within the metadata header;
3030
+ # add these here.
3031
+ metadata = tuple(metadata) + (
3032
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3033
+ )
3034
+
3035
+ # Validate the universe domain.
3036
+ self._validate_universe_domain()
3037
+
3038
+ # Send the request.
3039
+ response = rpc(
3040
+ request,
3041
+ retry=retry,
3042
+ timeout=timeout,
3043
+ metadata=metadata,
3044
+ )
3045
+
3046
+ # This method is paged; wrap the response in a pager, which provides
3047
+ # an `__iter__` convenience method.
3048
+ response = pagers.ListBackupsPager(
3049
+ method=rpc,
3050
+ request=request,
3051
+ response=response,
3052
+ retry=retry,
3053
+ timeout=timeout,
3054
+ metadata=metadata,
3055
+ )
3056
+
3057
+ # Done; return the response.
3058
+ return response
3059
+
3060
+ def restore_database(
3061
+ self,
3062
+ request: Optional[
3063
+ Union[spanner_database_admin.RestoreDatabaseRequest, dict]
3064
+ ] = None,
3065
+ *,
3066
+ parent: Optional[str] = None,
3067
+ database_id: Optional[str] = None,
3068
+ backup: Optional[str] = None,
3069
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3070
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3071
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3072
+ ) -> operation.Operation:
3073
+ r"""Create a new database by restoring from a completed backup. The
3074
+ new database must be in the same project and in an instance with
3075
+ the same instance configuration as the instance containing the
3076
+ backup. The returned database [long-running
3077
+ operation][google.longrunning.Operation] has a name of the
3078
+ format
3079
+ ``projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>``,
3080
+ and can be used to track the progress of the operation, and to
3081
+ cancel it. The [metadata][google.longrunning.Operation.metadata]
3082
+ field type is
3083
+ [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata].
3084
+ The [response][google.longrunning.Operation.response] type is
3085
+ [Database][google.spanner.admin.database.v1.Database], if
3086
+ successful. Cancelling the returned operation will stop the
3087
+ restore and delete the database. There can be only one database
3088
+ being restored into an instance at a time. Once the restore
3089
+ operation completes, a new restore operation can be initiated,
3090
+ without waiting for the optimize operation associated with the
3091
+ first restore to complete.
3092
+
3093
+ .. code-block:: python
3094
+
3095
+ # This snippet has been automatically generated and should be regarded as a
3096
+ # code template only.
3097
+ # It will require modifications to work:
3098
+ # - It may require correct/in-range values for request initialization.
3099
+ # - It may require specifying regional endpoints when creating the service
3100
+ # client as shown in:
3101
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3102
+ from google.cloud import spanner_admin_database_v1
3103
+
3104
+ def sample_restore_database():
3105
+ # Create a client
3106
+ client = spanner_admin_database_v1.DatabaseAdminClient()
3107
+
3108
+ # Initialize request argument(s)
3109
+ request = spanner_admin_database_v1.RestoreDatabaseRequest(
3110
+ backup="backup_value",
3111
+ parent="parent_value",
3112
+ database_id="database_id_value",
3113
+ )
3114
+
3115
+ # Make the request
3116
+ operation = client.restore_database(request=request)
3117
+
3118
+ print("Waiting for operation to complete...")
3119
+
3120
+ response = operation.result()
3121
+
3122
+ # Handle the response
3123
+ print(response)
3124
+
3125
+ Args:
3126
+ request (Union[google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest, dict]):
3127
+ The request object. The request for
3128
+ [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase].
3129
+ parent (str):
3130
+ Required. The name of the instance in which to create
3131
+ the restored database. This instance must be in the same
3132
+ project and have the same instance configuration as the
3133
+ instance containing the source backup. Values are of the
3134
+ form ``projects/<project>/instances/<instance>``.
3135
+
3136
+ This corresponds to the ``parent`` field
3137
+ on the ``request`` instance; if ``request`` is provided, this
3138
+ should not be set.
3139
+ database_id (str):
3140
+ Required. The id of the database to create and restore
3141
+ to. This database must not already exist. The
3142
+ ``database_id`` appended to ``parent`` forms the full
3143
+ database name of the form
3144
+ ``projects/<project>/instances/<instance>/databases/<database_id>``.
3145
+
3146
+ This corresponds to the ``database_id`` field
3147
+ on the ``request`` instance; if ``request`` is provided, this
3148
+ should not be set.
3149
+ backup (str):
3150
+ Name of the backup from which to restore. Values are of
3151
+ the form
3152
+ ``projects/<project>/instances/<instance>/backups/<backup>``.
3153
+
3154
+ This corresponds to the ``backup`` field
3155
+ on the ``request`` instance; if ``request`` is provided, this
3156
+ should not be set.
3157
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3158
+ should be retried.
3159
+ timeout (float): The timeout for this request.
3160
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3161
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3162
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3163
+ be of type `bytes`.
3164
+
3165
+ Returns:
3166
+ google.api_core.operation.Operation:
3167
+ An object representing a long-running operation.
3168
+
3169
+ The result type for the operation will be
3170
+ :class:`google.cloud.spanner_admin_database_v1.types.Database`
3171
+ A Cloud Spanner database.
3172
+
3173
+ """
3174
+ # Create or coerce a protobuf request object.
3175
+ # - Quick check: If we got a request object, we should *not* have
3176
+ # gotten any keyword arguments that map to the request.
3177
+ flattened_params = [parent, database_id, backup]
3178
+ has_flattened_params = (
3179
+ len([param for param in flattened_params if param is not None]) > 0
3180
+ )
3181
+ if request is not None and has_flattened_params:
3182
+ raise ValueError(
3183
+ "If the `request` argument is set, then none of "
3184
+ "the individual field arguments should be set."
3185
+ )
3186
+
3187
+ # - Use the request object if provided (there's no risk of modifying the input as
3188
+ # there are no flattened fields), or create one.
3189
+ if not isinstance(request, spanner_database_admin.RestoreDatabaseRequest):
3190
+ request = spanner_database_admin.RestoreDatabaseRequest(request)
3191
+ # If we have keyword arguments corresponding to fields on the
3192
+ # request, apply these.
3193
+ if parent is not None:
3194
+ request.parent = parent
3195
+ if database_id is not None:
3196
+ request.database_id = database_id
3197
+ if backup is not None:
3198
+ request.backup = backup
3199
+
3200
+ # Wrap the RPC method; this adds retry and timeout information,
3201
+ # and friendly error handling.
3202
+ rpc = self._transport._wrapped_methods[self._transport.restore_database]
3203
+
3204
+ # Certain fields should be provided within the metadata header;
3205
+ # add these here.
3206
+ metadata = tuple(metadata) + (
3207
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3208
+ )
3209
+
3210
+ # Validate the universe domain.
3211
+ self._validate_universe_domain()
3212
+
3213
+ # Send the request.
3214
+ response = rpc(
3215
+ request,
3216
+ retry=retry,
3217
+ timeout=timeout,
3218
+ metadata=metadata,
3219
+ )
3220
+
3221
+ # Wrap the response in an operation future.
3222
+ response = operation.from_gapic(
3223
+ response,
3224
+ self._transport.operations_client,
3225
+ spanner_database_admin.Database,
3226
+ metadata_type=spanner_database_admin.RestoreDatabaseMetadata,
3227
+ )
3228
+
3229
+ # Done; return the response.
3230
+ return response
3231
+
3232
+ def list_database_operations(
3233
+ self,
3234
+ request: Optional[
3235
+ Union[spanner_database_admin.ListDatabaseOperationsRequest, dict]
3236
+ ] = None,
3237
+ *,
3238
+ parent: Optional[str] = None,
3239
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3240
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3241
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3242
+ ) -> pagers.ListDatabaseOperationsPager:
3243
+ r"""Lists database
3244
+ [longrunning-operations][google.longrunning.Operation]. A
3245
+ database operation has a name of the form
3246
+ ``projects/<project>/instances/<instance>/databases/<database>/operations/<operation>``.
3247
+ The long-running operation
3248
+ [metadata][google.longrunning.Operation.metadata] field type
3249
+ ``metadata.type_url`` describes the type of the metadata.
3250
+ Operations returned include those that have
3251
+ completed/failed/canceled within the last 7 days, and pending
3252
+ operations.
3253
+
3254
+ .. code-block:: python
3255
+
3256
+ # This snippet has been automatically generated and should be regarded as a
3257
+ # code template only.
3258
+ # It will require modifications to work:
3259
+ # - It may require correct/in-range values for request initialization.
3260
+ # - It may require specifying regional endpoints when creating the service
3261
+ # client as shown in:
3262
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3263
+ from google.cloud import spanner_admin_database_v1
3264
+
3265
+ def sample_list_database_operations():
3266
+ # Create a client
3267
+ client = spanner_admin_database_v1.DatabaseAdminClient()
3268
+
3269
+ # Initialize request argument(s)
3270
+ request = spanner_admin_database_v1.ListDatabaseOperationsRequest(
3271
+ parent="parent_value",
3272
+ )
3273
+
3274
+ # Make the request
3275
+ page_result = client.list_database_operations(request=request)
3276
+
3277
+ # Handle the response
3278
+ for response in page_result:
3279
+ print(response)
3280
+
3281
+ Args:
3282
+ request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest, dict]):
3283
+ The request object. The request for
3284
+ [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations].
3285
+ parent (str):
3286
+ Required. The instance of the database operations.
3287
+ Values are of the form
3288
+ ``projects/<project>/instances/<instance>``.
3289
+
3290
+ This corresponds to the ``parent`` field
3291
+ on the ``request`` instance; if ``request`` is provided, this
3292
+ should not be set.
3293
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3294
+ should be retried.
3295
+ timeout (float): The timeout for this request.
3296
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3297
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3298
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3299
+ be of type `bytes`.
3300
+
3301
+ Returns:
3302
+ google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsPager:
3303
+ The response for
3304
+ [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations].
3305
+
3306
+ Iterating over this object will yield results and
3307
+ resolve additional pages automatically.
3308
+
3309
+ """
3310
+ # Create or coerce a protobuf request object.
3311
+ # - Quick check: If we got a request object, we should *not* have
3312
+ # gotten any keyword arguments that map to the request.
3313
+ flattened_params = [parent]
3314
+ has_flattened_params = (
3315
+ len([param for param in flattened_params if param is not None]) > 0
3316
+ )
3317
+ if request is not None and has_flattened_params:
3318
+ raise ValueError(
3319
+ "If the `request` argument is set, then none of "
3320
+ "the individual field arguments should be set."
3321
+ )
3322
+
3323
+ # - Use the request object if provided (there's no risk of modifying the input as
3324
+ # there are no flattened fields), or create one.
3325
+ if not isinstance(
3326
+ request, spanner_database_admin.ListDatabaseOperationsRequest
3327
+ ):
3328
+ request = spanner_database_admin.ListDatabaseOperationsRequest(request)
3329
+ # If we have keyword arguments corresponding to fields on the
3330
+ # request, apply these.
3331
+ if parent is not None:
3332
+ request.parent = parent
3333
+
3334
+ # Wrap the RPC method; this adds retry and timeout information,
3335
+ # and friendly error handling.
3336
+ rpc = self._transport._wrapped_methods[self._transport.list_database_operations]
3337
+
3338
+ # Certain fields should be provided within the metadata header;
3339
+ # add these here.
3340
+ metadata = tuple(metadata) + (
3341
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3342
+ )
3343
+
3344
+ # Validate the universe domain.
3345
+ self._validate_universe_domain()
3346
+
3347
+ # Send the request.
3348
+ response = rpc(
3349
+ request,
3350
+ retry=retry,
3351
+ timeout=timeout,
3352
+ metadata=metadata,
3353
+ )
3354
+
3355
+ # This method is paged; wrap the response in a pager, which provides
3356
+ # an `__iter__` convenience method.
3357
+ response = pagers.ListDatabaseOperationsPager(
3358
+ method=rpc,
3359
+ request=request,
3360
+ response=response,
3361
+ retry=retry,
3362
+ timeout=timeout,
3363
+ metadata=metadata,
3364
+ )
3365
+
3366
+ # Done; return the response.
3367
+ return response
3368
+
3369
+ def list_backup_operations(
3370
+ self,
3371
+ request: Optional[Union[backup.ListBackupOperationsRequest, dict]] = None,
3372
+ *,
3373
+ parent: Optional[str] = None,
3374
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3375
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3376
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3377
+ ) -> pagers.ListBackupOperationsPager:
3378
+ r"""Lists the backup [long-running
3379
+ operations][google.longrunning.Operation] in the given instance.
3380
+ A backup operation has a name of the form
3381
+ ``projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>``.
3382
+ The long-running operation
3383
+ [metadata][google.longrunning.Operation.metadata] field type
3384
+ ``metadata.type_url`` describes the type of the metadata.
3385
+ Operations returned include those that have
3386
+ completed/failed/canceled within the last 7 days, and pending
3387
+ operations. Operations returned are ordered by
3388
+ ``operation.metadata.value.progress.start_time`` in descending
3389
+ order starting from the most recently started operation.
3390
+
3391
+ .. code-block:: python
3392
+
3393
+ # This snippet has been automatically generated and should be regarded as a
3394
+ # code template only.
3395
+ # It will require modifications to work:
3396
+ # - It may require correct/in-range values for request initialization.
3397
+ # - It may require specifying regional endpoints when creating the service
3398
+ # client as shown in:
3399
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3400
+ from google.cloud import spanner_admin_database_v1
3401
+
3402
+ def sample_list_backup_operations():
3403
+ # Create a client
3404
+ client = spanner_admin_database_v1.DatabaseAdminClient()
3405
+
3406
+ # Initialize request argument(s)
3407
+ request = spanner_admin_database_v1.ListBackupOperationsRequest(
3408
+ parent="parent_value",
3409
+ )
3410
+
3411
+ # Make the request
3412
+ page_result = client.list_backup_operations(request=request)
3413
+
3414
+ # Handle the response
3415
+ for response in page_result:
3416
+ print(response)
3417
+
3418
+ Args:
3419
+ request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest, dict]):
3420
+ The request object. The request for
3421
+ [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations].
3422
+ parent (str):
3423
+ Required. The instance of the backup operations. Values
3424
+ are of the form
3425
+ ``projects/<project>/instances/<instance>``.
3426
+
3427
+ This corresponds to the ``parent`` field
3428
+ on the ``request`` instance; if ``request`` is provided, this
3429
+ should not be set.
3430
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3431
+ should be retried.
3432
+ timeout (float): The timeout for this request.
3433
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3434
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3435
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3436
+ be of type `bytes`.
3437
+
3438
+ Returns:
3439
+ google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsPager:
3440
+ The response for
3441
+ [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations].
3442
+
3443
+ Iterating over this object will yield results and
3444
+ resolve additional pages automatically.
3445
+
3446
+ """
3447
+ # Create or coerce a protobuf request object.
3448
+ # - Quick check: If we got a request object, we should *not* have
3449
+ # gotten any keyword arguments that map to the request.
3450
+ flattened_params = [parent]
3451
+ has_flattened_params = (
3452
+ len([param for param in flattened_params if param is not None]) > 0
3453
+ )
3454
+ if request is not None and has_flattened_params:
3455
+ raise ValueError(
3456
+ "If the `request` argument is set, then none of "
3457
+ "the individual field arguments should be set."
3458
+ )
3459
+
3460
+ # - Use the request object if provided (there's no risk of modifying the input as
3461
+ # there are no flattened fields), or create one.
3462
+ if not isinstance(request, backup.ListBackupOperationsRequest):
3463
+ request = backup.ListBackupOperationsRequest(request)
3464
+ # If we have keyword arguments corresponding to fields on the
3465
+ # request, apply these.
3466
+ if parent is not None:
3467
+ request.parent = parent
3468
+
3469
+ # Wrap the RPC method; this adds retry and timeout information,
3470
+ # and friendly error handling.
3471
+ rpc = self._transport._wrapped_methods[self._transport.list_backup_operations]
3472
+
3473
+ # Certain fields should be provided within the metadata header;
3474
+ # add these here.
3475
+ metadata = tuple(metadata) + (
3476
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3477
+ )
3478
+
3479
+ # Validate the universe domain.
3480
+ self._validate_universe_domain()
3481
+
3482
+ # Send the request.
3483
+ response = rpc(
3484
+ request,
3485
+ retry=retry,
3486
+ timeout=timeout,
3487
+ metadata=metadata,
3488
+ )
3489
+
3490
+ # This method is paged; wrap the response in a pager, which provides
3491
+ # an `__iter__` convenience method.
3492
+ response = pagers.ListBackupOperationsPager(
3493
+ method=rpc,
3494
+ request=request,
3495
+ response=response,
3496
+ retry=retry,
3497
+ timeout=timeout,
3498
+ metadata=metadata,
3499
+ )
3500
+
3501
+ # Done; return the response.
3502
+ return response
3503
+
3504
+ def list_database_roles(
3505
+ self,
3506
+ request: Optional[
3507
+ Union[spanner_database_admin.ListDatabaseRolesRequest, dict]
3508
+ ] = None,
3509
+ *,
3510
+ parent: Optional[str] = None,
3511
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3512
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3513
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3514
+ ) -> pagers.ListDatabaseRolesPager:
3515
+ r"""Lists Cloud Spanner database roles.
3516
+
3517
+ .. code-block:: python
3518
+
3519
+ # This snippet has been automatically generated and should be regarded as a
3520
+ # code template only.
3521
+ # It will require modifications to work:
3522
+ # - It may require correct/in-range values for request initialization.
3523
+ # - It may require specifying regional endpoints when creating the service
3524
+ # client as shown in:
3525
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3526
+ from google.cloud import spanner_admin_database_v1
3527
+
3528
+ def sample_list_database_roles():
3529
+ # Create a client
3530
+ client = spanner_admin_database_v1.DatabaseAdminClient()
3531
+
3532
+ # Initialize request argument(s)
3533
+ request = spanner_admin_database_v1.ListDatabaseRolesRequest(
3534
+ parent="parent_value",
3535
+ )
3536
+
3537
+ # Make the request
3538
+ page_result = client.list_database_roles(request=request)
3539
+
3540
+ # Handle the response
3541
+ for response in page_result:
3542
+ print(response)
3543
+
3544
+ Args:
3545
+ request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest, dict]):
3546
+ The request object. The request for
3547
+ [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles].
3548
+ parent (str):
3549
+ Required. The database whose roles should be listed.
3550
+ Values are of the form
3551
+ ``projects/<project>/instances/<instance>/databases/<database>``.
3552
+
3553
+ This corresponds to the ``parent`` field
3554
+ on the ``request`` instance; if ``request`` is provided, this
3555
+ should not be set.
3556
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3557
+ should be retried.
3558
+ timeout (float): The timeout for this request.
3559
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3560
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3561
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3562
+ be of type `bytes`.
3563
+
3564
+ Returns:
3565
+ google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesPager:
3566
+ The response for
3567
+ [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles].
3568
+
3569
+ Iterating over this object will yield results and
3570
+ resolve additional pages automatically.
3571
+
3572
+ """
3573
+ # Create or coerce a protobuf request object.
3574
+ # - Quick check: If we got a request object, we should *not* have
3575
+ # gotten any keyword arguments that map to the request.
3576
+ flattened_params = [parent]
3577
+ has_flattened_params = (
3578
+ len([param for param in flattened_params if param is not None]) > 0
3579
+ )
3580
+ if request is not None and has_flattened_params:
3581
+ raise ValueError(
3582
+ "If the `request` argument is set, then none of "
3583
+ "the individual field arguments should be set."
3584
+ )
3585
+
3586
+ # - Use the request object if provided (there's no risk of modifying the input as
3587
+ # there are no flattened fields), or create one.
3588
+ if not isinstance(request, spanner_database_admin.ListDatabaseRolesRequest):
3589
+ request = spanner_database_admin.ListDatabaseRolesRequest(request)
3590
+ # If we have keyword arguments corresponding to fields on the
3591
+ # request, apply these.
3592
+ if parent is not None:
3593
+ request.parent = parent
3594
+
3595
+ # Wrap the RPC method; this adds retry and timeout information,
3596
+ # and friendly error handling.
3597
+ rpc = self._transport._wrapped_methods[self._transport.list_database_roles]
3598
+
3599
+ # Certain fields should be provided within the metadata header;
3600
+ # add these here.
3601
+ metadata = tuple(metadata) + (
3602
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3603
+ )
3604
+
3605
+ # Validate the universe domain.
3606
+ self._validate_universe_domain()
3607
+
3608
+ # Send the request.
3609
+ response = rpc(
3610
+ request,
3611
+ retry=retry,
3612
+ timeout=timeout,
3613
+ metadata=metadata,
3614
+ )
3615
+
3616
+ # This method is paged; wrap the response in a pager, which provides
3617
+ # an `__iter__` convenience method.
3618
+ response = pagers.ListDatabaseRolesPager(
3619
+ method=rpc,
3620
+ request=request,
3621
+ response=response,
3622
+ retry=retry,
3623
+ timeout=timeout,
3624
+ metadata=metadata,
3625
+ )
3626
+
3627
+ # Done; return the response.
3628
+ return response
3629
+
3630
+ def add_split_points(
3631
+ self,
3632
+ request: Optional[
3633
+ Union[spanner_database_admin.AddSplitPointsRequest, dict]
3634
+ ] = None,
3635
+ *,
3636
+ database: Optional[str] = None,
3637
+ split_points: Optional[
3638
+ MutableSequence[spanner_database_admin.SplitPoints]
3639
+ ] = None,
3640
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3641
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3642
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3643
+ ) -> spanner_database_admin.AddSplitPointsResponse:
3644
+ r"""Adds split points to specified tables, indexes of a
3645
+ database.
3646
+
3647
+ .. code-block:: python
3648
+
3649
+ # This snippet has been automatically generated and should be regarded as a
3650
+ # code template only.
3651
+ # It will require modifications to work:
3652
+ # - It may require correct/in-range values for request initialization.
3653
+ # - It may require specifying regional endpoints when creating the service
3654
+ # client as shown in:
3655
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3656
+ from google.cloud import spanner_admin_database_v1
3657
+
3658
+ def sample_add_split_points():
3659
+ # Create a client
3660
+ client = spanner_admin_database_v1.DatabaseAdminClient()
3661
+
3662
+ # Initialize request argument(s)
3663
+ request = spanner_admin_database_v1.AddSplitPointsRequest(
3664
+ database="database_value",
3665
+ )
3666
+
3667
+ # Make the request
3668
+ response = client.add_split_points(request=request)
3669
+
3670
+ # Handle the response
3671
+ print(response)
3672
+
3673
+ Args:
3674
+ request (Union[google.cloud.spanner_admin_database_v1.types.AddSplitPointsRequest, dict]):
3675
+ The request object. The request for
3676
+ [AddSplitPoints][google.spanner.admin.database.v1.DatabaseAdmin.AddSplitPoints].
3677
+ database (str):
3678
+ Required. The database on whose tables/indexes split
3679
+ points are to be added. Values are of the form
3680
+ ``projects/<project>/instances/<instance>/databases/<database>``.
3681
+
3682
+ This corresponds to the ``database`` field
3683
+ on the ``request`` instance; if ``request`` is provided, this
3684
+ should not be set.
3685
+ split_points (MutableSequence[google.cloud.spanner_admin_database_v1.types.SplitPoints]):
3686
+ Required. The split points to add.
3687
+ This corresponds to the ``split_points`` field
3688
+ on the ``request`` instance; if ``request`` is provided, this
3689
+ should not be set.
3690
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3691
+ should be retried.
3692
+ timeout (float): The timeout for this request.
3693
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3694
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3695
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3696
+ be of type `bytes`.
3697
+
3698
+ Returns:
3699
+ google.cloud.spanner_admin_database_v1.types.AddSplitPointsResponse:
3700
+ The response for
3701
+ [AddSplitPoints][google.spanner.admin.database.v1.DatabaseAdmin.AddSplitPoints].
3702
+
3703
+ """
3704
+ # Create or coerce a protobuf request object.
3705
+ # - Quick check: If we got a request object, we should *not* have
3706
+ # gotten any keyword arguments that map to the request.
3707
+ flattened_params = [database, split_points]
3708
+ has_flattened_params = (
3709
+ len([param for param in flattened_params if param is not None]) > 0
3710
+ )
3711
+ if request is not None and has_flattened_params:
3712
+ raise ValueError(
3713
+ "If the `request` argument is set, then none of "
3714
+ "the individual field arguments should be set."
3715
+ )
3716
+
3717
+ # - Use the request object if provided (there's no risk of modifying the input as
3718
+ # there are no flattened fields), or create one.
3719
+ if not isinstance(request, spanner_database_admin.AddSplitPointsRequest):
3720
+ request = spanner_database_admin.AddSplitPointsRequest(request)
3721
+ # If we have keyword arguments corresponding to fields on the
3722
+ # request, apply these.
3723
+ if database is not None:
3724
+ request.database = database
3725
+ if split_points is not None:
3726
+ request.split_points = split_points
3727
+
3728
+ # Wrap the RPC method; this adds retry and timeout information,
3729
+ # and friendly error handling.
3730
+ rpc = self._transport._wrapped_methods[self._transport.add_split_points]
3731
+
3732
+ # Certain fields should be provided within the metadata header;
3733
+ # add these here.
3734
+ metadata = tuple(metadata) + (
3735
+ gapic_v1.routing_header.to_grpc_metadata((("database", request.database),)),
3736
+ )
3737
+
3738
+ # Validate the universe domain.
3739
+ self._validate_universe_domain()
3740
+
3741
+ # Send the request.
3742
+ response = rpc(
3743
+ request,
3744
+ retry=retry,
3745
+ timeout=timeout,
3746
+ metadata=metadata,
3747
+ )
3748
+
3749
+ # Done; return the response.
3750
+ return response
3751
+
3752
+ def create_backup_schedule(
3753
+ self,
3754
+ request: Optional[
3755
+ Union[gsad_backup_schedule.CreateBackupScheduleRequest, dict]
3756
+ ] = None,
3757
+ *,
3758
+ parent: Optional[str] = None,
3759
+ backup_schedule: Optional[gsad_backup_schedule.BackupSchedule] = None,
3760
+ backup_schedule_id: Optional[str] = None,
3761
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3762
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3763
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3764
+ ) -> gsad_backup_schedule.BackupSchedule:
3765
+ r"""Creates a new backup schedule.
3766
+
3767
+ .. code-block:: python
3768
+
3769
+ # This snippet has been automatically generated and should be regarded as a
3770
+ # code template only.
3771
+ # It will require modifications to work:
3772
+ # - It may require correct/in-range values for request initialization.
3773
+ # - It may require specifying regional endpoints when creating the service
3774
+ # client as shown in:
3775
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3776
+ from google.cloud import spanner_admin_database_v1
3777
+
3778
+ def sample_create_backup_schedule():
3779
+ # Create a client
3780
+ client = spanner_admin_database_v1.DatabaseAdminClient()
3781
+
3782
+ # Initialize request argument(s)
3783
+ request = spanner_admin_database_v1.CreateBackupScheduleRequest(
3784
+ parent="parent_value",
3785
+ backup_schedule_id="backup_schedule_id_value",
3786
+ )
3787
+
3788
+ # Make the request
3789
+ response = client.create_backup_schedule(request=request)
3790
+
3791
+ # Handle the response
3792
+ print(response)
3793
+
3794
+ Args:
3795
+ request (Union[google.cloud.spanner_admin_database_v1.types.CreateBackupScheduleRequest, dict]):
3796
+ The request object. The request for
3797
+ [CreateBackupSchedule][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackupSchedule].
3798
+ parent (str):
3799
+ Required. The name of the database
3800
+ that this backup schedule applies to.
3801
+
3802
+ This corresponds to the ``parent`` field
3803
+ on the ``request`` instance; if ``request`` is provided, this
3804
+ should not be set.
3805
+ backup_schedule (google.cloud.spanner_admin_database_v1.types.BackupSchedule):
3806
+ Required. The backup schedule to
3807
+ create.
3808
+
3809
+ This corresponds to the ``backup_schedule`` field
3810
+ on the ``request`` instance; if ``request`` is provided, this
3811
+ should not be set.
3812
+ backup_schedule_id (str):
3813
+ Required. The Id to use for the backup schedule. The
3814
+ ``backup_schedule_id`` appended to ``parent`` forms the
3815
+ full backup schedule name of the form
3816
+ ``projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>``.
3817
+
3818
+ This corresponds to the ``backup_schedule_id`` field
3819
+ on the ``request`` instance; if ``request`` is provided, this
3820
+ should not be set.
3821
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3822
+ should be retried.
3823
+ timeout (float): The timeout for this request.
3824
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3825
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3826
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3827
+ be of type `bytes`.
3828
+
3829
+ Returns:
3830
+ google.cloud.spanner_admin_database_v1.types.BackupSchedule:
3831
+ BackupSchedule expresses the
3832
+ automated backup creation specification
3833
+ for a Spanner database. Next ID: 10
3834
+
3835
+ """
3836
+ # Create or coerce a protobuf request object.
3837
+ # - Quick check: If we got a request object, we should *not* have
3838
+ # gotten any keyword arguments that map to the request.
3839
+ flattened_params = [parent, backup_schedule, backup_schedule_id]
3840
+ has_flattened_params = (
3841
+ len([param for param in flattened_params if param is not None]) > 0
3842
+ )
3843
+ if request is not None and has_flattened_params:
3844
+ raise ValueError(
3845
+ "If the `request` argument is set, then none of "
3846
+ "the individual field arguments should be set."
3847
+ )
3848
+
3849
+ # - Use the request object if provided (there's no risk of modifying the input as
3850
+ # there are no flattened fields), or create one.
3851
+ if not isinstance(request, gsad_backup_schedule.CreateBackupScheduleRequest):
3852
+ request = gsad_backup_schedule.CreateBackupScheduleRequest(request)
3853
+ # If we have keyword arguments corresponding to fields on the
3854
+ # request, apply these.
3855
+ if parent is not None:
3856
+ request.parent = parent
3857
+ if backup_schedule is not None:
3858
+ request.backup_schedule = backup_schedule
3859
+ if backup_schedule_id is not None:
3860
+ request.backup_schedule_id = backup_schedule_id
3861
+
3862
+ # Wrap the RPC method; this adds retry and timeout information,
3863
+ # and friendly error handling.
3864
+ rpc = self._transport._wrapped_methods[self._transport.create_backup_schedule]
3865
+
3866
+ # Certain fields should be provided within the metadata header;
3867
+ # add these here.
3868
+ metadata = tuple(metadata) + (
3869
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3870
+ )
3871
+
3872
+ # Validate the universe domain.
3873
+ self._validate_universe_domain()
3874
+
3875
+ # Send the request.
3876
+ response = rpc(
3877
+ request,
3878
+ retry=retry,
3879
+ timeout=timeout,
3880
+ metadata=metadata,
3881
+ )
3882
+
3883
+ # Done; return the response.
3884
+ return response
3885
+
3886
+ def get_backup_schedule(
3887
+ self,
3888
+ request: Optional[Union[backup_schedule.GetBackupScheduleRequest, dict]] = None,
3889
+ *,
3890
+ name: Optional[str] = None,
3891
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3892
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3893
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3894
+ ) -> backup_schedule.BackupSchedule:
3895
+ r"""Gets backup schedule for the input schedule name.
3896
+
3897
+ .. code-block:: python
3898
+
3899
+ # This snippet has been automatically generated and should be regarded as a
3900
+ # code template only.
3901
+ # It will require modifications to work:
3902
+ # - It may require correct/in-range values for request initialization.
3903
+ # - It may require specifying regional endpoints when creating the service
3904
+ # client as shown in:
3905
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3906
+ from google.cloud import spanner_admin_database_v1
3907
+
3908
+ def sample_get_backup_schedule():
3909
+ # Create a client
3910
+ client = spanner_admin_database_v1.DatabaseAdminClient()
3911
+
3912
+ # Initialize request argument(s)
3913
+ request = spanner_admin_database_v1.GetBackupScheduleRequest(
3914
+ name="name_value",
3915
+ )
3916
+
3917
+ # Make the request
3918
+ response = client.get_backup_schedule(request=request)
3919
+
3920
+ # Handle the response
3921
+ print(response)
3922
+
3923
+ Args:
3924
+ request (Union[google.cloud.spanner_admin_database_v1.types.GetBackupScheduleRequest, dict]):
3925
+ The request object. The request for
3926
+ [GetBackupSchedule][google.spanner.admin.database.v1.DatabaseAdmin.GetBackupSchedule].
3927
+ name (str):
3928
+ Required. The name of the schedule to retrieve. Values
3929
+ are of the form
3930
+ ``projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>``.
3931
+
3932
+ This corresponds to the ``name`` field
3933
+ on the ``request`` instance; if ``request`` is provided, this
3934
+ should not be set.
3935
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3936
+ should be retried.
3937
+ timeout (float): The timeout for this request.
3938
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3939
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3940
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3941
+ be of type `bytes`.
3942
+
3943
+ Returns:
3944
+ google.cloud.spanner_admin_database_v1.types.BackupSchedule:
3945
+ BackupSchedule expresses the
3946
+ automated backup creation specification
3947
+ for a Spanner database. Next ID: 10
3948
+
3949
+ """
3950
+ # Create or coerce a protobuf request object.
3951
+ # - Quick check: If we got a request object, we should *not* have
3952
+ # gotten any keyword arguments that map to the request.
3953
+ flattened_params = [name]
3954
+ has_flattened_params = (
3955
+ len([param for param in flattened_params if param is not None]) > 0
3956
+ )
3957
+ if request is not None and has_flattened_params:
3958
+ raise ValueError(
3959
+ "If the `request` argument is set, then none of "
3960
+ "the individual field arguments should be set."
3961
+ )
3962
+
3963
+ # - Use the request object if provided (there's no risk of modifying the input as
3964
+ # there are no flattened fields), or create one.
3965
+ if not isinstance(request, backup_schedule.GetBackupScheduleRequest):
3966
+ request = backup_schedule.GetBackupScheduleRequest(request)
3967
+ # If we have keyword arguments corresponding to fields on the
3968
+ # request, apply these.
3969
+ if name is not None:
3970
+ request.name = name
3971
+
3972
+ # Wrap the RPC method; this adds retry and timeout information,
3973
+ # and friendly error handling.
3974
+ rpc = self._transport._wrapped_methods[self._transport.get_backup_schedule]
3975
+
3976
+ # Certain fields should be provided within the metadata header;
3977
+ # add these here.
3978
+ metadata = tuple(metadata) + (
3979
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3980
+ )
3981
+
3982
+ # Validate the universe domain.
3983
+ self._validate_universe_domain()
3984
+
3985
+ # Send the request.
3986
+ response = rpc(
3987
+ request,
3988
+ retry=retry,
3989
+ timeout=timeout,
3990
+ metadata=metadata,
3991
+ )
3992
+
3993
+ # Done; return the response.
3994
+ return response
3995
+
3996
+ def update_backup_schedule(
3997
+ self,
3998
+ request: Optional[
3999
+ Union[gsad_backup_schedule.UpdateBackupScheduleRequest, dict]
4000
+ ] = None,
4001
+ *,
4002
+ backup_schedule: Optional[gsad_backup_schedule.BackupSchedule] = None,
4003
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
4004
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
4005
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4006
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4007
+ ) -> gsad_backup_schedule.BackupSchedule:
4008
+ r"""Updates a backup schedule.
4009
+
4010
+ .. code-block:: python
4011
+
4012
+ # This snippet has been automatically generated and should be regarded as a
4013
+ # code template only.
4014
+ # It will require modifications to work:
4015
+ # - It may require correct/in-range values for request initialization.
4016
+ # - It may require specifying regional endpoints when creating the service
4017
+ # client as shown in:
4018
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
4019
+ from google.cloud import spanner_admin_database_v1
4020
+
4021
+ def sample_update_backup_schedule():
4022
+ # Create a client
4023
+ client = spanner_admin_database_v1.DatabaseAdminClient()
4024
+
4025
+ # Initialize request argument(s)
4026
+ request = spanner_admin_database_v1.UpdateBackupScheduleRequest(
4027
+ )
4028
+
4029
+ # Make the request
4030
+ response = client.update_backup_schedule(request=request)
4031
+
4032
+ # Handle the response
4033
+ print(response)
4034
+
4035
+ Args:
4036
+ request (Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupScheduleRequest, dict]):
4037
+ The request object. The request for
4038
+ [UpdateBackupScheduleRequest][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackupSchedule].
4039
+ backup_schedule (google.cloud.spanner_admin_database_v1.types.BackupSchedule):
4040
+ Required. The backup schedule to update.
4041
+ ``backup_schedule.name``, and the fields to be updated
4042
+ as specified by ``update_mask`` are required. Other
4043
+ fields are ignored.
4044
+
4045
+ This corresponds to the ``backup_schedule`` field
4046
+ on the ``request`` instance; if ``request`` is provided, this
4047
+ should not be set.
4048
+ update_mask (google.protobuf.field_mask_pb2.FieldMask):
4049
+ Required. A mask specifying which
4050
+ fields in the BackupSchedule resource
4051
+ should be updated. This mask is relative
4052
+ to the BackupSchedule resource, not to
4053
+ the request message. The field mask must
4054
+ always be specified; this prevents any
4055
+ future fields from being erased
4056
+ accidentally.
4057
+
4058
+ This corresponds to the ``update_mask`` field
4059
+ on the ``request`` instance; if ``request`` is provided, this
4060
+ should not be set.
4061
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
4062
+ should be retried.
4063
+ timeout (float): The timeout for this request.
4064
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4065
+ sent along with the request as metadata. Normally, each value must be of type `str`,
4066
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
4067
+ be of type `bytes`.
4068
+
4069
+ Returns:
4070
+ google.cloud.spanner_admin_database_v1.types.BackupSchedule:
4071
+ BackupSchedule expresses the
4072
+ automated backup creation specification
4073
+ for a Spanner database. Next ID: 10
4074
+
4075
+ """
4076
+ # Create or coerce a protobuf request object.
4077
+ # - Quick check: If we got a request object, we should *not* have
4078
+ # gotten any keyword arguments that map to the request.
4079
+ flattened_params = [backup_schedule, update_mask]
4080
+ has_flattened_params = (
4081
+ len([param for param in flattened_params if param is not None]) > 0
4082
+ )
4083
+ if request is not None and has_flattened_params:
4084
+ raise ValueError(
4085
+ "If the `request` argument is set, then none of "
4086
+ "the individual field arguments should be set."
4087
+ )
4088
+
4089
+ # - Use the request object if provided (there's no risk of modifying the input as
4090
+ # there are no flattened fields), or create one.
4091
+ if not isinstance(request, gsad_backup_schedule.UpdateBackupScheduleRequest):
4092
+ request = gsad_backup_schedule.UpdateBackupScheduleRequest(request)
4093
+ # If we have keyword arguments corresponding to fields on the
4094
+ # request, apply these.
4095
+ if backup_schedule is not None:
4096
+ request.backup_schedule = backup_schedule
4097
+ if update_mask is not None:
4098
+ request.update_mask = update_mask
4099
+
4100
+ # Wrap the RPC method; this adds retry and timeout information,
4101
+ # and friendly error handling.
4102
+ rpc = self._transport._wrapped_methods[self._transport.update_backup_schedule]
4103
+
4104
+ # Certain fields should be provided within the metadata header;
4105
+ # add these here.
4106
+ metadata = tuple(metadata) + (
4107
+ gapic_v1.routing_header.to_grpc_metadata(
4108
+ (("backup_schedule.name", request.backup_schedule.name),)
4109
+ ),
4110
+ )
4111
+
4112
+ # Validate the universe domain.
4113
+ self._validate_universe_domain()
4114
+
4115
+ # Send the request.
4116
+ response = rpc(
4117
+ request,
4118
+ retry=retry,
4119
+ timeout=timeout,
4120
+ metadata=metadata,
4121
+ )
4122
+
4123
+ # Done; return the response.
4124
+ return response
4125
+
4126
+ def delete_backup_schedule(
4127
+ self,
4128
+ request: Optional[
4129
+ Union[backup_schedule.DeleteBackupScheduleRequest, dict]
4130
+ ] = None,
4131
+ *,
4132
+ name: Optional[str] = None,
4133
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
4134
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4135
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4136
+ ) -> None:
4137
+ r"""Deletes a backup schedule.
4138
+
4139
+ .. code-block:: python
4140
+
4141
+ # This snippet has been automatically generated and should be regarded as a
4142
+ # code template only.
4143
+ # It will require modifications to work:
4144
+ # - It may require correct/in-range values for request initialization.
4145
+ # - It may require specifying regional endpoints when creating the service
4146
+ # client as shown in:
4147
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
4148
+ from google.cloud import spanner_admin_database_v1
4149
+
4150
+ def sample_delete_backup_schedule():
4151
+ # Create a client
4152
+ client = spanner_admin_database_v1.DatabaseAdminClient()
4153
+
4154
+ # Initialize request argument(s)
4155
+ request = spanner_admin_database_v1.DeleteBackupScheduleRequest(
4156
+ name="name_value",
4157
+ )
4158
+
4159
+ # Make the request
4160
+ client.delete_backup_schedule(request=request)
4161
+
4162
+ Args:
4163
+ request (Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupScheduleRequest, dict]):
4164
+ The request object. The request for
4165
+ [DeleteBackupSchedule][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackupSchedule].
4166
+ name (str):
4167
+ Required. The name of the schedule to delete. Values are
4168
+ of the form
4169
+ ``projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>``.
4170
+
4171
+ This corresponds to the ``name`` field
4172
+ on the ``request`` instance; if ``request`` is provided, this
4173
+ should not be set.
4174
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
4175
+ should be retried.
4176
+ timeout (float): The timeout for this request.
4177
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4178
+ sent along with the request as metadata. Normally, each value must be of type `str`,
4179
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
4180
+ be of type `bytes`.
4181
+ """
4182
+ # Create or coerce a protobuf request object.
4183
+ # - Quick check: If we got a request object, we should *not* have
4184
+ # gotten any keyword arguments that map to the request.
4185
+ flattened_params = [name]
4186
+ has_flattened_params = (
4187
+ len([param for param in flattened_params if param is not None]) > 0
4188
+ )
4189
+ if request is not None and has_flattened_params:
4190
+ raise ValueError(
4191
+ "If the `request` argument is set, then none of "
4192
+ "the individual field arguments should be set."
4193
+ )
4194
+
4195
+ # - Use the request object if provided (there's no risk of modifying the input as
4196
+ # there are no flattened fields), or create one.
4197
+ if not isinstance(request, backup_schedule.DeleteBackupScheduleRequest):
4198
+ request = backup_schedule.DeleteBackupScheduleRequest(request)
4199
+ # If we have keyword arguments corresponding to fields on the
4200
+ # request, apply these.
4201
+ if name is not None:
4202
+ request.name = name
4203
+
4204
+ # Wrap the RPC method; this adds retry and timeout information,
4205
+ # and friendly error handling.
4206
+ rpc = self._transport._wrapped_methods[self._transport.delete_backup_schedule]
4207
+
4208
+ # Certain fields should be provided within the metadata header;
4209
+ # add these here.
4210
+ metadata = tuple(metadata) + (
4211
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4212
+ )
4213
+
4214
+ # Validate the universe domain.
4215
+ self._validate_universe_domain()
4216
+
4217
+ # Send the request.
4218
+ rpc(
4219
+ request,
4220
+ retry=retry,
4221
+ timeout=timeout,
4222
+ metadata=metadata,
4223
+ )
4224
+
4225
+ def list_backup_schedules(
4226
+ self,
4227
+ request: Optional[
4228
+ Union[backup_schedule.ListBackupSchedulesRequest, dict]
4229
+ ] = None,
4230
+ *,
4231
+ parent: Optional[str] = None,
4232
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
4233
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4234
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4235
+ ) -> pagers.ListBackupSchedulesPager:
4236
+ r"""Lists all the backup schedules for the database.
4237
+
4238
+ .. code-block:: python
4239
+
4240
+ # This snippet has been automatically generated and should be regarded as a
4241
+ # code template only.
4242
+ # It will require modifications to work:
4243
+ # - It may require correct/in-range values for request initialization.
4244
+ # - It may require specifying regional endpoints when creating the service
4245
+ # client as shown in:
4246
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
4247
+ from google.cloud import spanner_admin_database_v1
4248
+
4249
+ def sample_list_backup_schedules():
4250
+ # Create a client
4251
+ client = spanner_admin_database_v1.DatabaseAdminClient()
4252
+
4253
+ # Initialize request argument(s)
4254
+ request = spanner_admin_database_v1.ListBackupSchedulesRequest(
4255
+ parent="parent_value",
4256
+ )
4257
+
4258
+ # Make the request
4259
+ page_result = client.list_backup_schedules(request=request)
4260
+
4261
+ # Handle the response
4262
+ for response in page_result:
4263
+ print(response)
4264
+
4265
+ Args:
4266
+ request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupSchedulesRequest, dict]):
4267
+ The request object. The request for
4268
+ [ListBackupSchedules][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupSchedules].
4269
+ parent (str):
4270
+ Required. Database is the parent
4271
+ resource whose backup schedules should
4272
+ be listed. Values are of the form
4273
+ projects/<project>/instances/<instance>/databases/<database>
4274
+
4275
+ This corresponds to the ``parent`` field
4276
+ on the ``request`` instance; if ``request`` is provided, this
4277
+ should not be set.
4278
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
4279
+ should be retried.
4280
+ timeout (float): The timeout for this request.
4281
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4282
+ sent along with the request as metadata. Normally, each value must be of type `str`,
4283
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
4284
+ be of type `bytes`.
4285
+
4286
+ Returns:
4287
+ google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupSchedulesPager:
4288
+ The response for
4289
+ [ListBackupSchedules][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupSchedules].
4290
+
4291
+ Iterating over this object will yield results and
4292
+ resolve additional pages automatically.
4293
+
4294
+ """
4295
+ # Create or coerce a protobuf request object.
4296
+ # - Quick check: If we got a request object, we should *not* have
4297
+ # gotten any keyword arguments that map to the request.
4298
+ flattened_params = [parent]
4299
+ has_flattened_params = (
4300
+ len([param for param in flattened_params if param is not None]) > 0
4301
+ )
4302
+ if request is not None and has_flattened_params:
4303
+ raise ValueError(
4304
+ "If the `request` argument is set, then none of "
4305
+ "the individual field arguments should be set."
4306
+ )
4307
+
4308
+ # - Use the request object if provided (there's no risk of modifying the input as
4309
+ # there are no flattened fields), or create one.
4310
+ if not isinstance(request, backup_schedule.ListBackupSchedulesRequest):
4311
+ request = backup_schedule.ListBackupSchedulesRequest(request)
4312
+ # If we have keyword arguments corresponding to fields on the
4313
+ # request, apply these.
4314
+ if parent is not None:
4315
+ request.parent = parent
4316
+
4317
+ # Wrap the RPC method; this adds retry and timeout information,
4318
+ # and friendly error handling.
4319
+ rpc = self._transport._wrapped_methods[self._transport.list_backup_schedules]
4320
+
4321
+ # Certain fields should be provided within the metadata header;
4322
+ # add these here.
4323
+ metadata = tuple(metadata) + (
4324
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
4325
+ )
4326
+
4327
+ # Validate the universe domain.
4328
+ self._validate_universe_domain()
4329
+
4330
+ # Send the request.
4331
+ response = rpc(
4332
+ request,
4333
+ retry=retry,
4334
+ timeout=timeout,
4335
+ metadata=metadata,
4336
+ )
4337
+
4338
+ # This method is paged; wrap the response in a pager, which provides
4339
+ # an `__iter__` convenience method.
4340
+ response = pagers.ListBackupSchedulesPager(
4341
+ method=rpc,
4342
+ request=request,
4343
+ response=response,
4344
+ retry=retry,
4345
+ timeout=timeout,
4346
+ metadata=metadata,
4347
+ )
4348
+
4349
+ # Done; return the response.
4350
+ return response
4351
+
4352
+ def __enter__(self) -> "DatabaseAdminClient":
4353
+ return self
4354
+
4355
+ def __exit__(self, type, value, traceback):
4356
+ """Releases underlying transport's resources.
4357
+
4358
+ .. warning::
4359
+ ONLY use as a context manager if the transport is NOT shared
4360
+ with other clients! Exiting the with block will CLOSE the transport
4361
+ and may cause errors in other clients!
4362
+ """
4363
+ self.transport.close()
4364
+
4365
+ def list_operations(
4366
+ self,
4367
+ request: Optional[operations_pb2.ListOperationsRequest] = None,
4368
+ *,
4369
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
4370
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4371
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4372
+ ) -> operations_pb2.ListOperationsResponse:
4373
+ r"""Lists operations that match the specified filter in the request.
4374
+
4375
+ Args:
4376
+ request (:class:`~.operations_pb2.ListOperationsRequest`):
4377
+ The request object. Request message for
4378
+ `ListOperations` method.
4379
+ retry (google.api_core.retry.Retry): Designation of what errors,
4380
+ if any, should be retried.
4381
+ timeout (float): The timeout for this request.
4382
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4383
+ sent along with the request as metadata. Normally, each value must be of type `str`,
4384
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
4385
+ be of type `bytes`.
4386
+ Returns:
4387
+ ~.operations_pb2.ListOperationsResponse:
4388
+ Response message for ``ListOperations`` method.
4389
+ """
4390
+ # Create or coerce a protobuf request object.
4391
+ # The request isn't a proto-plus wrapped type,
4392
+ # so it must be constructed via keyword expansion.
4393
+ if isinstance(request, dict):
4394
+ request = operations_pb2.ListOperationsRequest(**request)
4395
+
4396
+ # Wrap the RPC method; this adds retry and timeout information,
4397
+ # and friendly error handling.
4398
+ rpc = self._transport._wrapped_methods[self._transport.list_operations]
4399
+
4400
+ # Certain fields should be provided within the metadata header;
4401
+ # add these here.
4402
+ metadata = tuple(metadata) + (
4403
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4404
+ )
4405
+
4406
+ # Validate the universe domain.
4407
+ self._validate_universe_domain()
4408
+
4409
+ try:
4410
+ # Send the request.
4411
+ response = rpc(
4412
+ request,
4413
+ retry=retry,
4414
+ timeout=timeout,
4415
+ metadata=metadata,
4416
+ )
4417
+
4418
+ # Done; return the response.
4419
+ return response
4420
+ except core_exceptions.GoogleAPICallError as e:
4421
+ self._add_cred_info_for_auth_errors(e)
4422
+ raise e
4423
+
4424
+ def get_operation(
4425
+ self,
4426
+ request: Optional[operations_pb2.GetOperationRequest] = None,
4427
+ *,
4428
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
4429
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4430
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4431
+ ) -> operations_pb2.Operation:
4432
+ r"""Gets the latest state of a long-running operation.
4433
+
4434
+ Args:
4435
+ request (:class:`~.operations_pb2.GetOperationRequest`):
4436
+ The request object. Request message for
4437
+ `GetOperation` method.
4438
+ retry (google.api_core.retry.Retry): Designation of what errors,
4439
+ if any, should be retried.
4440
+ timeout (float): The timeout for this request.
4441
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4442
+ sent along with the request as metadata. Normally, each value must be of type `str`,
4443
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
4444
+ be of type `bytes`.
4445
+ Returns:
4446
+ ~.operations_pb2.Operation:
4447
+ An ``Operation`` object.
4448
+ """
4449
+ # Create or coerce a protobuf request object.
4450
+ # The request isn't a proto-plus wrapped type,
4451
+ # so it must be constructed via keyword expansion.
4452
+ if isinstance(request, dict):
4453
+ request = operations_pb2.GetOperationRequest(**request)
4454
+
4455
+ # Wrap the RPC method; this adds retry and timeout information,
4456
+ # and friendly error handling.
4457
+ rpc = self._transport._wrapped_methods[self._transport.get_operation]
4458
+
4459
+ # Certain fields should be provided within the metadata header;
4460
+ # add these here.
4461
+ metadata = tuple(metadata) + (
4462
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4463
+ )
4464
+
4465
+ # Validate the universe domain.
4466
+ self._validate_universe_domain()
4467
+
4468
+ try:
4469
+ # Send the request.
4470
+ response = rpc(
4471
+ request,
4472
+ retry=retry,
4473
+ timeout=timeout,
4474
+ metadata=metadata,
4475
+ )
4476
+
4477
+ # Done; return the response.
4478
+ return response
4479
+ except core_exceptions.GoogleAPICallError as e:
4480
+ self._add_cred_info_for_auth_errors(e)
4481
+ raise e
4482
+
4483
+ def delete_operation(
4484
+ self,
4485
+ request: Optional[operations_pb2.DeleteOperationRequest] = None,
4486
+ *,
4487
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
4488
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4489
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4490
+ ) -> None:
4491
+ r"""Deletes a long-running operation.
4492
+
4493
+ This method indicates that the client is no longer interested
4494
+ in the operation result. It does not cancel the operation.
4495
+ If the server doesn't support this method, it returns
4496
+ `google.rpc.Code.UNIMPLEMENTED`.
4497
+
4498
+ Args:
4499
+ request (:class:`~.operations_pb2.DeleteOperationRequest`):
4500
+ The request object. Request message for
4501
+ `DeleteOperation` method.
4502
+ retry (google.api_core.retry.Retry): Designation of what errors,
4503
+ if any, should be retried.
4504
+ timeout (float): The timeout for this request.
4505
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4506
+ sent along with the request as metadata. Normally, each value must be of type `str`,
4507
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
4508
+ be of type `bytes`.
4509
+ Returns:
4510
+ None
4511
+ """
4512
+ # Create or coerce a protobuf request object.
4513
+ # The request isn't a proto-plus wrapped type,
4514
+ # so it must be constructed via keyword expansion.
4515
+ if isinstance(request, dict):
4516
+ request = operations_pb2.DeleteOperationRequest(**request)
4517
+
4518
+ # Wrap the RPC method; this adds retry and timeout information,
4519
+ # and friendly error handling.
4520
+ rpc = self._transport._wrapped_methods[self._transport.delete_operation]
4521
+
4522
+ # Certain fields should be provided within the metadata header;
4523
+ # add these here.
4524
+ metadata = tuple(metadata) + (
4525
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4526
+ )
4527
+
4528
+ # Validate the universe domain.
4529
+ self._validate_universe_domain()
4530
+
4531
+ # Send the request.
4532
+ rpc(
4533
+ request,
4534
+ retry=retry,
4535
+ timeout=timeout,
4536
+ metadata=metadata,
4537
+ )
4538
+
4539
+ def cancel_operation(
4540
+ self,
4541
+ request: Optional[operations_pb2.CancelOperationRequest] = None,
4542
+ *,
4543
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
4544
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
4545
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
4546
+ ) -> None:
4547
+ r"""Starts asynchronous cancellation on a long-running operation.
4548
+
4549
+ The server makes a best effort to cancel the operation, but success
4550
+ is not guaranteed. If the server doesn't support this method, it returns
4551
+ `google.rpc.Code.UNIMPLEMENTED`.
4552
+
4553
+ Args:
4554
+ request (:class:`~.operations_pb2.CancelOperationRequest`):
4555
+ The request object. Request message for
4556
+ `CancelOperation` method.
4557
+ retry (google.api_core.retry.Retry): Designation of what errors,
4558
+ if any, should be retried.
4559
+ timeout (float): The timeout for this request.
4560
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
4561
+ sent along with the request as metadata. Normally, each value must be of type `str`,
4562
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
4563
+ be of type `bytes`.
4564
+ Returns:
4565
+ None
4566
+ """
4567
+ # Create or coerce a protobuf request object.
4568
+ # The request isn't a proto-plus wrapped type,
4569
+ # so it must be constructed via keyword expansion.
4570
+ if isinstance(request, dict):
4571
+ request = operations_pb2.CancelOperationRequest(**request)
4572
+
4573
+ # Wrap the RPC method; this adds retry and timeout information,
4574
+ # and friendly error handling.
4575
+ rpc = self._transport._wrapped_methods[self._transport.cancel_operation]
4576
+
4577
+ # Certain fields should be provided within the metadata header;
4578
+ # add these here.
4579
+ metadata = tuple(metadata) + (
4580
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
4581
+ )
4582
+
4583
+ # Validate the universe domain.
4584
+ self._validate_universe_domain()
4585
+
4586
+ # Send the request.
4587
+ rpc(
4588
+ request,
4589
+ retry=retry,
4590
+ timeout=timeout,
4591
+ metadata=metadata,
4592
+ )
4593
+
4594
+
4595
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
4596
+ gapic_version=package_version.__version__
4597
+ )
4598
+
4599
+ if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
4600
+ DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
4601
+
4602
+ __all__ = ("DatabaseAdminClient",)