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,3881 @@
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_instance_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_instance_v1.services.instance_admin import pagers
67
+ from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin
68
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
69
+ from google.iam.v1 import policy_pb2 # type: ignore
70
+ from google.longrunning import operations_pb2 # type: ignore
71
+ from google.protobuf import field_mask_pb2 # type: ignore
72
+ from google.protobuf import timestamp_pb2 # type: ignore
73
+ from .transports.base import InstanceAdminTransport, DEFAULT_CLIENT_INFO
74
+ from .transports.grpc import InstanceAdminGrpcTransport
75
+ from .transports.grpc_asyncio import InstanceAdminGrpcAsyncIOTransport
76
+ from .transports.rest import InstanceAdminRestTransport
77
+
78
+
79
+ class InstanceAdminClientMeta(type):
80
+ """Metaclass for the InstanceAdmin client.
81
+
82
+ This provides class-level methods for building and retrieving
83
+ support objects (e.g. transport) without polluting the client instance
84
+ objects.
85
+ """
86
+
87
+ _transport_registry = OrderedDict() # type: Dict[str, Type[InstanceAdminTransport]]
88
+ _transport_registry["grpc"] = InstanceAdminGrpcTransport
89
+ _transport_registry["grpc_asyncio"] = InstanceAdminGrpcAsyncIOTransport
90
+ _transport_registry["rest"] = InstanceAdminRestTransport
91
+
92
+ def get_transport_class(
93
+ cls,
94
+ label: Optional[str] = None,
95
+ ) -> Type[InstanceAdminTransport]:
96
+ """Returns an appropriate transport class.
97
+
98
+ Args:
99
+ label: The name of the desired transport. If none is
100
+ provided, then the first transport in the registry is used.
101
+
102
+ Returns:
103
+ The transport class to use.
104
+ """
105
+ # If a specific transport is requested, return that one.
106
+ if label:
107
+ return cls._transport_registry[label]
108
+
109
+ # No transport is requested; return the default (that is, the first one
110
+ # in the dictionary).
111
+ return next(iter(cls._transport_registry.values()))
112
+
113
+
114
+ class InstanceAdminClient(metaclass=InstanceAdminClientMeta):
115
+ """Cloud Spanner Instance Admin API
116
+
117
+ The Cloud Spanner Instance Admin API can be used to create,
118
+ delete, modify and list instances. Instances are dedicated Cloud
119
+ Spanner serving and storage resources to be used by Cloud
120
+ Spanner databases.
121
+
122
+ Each instance has a "configuration", which dictates where the
123
+ serving resources for the Cloud Spanner instance are located
124
+ (e.g., US-central, Europe). Configurations are created by Google
125
+ based on resource availability.
126
+
127
+ Cloud Spanner billing is based on the instances that exist and
128
+ their sizes. After an instance exists, there are no additional
129
+ per-database or per-operation charges for use of the instance
130
+ (though there may be additional network bandwidth charges).
131
+ Instances offer isolation: problems with databases in one
132
+ instance will not affect other instances. However, within an
133
+ instance databases can affect each other. For example, if one
134
+ database in an instance receives a lot of requests and consumes
135
+ most of the instance resources, fewer resources are available
136
+ for other databases in that instance, and their performance may
137
+ suffer.
138
+ """
139
+
140
+ @staticmethod
141
+ def _get_default_mtls_endpoint(api_endpoint):
142
+ """Converts api endpoint to mTLS endpoint.
143
+
144
+ Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
145
+ "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
146
+ Args:
147
+ api_endpoint (Optional[str]): the api endpoint to convert.
148
+ Returns:
149
+ str: converted mTLS api endpoint.
150
+ """
151
+ if not api_endpoint:
152
+ return api_endpoint
153
+
154
+ mtls_endpoint_re = re.compile(
155
+ r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
156
+ )
157
+
158
+ m = mtls_endpoint_re.match(api_endpoint)
159
+ name, mtls, sandbox, googledomain = m.groups()
160
+ if mtls or not googledomain:
161
+ return api_endpoint
162
+
163
+ if sandbox:
164
+ return api_endpoint.replace(
165
+ "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
166
+ )
167
+
168
+ return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
169
+
170
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
171
+ DEFAULT_ENDPOINT = "spanner.googleapis.com"
172
+ DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
173
+ DEFAULT_ENDPOINT
174
+ )
175
+
176
+ _DEFAULT_ENDPOINT_TEMPLATE = "spanner.{UNIVERSE_DOMAIN}"
177
+ _DEFAULT_UNIVERSE = "googleapis.com"
178
+
179
+ @classmethod
180
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
181
+ """Creates an instance of this client using the provided credentials
182
+ info.
183
+
184
+ Args:
185
+ info (dict): The service account private key info.
186
+ args: Additional arguments to pass to the constructor.
187
+ kwargs: Additional arguments to pass to the constructor.
188
+
189
+ Returns:
190
+ InstanceAdminClient: The constructed client.
191
+ """
192
+ credentials = service_account.Credentials.from_service_account_info(info)
193
+ kwargs["credentials"] = credentials
194
+ return cls(*args, **kwargs)
195
+
196
+ @classmethod
197
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
198
+ """Creates an instance of this client using the provided credentials
199
+ file.
200
+
201
+ Args:
202
+ filename (str): The path to the service account private key json
203
+ file.
204
+ args: Additional arguments to pass to the constructor.
205
+ kwargs: Additional arguments to pass to the constructor.
206
+
207
+ Returns:
208
+ InstanceAdminClient: The constructed client.
209
+ """
210
+ credentials = service_account.Credentials.from_service_account_file(filename)
211
+ kwargs["credentials"] = credentials
212
+ return cls(*args, **kwargs)
213
+
214
+ from_service_account_json = from_service_account_file
215
+
216
+ @property
217
+ def transport(self) -> InstanceAdminTransport:
218
+ """Returns the transport used by the client instance.
219
+
220
+ Returns:
221
+ InstanceAdminTransport: The transport used by the client
222
+ instance.
223
+ """
224
+ return self._transport
225
+
226
+ @staticmethod
227
+ def instance_path(
228
+ project: str,
229
+ instance: str,
230
+ ) -> str:
231
+ """Returns a fully-qualified instance string."""
232
+ return "projects/{project}/instances/{instance}".format(
233
+ project=project,
234
+ instance=instance,
235
+ )
236
+
237
+ @staticmethod
238
+ def parse_instance_path(path: str) -> Dict[str, str]:
239
+ """Parses a instance path into its component segments."""
240
+ m = re.match(r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)$", path)
241
+ return m.groupdict() if m else {}
242
+
243
+ @staticmethod
244
+ def instance_config_path(
245
+ project: str,
246
+ instance_config: str,
247
+ ) -> str:
248
+ """Returns a fully-qualified instance_config string."""
249
+ return "projects/{project}/instanceConfigs/{instance_config}".format(
250
+ project=project,
251
+ instance_config=instance_config,
252
+ )
253
+
254
+ @staticmethod
255
+ def parse_instance_config_path(path: str) -> Dict[str, str]:
256
+ """Parses a instance_config path into its component segments."""
257
+ m = re.match(
258
+ r"^projects/(?P<project>.+?)/instanceConfigs/(?P<instance_config>.+?)$",
259
+ path,
260
+ )
261
+ return m.groupdict() if m else {}
262
+
263
+ @staticmethod
264
+ def instance_partition_path(
265
+ project: str,
266
+ instance: str,
267
+ instance_partition: str,
268
+ ) -> str:
269
+ """Returns a fully-qualified instance_partition string."""
270
+ return "projects/{project}/instances/{instance}/instancePartitions/{instance_partition}".format(
271
+ project=project,
272
+ instance=instance,
273
+ instance_partition=instance_partition,
274
+ )
275
+
276
+ @staticmethod
277
+ def parse_instance_partition_path(path: str) -> Dict[str, str]:
278
+ """Parses a instance_partition path into its component segments."""
279
+ m = re.match(
280
+ r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/instancePartitions/(?P<instance_partition>.+?)$",
281
+ path,
282
+ )
283
+ return m.groupdict() if m else {}
284
+
285
+ @staticmethod
286
+ def common_billing_account_path(
287
+ billing_account: str,
288
+ ) -> str:
289
+ """Returns a fully-qualified billing_account string."""
290
+ return "billingAccounts/{billing_account}".format(
291
+ billing_account=billing_account,
292
+ )
293
+
294
+ @staticmethod
295
+ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
296
+ """Parse a billing_account path into its component segments."""
297
+ m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
298
+ return m.groupdict() if m else {}
299
+
300
+ @staticmethod
301
+ def common_folder_path(
302
+ folder: str,
303
+ ) -> str:
304
+ """Returns a fully-qualified folder string."""
305
+ return "folders/{folder}".format(
306
+ folder=folder,
307
+ )
308
+
309
+ @staticmethod
310
+ def parse_common_folder_path(path: str) -> Dict[str, str]:
311
+ """Parse a folder path into its component segments."""
312
+ m = re.match(r"^folders/(?P<folder>.+?)$", path)
313
+ return m.groupdict() if m else {}
314
+
315
+ @staticmethod
316
+ def common_organization_path(
317
+ organization: str,
318
+ ) -> str:
319
+ """Returns a fully-qualified organization string."""
320
+ return "organizations/{organization}".format(
321
+ organization=organization,
322
+ )
323
+
324
+ @staticmethod
325
+ def parse_common_organization_path(path: str) -> Dict[str, str]:
326
+ """Parse a organization path into its component segments."""
327
+ m = re.match(r"^organizations/(?P<organization>.+?)$", path)
328
+ return m.groupdict() if m else {}
329
+
330
+ @staticmethod
331
+ def common_project_path(
332
+ project: str,
333
+ ) -> str:
334
+ """Returns a fully-qualified project string."""
335
+ return "projects/{project}".format(
336
+ project=project,
337
+ )
338
+
339
+ @staticmethod
340
+ def parse_common_project_path(path: str) -> Dict[str, str]:
341
+ """Parse a project path into its component segments."""
342
+ m = re.match(r"^projects/(?P<project>.+?)$", path)
343
+ return m.groupdict() if m else {}
344
+
345
+ @staticmethod
346
+ def common_location_path(
347
+ project: str,
348
+ location: str,
349
+ ) -> str:
350
+ """Returns a fully-qualified location string."""
351
+ return "projects/{project}/locations/{location}".format(
352
+ project=project,
353
+ location=location,
354
+ )
355
+
356
+ @staticmethod
357
+ def parse_common_location_path(path: str) -> Dict[str, str]:
358
+ """Parse a location path into its component segments."""
359
+ m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
360
+ return m.groupdict() if m else {}
361
+
362
+ @classmethod
363
+ def get_mtls_endpoint_and_cert_source(
364
+ cls, client_options: Optional[client_options_lib.ClientOptions] = None
365
+ ):
366
+ """Deprecated. Return the API endpoint and client cert source for mutual TLS.
367
+
368
+ The client cert source is determined in the following order:
369
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
370
+ client cert source is None.
371
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
372
+ default client cert source exists, use the default one; otherwise the client cert
373
+ source is None.
374
+
375
+ The API endpoint is determined in the following order:
376
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
377
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
378
+ default mTLS endpoint; if the environment variable is "never", use the default API
379
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
380
+ use the default API endpoint.
381
+
382
+ More details can be found at https://google.aip.dev/auth/4114.
383
+
384
+ Args:
385
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
386
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
387
+ in this method.
388
+
389
+ Returns:
390
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
391
+ client cert source to use.
392
+
393
+ Raises:
394
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
395
+ """
396
+
397
+ warnings.warn(
398
+ "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
399
+ DeprecationWarning,
400
+ )
401
+ if client_options is None:
402
+ client_options = client_options_lib.ClientOptions()
403
+ use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
404
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
405
+ if use_client_cert not in ("true", "false"):
406
+ raise ValueError(
407
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
408
+ )
409
+ if use_mtls_endpoint not in ("auto", "never", "always"):
410
+ raise MutualTLSChannelError(
411
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
412
+ )
413
+
414
+ # Figure out the client cert source to use.
415
+ client_cert_source = None
416
+ if use_client_cert == "true":
417
+ if client_options.client_cert_source:
418
+ client_cert_source = client_options.client_cert_source
419
+ elif mtls.has_default_client_cert_source():
420
+ client_cert_source = mtls.default_client_cert_source()
421
+
422
+ # Figure out which api endpoint to use.
423
+ if client_options.api_endpoint is not None:
424
+ api_endpoint = client_options.api_endpoint
425
+ elif use_mtls_endpoint == "always" or (
426
+ use_mtls_endpoint == "auto" and client_cert_source
427
+ ):
428
+ api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
429
+ else:
430
+ api_endpoint = cls.DEFAULT_ENDPOINT
431
+
432
+ return api_endpoint, client_cert_source
433
+
434
+ @staticmethod
435
+ def _read_environment_variables():
436
+ """Returns the environment variables used by the client.
437
+
438
+ Returns:
439
+ Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
440
+ GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
441
+
442
+ Raises:
443
+ ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
444
+ any of ["true", "false"].
445
+ google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
446
+ is not any of ["auto", "never", "always"].
447
+ """
448
+ use_client_cert = os.getenv(
449
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
450
+ ).lower()
451
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
452
+ universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
453
+ if use_client_cert not in ("true", "false"):
454
+ raise ValueError(
455
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
456
+ )
457
+ if use_mtls_endpoint not in ("auto", "never", "always"):
458
+ raise MutualTLSChannelError(
459
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
460
+ )
461
+ return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
462
+
463
+ @staticmethod
464
+ def _get_client_cert_source(provided_cert_source, use_cert_flag):
465
+ """Return the client cert source to be used by the client.
466
+
467
+ Args:
468
+ provided_cert_source (bytes): The client certificate source provided.
469
+ use_cert_flag (bool): A flag indicating whether to use the client certificate.
470
+
471
+ Returns:
472
+ bytes or None: The client cert source to be used by the client.
473
+ """
474
+ client_cert_source = None
475
+ if use_cert_flag:
476
+ if provided_cert_source:
477
+ client_cert_source = provided_cert_source
478
+ elif mtls.has_default_client_cert_source():
479
+ client_cert_source = mtls.default_client_cert_source()
480
+ return client_cert_source
481
+
482
+ @staticmethod
483
+ def _get_api_endpoint(
484
+ api_override, client_cert_source, universe_domain, use_mtls_endpoint
485
+ ):
486
+ """Return the API endpoint used by the client.
487
+
488
+ Args:
489
+ api_override (str): The API endpoint override. If specified, this is always
490
+ the return value of this function and the other arguments are not used.
491
+ client_cert_source (bytes): The client certificate source used by the client.
492
+ universe_domain (str): The universe domain used by the client.
493
+ use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
494
+ Possible values are "always", "auto", or "never".
495
+
496
+ Returns:
497
+ str: The API endpoint to be used by the client.
498
+ """
499
+ if api_override is not None:
500
+ api_endpoint = api_override
501
+ elif use_mtls_endpoint == "always" or (
502
+ use_mtls_endpoint == "auto" and client_cert_source
503
+ ):
504
+ _default_universe = InstanceAdminClient._DEFAULT_UNIVERSE
505
+ if universe_domain != _default_universe:
506
+ raise MutualTLSChannelError(
507
+ f"mTLS is not supported in any universe other than {_default_universe}."
508
+ )
509
+ api_endpoint = InstanceAdminClient.DEFAULT_MTLS_ENDPOINT
510
+ else:
511
+ api_endpoint = InstanceAdminClient._DEFAULT_ENDPOINT_TEMPLATE.format(
512
+ UNIVERSE_DOMAIN=universe_domain
513
+ )
514
+ return api_endpoint
515
+
516
+ @staticmethod
517
+ def _get_universe_domain(
518
+ client_universe_domain: Optional[str], universe_domain_env: Optional[str]
519
+ ) -> str:
520
+ """Return the universe domain used by the client.
521
+
522
+ Args:
523
+ client_universe_domain (Optional[str]): The universe domain configured via the client options.
524
+ universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
525
+
526
+ Returns:
527
+ str: The universe domain to be used by the client.
528
+
529
+ Raises:
530
+ ValueError: If the universe domain is an empty string.
531
+ """
532
+ universe_domain = InstanceAdminClient._DEFAULT_UNIVERSE
533
+ if client_universe_domain is not None:
534
+ universe_domain = client_universe_domain
535
+ elif universe_domain_env is not None:
536
+ universe_domain = universe_domain_env
537
+ if len(universe_domain.strip()) == 0:
538
+ raise ValueError("Universe Domain cannot be an empty string.")
539
+ return universe_domain
540
+
541
+ def _validate_universe_domain(self):
542
+ """Validates client's and credentials' universe domains are consistent.
543
+
544
+ Returns:
545
+ bool: True iff the configured universe domain is valid.
546
+
547
+ Raises:
548
+ ValueError: If the configured universe domain is not valid.
549
+ """
550
+
551
+ # NOTE (b/349488459): universe validation is disabled until further notice.
552
+ return True
553
+
554
+ def _add_cred_info_for_auth_errors(
555
+ self, error: core_exceptions.GoogleAPICallError
556
+ ) -> None:
557
+ """Adds credential info string to error details for 401/403/404 errors.
558
+
559
+ Args:
560
+ error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
561
+ """
562
+ if error.code not in [
563
+ HTTPStatus.UNAUTHORIZED,
564
+ HTTPStatus.FORBIDDEN,
565
+ HTTPStatus.NOT_FOUND,
566
+ ]:
567
+ return
568
+
569
+ cred = self._transport._credentials
570
+
571
+ # get_cred_info is only available in google-auth>=2.35.0
572
+ if not hasattr(cred, "get_cred_info"):
573
+ return
574
+
575
+ # ignore the type check since pypy test fails when get_cred_info
576
+ # is not available
577
+ cred_info = cred.get_cred_info() # type: ignore
578
+ if cred_info and hasattr(error._details, "append"):
579
+ error._details.append(json.dumps(cred_info))
580
+
581
+ @property
582
+ def api_endpoint(self):
583
+ """Return the API endpoint used by the client instance.
584
+
585
+ Returns:
586
+ str: The API endpoint used by the client instance.
587
+ """
588
+ return self._api_endpoint
589
+
590
+ @property
591
+ def universe_domain(self) -> str:
592
+ """Return the universe domain used by the client instance.
593
+
594
+ Returns:
595
+ str: The universe domain used by the client instance.
596
+ """
597
+ return self._universe_domain
598
+
599
+ def __init__(
600
+ self,
601
+ *,
602
+ credentials: Optional[ga_credentials.Credentials] = None,
603
+ transport: Optional[
604
+ Union[str, InstanceAdminTransport, Callable[..., InstanceAdminTransport]]
605
+ ] = None,
606
+ client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
607
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
608
+ ) -> None:
609
+ """Instantiates the instance admin client.
610
+
611
+ Args:
612
+ credentials (Optional[google.auth.credentials.Credentials]): The
613
+ authorization credentials to attach to requests. These
614
+ credentials identify the application to the service; if none
615
+ are specified, the client will attempt to ascertain the
616
+ credentials from the environment.
617
+ transport (Optional[Union[str,InstanceAdminTransport,Callable[..., InstanceAdminTransport]]]):
618
+ The transport to use, or a Callable that constructs and returns a new transport.
619
+ If a Callable is given, it will be called with the same set of initialization
620
+ arguments as used in the InstanceAdminTransport constructor.
621
+ If set to None, a transport is chosen automatically.
622
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
623
+ Custom options for the client.
624
+
625
+ 1. The ``api_endpoint`` property can be used to override the
626
+ default endpoint provided by the client when ``transport`` is
627
+ not explicitly provided. Only if this property is not set and
628
+ ``transport`` was not explicitly provided, the endpoint is
629
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
630
+ variable, which have one of the following values:
631
+ "always" (always use the default mTLS endpoint), "never" (always
632
+ use the default regular endpoint) and "auto" (auto-switch to the
633
+ default mTLS endpoint if client certificate is present; this is
634
+ the default value).
635
+
636
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
637
+ is "true", then the ``client_cert_source`` property can be used
638
+ to provide a client certificate for mTLS transport. If
639
+ not provided, the default SSL client certificate will be used if
640
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
641
+ set, no client certificate will be used.
642
+
643
+ 3. The ``universe_domain`` property can be used to override the
644
+ default "googleapis.com" universe. Note that the ``api_endpoint``
645
+ property still takes precedence; and ``universe_domain`` is
646
+ currently not supported for mTLS.
647
+
648
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
649
+ The client info used to send a user-agent string along with
650
+ API requests. If ``None``, then default info will be used.
651
+ Generally, you only need to set this if you're developing
652
+ your own client library.
653
+
654
+ Raises:
655
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
656
+ creation failed for any reason.
657
+ """
658
+ self._client_options = client_options
659
+ if isinstance(self._client_options, dict):
660
+ self._client_options = client_options_lib.from_dict(self._client_options)
661
+ if self._client_options is None:
662
+ self._client_options = client_options_lib.ClientOptions()
663
+ self._client_options = cast(
664
+ client_options_lib.ClientOptions, self._client_options
665
+ )
666
+
667
+ universe_domain_opt = getattr(self._client_options, "universe_domain", None)
668
+
669
+ (
670
+ self._use_client_cert,
671
+ self._use_mtls_endpoint,
672
+ self._universe_domain_env,
673
+ ) = InstanceAdminClient._read_environment_variables()
674
+ self._client_cert_source = InstanceAdminClient._get_client_cert_source(
675
+ self._client_options.client_cert_source, self._use_client_cert
676
+ )
677
+ self._universe_domain = InstanceAdminClient._get_universe_domain(
678
+ universe_domain_opt, self._universe_domain_env
679
+ )
680
+ self._api_endpoint = None # updated below, depending on `transport`
681
+
682
+ # Initialize the universe domain validation.
683
+ self._is_universe_domain_valid = False
684
+
685
+ if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
686
+ # Setup logging.
687
+ client_logging.initialize_logging()
688
+
689
+ api_key_value = getattr(self._client_options, "api_key", None)
690
+ if api_key_value and credentials:
691
+ raise ValueError(
692
+ "client_options.api_key and credentials are mutually exclusive"
693
+ )
694
+
695
+ # Save or instantiate the transport.
696
+ # Ordinarily, we provide the transport, but allowing a custom transport
697
+ # instance provides an extensibility point for unusual situations.
698
+ transport_provided = isinstance(transport, InstanceAdminTransport)
699
+ if transport_provided:
700
+ # transport is a InstanceAdminTransport instance.
701
+ if credentials or self._client_options.credentials_file or api_key_value:
702
+ raise ValueError(
703
+ "When providing a transport instance, "
704
+ "provide its credentials directly."
705
+ )
706
+ if self._client_options.scopes:
707
+ raise ValueError(
708
+ "When providing a transport instance, provide its scopes "
709
+ "directly."
710
+ )
711
+ self._transport = cast(InstanceAdminTransport, transport)
712
+ self._api_endpoint = self._transport.host
713
+
714
+ self._api_endpoint = (
715
+ self._api_endpoint
716
+ or InstanceAdminClient._get_api_endpoint(
717
+ self._client_options.api_endpoint,
718
+ self._client_cert_source,
719
+ self._universe_domain,
720
+ self._use_mtls_endpoint,
721
+ )
722
+ )
723
+
724
+ if not transport_provided:
725
+ import google.auth._default # type: ignore
726
+
727
+ if api_key_value and hasattr(
728
+ google.auth._default, "get_api_key_credentials"
729
+ ):
730
+ credentials = google.auth._default.get_api_key_credentials(
731
+ api_key_value
732
+ )
733
+
734
+ transport_init: Union[
735
+ Type[InstanceAdminTransport], Callable[..., InstanceAdminTransport]
736
+ ] = (
737
+ InstanceAdminClient.get_transport_class(transport)
738
+ if isinstance(transport, str) or transport is None
739
+ else cast(Callable[..., InstanceAdminTransport], transport)
740
+ )
741
+ # initialize with the provided callable or the passed in class
742
+ self._transport = transport_init(
743
+ credentials=credentials,
744
+ credentials_file=self._client_options.credentials_file,
745
+ host=self._api_endpoint,
746
+ scopes=self._client_options.scopes,
747
+ client_cert_source_for_mtls=self._client_cert_source,
748
+ quota_project_id=self._client_options.quota_project_id,
749
+ client_info=client_info,
750
+ always_use_jwt_access=True,
751
+ api_audience=self._client_options.api_audience,
752
+ )
753
+
754
+ if "async" not in str(self._transport):
755
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
756
+ std_logging.DEBUG
757
+ ): # pragma: NO COVER
758
+ _LOGGER.debug(
759
+ "Created client `google.spanner.admin.instance_v1.InstanceAdminClient`.",
760
+ extra={
761
+ "serviceName": "google.spanner.admin.instance.v1.InstanceAdmin",
762
+ "universeDomain": getattr(
763
+ self._transport._credentials, "universe_domain", ""
764
+ ),
765
+ "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
766
+ "credentialsInfo": getattr(
767
+ self.transport._credentials, "get_cred_info", lambda: None
768
+ )(),
769
+ }
770
+ if hasattr(self._transport, "_credentials")
771
+ else {
772
+ "serviceName": "google.spanner.admin.instance.v1.InstanceAdmin",
773
+ "credentialsType": None,
774
+ },
775
+ )
776
+
777
+ def list_instance_configs(
778
+ self,
779
+ request: Optional[
780
+ Union[spanner_instance_admin.ListInstanceConfigsRequest, dict]
781
+ ] = None,
782
+ *,
783
+ parent: Optional[str] = None,
784
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
785
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
786
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
787
+ ) -> pagers.ListInstanceConfigsPager:
788
+ r"""Lists the supported instance configurations for a
789
+ given project.
790
+ Returns both Google-managed configurations and
791
+ user-managed configurations.
792
+
793
+ .. code-block:: python
794
+
795
+ # This snippet has been automatically generated and should be regarded as a
796
+ # code template only.
797
+ # It will require modifications to work:
798
+ # - It may require correct/in-range values for request initialization.
799
+ # - It may require specifying regional endpoints when creating the service
800
+ # client as shown in:
801
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
802
+ from google.cloud import spanner_admin_instance_v1
803
+
804
+ def sample_list_instance_configs():
805
+ # Create a client
806
+ client = spanner_admin_instance_v1.InstanceAdminClient()
807
+
808
+ # Initialize request argument(s)
809
+ request = spanner_admin_instance_v1.ListInstanceConfigsRequest(
810
+ parent="parent_value",
811
+ )
812
+
813
+ # Make the request
814
+ page_result = client.list_instance_configs(request=request)
815
+
816
+ # Handle the response
817
+ for response in page_result:
818
+ print(response)
819
+
820
+ Args:
821
+ request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest, dict]):
822
+ The request object. The request for
823
+ [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs].
824
+ parent (str):
825
+ Required. The name of the project for which a list of
826
+ supported instance configurations is requested. Values
827
+ are of the form ``projects/<project>``.
828
+
829
+ This corresponds to the ``parent`` field
830
+ on the ``request`` instance; if ``request`` is provided, this
831
+ should not be set.
832
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
833
+ should be retried.
834
+ timeout (float): The timeout for this request.
835
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
836
+ sent along with the request as metadata. Normally, each value must be of type `str`,
837
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
838
+ be of type `bytes`.
839
+
840
+ Returns:
841
+ google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsPager:
842
+ The response for
843
+ [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs].
844
+
845
+ Iterating over this object will yield results and
846
+ resolve additional pages automatically.
847
+
848
+ """
849
+ # Create or coerce a protobuf request object.
850
+ # - Quick check: If we got a request object, we should *not* have
851
+ # gotten any keyword arguments that map to the request.
852
+ flattened_params = [parent]
853
+ has_flattened_params = (
854
+ len([param for param in flattened_params if param is not None]) > 0
855
+ )
856
+ if request is not None and has_flattened_params:
857
+ raise ValueError(
858
+ "If the `request` argument is set, then none of "
859
+ "the individual field arguments should be set."
860
+ )
861
+
862
+ # - Use the request object if provided (there's no risk of modifying the input as
863
+ # there are no flattened fields), or create one.
864
+ if not isinstance(request, spanner_instance_admin.ListInstanceConfigsRequest):
865
+ request = spanner_instance_admin.ListInstanceConfigsRequest(request)
866
+ # If we have keyword arguments corresponding to fields on the
867
+ # request, apply these.
868
+ if parent is not None:
869
+ request.parent = parent
870
+
871
+ # Wrap the RPC method; this adds retry and timeout information,
872
+ # and friendly error handling.
873
+ rpc = self._transport._wrapped_methods[self._transport.list_instance_configs]
874
+
875
+ # Certain fields should be provided within the metadata header;
876
+ # add these here.
877
+ metadata = tuple(metadata) + (
878
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
879
+ )
880
+
881
+ # Validate the universe domain.
882
+ self._validate_universe_domain()
883
+
884
+ # Send the request.
885
+ response = rpc(
886
+ request,
887
+ retry=retry,
888
+ timeout=timeout,
889
+ metadata=metadata,
890
+ )
891
+
892
+ # This method is paged; wrap the response in a pager, which provides
893
+ # an `__iter__` convenience method.
894
+ response = pagers.ListInstanceConfigsPager(
895
+ method=rpc,
896
+ request=request,
897
+ response=response,
898
+ retry=retry,
899
+ timeout=timeout,
900
+ metadata=metadata,
901
+ )
902
+
903
+ # Done; return the response.
904
+ return response
905
+
906
+ def get_instance_config(
907
+ self,
908
+ request: Optional[
909
+ Union[spanner_instance_admin.GetInstanceConfigRequest, dict]
910
+ ] = None,
911
+ *,
912
+ name: Optional[str] = None,
913
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
914
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
915
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
916
+ ) -> spanner_instance_admin.InstanceConfig:
917
+ r"""Gets information about a particular instance
918
+ configuration.
919
+
920
+ .. code-block:: python
921
+
922
+ # This snippet has been automatically generated and should be regarded as a
923
+ # code template only.
924
+ # It will require modifications to work:
925
+ # - It may require correct/in-range values for request initialization.
926
+ # - It may require specifying regional endpoints when creating the service
927
+ # client as shown in:
928
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
929
+ from google.cloud import spanner_admin_instance_v1
930
+
931
+ def sample_get_instance_config():
932
+ # Create a client
933
+ client = spanner_admin_instance_v1.InstanceAdminClient()
934
+
935
+ # Initialize request argument(s)
936
+ request = spanner_admin_instance_v1.GetInstanceConfigRequest(
937
+ name="name_value",
938
+ )
939
+
940
+ # Make the request
941
+ response = client.get_instance_config(request=request)
942
+
943
+ # Handle the response
944
+ print(response)
945
+
946
+ Args:
947
+ request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest, dict]):
948
+ The request object. The request for
949
+ [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig].
950
+ name (str):
951
+ Required. The name of the requested instance
952
+ configuration. Values are of the form
953
+ ``projects/<project>/instanceConfigs/<config>``.
954
+
955
+ This corresponds to the ``name`` field
956
+ on the ``request`` instance; if ``request`` is provided, this
957
+ should not be set.
958
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
959
+ should be retried.
960
+ timeout (float): The timeout for this request.
961
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
962
+ sent along with the request as metadata. Normally, each value must be of type `str`,
963
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
964
+ be of type `bytes`.
965
+
966
+ Returns:
967
+ google.cloud.spanner_admin_instance_v1.types.InstanceConfig:
968
+ A possible configuration for a Cloud
969
+ Spanner instance. Configurations define
970
+ the geographic placement of nodes and
971
+ their replication.
972
+
973
+ """
974
+ # Create or coerce a protobuf request object.
975
+ # - Quick check: If we got a request object, we should *not* have
976
+ # gotten any keyword arguments that map to the request.
977
+ flattened_params = [name]
978
+ has_flattened_params = (
979
+ len([param for param in flattened_params if param is not None]) > 0
980
+ )
981
+ if request is not None and has_flattened_params:
982
+ raise ValueError(
983
+ "If the `request` argument is set, then none of "
984
+ "the individual field arguments should be set."
985
+ )
986
+
987
+ # - Use the request object if provided (there's no risk of modifying the input as
988
+ # there are no flattened fields), or create one.
989
+ if not isinstance(request, spanner_instance_admin.GetInstanceConfigRequest):
990
+ request = spanner_instance_admin.GetInstanceConfigRequest(request)
991
+ # If we have keyword arguments corresponding to fields on the
992
+ # request, apply these.
993
+ if name is not None:
994
+ request.name = name
995
+
996
+ # Wrap the RPC method; this adds retry and timeout information,
997
+ # and friendly error handling.
998
+ rpc = self._transport._wrapped_methods[self._transport.get_instance_config]
999
+
1000
+ # Certain fields should be provided within the metadata header;
1001
+ # add these here.
1002
+ metadata = tuple(metadata) + (
1003
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1004
+ )
1005
+
1006
+ # Validate the universe domain.
1007
+ self._validate_universe_domain()
1008
+
1009
+ # Send the request.
1010
+ response = rpc(
1011
+ request,
1012
+ retry=retry,
1013
+ timeout=timeout,
1014
+ metadata=metadata,
1015
+ )
1016
+
1017
+ # Done; return the response.
1018
+ return response
1019
+
1020
+ def create_instance_config(
1021
+ self,
1022
+ request: Optional[
1023
+ Union[spanner_instance_admin.CreateInstanceConfigRequest, dict]
1024
+ ] = None,
1025
+ *,
1026
+ parent: Optional[str] = None,
1027
+ instance_config: Optional[spanner_instance_admin.InstanceConfig] = None,
1028
+ instance_config_id: Optional[str] = None,
1029
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1030
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1031
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1032
+ ) -> operation.Operation:
1033
+ r"""Creates an instance configuration and begins preparing it to be
1034
+ used. The returned long-running operation can be used to track
1035
+ the progress of preparing the new instance configuration. The
1036
+ instance configuration name is assigned by the caller. If the
1037
+ named instance configuration already exists,
1038
+ ``CreateInstanceConfig`` returns ``ALREADY_EXISTS``.
1039
+
1040
+ Immediately after the request returns:
1041
+
1042
+ - The instance configuration is readable via the API, with all
1043
+ requested attributes. The instance configuration's
1044
+ [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling]
1045
+ field is set to true. Its state is ``CREATING``.
1046
+
1047
+ While the operation is pending:
1048
+
1049
+ - Cancelling the operation renders the instance configuration
1050
+ immediately unreadable via the API.
1051
+ - Except for deleting the creating resource, all other attempts
1052
+ to modify the instance configuration are rejected.
1053
+
1054
+ Upon completion of the returned operation:
1055
+
1056
+ - Instances can be created using the instance configuration.
1057
+ - The instance configuration's
1058
+ [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling]
1059
+ field becomes false. Its state becomes ``READY``.
1060
+
1061
+ The returned long-running operation will have a name of the
1062
+ format ``<instance_config_name>/operations/<operation_id>`` and
1063
+ can be used to track creation of the instance configuration. The
1064
+ metadata field type is
1065
+ [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata].
1066
+ The response field type is
1067
+ [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig],
1068
+ if successful.
1069
+
1070
+ Authorization requires ``spanner.instanceConfigs.create``
1071
+ permission on the resource
1072
+ [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent].
1073
+
1074
+ .. code-block:: python
1075
+
1076
+ # This snippet has been automatically generated and should be regarded as a
1077
+ # code template only.
1078
+ # It will require modifications to work:
1079
+ # - It may require correct/in-range values for request initialization.
1080
+ # - It may require specifying regional endpoints when creating the service
1081
+ # client as shown in:
1082
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1083
+ from google.cloud import spanner_admin_instance_v1
1084
+
1085
+ def sample_create_instance_config():
1086
+ # Create a client
1087
+ client = spanner_admin_instance_v1.InstanceAdminClient()
1088
+
1089
+ # Initialize request argument(s)
1090
+ request = spanner_admin_instance_v1.CreateInstanceConfigRequest(
1091
+ parent="parent_value",
1092
+ instance_config_id="instance_config_id_value",
1093
+ )
1094
+
1095
+ # Make the request
1096
+ operation = client.create_instance_config(request=request)
1097
+
1098
+ print("Waiting for operation to complete...")
1099
+
1100
+ response = operation.result()
1101
+
1102
+ # Handle the response
1103
+ print(response)
1104
+
1105
+ Args:
1106
+ request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest, dict]):
1107
+ The request object. The request for
1108
+ [CreateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig].
1109
+ parent (str):
1110
+ Required. The name of the project in which to create the
1111
+ instance configuration. Values are of the form
1112
+ ``projects/<project>``.
1113
+
1114
+ This corresponds to the ``parent`` field
1115
+ on the ``request`` instance; if ``request`` is provided, this
1116
+ should not be set.
1117
+ instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig):
1118
+ Required. The ``InstanceConfig`` proto of the
1119
+ configuration to create. ``instance_config.name`` must
1120
+ be ``<parent>/instanceConfigs/<instance_config_id>``.
1121
+ ``instance_config.base_config`` must be a Google-managed
1122
+ configuration name, e.g. /instanceConfigs/us-east1,
1123
+ /instanceConfigs/nam3.
1124
+
1125
+ This corresponds to the ``instance_config`` field
1126
+ on the ``request`` instance; if ``request`` is provided, this
1127
+ should not be set.
1128
+ instance_config_id (str):
1129
+ Required. The ID of the instance configuration to
1130
+ create. Valid identifiers are of the form
1131
+ ``custom-[-a-z0-9]*[a-z0-9]`` and must be between 2 and
1132
+ 64 characters in length. The ``custom-`` prefix is
1133
+ required to avoid name conflicts with Google-managed
1134
+ configurations.
1135
+
1136
+ This corresponds to the ``instance_config_id`` field
1137
+ on the ``request`` instance; if ``request`` is provided, this
1138
+ should not be set.
1139
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1140
+ should be retried.
1141
+ timeout (float): The timeout for this request.
1142
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1143
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1144
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1145
+ be of type `bytes`.
1146
+
1147
+ Returns:
1148
+ google.api_core.operation.Operation:
1149
+ An object representing a long-running operation.
1150
+
1151
+ The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations
1152
+ define the geographic placement of nodes and their
1153
+ replication.
1154
+
1155
+ """
1156
+ # Create or coerce a protobuf request object.
1157
+ # - Quick check: If we got a request object, we should *not* have
1158
+ # gotten any keyword arguments that map to the request.
1159
+ flattened_params = [parent, instance_config, instance_config_id]
1160
+ has_flattened_params = (
1161
+ len([param for param in flattened_params if param is not None]) > 0
1162
+ )
1163
+ if request is not None and has_flattened_params:
1164
+ raise ValueError(
1165
+ "If the `request` argument is set, then none of "
1166
+ "the individual field arguments should be set."
1167
+ )
1168
+
1169
+ # - Use the request object if provided (there's no risk of modifying the input as
1170
+ # there are no flattened fields), or create one.
1171
+ if not isinstance(request, spanner_instance_admin.CreateInstanceConfigRequest):
1172
+ request = spanner_instance_admin.CreateInstanceConfigRequest(request)
1173
+ # If we have keyword arguments corresponding to fields on the
1174
+ # request, apply these.
1175
+ if parent is not None:
1176
+ request.parent = parent
1177
+ if instance_config is not None:
1178
+ request.instance_config = instance_config
1179
+ if instance_config_id is not None:
1180
+ request.instance_config_id = instance_config_id
1181
+
1182
+ # Wrap the RPC method; this adds retry and timeout information,
1183
+ # and friendly error handling.
1184
+ rpc = self._transport._wrapped_methods[self._transport.create_instance_config]
1185
+
1186
+ # Certain fields should be provided within the metadata header;
1187
+ # add these here.
1188
+ metadata = tuple(metadata) + (
1189
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1190
+ )
1191
+
1192
+ # Validate the universe domain.
1193
+ self._validate_universe_domain()
1194
+
1195
+ # Send the request.
1196
+ response = rpc(
1197
+ request,
1198
+ retry=retry,
1199
+ timeout=timeout,
1200
+ metadata=metadata,
1201
+ )
1202
+
1203
+ # Wrap the response in an operation future.
1204
+ response = operation.from_gapic(
1205
+ response,
1206
+ self._transport.operations_client,
1207
+ spanner_instance_admin.InstanceConfig,
1208
+ metadata_type=spanner_instance_admin.CreateInstanceConfigMetadata,
1209
+ )
1210
+
1211
+ # Done; return the response.
1212
+ return response
1213
+
1214
+ def update_instance_config(
1215
+ self,
1216
+ request: Optional[
1217
+ Union[spanner_instance_admin.UpdateInstanceConfigRequest, dict]
1218
+ ] = None,
1219
+ *,
1220
+ instance_config: Optional[spanner_instance_admin.InstanceConfig] = None,
1221
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
1222
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1223
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1224
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1225
+ ) -> operation.Operation:
1226
+ r"""Updates an instance configuration. The returned long-running
1227
+ operation can be used to track the progress of updating the
1228
+ instance. If the named instance configuration does not exist,
1229
+ returns ``NOT_FOUND``.
1230
+
1231
+ Only user-managed configurations can be updated.
1232
+
1233
+ Immediately after the request returns:
1234
+
1235
+ - The instance configuration's
1236
+ [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling]
1237
+ field is set to true.
1238
+
1239
+ While the operation is pending:
1240
+
1241
+ - Cancelling the operation sets its metadata's
1242
+ [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time].
1243
+ The operation is guaranteed to succeed at undoing all
1244
+ changes, after which point it terminates with a ``CANCELLED``
1245
+ status.
1246
+ - All other attempts to modify the instance configuration are
1247
+ rejected.
1248
+ - Reading the instance configuration via the API continues to
1249
+ give the pre-request values.
1250
+
1251
+ Upon completion of the returned operation:
1252
+
1253
+ - Creating instances using the instance configuration uses the
1254
+ new values.
1255
+ - The new values of the instance configuration are readable via
1256
+ the API.
1257
+ - The instance configuration's
1258
+ [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling]
1259
+ field becomes false.
1260
+
1261
+ The returned long-running operation will have a name of the
1262
+ format ``<instance_config_name>/operations/<operation_id>`` and
1263
+ can be used to track the instance configuration modification.
1264
+ The metadata field type is
1265
+ [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata].
1266
+ The response field type is
1267
+ [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig],
1268
+ if successful.
1269
+
1270
+ Authorization requires ``spanner.instanceConfigs.update``
1271
+ permission on the resource
1272
+ [name][google.spanner.admin.instance.v1.InstanceConfig.name].
1273
+
1274
+ .. code-block:: python
1275
+
1276
+ # This snippet has been automatically generated and should be regarded as a
1277
+ # code template only.
1278
+ # It will require modifications to work:
1279
+ # - It may require correct/in-range values for request initialization.
1280
+ # - It may require specifying regional endpoints when creating the service
1281
+ # client as shown in:
1282
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1283
+ from google.cloud import spanner_admin_instance_v1
1284
+
1285
+ def sample_update_instance_config():
1286
+ # Create a client
1287
+ client = spanner_admin_instance_v1.InstanceAdminClient()
1288
+
1289
+ # Initialize request argument(s)
1290
+ request = spanner_admin_instance_v1.UpdateInstanceConfigRequest(
1291
+ )
1292
+
1293
+ # Make the request
1294
+ operation = client.update_instance_config(request=request)
1295
+
1296
+ print("Waiting for operation to complete...")
1297
+
1298
+ response = operation.result()
1299
+
1300
+ # Handle the response
1301
+ print(response)
1302
+
1303
+ Args:
1304
+ request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest, dict]):
1305
+ The request object. The request for
1306
+ [UpdateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig].
1307
+ instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig):
1308
+ Required. The user instance configuration to update,
1309
+ which must always include the instance configuration
1310
+ name. Otherwise, only fields mentioned in
1311
+ [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask]
1312
+ need be included. To prevent conflicts of concurrent
1313
+ updates,
1314
+ [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling]
1315
+ can be used.
1316
+
1317
+ This corresponds to the ``instance_config`` field
1318
+ on the ``request`` instance; if ``request`` is provided, this
1319
+ should not be set.
1320
+ update_mask (google.protobuf.field_mask_pb2.FieldMask):
1321
+ Required. A mask specifying which fields in
1322
+ [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig]
1323
+ should be updated. The field mask must always be
1324
+ specified; this prevents any future fields in
1325
+ [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig]
1326
+ from being erased accidentally by clients that do not
1327
+ know about them. Only display_name and labels can be
1328
+ updated.
1329
+
1330
+ This corresponds to the ``update_mask`` field
1331
+ on the ``request`` instance; if ``request`` is provided, this
1332
+ should not be set.
1333
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1334
+ should be retried.
1335
+ timeout (float): The timeout for this request.
1336
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1337
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1338
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1339
+ be of type `bytes`.
1340
+
1341
+ Returns:
1342
+ google.api_core.operation.Operation:
1343
+ An object representing a long-running operation.
1344
+
1345
+ The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations
1346
+ define the geographic placement of nodes and their
1347
+ replication.
1348
+
1349
+ """
1350
+ # Create or coerce a protobuf request object.
1351
+ # - Quick check: If we got a request object, we should *not* have
1352
+ # gotten any keyword arguments that map to the request.
1353
+ flattened_params = [instance_config, update_mask]
1354
+ has_flattened_params = (
1355
+ len([param for param in flattened_params if param is not None]) > 0
1356
+ )
1357
+ if request is not None and has_flattened_params:
1358
+ raise ValueError(
1359
+ "If the `request` argument is set, then none of "
1360
+ "the individual field arguments should be set."
1361
+ )
1362
+
1363
+ # - Use the request object if provided (there's no risk of modifying the input as
1364
+ # there are no flattened fields), or create one.
1365
+ if not isinstance(request, spanner_instance_admin.UpdateInstanceConfigRequest):
1366
+ request = spanner_instance_admin.UpdateInstanceConfigRequest(request)
1367
+ # If we have keyword arguments corresponding to fields on the
1368
+ # request, apply these.
1369
+ if instance_config is not None:
1370
+ request.instance_config = instance_config
1371
+ if update_mask is not None:
1372
+ request.update_mask = update_mask
1373
+
1374
+ # Wrap the RPC method; this adds retry and timeout information,
1375
+ # and friendly error handling.
1376
+ rpc = self._transport._wrapped_methods[self._transport.update_instance_config]
1377
+
1378
+ # Certain fields should be provided within the metadata header;
1379
+ # add these here.
1380
+ metadata = tuple(metadata) + (
1381
+ gapic_v1.routing_header.to_grpc_metadata(
1382
+ (("instance_config.name", request.instance_config.name),)
1383
+ ),
1384
+ )
1385
+
1386
+ # Validate the universe domain.
1387
+ self._validate_universe_domain()
1388
+
1389
+ # Send the request.
1390
+ response = rpc(
1391
+ request,
1392
+ retry=retry,
1393
+ timeout=timeout,
1394
+ metadata=metadata,
1395
+ )
1396
+
1397
+ # Wrap the response in an operation future.
1398
+ response = operation.from_gapic(
1399
+ response,
1400
+ self._transport.operations_client,
1401
+ spanner_instance_admin.InstanceConfig,
1402
+ metadata_type=spanner_instance_admin.UpdateInstanceConfigMetadata,
1403
+ )
1404
+
1405
+ # Done; return the response.
1406
+ return response
1407
+
1408
+ def delete_instance_config(
1409
+ self,
1410
+ request: Optional[
1411
+ Union[spanner_instance_admin.DeleteInstanceConfigRequest, dict]
1412
+ ] = None,
1413
+ *,
1414
+ name: Optional[str] = None,
1415
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1416
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1417
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1418
+ ) -> None:
1419
+ r"""Deletes the instance configuration. Deletion is only allowed
1420
+ when no instances are using the configuration. If any instances
1421
+ are using the configuration, returns ``FAILED_PRECONDITION``.
1422
+
1423
+ Only user-managed configurations can be deleted.
1424
+
1425
+ Authorization requires ``spanner.instanceConfigs.delete``
1426
+ permission on the resource
1427
+ [name][google.spanner.admin.instance.v1.InstanceConfig.name].
1428
+
1429
+ .. code-block:: python
1430
+
1431
+ # This snippet has been automatically generated and should be regarded as a
1432
+ # code template only.
1433
+ # It will require modifications to work:
1434
+ # - It may require correct/in-range values for request initialization.
1435
+ # - It may require specifying regional endpoints when creating the service
1436
+ # client as shown in:
1437
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1438
+ from google.cloud import spanner_admin_instance_v1
1439
+
1440
+ def sample_delete_instance_config():
1441
+ # Create a client
1442
+ client = spanner_admin_instance_v1.InstanceAdminClient()
1443
+
1444
+ # Initialize request argument(s)
1445
+ request = spanner_admin_instance_v1.DeleteInstanceConfigRequest(
1446
+ name="name_value",
1447
+ )
1448
+
1449
+ # Make the request
1450
+ client.delete_instance_config(request=request)
1451
+
1452
+ Args:
1453
+ request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest, dict]):
1454
+ The request object. The request for
1455
+ [DeleteInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig].
1456
+ name (str):
1457
+ Required. The name of the instance configuration to be
1458
+ deleted. Values are of the form
1459
+ ``projects/<project>/instanceConfigs/<instance_config>``
1460
+
1461
+ This corresponds to the ``name`` field
1462
+ on the ``request`` instance; if ``request`` is provided, this
1463
+ should not be set.
1464
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1465
+ should be retried.
1466
+ timeout (float): The timeout for this request.
1467
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1468
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1469
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1470
+ be of type `bytes`.
1471
+ """
1472
+ # Create or coerce a protobuf request object.
1473
+ # - Quick check: If we got a request object, we should *not* have
1474
+ # gotten any keyword arguments that map to the request.
1475
+ flattened_params = [name]
1476
+ has_flattened_params = (
1477
+ len([param for param in flattened_params if param is not None]) > 0
1478
+ )
1479
+ if request is not None and has_flattened_params:
1480
+ raise ValueError(
1481
+ "If the `request` argument is set, then none of "
1482
+ "the individual field arguments should be set."
1483
+ )
1484
+
1485
+ # - Use the request object if provided (there's no risk of modifying the input as
1486
+ # there are no flattened fields), or create one.
1487
+ if not isinstance(request, spanner_instance_admin.DeleteInstanceConfigRequest):
1488
+ request = spanner_instance_admin.DeleteInstanceConfigRequest(request)
1489
+ # If we have keyword arguments corresponding to fields on the
1490
+ # request, apply these.
1491
+ if name is not None:
1492
+ request.name = name
1493
+
1494
+ # Wrap the RPC method; this adds retry and timeout information,
1495
+ # and friendly error handling.
1496
+ rpc = self._transport._wrapped_methods[self._transport.delete_instance_config]
1497
+
1498
+ # Certain fields should be provided within the metadata header;
1499
+ # add these here.
1500
+ metadata = tuple(metadata) + (
1501
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1502
+ )
1503
+
1504
+ # Validate the universe domain.
1505
+ self._validate_universe_domain()
1506
+
1507
+ # Send the request.
1508
+ rpc(
1509
+ request,
1510
+ retry=retry,
1511
+ timeout=timeout,
1512
+ metadata=metadata,
1513
+ )
1514
+
1515
+ def list_instance_config_operations(
1516
+ self,
1517
+ request: Optional[
1518
+ Union[spanner_instance_admin.ListInstanceConfigOperationsRequest, dict]
1519
+ ] = None,
1520
+ *,
1521
+ parent: Optional[str] = None,
1522
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1523
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1524
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1525
+ ) -> pagers.ListInstanceConfigOperationsPager:
1526
+ r"""Lists the user-managed instance configuration long-running
1527
+ operations in the given project. An instance configuration
1528
+ operation has a name of the form
1529
+ ``projects/<project>/instanceConfigs/<instance_config>/operations/<operation>``.
1530
+ The long-running operation metadata field type
1531
+ ``metadata.type_url`` describes the type of the metadata.
1532
+ Operations returned include those that have
1533
+ completed/failed/canceled within the last 7 days, and pending
1534
+ operations. Operations returned are ordered by
1535
+ ``operation.metadata.value.start_time`` in descending order
1536
+ starting from the most recently started operation.
1537
+
1538
+ .. code-block:: python
1539
+
1540
+ # This snippet has been automatically generated and should be regarded as a
1541
+ # code template only.
1542
+ # It will require modifications to work:
1543
+ # - It may require correct/in-range values for request initialization.
1544
+ # - It may require specifying regional endpoints when creating the service
1545
+ # client as shown in:
1546
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1547
+ from google.cloud import spanner_admin_instance_v1
1548
+
1549
+ def sample_list_instance_config_operations():
1550
+ # Create a client
1551
+ client = spanner_admin_instance_v1.InstanceAdminClient()
1552
+
1553
+ # Initialize request argument(s)
1554
+ request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest(
1555
+ parent="parent_value",
1556
+ )
1557
+
1558
+ # Make the request
1559
+ page_result = client.list_instance_config_operations(request=request)
1560
+
1561
+ # Handle the response
1562
+ for response in page_result:
1563
+ print(response)
1564
+
1565
+ Args:
1566
+ request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest, dict]):
1567
+ The request object. The request for
1568
+ [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations].
1569
+ parent (str):
1570
+ Required. The project of the instance configuration
1571
+ operations. Values are of the form
1572
+ ``projects/<project>``.
1573
+
1574
+ This corresponds to the ``parent`` field
1575
+ on the ``request`` instance; if ``request`` is provided, this
1576
+ should not be set.
1577
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1578
+ should be retried.
1579
+ timeout (float): The timeout for this request.
1580
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1581
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1582
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1583
+ be of type `bytes`.
1584
+
1585
+ Returns:
1586
+ google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsPager:
1587
+ The response for
1588
+ [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations].
1589
+
1590
+ Iterating over this object will yield results and
1591
+ resolve additional pages automatically.
1592
+
1593
+ """
1594
+ # Create or coerce a protobuf request object.
1595
+ # - Quick check: If we got a request object, we should *not* have
1596
+ # gotten any keyword arguments that map to the request.
1597
+ flattened_params = [parent]
1598
+ has_flattened_params = (
1599
+ len([param for param in flattened_params if param is not None]) > 0
1600
+ )
1601
+ if request is not None and has_flattened_params:
1602
+ raise ValueError(
1603
+ "If the `request` argument is set, then none of "
1604
+ "the individual field arguments should be set."
1605
+ )
1606
+
1607
+ # - Use the request object if provided (there's no risk of modifying the input as
1608
+ # there are no flattened fields), or create one.
1609
+ if not isinstance(
1610
+ request, spanner_instance_admin.ListInstanceConfigOperationsRequest
1611
+ ):
1612
+ request = spanner_instance_admin.ListInstanceConfigOperationsRequest(
1613
+ request
1614
+ )
1615
+ # If we have keyword arguments corresponding to fields on the
1616
+ # request, apply these.
1617
+ if parent is not None:
1618
+ request.parent = parent
1619
+
1620
+ # Wrap the RPC method; this adds retry and timeout information,
1621
+ # and friendly error handling.
1622
+ rpc = self._transport._wrapped_methods[
1623
+ self._transport.list_instance_config_operations
1624
+ ]
1625
+
1626
+ # Certain fields should be provided within the metadata header;
1627
+ # add these here.
1628
+ metadata = tuple(metadata) + (
1629
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1630
+ )
1631
+
1632
+ # Validate the universe domain.
1633
+ self._validate_universe_domain()
1634
+
1635
+ # Send the request.
1636
+ response = rpc(
1637
+ request,
1638
+ retry=retry,
1639
+ timeout=timeout,
1640
+ metadata=metadata,
1641
+ )
1642
+
1643
+ # This method is paged; wrap the response in a pager, which provides
1644
+ # an `__iter__` convenience method.
1645
+ response = pagers.ListInstanceConfigOperationsPager(
1646
+ method=rpc,
1647
+ request=request,
1648
+ response=response,
1649
+ retry=retry,
1650
+ timeout=timeout,
1651
+ metadata=metadata,
1652
+ )
1653
+
1654
+ # Done; return the response.
1655
+ return response
1656
+
1657
+ def list_instances(
1658
+ self,
1659
+ request: Optional[
1660
+ Union[spanner_instance_admin.ListInstancesRequest, dict]
1661
+ ] = None,
1662
+ *,
1663
+ parent: Optional[str] = None,
1664
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1665
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1666
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1667
+ ) -> pagers.ListInstancesPager:
1668
+ r"""Lists all instances in the given project.
1669
+
1670
+ .. code-block:: python
1671
+
1672
+ # This snippet has been automatically generated and should be regarded as a
1673
+ # code template only.
1674
+ # It will require modifications to work:
1675
+ # - It may require correct/in-range values for request initialization.
1676
+ # - It may require specifying regional endpoints when creating the service
1677
+ # client as shown in:
1678
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1679
+ from google.cloud import spanner_admin_instance_v1
1680
+
1681
+ def sample_list_instances():
1682
+ # Create a client
1683
+ client = spanner_admin_instance_v1.InstanceAdminClient()
1684
+
1685
+ # Initialize request argument(s)
1686
+ request = spanner_admin_instance_v1.ListInstancesRequest(
1687
+ parent="parent_value",
1688
+ )
1689
+
1690
+ # Make the request
1691
+ page_result = client.list_instances(request=request)
1692
+
1693
+ # Handle the response
1694
+ for response in page_result:
1695
+ print(response)
1696
+
1697
+ Args:
1698
+ request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest, dict]):
1699
+ The request object. The request for
1700
+ [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances].
1701
+ parent (str):
1702
+ Required. The name of the project for which a list of
1703
+ instances is requested. Values are of the form
1704
+ ``projects/<project>``.
1705
+
1706
+ This corresponds to the ``parent`` field
1707
+ on the ``request`` instance; if ``request`` is provided, this
1708
+ should not be set.
1709
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1710
+ should be retried.
1711
+ timeout (float): The timeout for this request.
1712
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1713
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1714
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1715
+ be of type `bytes`.
1716
+
1717
+ Returns:
1718
+ google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesPager:
1719
+ The response for
1720
+ [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances].
1721
+
1722
+ Iterating over this object will yield results and
1723
+ resolve additional pages automatically.
1724
+
1725
+ """
1726
+ # Create or coerce a protobuf request object.
1727
+ # - Quick check: If we got a request object, we should *not* have
1728
+ # gotten any keyword arguments that map to the request.
1729
+ flattened_params = [parent]
1730
+ has_flattened_params = (
1731
+ len([param for param in flattened_params if param is not None]) > 0
1732
+ )
1733
+ if request is not None and has_flattened_params:
1734
+ raise ValueError(
1735
+ "If the `request` argument is set, then none of "
1736
+ "the individual field arguments should be set."
1737
+ )
1738
+
1739
+ # - Use the request object if provided (there's no risk of modifying the input as
1740
+ # there are no flattened fields), or create one.
1741
+ if not isinstance(request, spanner_instance_admin.ListInstancesRequest):
1742
+ request = spanner_instance_admin.ListInstancesRequest(request)
1743
+ # If we have keyword arguments corresponding to fields on the
1744
+ # request, apply these.
1745
+ if parent is not None:
1746
+ request.parent = parent
1747
+
1748
+ # Wrap the RPC method; this adds retry and timeout information,
1749
+ # and friendly error handling.
1750
+ rpc = self._transport._wrapped_methods[self._transport.list_instances]
1751
+
1752
+ # Certain fields should be provided within the metadata header;
1753
+ # add these here.
1754
+ metadata = tuple(metadata) + (
1755
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1756
+ )
1757
+
1758
+ # Validate the universe domain.
1759
+ self._validate_universe_domain()
1760
+
1761
+ # Send the request.
1762
+ response = rpc(
1763
+ request,
1764
+ retry=retry,
1765
+ timeout=timeout,
1766
+ metadata=metadata,
1767
+ )
1768
+
1769
+ # This method is paged; wrap the response in a pager, which provides
1770
+ # an `__iter__` convenience method.
1771
+ response = pagers.ListInstancesPager(
1772
+ method=rpc,
1773
+ request=request,
1774
+ response=response,
1775
+ retry=retry,
1776
+ timeout=timeout,
1777
+ metadata=metadata,
1778
+ )
1779
+
1780
+ # Done; return the response.
1781
+ return response
1782
+
1783
+ def list_instance_partitions(
1784
+ self,
1785
+ request: Optional[
1786
+ Union[spanner_instance_admin.ListInstancePartitionsRequest, dict]
1787
+ ] = None,
1788
+ *,
1789
+ parent: Optional[str] = None,
1790
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1791
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1792
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1793
+ ) -> pagers.ListInstancePartitionsPager:
1794
+ r"""Lists all instance partitions for the given instance.
1795
+
1796
+ .. code-block:: python
1797
+
1798
+ # This snippet has been automatically generated and should be regarded as a
1799
+ # code template only.
1800
+ # It will require modifications to work:
1801
+ # - It may require correct/in-range values for request initialization.
1802
+ # - It may require specifying regional endpoints when creating the service
1803
+ # client as shown in:
1804
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1805
+ from google.cloud import spanner_admin_instance_v1
1806
+
1807
+ def sample_list_instance_partitions():
1808
+ # Create a client
1809
+ client = spanner_admin_instance_v1.InstanceAdminClient()
1810
+
1811
+ # Initialize request argument(s)
1812
+ request = spanner_admin_instance_v1.ListInstancePartitionsRequest(
1813
+ parent="parent_value",
1814
+ )
1815
+
1816
+ # Make the request
1817
+ page_result = client.list_instance_partitions(request=request)
1818
+
1819
+ # Handle the response
1820
+ for response in page_result:
1821
+ print(response)
1822
+
1823
+ Args:
1824
+ request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstancePartitionsRequest, dict]):
1825
+ The request object. The request for
1826
+ [ListInstancePartitions][google.spanner.admin.instance.v1.InstanceAdmin.ListInstancePartitions].
1827
+ parent (str):
1828
+ Required. The instance whose instance partitions should
1829
+ be listed. Values are of the form
1830
+ ``projects/<project>/instances/<instance>``. Use
1831
+ ``{instance} = '-'`` to list instance partitions for all
1832
+ Instances in a project, e.g.,
1833
+ ``projects/myproject/instances/-``.
1834
+
1835
+ This corresponds to the ``parent`` field
1836
+ on the ``request`` instance; if ``request`` is provided, this
1837
+ should not be set.
1838
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1839
+ should be retried.
1840
+ timeout (float): The timeout for this request.
1841
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1842
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1843
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1844
+ be of type `bytes`.
1845
+
1846
+ Returns:
1847
+ google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancePartitionsPager:
1848
+ The response for
1849
+ [ListInstancePartitions][google.spanner.admin.instance.v1.InstanceAdmin.ListInstancePartitions].
1850
+
1851
+ Iterating over this object will yield results and
1852
+ resolve additional pages automatically.
1853
+
1854
+ """
1855
+ # Create or coerce a protobuf request object.
1856
+ # - Quick check: If we got a request object, we should *not* have
1857
+ # gotten any keyword arguments that map to the request.
1858
+ flattened_params = [parent]
1859
+ has_flattened_params = (
1860
+ len([param for param in flattened_params if param is not None]) > 0
1861
+ )
1862
+ if request is not None and has_flattened_params:
1863
+ raise ValueError(
1864
+ "If the `request` argument is set, then none of "
1865
+ "the individual field arguments should be set."
1866
+ )
1867
+
1868
+ # - Use the request object if provided (there's no risk of modifying the input as
1869
+ # there are no flattened fields), or create one.
1870
+ if not isinstance(
1871
+ request, spanner_instance_admin.ListInstancePartitionsRequest
1872
+ ):
1873
+ request = spanner_instance_admin.ListInstancePartitionsRequest(request)
1874
+ # If we have keyword arguments corresponding to fields on the
1875
+ # request, apply these.
1876
+ if parent is not None:
1877
+ request.parent = parent
1878
+
1879
+ # Wrap the RPC method; this adds retry and timeout information,
1880
+ # and friendly error handling.
1881
+ rpc = self._transport._wrapped_methods[self._transport.list_instance_partitions]
1882
+
1883
+ # Certain fields should be provided within the metadata header;
1884
+ # add these here.
1885
+ metadata = tuple(metadata) + (
1886
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1887
+ )
1888
+
1889
+ # Validate the universe domain.
1890
+ self._validate_universe_domain()
1891
+
1892
+ # Send the request.
1893
+ response = rpc(
1894
+ request,
1895
+ retry=retry,
1896
+ timeout=timeout,
1897
+ metadata=metadata,
1898
+ )
1899
+
1900
+ # This method is paged; wrap the response in a pager, which provides
1901
+ # an `__iter__` convenience method.
1902
+ response = pagers.ListInstancePartitionsPager(
1903
+ method=rpc,
1904
+ request=request,
1905
+ response=response,
1906
+ retry=retry,
1907
+ timeout=timeout,
1908
+ metadata=metadata,
1909
+ )
1910
+
1911
+ # Done; return the response.
1912
+ return response
1913
+
1914
+ def get_instance(
1915
+ self,
1916
+ request: Optional[
1917
+ Union[spanner_instance_admin.GetInstanceRequest, dict]
1918
+ ] = None,
1919
+ *,
1920
+ name: Optional[str] = None,
1921
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1922
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1923
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1924
+ ) -> spanner_instance_admin.Instance:
1925
+ r"""Gets information about a particular instance.
1926
+
1927
+ .. code-block:: python
1928
+
1929
+ # This snippet has been automatically generated and should be regarded as a
1930
+ # code template only.
1931
+ # It will require modifications to work:
1932
+ # - It may require correct/in-range values for request initialization.
1933
+ # - It may require specifying regional endpoints when creating the service
1934
+ # client as shown in:
1935
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1936
+ from google.cloud import spanner_admin_instance_v1
1937
+
1938
+ def sample_get_instance():
1939
+ # Create a client
1940
+ client = spanner_admin_instance_v1.InstanceAdminClient()
1941
+
1942
+ # Initialize request argument(s)
1943
+ request = spanner_admin_instance_v1.GetInstanceRequest(
1944
+ name="name_value",
1945
+ )
1946
+
1947
+ # Make the request
1948
+ response = client.get_instance(request=request)
1949
+
1950
+ # Handle the response
1951
+ print(response)
1952
+
1953
+ Args:
1954
+ request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest, dict]):
1955
+ The request object. The request for
1956
+ [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance].
1957
+ name (str):
1958
+ Required. The name of the requested instance. Values are
1959
+ of the form ``projects/<project>/instances/<instance>``.
1960
+
1961
+ This corresponds to the ``name`` field
1962
+ on the ``request`` instance; if ``request`` is provided, this
1963
+ should not be set.
1964
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1965
+ should be retried.
1966
+ timeout (float): The timeout for this request.
1967
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1968
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1969
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1970
+ be of type `bytes`.
1971
+
1972
+ Returns:
1973
+ google.cloud.spanner_admin_instance_v1.types.Instance:
1974
+ An isolated set of Cloud Spanner
1975
+ resources on which databases can be
1976
+ hosted.
1977
+
1978
+ """
1979
+ # Create or coerce a protobuf request object.
1980
+ # - Quick check: If we got a request object, we should *not* have
1981
+ # gotten any keyword arguments that map to the request.
1982
+ flattened_params = [name]
1983
+ has_flattened_params = (
1984
+ len([param for param in flattened_params if param is not None]) > 0
1985
+ )
1986
+ if request is not None and has_flattened_params:
1987
+ raise ValueError(
1988
+ "If the `request` argument is set, then none of "
1989
+ "the individual field arguments should be set."
1990
+ )
1991
+
1992
+ # - Use the request object if provided (there's no risk of modifying the input as
1993
+ # there are no flattened fields), or create one.
1994
+ if not isinstance(request, spanner_instance_admin.GetInstanceRequest):
1995
+ request = spanner_instance_admin.GetInstanceRequest(request)
1996
+ # If we have keyword arguments corresponding to fields on the
1997
+ # request, apply these.
1998
+ if name is not None:
1999
+ request.name = name
2000
+
2001
+ # Wrap the RPC method; this adds retry and timeout information,
2002
+ # and friendly error handling.
2003
+ rpc = self._transport._wrapped_methods[self._transport.get_instance]
2004
+
2005
+ # Certain fields should be provided within the metadata header;
2006
+ # add these here.
2007
+ metadata = tuple(metadata) + (
2008
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2009
+ )
2010
+
2011
+ # Validate the universe domain.
2012
+ self._validate_universe_domain()
2013
+
2014
+ # Send the request.
2015
+ response = rpc(
2016
+ request,
2017
+ retry=retry,
2018
+ timeout=timeout,
2019
+ metadata=metadata,
2020
+ )
2021
+
2022
+ # Done; return the response.
2023
+ return response
2024
+
2025
+ def create_instance(
2026
+ self,
2027
+ request: Optional[
2028
+ Union[spanner_instance_admin.CreateInstanceRequest, dict]
2029
+ ] = None,
2030
+ *,
2031
+ parent: Optional[str] = None,
2032
+ instance_id: Optional[str] = None,
2033
+ instance: Optional[spanner_instance_admin.Instance] = None,
2034
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2035
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2036
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2037
+ ) -> operation.Operation:
2038
+ r"""Creates an instance and begins preparing it to begin serving.
2039
+ The returned long-running operation can be used to track the
2040
+ progress of preparing the new instance. The instance name is
2041
+ assigned by the caller. If the named instance already exists,
2042
+ ``CreateInstance`` returns ``ALREADY_EXISTS``.
2043
+
2044
+ Immediately upon completion of this request:
2045
+
2046
+ - The instance is readable via the API, with all requested
2047
+ attributes but no allocated resources. Its state is
2048
+ ``CREATING``.
2049
+
2050
+ Until completion of the returned operation:
2051
+
2052
+ - Cancelling the operation renders the instance immediately
2053
+ unreadable via the API.
2054
+ - The instance can be deleted.
2055
+ - All other attempts to modify the instance are rejected.
2056
+
2057
+ Upon completion of the returned operation:
2058
+
2059
+ - Billing for all successfully-allocated resources begins (some
2060
+ types may have lower than the requested levels).
2061
+ - Databases can be created in the instance.
2062
+ - The instance's allocated resource levels are readable via the
2063
+ API.
2064
+ - The instance's state becomes ``READY``.
2065
+
2066
+ The returned long-running operation will have a name of the
2067
+ format ``<instance_name>/operations/<operation_id>`` and can be
2068
+ used to track creation of the instance. The metadata field type
2069
+ is
2070
+ [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata].
2071
+ The response field type is
2072
+ [Instance][google.spanner.admin.instance.v1.Instance], if
2073
+ successful.
2074
+
2075
+ .. code-block:: python
2076
+
2077
+ # This snippet has been automatically generated and should be regarded as a
2078
+ # code template only.
2079
+ # It will require modifications to work:
2080
+ # - It may require correct/in-range values for request initialization.
2081
+ # - It may require specifying regional endpoints when creating the service
2082
+ # client as shown in:
2083
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2084
+ from google.cloud import spanner_admin_instance_v1
2085
+
2086
+ def sample_create_instance():
2087
+ # Create a client
2088
+ client = spanner_admin_instance_v1.InstanceAdminClient()
2089
+
2090
+ # Initialize request argument(s)
2091
+ instance = spanner_admin_instance_v1.Instance()
2092
+ instance.name = "name_value"
2093
+ instance.config = "config_value"
2094
+ instance.display_name = "display_name_value"
2095
+
2096
+ request = spanner_admin_instance_v1.CreateInstanceRequest(
2097
+ parent="parent_value",
2098
+ instance_id="instance_id_value",
2099
+ instance=instance,
2100
+ )
2101
+
2102
+ # Make the request
2103
+ operation = client.create_instance(request=request)
2104
+
2105
+ print("Waiting for operation to complete...")
2106
+
2107
+ response = operation.result()
2108
+
2109
+ # Handle the response
2110
+ print(response)
2111
+
2112
+ Args:
2113
+ request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest, dict]):
2114
+ The request object. The request for
2115
+ [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance].
2116
+ parent (str):
2117
+ Required. The name of the project in which to create the
2118
+ instance. Values are of the form ``projects/<project>``.
2119
+
2120
+ This corresponds to the ``parent`` field
2121
+ on the ``request`` instance; if ``request`` is provided, this
2122
+ should not be set.
2123
+ instance_id (str):
2124
+ Required. The ID of the instance to create. Valid
2125
+ identifiers are of the form ``[a-z][-a-z0-9]*[a-z0-9]``
2126
+ and must be between 2 and 64 characters in length.
2127
+
2128
+ This corresponds to the ``instance_id`` field
2129
+ on the ``request`` instance; if ``request`` is provided, this
2130
+ should not be set.
2131
+ instance (google.cloud.spanner_admin_instance_v1.types.Instance):
2132
+ Required. The instance to create. The name may be
2133
+ omitted, but if specified must be
2134
+ ``<parent>/instances/<instance_id>``.
2135
+
2136
+ This corresponds to the ``instance`` field
2137
+ on the ``request`` instance; if ``request`` is provided, this
2138
+ should not be set.
2139
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2140
+ should be retried.
2141
+ timeout (float): The timeout for this request.
2142
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2143
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2144
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2145
+ be of type `bytes`.
2146
+
2147
+ Returns:
2148
+ google.api_core.operation.Operation:
2149
+ An object representing a long-running operation.
2150
+
2151
+ The result type for the operation will be
2152
+ :class:`google.cloud.spanner_admin_instance_v1.types.Instance`
2153
+ An isolated set of Cloud Spanner resources on which
2154
+ databases can be hosted.
2155
+
2156
+ """
2157
+ # Create or coerce a protobuf request object.
2158
+ # - Quick check: If we got a request object, we should *not* have
2159
+ # gotten any keyword arguments that map to the request.
2160
+ flattened_params = [parent, instance_id, instance]
2161
+ has_flattened_params = (
2162
+ len([param for param in flattened_params if param is not None]) > 0
2163
+ )
2164
+ if request is not None and has_flattened_params:
2165
+ raise ValueError(
2166
+ "If the `request` argument is set, then none of "
2167
+ "the individual field arguments should be set."
2168
+ )
2169
+
2170
+ # - Use the request object if provided (there's no risk of modifying the input as
2171
+ # there are no flattened fields), or create one.
2172
+ if not isinstance(request, spanner_instance_admin.CreateInstanceRequest):
2173
+ request = spanner_instance_admin.CreateInstanceRequest(request)
2174
+ # If we have keyword arguments corresponding to fields on the
2175
+ # request, apply these.
2176
+ if parent is not None:
2177
+ request.parent = parent
2178
+ if instance_id is not None:
2179
+ request.instance_id = instance_id
2180
+ if instance is not None:
2181
+ request.instance = instance
2182
+
2183
+ # Wrap the RPC method; this adds retry and timeout information,
2184
+ # and friendly error handling.
2185
+ rpc = self._transport._wrapped_methods[self._transport.create_instance]
2186
+
2187
+ # Certain fields should be provided within the metadata header;
2188
+ # add these here.
2189
+ metadata = tuple(metadata) + (
2190
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
2191
+ )
2192
+
2193
+ # Validate the universe domain.
2194
+ self._validate_universe_domain()
2195
+
2196
+ # Send the request.
2197
+ response = rpc(
2198
+ request,
2199
+ retry=retry,
2200
+ timeout=timeout,
2201
+ metadata=metadata,
2202
+ )
2203
+
2204
+ # Wrap the response in an operation future.
2205
+ response = operation.from_gapic(
2206
+ response,
2207
+ self._transport.operations_client,
2208
+ spanner_instance_admin.Instance,
2209
+ metadata_type=spanner_instance_admin.CreateInstanceMetadata,
2210
+ )
2211
+
2212
+ # Done; return the response.
2213
+ return response
2214
+
2215
+ def update_instance(
2216
+ self,
2217
+ request: Optional[
2218
+ Union[spanner_instance_admin.UpdateInstanceRequest, dict]
2219
+ ] = None,
2220
+ *,
2221
+ instance: Optional[spanner_instance_admin.Instance] = None,
2222
+ field_mask: Optional[field_mask_pb2.FieldMask] = None,
2223
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2224
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2225
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2226
+ ) -> operation.Operation:
2227
+ r"""Updates an instance, and begins allocating or releasing
2228
+ resources as requested. The returned long-running operation can
2229
+ be used to track the progress of updating the instance. If the
2230
+ named instance does not exist, returns ``NOT_FOUND``.
2231
+
2232
+ Immediately upon completion of this request:
2233
+
2234
+ - For resource types for which a decrease in the instance's
2235
+ allocation has been requested, billing is based on the
2236
+ newly-requested level.
2237
+
2238
+ Until completion of the returned operation:
2239
+
2240
+ - Cancelling the operation sets its metadata's
2241
+ [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time],
2242
+ and begins restoring resources to their pre-request values.
2243
+ The operation is guaranteed to succeed at undoing all
2244
+ resource changes, after which point it terminates with a
2245
+ ``CANCELLED`` status.
2246
+ - All other attempts to modify the instance are rejected.
2247
+ - Reading the instance via the API continues to give the
2248
+ pre-request resource levels.
2249
+
2250
+ Upon completion of the returned operation:
2251
+
2252
+ - Billing begins for all successfully-allocated resources (some
2253
+ types may have lower than the requested levels).
2254
+ - All newly-reserved resources are available for serving the
2255
+ instance's tables.
2256
+ - The instance's new resource levels are readable via the API.
2257
+
2258
+ The returned long-running operation will have a name of the
2259
+ format ``<instance_name>/operations/<operation_id>`` and can be
2260
+ used to track the instance modification. The metadata field type
2261
+ is
2262
+ [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata].
2263
+ The response field type is
2264
+ [Instance][google.spanner.admin.instance.v1.Instance], if
2265
+ successful.
2266
+
2267
+ Authorization requires ``spanner.instances.update`` permission
2268
+ on the resource
2269
+ [name][google.spanner.admin.instance.v1.Instance.name].
2270
+
2271
+ .. code-block:: python
2272
+
2273
+ # This snippet has been automatically generated and should be regarded as a
2274
+ # code template only.
2275
+ # It will require modifications to work:
2276
+ # - It may require correct/in-range values for request initialization.
2277
+ # - It may require specifying regional endpoints when creating the service
2278
+ # client as shown in:
2279
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2280
+ from google.cloud import spanner_admin_instance_v1
2281
+
2282
+ def sample_update_instance():
2283
+ # Create a client
2284
+ client = spanner_admin_instance_v1.InstanceAdminClient()
2285
+
2286
+ # Initialize request argument(s)
2287
+ instance = spanner_admin_instance_v1.Instance()
2288
+ instance.name = "name_value"
2289
+ instance.config = "config_value"
2290
+ instance.display_name = "display_name_value"
2291
+
2292
+ request = spanner_admin_instance_v1.UpdateInstanceRequest(
2293
+ instance=instance,
2294
+ )
2295
+
2296
+ # Make the request
2297
+ operation = client.update_instance(request=request)
2298
+
2299
+ print("Waiting for operation to complete...")
2300
+
2301
+ response = operation.result()
2302
+
2303
+ # Handle the response
2304
+ print(response)
2305
+
2306
+ Args:
2307
+ request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest, dict]):
2308
+ The request object. The request for
2309
+ [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance].
2310
+ instance (google.cloud.spanner_admin_instance_v1.types.Instance):
2311
+ Required. The instance to update, which must always
2312
+ include the instance name. Otherwise, only fields
2313
+ mentioned in
2314
+ [field_mask][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask]
2315
+ need be included.
2316
+
2317
+ This corresponds to the ``instance`` field
2318
+ on the ``request`` instance; if ``request`` is provided, this
2319
+ should not be set.
2320
+ field_mask (google.protobuf.field_mask_pb2.FieldMask):
2321
+ Required. A mask specifying which fields in
2322
+ [Instance][google.spanner.admin.instance.v1.Instance]
2323
+ should be updated. The field mask must always be
2324
+ specified; this prevents any future fields in
2325
+ [Instance][google.spanner.admin.instance.v1.Instance]
2326
+ from being erased accidentally by clients that do not
2327
+ know about them.
2328
+
2329
+ This corresponds to the ``field_mask`` field
2330
+ on the ``request`` instance; if ``request`` is provided, this
2331
+ should not be set.
2332
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2333
+ should be retried.
2334
+ timeout (float): The timeout for this request.
2335
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2336
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2337
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2338
+ be of type `bytes`.
2339
+
2340
+ Returns:
2341
+ google.api_core.operation.Operation:
2342
+ An object representing a long-running operation.
2343
+
2344
+ The result type for the operation will be
2345
+ :class:`google.cloud.spanner_admin_instance_v1.types.Instance`
2346
+ An isolated set of Cloud Spanner resources on which
2347
+ databases can be hosted.
2348
+
2349
+ """
2350
+ # Create or coerce a protobuf request object.
2351
+ # - Quick check: If we got a request object, we should *not* have
2352
+ # gotten any keyword arguments that map to the request.
2353
+ flattened_params = [instance, field_mask]
2354
+ has_flattened_params = (
2355
+ len([param for param in flattened_params if param is not None]) > 0
2356
+ )
2357
+ if request is not None and has_flattened_params:
2358
+ raise ValueError(
2359
+ "If the `request` argument is set, then none of "
2360
+ "the individual field arguments should be set."
2361
+ )
2362
+
2363
+ # - Use the request object if provided (there's no risk of modifying the input as
2364
+ # there are no flattened fields), or create one.
2365
+ if not isinstance(request, spanner_instance_admin.UpdateInstanceRequest):
2366
+ request = spanner_instance_admin.UpdateInstanceRequest(request)
2367
+ # If we have keyword arguments corresponding to fields on the
2368
+ # request, apply these.
2369
+ if instance is not None:
2370
+ request.instance = instance
2371
+ if field_mask is not None:
2372
+ request.field_mask = field_mask
2373
+
2374
+ # Wrap the RPC method; this adds retry and timeout information,
2375
+ # and friendly error handling.
2376
+ rpc = self._transport._wrapped_methods[self._transport.update_instance]
2377
+
2378
+ # Certain fields should be provided within the metadata header;
2379
+ # add these here.
2380
+ metadata = tuple(metadata) + (
2381
+ gapic_v1.routing_header.to_grpc_metadata(
2382
+ (("instance.name", request.instance.name),)
2383
+ ),
2384
+ )
2385
+
2386
+ # Validate the universe domain.
2387
+ self._validate_universe_domain()
2388
+
2389
+ # Send the request.
2390
+ response = rpc(
2391
+ request,
2392
+ retry=retry,
2393
+ timeout=timeout,
2394
+ metadata=metadata,
2395
+ )
2396
+
2397
+ # Wrap the response in an operation future.
2398
+ response = operation.from_gapic(
2399
+ response,
2400
+ self._transport.operations_client,
2401
+ spanner_instance_admin.Instance,
2402
+ metadata_type=spanner_instance_admin.UpdateInstanceMetadata,
2403
+ )
2404
+
2405
+ # Done; return the response.
2406
+ return response
2407
+
2408
+ def delete_instance(
2409
+ self,
2410
+ request: Optional[
2411
+ Union[spanner_instance_admin.DeleteInstanceRequest, dict]
2412
+ ] = None,
2413
+ *,
2414
+ name: Optional[str] = None,
2415
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2416
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2417
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2418
+ ) -> None:
2419
+ r"""Deletes an instance.
2420
+
2421
+ Immediately upon completion of the request:
2422
+
2423
+ - Billing ceases for all of the instance's reserved resources.
2424
+
2425
+ Soon afterward:
2426
+
2427
+ - The instance and *all of its databases* immediately and
2428
+ irrevocably disappear from the API. All data in the databases
2429
+ is permanently deleted.
2430
+
2431
+ .. code-block:: python
2432
+
2433
+ # This snippet has been automatically generated and should be regarded as a
2434
+ # code template only.
2435
+ # It will require modifications to work:
2436
+ # - It may require correct/in-range values for request initialization.
2437
+ # - It may require specifying regional endpoints when creating the service
2438
+ # client as shown in:
2439
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2440
+ from google.cloud import spanner_admin_instance_v1
2441
+
2442
+ def sample_delete_instance():
2443
+ # Create a client
2444
+ client = spanner_admin_instance_v1.InstanceAdminClient()
2445
+
2446
+ # Initialize request argument(s)
2447
+ request = spanner_admin_instance_v1.DeleteInstanceRequest(
2448
+ name="name_value",
2449
+ )
2450
+
2451
+ # Make the request
2452
+ client.delete_instance(request=request)
2453
+
2454
+ Args:
2455
+ request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest, dict]):
2456
+ The request object. The request for
2457
+ [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance].
2458
+ name (str):
2459
+ Required. The name of the instance to be deleted. Values
2460
+ are of the form
2461
+ ``projects/<project>/instances/<instance>``
2462
+
2463
+ This corresponds to the ``name`` field
2464
+ on the ``request`` instance; if ``request`` is provided, this
2465
+ should not be set.
2466
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2467
+ should be retried.
2468
+ timeout (float): The timeout for this request.
2469
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2470
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2471
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2472
+ be of type `bytes`.
2473
+ """
2474
+ # Create or coerce a protobuf request object.
2475
+ # - Quick check: If we got a request object, we should *not* have
2476
+ # gotten any keyword arguments that map to the request.
2477
+ flattened_params = [name]
2478
+ has_flattened_params = (
2479
+ len([param for param in flattened_params if param is not None]) > 0
2480
+ )
2481
+ if request is not None and has_flattened_params:
2482
+ raise ValueError(
2483
+ "If the `request` argument is set, then none of "
2484
+ "the individual field arguments should be set."
2485
+ )
2486
+
2487
+ # - Use the request object if provided (there's no risk of modifying the input as
2488
+ # there are no flattened fields), or create one.
2489
+ if not isinstance(request, spanner_instance_admin.DeleteInstanceRequest):
2490
+ request = spanner_instance_admin.DeleteInstanceRequest(request)
2491
+ # If we have keyword arguments corresponding to fields on the
2492
+ # request, apply these.
2493
+ if name is not None:
2494
+ request.name = name
2495
+
2496
+ # Wrap the RPC method; this adds retry and timeout information,
2497
+ # and friendly error handling.
2498
+ rpc = self._transport._wrapped_methods[self._transport.delete_instance]
2499
+
2500
+ # Certain fields should be provided within the metadata header;
2501
+ # add these here.
2502
+ metadata = tuple(metadata) + (
2503
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
2504
+ )
2505
+
2506
+ # Validate the universe domain.
2507
+ self._validate_universe_domain()
2508
+
2509
+ # Send the request.
2510
+ rpc(
2511
+ request,
2512
+ retry=retry,
2513
+ timeout=timeout,
2514
+ metadata=metadata,
2515
+ )
2516
+
2517
+ def set_iam_policy(
2518
+ self,
2519
+ request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None,
2520
+ *,
2521
+ resource: Optional[str] = None,
2522
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2523
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2524
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2525
+ ) -> policy_pb2.Policy:
2526
+ r"""Sets the access control policy on an instance resource. Replaces
2527
+ any existing policy.
2528
+
2529
+ Authorization requires ``spanner.instances.setIamPolicy`` on
2530
+ [resource][google.iam.v1.SetIamPolicyRequest.resource].
2531
+
2532
+ .. code-block:: python
2533
+
2534
+ # This snippet has been automatically generated and should be regarded as a
2535
+ # code template only.
2536
+ # It will require modifications to work:
2537
+ # - It may require correct/in-range values for request initialization.
2538
+ # - It may require specifying regional endpoints when creating the service
2539
+ # client as shown in:
2540
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2541
+ from google.cloud import spanner_admin_instance_v1
2542
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
2543
+
2544
+ def sample_set_iam_policy():
2545
+ # Create a client
2546
+ client = spanner_admin_instance_v1.InstanceAdminClient()
2547
+
2548
+ # Initialize request argument(s)
2549
+ request = iam_policy_pb2.SetIamPolicyRequest(
2550
+ resource="resource_value",
2551
+ )
2552
+
2553
+ # Make the request
2554
+ response = client.set_iam_policy(request=request)
2555
+
2556
+ # Handle the response
2557
+ print(response)
2558
+
2559
+ Args:
2560
+ request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]):
2561
+ The request object. Request message for ``SetIamPolicy`` method.
2562
+ resource (str):
2563
+ REQUIRED: The resource for which the
2564
+ policy is being specified. See the
2565
+ operation documentation for the
2566
+ appropriate value for this field.
2567
+
2568
+ This corresponds to the ``resource`` field
2569
+ on the ``request`` instance; if ``request`` is provided, this
2570
+ should not be set.
2571
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2572
+ should be retried.
2573
+ timeout (float): The timeout for this request.
2574
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2575
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2576
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2577
+ be of type `bytes`.
2578
+
2579
+ Returns:
2580
+ google.iam.v1.policy_pb2.Policy:
2581
+ An Identity and Access Management (IAM) policy, which specifies access
2582
+ controls for Google Cloud resources.
2583
+
2584
+ A Policy is a collection of bindings. A binding binds
2585
+ one or more members, or principals, to a single role.
2586
+ Principals can be user accounts, service accounts,
2587
+ Google groups, and domains (such as G Suite). A role
2588
+ is a named list of permissions; each role can be an
2589
+ IAM predefined role or a user-created custom role.
2590
+
2591
+ For some types of Google Cloud resources, a binding
2592
+ can also specify a condition, which is a logical
2593
+ expression that allows access to a resource only if
2594
+ the expression evaluates to true. A condition can add
2595
+ constraints based on attributes of the request, the
2596
+ resource, or both. To learn which resources support
2597
+ conditions in their IAM policies, see the [IAM
2598
+ documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
2599
+
2600
+ **JSON example:**
2601
+
2602
+ :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 }`\ \`
2603
+
2604
+ **YAML example:**
2605
+
2606
+ :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`\ \`
2607
+
2608
+ For a description of IAM and its features, see the
2609
+ [IAM
2610
+ documentation](\ https://cloud.google.com/iam/docs/).
2611
+
2612
+ """
2613
+ # Create or coerce a protobuf request object.
2614
+ # - Quick check: If we got a request object, we should *not* have
2615
+ # gotten any keyword arguments that map to the request.
2616
+ flattened_params = [resource]
2617
+ has_flattened_params = (
2618
+ len([param for param in flattened_params if param is not None]) > 0
2619
+ )
2620
+ if request is not None and has_flattened_params:
2621
+ raise ValueError(
2622
+ "If the `request` argument is set, then none of "
2623
+ "the individual field arguments should be set."
2624
+ )
2625
+
2626
+ if isinstance(request, dict):
2627
+ # - The request isn't a proto-plus wrapped type,
2628
+ # so it must be constructed via keyword expansion.
2629
+ request = iam_policy_pb2.SetIamPolicyRequest(**request)
2630
+ elif not request:
2631
+ # Null request, just make one.
2632
+ request = iam_policy_pb2.SetIamPolicyRequest()
2633
+ if resource is not None:
2634
+ request.resource = resource
2635
+
2636
+ # Wrap the RPC method; this adds retry and timeout information,
2637
+ # and friendly error handling.
2638
+ rpc = self._transport._wrapped_methods[self._transport.set_iam_policy]
2639
+
2640
+ # Certain fields should be provided within the metadata header;
2641
+ # add these here.
2642
+ metadata = tuple(metadata) + (
2643
+ gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
2644
+ )
2645
+
2646
+ # Validate the universe domain.
2647
+ self._validate_universe_domain()
2648
+
2649
+ # Send the request.
2650
+ response = rpc(
2651
+ request,
2652
+ retry=retry,
2653
+ timeout=timeout,
2654
+ metadata=metadata,
2655
+ )
2656
+
2657
+ # Done; return the response.
2658
+ return response
2659
+
2660
+ def get_iam_policy(
2661
+ self,
2662
+ request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None,
2663
+ *,
2664
+ resource: Optional[str] = None,
2665
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2666
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2667
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2668
+ ) -> policy_pb2.Policy:
2669
+ r"""Gets the access control policy for an instance resource. Returns
2670
+ an empty policy if an instance exists but does not have a policy
2671
+ set.
2672
+
2673
+ Authorization requires ``spanner.instances.getIamPolicy`` on
2674
+ [resource][google.iam.v1.GetIamPolicyRequest.resource].
2675
+
2676
+ .. code-block:: python
2677
+
2678
+ # This snippet has been automatically generated and should be regarded as a
2679
+ # code template only.
2680
+ # It will require modifications to work:
2681
+ # - It may require correct/in-range values for request initialization.
2682
+ # - It may require specifying regional endpoints when creating the service
2683
+ # client as shown in:
2684
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2685
+ from google.cloud import spanner_admin_instance_v1
2686
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
2687
+
2688
+ def sample_get_iam_policy():
2689
+ # Create a client
2690
+ client = spanner_admin_instance_v1.InstanceAdminClient()
2691
+
2692
+ # Initialize request argument(s)
2693
+ request = iam_policy_pb2.GetIamPolicyRequest(
2694
+ resource="resource_value",
2695
+ )
2696
+
2697
+ # Make the request
2698
+ response = client.get_iam_policy(request=request)
2699
+
2700
+ # Handle the response
2701
+ print(response)
2702
+
2703
+ Args:
2704
+ request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]):
2705
+ The request object. Request message for ``GetIamPolicy`` method.
2706
+ resource (str):
2707
+ REQUIRED: The resource for which the
2708
+ policy is being requested. See the
2709
+ operation documentation for the
2710
+ appropriate value for this field.
2711
+
2712
+ This corresponds to the ``resource`` field
2713
+ on the ``request`` instance; if ``request`` is provided, this
2714
+ should not be set.
2715
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2716
+ should be retried.
2717
+ timeout (float): The timeout for this request.
2718
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2719
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2720
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2721
+ be of type `bytes`.
2722
+
2723
+ Returns:
2724
+ google.iam.v1.policy_pb2.Policy:
2725
+ An Identity and Access Management (IAM) policy, which specifies access
2726
+ controls for Google Cloud resources.
2727
+
2728
+ A Policy is a collection of bindings. A binding binds
2729
+ one or more members, or principals, to a single role.
2730
+ Principals can be user accounts, service accounts,
2731
+ Google groups, and domains (such as G Suite). A role
2732
+ is a named list of permissions; each role can be an
2733
+ IAM predefined role or a user-created custom role.
2734
+
2735
+ For some types of Google Cloud resources, a binding
2736
+ can also specify a condition, which is a logical
2737
+ expression that allows access to a resource only if
2738
+ the expression evaluates to true. A condition can add
2739
+ constraints based on attributes of the request, the
2740
+ resource, or both. To learn which resources support
2741
+ conditions in their IAM policies, see the [IAM
2742
+ documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
2743
+
2744
+ **JSON example:**
2745
+
2746
+ :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 }`\ \`
2747
+
2748
+ **YAML example:**
2749
+
2750
+ :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`\ \`
2751
+
2752
+ For a description of IAM and its features, see the
2753
+ [IAM
2754
+ documentation](\ https://cloud.google.com/iam/docs/).
2755
+
2756
+ """
2757
+ # Create or coerce a protobuf request object.
2758
+ # - Quick check: If we got a request object, we should *not* have
2759
+ # gotten any keyword arguments that map to the request.
2760
+ flattened_params = [resource]
2761
+ has_flattened_params = (
2762
+ len([param for param in flattened_params if param is not None]) > 0
2763
+ )
2764
+ if request is not None and has_flattened_params:
2765
+ raise ValueError(
2766
+ "If the `request` argument is set, then none of "
2767
+ "the individual field arguments should be set."
2768
+ )
2769
+
2770
+ if isinstance(request, dict):
2771
+ # - The request isn't a proto-plus wrapped type,
2772
+ # so it must be constructed via keyword expansion.
2773
+ request = iam_policy_pb2.GetIamPolicyRequest(**request)
2774
+ elif not request:
2775
+ # Null request, just make one.
2776
+ request = iam_policy_pb2.GetIamPolicyRequest()
2777
+ if resource is not None:
2778
+ request.resource = resource
2779
+
2780
+ # Wrap the RPC method; this adds retry and timeout information,
2781
+ # and friendly error handling.
2782
+ rpc = self._transport._wrapped_methods[self._transport.get_iam_policy]
2783
+
2784
+ # Certain fields should be provided within the metadata header;
2785
+ # add these here.
2786
+ metadata = tuple(metadata) + (
2787
+ gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
2788
+ )
2789
+
2790
+ # Validate the universe domain.
2791
+ self._validate_universe_domain()
2792
+
2793
+ # Send the request.
2794
+ response = rpc(
2795
+ request,
2796
+ retry=retry,
2797
+ timeout=timeout,
2798
+ metadata=metadata,
2799
+ )
2800
+
2801
+ # Done; return the response.
2802
+ return response
2803
+
2804
+ def test_iam_permissions(
2805
+ self,
2806
+ request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None,
2807
+ *,
2808
+ resource: Optional[str] = None,
2809
+ permissions: Optional[MutableSequence[str]] = None,
2810
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2811
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2812
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2813
+ ) -> iam_policy_pb2.TestIamPermissionsResponse:
2814
+ r"""Returns permissions that the caller has on the specified
2815
+ instance resource.
2816
+
2817
+ Attempting this RPC on a non-existent Cloud Spanner instance
2818
+ resource will result in a NOT_FOUND error if the user has
2819
+ ``spanner.instances.list`` permission on the containing Google
2820
+ Cloud Project. Otherwise returns an empty set of permissions.
2821
+
2822
+ .. code-block:: python
2823
+
2824
+ # This snippet has been automatically generated and should be regarded as a
2825
+ # code template only.
2826
+ # It will require modifications to work:
2827
+ # - It may require correct/in-range values for request initialization.
2828
+ # - It may require specifying regional endpoints when creating the service
2829
+ # client as shown in:
2830
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2831
+ from google.cloud import spanner_admin_instance_v1
2832
+ from google.iam.v1 import iam_policy_pb2 # type: ignore
2833
+
2834
+ def sample_test_iam_permissions():
2835
+ # Create a client
2836
+ client = spanner_admin_instance_v1.InstanceAdminClient()
2837
+
2838
+ # Initialize request argument(s)
2839
+ request = iam_policy_pb2.TestIamPermissionsRequest(
2840
+ resource="resource_value",
2841
+ permissions=['permissions_value1', 'permissions_value2'],
2842
+ )
2843
+
2844
+ # Make the request
2845
+ response = client.test_iam_permissions(request=request)
2846
+
2847
+ # Handle the response
2848
+ print(response)
2849
+
2850
+ Args:
2851
+ request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]):
2852
+ The request object. Request message for ``TestIamPermissions`` method.
2853
+ resource (str):
2854
+ REQUIRED: The resource for which the
2855
+ policy detail is being requested. See
2856
+ the operation documentation for the
2857
+ appropriate value for this field.
2858
+
2859
+ This corresponds to the ``resource`` field
2860
+ on the ``request`` instance; if ``request`` is provided, this
2861
+ should not be set.
2862
+ permissions (MutableSequence[str]):
2863
+ The set of permissions to check for the ``resource``.
2864
+ Permissions with wildcards (such as '*' or 'storage.*')
2865
+ are not allowed. For more information see `IAM
2866
+ Overview <https://cloud.google.com/iam/docs/overview#permissions>`__.
2867
+
2868
+ This corresponds to the ``permissions`` field
2869
+ on the ``request`` instance; if ``request`` is provided, this
2870
+ should not be set.
2871
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2872
+ should be retried.
2873
+ timeout (float): The timeout for this request.
2874
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2875
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2876
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2877
+ be of type `bytes`.
2878
+
2879
+ Returns:
2880
+ google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse:
2881
+ Response message for TestIamPermissions method.
2882
+ """
2883
+ # Create or coerce a protobuf request object.
2884
+ # - Quick check: If we got a request object, we should *not* have
2885
+ # gotten any keyword arguments that map to the request.
2886
+ flattened_params = [resource, permissions]
2887
+ has_flattened_params = (
2888
+ len([param for param in flattened_params if param is not None]) > 0
2889
+ )
2890
+ if request is not None and has_flattened_params:
2891
+ raise ValueError(
2892
+ "If the `request` argument is set, then none of "
2893
+ "the individual field arguments should be set."
2894
+ )
2895
+
2896
+ if isinstance(request, dict):
2897
+ # - The request isn't a proto-plus wrapped type,
2898
+ # so it must be constructed via keyword expansion.
2899
+ request = iam_policy_pb2.TestIamPermissionsRequest(**request)
2900
+ elif not request:
2901
+ # Null request, just make one.
2902
+ request = iam_policy_pb2.TestIamPermissionsRequest()
2903
+ if resource is not None:
2904
+ request.resource = resource
2905
+ if permissions:
2906
+ request.permissions.extend(permissions)
2907
+
2908
+ # Wrap the RPC method; this adds retry and timeout information,
2909
+ # and friendly error handling.
2910
+ rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions]
2911
+
2912
+ # Certain fields should be provided within the metadata header;
2913
+ # add these here.
2914
+ metadata = tuple(metadata) + (
2915
+ gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
2916
+ )
2917
+
2918
+ # Validate the universe domain.
2919
+ self._validate_universe_domain()
2920
+
2921
+ # Send the request.
2922
+ response = rpc(
2923
+ request,
2924
+ retry=retry,
2925
+ timeout=timeout,
2926
+ metadata=metadata,
2927
+ )
2928
+
2929
+ # Done; return the response.
2930
+ return response
2931
+
2932
+ def get_instance_partition(
2933
+ self,
2934
+ request: Optional[
2935
+ Union[spanner_instance_admin.GetInstancePartitionRequest, dict]
2936
+ ] = None,
2937
+ *,
2938
+ name: Optional[str] = None,
2939
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
2940
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
2941
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
2942
+ ) -> spanner_instance_admin.InstancePartition:
2943
+ r"""Gets information about a particular instance
2944
+ partition.
2945
+
2946
+ .. code-block:: python
2947
+
2948
+ # This snippet has been automatically generated and should be regarded as a
2949
+ # code template only.
2950
+ # It will require modifications to work:
2951
+ # - It may require correct/in-range values for request initialization.
2952
+ # - It may require specifying regional endpoints when creating the service
2953
+ # client as shown in:
2954
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
2955
+ from google.cloud import spanner_admin_instance_v1
2956
+
2957
+ def sample_get_instance_partition():
2958
+ # Create a client
2959
+ client = spanner_admin_instance_v1.InstanceAdminClient()
2960
+
2961
+ # Initialize request argument(s)
2962
+ request = spanner_admin_instance_v1.GetInstancePartitionRequest(
2963
+ name="name_value",
2964
+ )
2965
+
2966
+ # Make the request
2967
+ response = client.get_instance_partition(request=request)
2968
+
2969
+ # Handle the response
2970
+ print(response)
2971
+
2972
+ Args:
2973
+ request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstancePartitionRequest, dict]):
2974
+ The request object. The request for
2975
+ [GetInstancePartition][google.spanner.admin.instance.v1.InstanceAdmin.GetInstancePartition].
2976
+ name (str):
2977
+ Required. The name of the requested instance partition.
2978
+ Values are of the form
2979
+ ``projects/{project}/instances/{instance}/instancePartitions/{instance_partition}``.
2980
+
2981
+ This corresponds to the ``name`` field
2982
+ on the ``request`` instance; if ``request`` is provided, this
2983
+ should not be set.
2984
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
2985
+ should be retried.
2986
+ timeout (float): The timeout for this request.
2987
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
2988
+ sent along with the request as metadata. Normally, each value must be of type `str`,
2989
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
2990
+ be of type `bytes`.
2991
+
2992
+ Returns:
2993
+ google.cloud.spanner_admin_instance_v1.types.InstancePartition:
2994
+ An isolated set of Cloud Spanner
2995
+ resources that databases can define
2996
+ placements on.
2997
+
2998
+ """
2999
+ # Create or coerce a protobuf request object.
3000
+ # - Quick check: If we got a request object, we should *not* have
3001
+ # gotten any keyword arguments that map to the request.
3002
+ flattened_params = [name]
3003
+ has_flattened_params = (
3004
+ len([param for param in flattened_params if param is not None]) > 0
3005
+ )
3006
+ if request is not None and has_flattened_params:
3007
+ raise ValueError(
3008
+ "If the `request` argument is set, then none of "
3009
+ "the individual field arguments should be set."
3010
+ )
3011
+
3012
+ # - Use the request object if provided (there's no risk of modifying the input as
3013
+ # there are no flattened fields), or create one.
3014
+ if not isinstance(request, spanner_instance_admin.GetInstancePartitionRequest):
3015
+ request = spanner_instance_admin.GetInstancePartitionRequest(request)
3016
+ # If we have keyword arguments corresponding to fields on the
3017
+ # request, apply these.
3018
+ if name is not None:
3019
+ request.name = name
3020
+
3021
+ # Wrap the RPC method; this adds retry and timeout information,
3022
+ # and friendly error handling.
3023
+ rpc = self._transport._wrapped_methods[self._transport.get_instance_partition]
3024
+
3025
+ # Certain fields should be provided within the metadata header;
3026
+ # add these here.
3027
+ metadata = tuple(metadata) + (
3028
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3029
+ )
3030
+
3031
+ # Validate the universe domain.
3032
+ self._validate_universe_domain()
3033
+
3034
+ # Send the request.
3035
+ response = rpc(
3036
+ request,
3037
+ retry=retry,
3038
+ timeout=timeout,
3039
+ metadata=metadata,
3040
+ )
3041
+
3042
+ # Done; return the response.
3043
+ return response
3044
+
3045
+ def create_instance_partition(
3046
+ self,
3047
+ request: Optional[
3048
+ Union[spanner_instance_admin.CreateInstancePartitionRequest, dict]
3049
+ ] = None,
3050
+ *,
3051
+ parent: Optional[str] = None,
3052
+ instance_partition: Optional[spanner_instance_admin.InstancePartition] = None,
3053
+ instance_partition_id: Optional[str] = None,
3054
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3055
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3056
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3057
+ ) -> operation.Operation:
3058
+ r"""Creates an instance partition and begins preparing it to be
3059
+ used. The returned long-running operation can be used to track
3060
+ the progress of preparing the new instance partition. The
3061
+ instance partition name is assigned by the caller. If the named
3062
+ instance partition already exists, ``CreateInstancePartition``
3063
+ returns ``ALREADY_EXISTS``.
3064
+
3065
+ Immediately upon completion of this request:
3066
+
3067
+ - The instance partition is readable via the API, with all
3068
+ requested attributes but no allocated resources. Its state is
3069
+ ``CREATING``.
3070
+
3071
+ Until completion of the returned operation:
3072
+
3073
+ - Cancelling the operation renders the instance partition
3074
+ immediately unreadable via the API.
3075
+ - The instance partition can be deleted.
3076
+ - All other attempts to modify the instance partition are
3077
+ rejected.
3078
+
3079
+ Upon completion of the returned operation:
3080
+
3081
+ - Billing for all successfully-allocated resources begins (some
3082
+ types may have lower than the requested levels).
3083
+ - Databases can start using this instance partition.
3084
+ - The instance partition's allocated resource levels are
3085
+ readable via the API.
3086
+ - The instance partition's state becomes ``READY``.
3087
+
3088
+ The returned long-running operation will have a name of the
3089
+ format ``<instance_partition_name>/operations/<operation_id>``
3090
+ and can be used to track creation of the instance partition. The
3091
+ metadata field type is
3092
+ [CreateInstancePartitionMetadata][google.spanner.admin.instance.v1.CreateInstancePartitionMetadata].
3093
+ The response field type is
3094
+ [InstancePartition][google.spanner.admin.instance.v1.InstancePartition],
3095
+ if successful.
3096
+
3097
+ .. code-block:: python
3098
+
3099
+ # This snippet has been automatically generated and should be regarded as a
3100
+ # code template only.
3101
+ # It will require modifications to work:
3102
+ # - It may require correct/in-range values for request initialization.
3103
+ # - It may require specifying regional endpoints when creating the service
3104
+ # client as shown in:
3105
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3106
+ from google.cloud import spanner_admin_instance_v1
3107
+
3108
+ def sample_create_instance_partition():
3109
+ # Create a client
3110
+ client = spanner_admin_instance_v1.InstanceAdminClient()
3111
+
3112
+ # Initialize request argument(s)
3113
+ instance_partition = spanner_admin_instance_v1.InstancePartition()
3114
+ instance_partition.node_count = 1070
3115
+ instance_partition.name = "name_value"
3116
+ instance_partition.config = "config_value"
3117
+ instance_partition.display_name = "display_name_value"
3118
+
3119
+ request = spanner_admin_instance_v1.CreateInstancePartitionRequest(
3120
+ parent="parent_value",
3121
+ instance_partition_id="instance_partition_id_value",
3122
+ instance_partition=instance_partition,
3123
+ )
3124
+
3125
+ # Make the request
3126
+ operation = client.create_instance_partition(request=request)
3127
+
3128
+ print("Waiting for operation to complete...")
3129
+
3130
+ response = operation.result()
3131
+
3132
+ # Handle the response
3133
+ print(response)
3134
+
3135
+ Args:
3136
+ request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstancePartitionRequest, dict]):
3137
+ The request object. The request for
3138
+ [CreateInstancePartition][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstancePartition].
3139
+ parent (str):
3140
+ Required. The name of the instance in which to create
3141
+ the instance partition. Values are of the form
3142
+ ``projects/<project>/instances/<instance>``.
3143
+
3144
+ This corresponds to the ``parent`` field
3145
+ on the ``request`` instance; if ``request`` is provided, this
3146
+ should not be set.
3147
+ instance_partition (google.cloud.spanner_admin_instance_v1.types.InstancePartition):
3148
+ Required. The instance partition to create. The
3149
+ instance_partition.name may be omitted, but if specified
3150
+ must be
3151
+ ``<parent>/instancePartitions/<instance_partition_id>``.
3152
+
3153
+ This corresponds to the ``instance_partition`` field
3154
+ on the ``request`` instance; if ``request`` is provided, this
3155
+ should not be set.
3156
+ instance_partition_id (str):
3157
+ Required. The ID of the instance partition to create.
3158
+ Valid identifiers are of the form
3159
+ ``[a-z][-a-z0-9]*[a-z0-9]`` and must be between 2 and 64
3160
+ characters in length.
3161
+
3162
+ This corresponds to the ``instance_partition_id`` field
3163
+ on the ``request`` instance; if ``request`` is provided, this
3164
+ should not be set.
3165
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3166
+ should be retried.
3167
+ timeout (float): The timeout for this request.
3168
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3169
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3170
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3171
+ be of type `bytes`.
3172
+
3173
+ Returns:
3174
+ google.api_core.operation.Operation:
3175
+ An object representing a long-running operation.
3176
+
3177
+ The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstancePartition` An isolated set of Cloud Spanner resources that databases can define
3178
+ placements on.
3179
+
3180
+ """
3181
+ # Create or coerce a protobuf request object.
3182
+ # - Quick check: If we got a request object, we should *not* have
3183
+ # gotten any keyword arguments that map to the request.
3184
+ flattened_params = [parent, instance_partition, instance_partition_id]
3185
+ has_flattened_params = (
3186
+ len([param for param in flattened_params if param is not None]) > 0
3187
+ )
3188
+ if request is not None and has_flattened_params:
3189
+ raise ValueError(
3190
+ "If the `request` argument is set, then none of "
3191
+ "the individual field arguments should be set."
3192
+ )
3193
+
3194
+ # - Use the request object if provided (there's no risk of modifying the input as
3195
+ # there are no flattened fields), or create one.
3196
+ if not isinstance(
3197
+ request, spanner_instance_admin.CreateInstancePartitionRequest
3198
+ ):
3199
+ request = spanner_instance_admin.CreateInstancePartitionRequest(request)
3200
+ # If we have keyword arguments corresponding to fields on the
3201
+ # request, apply these.
3202
+ if parent is not None:
3203
+ request.parent = parent
3204
+ if instance_partition is not None:
3205
+ request.instance_partition = instance_partition
3206
+ if instance_partition_id is not None:
3207
+ request.instance_partition_id = instance_partition_id
3208
+
3209
+ # Wrap the RPC method; this adds retry and timeout information,
3210
+ # and friendly error handling.
3211
+ rpc = self._transport._wrapped_methods[
3212
+ self._transport.create_instance_partition
3213
+ ]
3214
+
3215
+ # Certain fields should be provided within the metadata header;
3216
+ # add these here.
3217
+ metadata = tuple(metadata) + (
3218
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3219
+ )
3220
+
3221
+ # Validate the universe domain.
3222
+ self._validate_universe_domain()
3223
+
3224
+ # Send the request.
3225
+ response = rpc(
3226
+ request,
3227
+ retry=retry,
3228
+ timeout=timeout,
3229
+ metadata=metadata,
3230
+ )
3231
+
3232
+ # Wrap the response in an operation future.
3233
+ response = operation.from_gapic(
3234
+ response,
3235
+ self._transport.operations_client,
3236
+ spanner_instance_admin.InstancePartition,
3237
+ metadata_type=spanner_instance_admin.CreateInstancePartitionMetadata,
3238
+ )
3239
+
3240
+ # Done; return the response.
3241
+ return response
3242
+
3243
+ def delete_instance_partition(
3244
+ self,
3245
+ request: Optional[
3246
+ Union[spanner_instance_admin.DeleteInstancePartitionRequest, dict]
3247
+ ] = None,
3248
+ *,
3249
+ name: Optional[str] = None,
3250
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3251
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3252
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3253
+ ) -> None:
3254
+ r"""Deletes an existing instance partition. Requires that the
3255
+ instance partition is not used by any database or backup and is
3256
+ not the default instance partition of an instance.
3257
+
3258
+ Authorization requires ``spanner.instancePartitions.delete``
3259
+ permission on the resource
3260
+ [name][google.spanner.admin.instance.v1.InstancePartition.name].
3261
+
3262
+ .. code-block:: python
3263
+
3264
+ # This snippet has been automatically generated and should be regarded as a
3265
+ # code template only.
3266
+ # It will require modifications to work:
3267
+ # - It may require correct/in-range values for request initialization.
3268
+ # - It may require specifying regional endpoints when creating the service
3269
+ # client as shown in:
3270
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3271
+ from google.cloud import spanner_admin_instance_v1
3272
+
3273
+ def sample_delete_instance_partition():
3274
+ # Create a client
3275
+ client = spanner_admin_instance_v1.InstanceAdminClient()
3276
+
3277
+ # Initialize request argument(s)
3278
+ request = spanner_admin_instance_v1.DeleteInstancePartitionRequest(
3279
+ name="name_value",
3280
+ )
3281
+
3282
+ # Make the request
3283
+ client.delete_instance_partition(request=request)
3284
+
3285
+ Args:
3286
+ request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstancePartitionRequest, dict]):
3287
+ The request object. The request for
3288
+ [DeleteInstancePartition][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstancePartition].
3289
+ name (str):
3290
+ Required. The name of the instance partition to be
3291
+ deleted. Values are of the form
3292
+ ``projects/{project}/instances/{instance}/instancePartitions/{instance_partition}``
3293
+
3294
+ This corresponds to the ``name`` field
3295
+ on the ``request`` instance; if ``request`` is provided, this
3296
+ should not be set.
3297
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3298
+ should be retried.
3299
+ timeout (float): The timeout for this request.
3300
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3301
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3302
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3303
+ be of type `bytes`.
3304
+ """
3305
+ # Create or coerce a protobuf request object.
3306
+ # - Quick check: If we got a request object, we should *not* have
3307
+ # gotten any keyword arguments that map to the request.
3308
+ flattened_params = [name]
3309
+ has_flattened_params = (
3310
+ len([param for param in flattened_params if param is not None]) > 0
3311
+ )
3312
+ if request is not None and has_flattened_params:
3313
+ raise ValueError(
3314
+ "If the `request` argument is set, then none of "
3315
+ "the individual field arguments should be set."
3316
+ )
3317
+
3318
+ # - Use the request object if provided (there's no risk of modifying the input as
3319
+ # there are no flattened fields), or create one.
3320
+ if not isinstance(
3321
+ request, spanner_instance_admin.DeleteInstancePartitionRequest
3322
+ ):
3323
+ request = spanner_instance_admin.DeleteInstancePartitionRequest(request)
3324
+ # If we have keyword arguments corresponding to fields on the
3325
+ # request, apply these.
3326
+ if name is not None:
3327
+ request.name = name
3328
+
3329
+ # Wrap the RPC method; this adds retry and timeout information,
3330
+ # and friendly error handling.
3331
+ rpc = self._transport._wrapped_methods[
3332
+ self._transport.delete_instance_partition
3333
+ ]
3334
+
3335
+ # Certain fields should be provided within the metadata header;
3336
+ # add these here.
3337
+ metadata = tuple(metadata) + (
3338
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3339
+ )
3340
+
3341
+ # Validate the universe domain.
3342
+ self._validate_universe_domain()
3343
+
3344
+ # Send the request.
3345
+ rpc(
3346
+ request,
3347
+ retry=retry,
3348
+ timeout=timeout,
3349
+ metadata=metadata,
3350
+ )
3351
+
3352
+ def update_instance_partition(
3353
+ self,
3354
+ request: Optional[
3355
+ Union[spanner_instance_admin.UpdateInstancePartitionRequest, dict]
3356
+ ] = None,
3357
+ *,
3358
+ instance_partition: Optional[spanner_instance_admin.InstancePartition] = None,
3359
+ field_mask: Optional[field_mask_pb2.FieldMask] = None,
3360
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3361
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3362
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3363
+ ) -> operation.Operation:
3364
+ r"""Updates an instance partition, and begins allocating or
3365
+ releasing resources as requested. The returned long-running
3366
+ operation can be used to track the progress of updating the
3367
+ instance partition. If the named instance partition does not
3368
+ exist, returns ``NOT_FOUND``.
3369
+
3370
+ Immediately upon completion of this request:
3371
+
3372
+ - For resource types for which a decrease in the instance
3373
+ partition's allocation has been requested, billing is based
3374
+ on the newly-requested level.
3375
+
3376
+ Until completion of the returned operation:
3377
+
3378
+ - Cancelling the operation sets its metadata's
3379
+ [cancel_time][google.spanner.admin.instance.v1.UpdateInstancePartitionMetadata.cancel_time],
3380
+ and begins restoring resources to their pre-request values.
3381
+ The operation is guaranteed to succeed at undoing all
3382
+ resource changes, after which point it terminates with a
3383
+ ``CANCELLED`` status.
3384
+ - All other attempts to modify the instance partition are
3385
+ rejected.
3386
+ - Reading the instance partition via the API continues to give
3387
+ the pre-request resource levels.
3388
+
3389
+ Upon completion of the returned operation:
3390
+
3391
+ - Billing begins for all successfully-allocated resources (some
3392
+ types may have lower than the requested levels).
3393
+ - All newly-reserved resources are available for serving the
3394
+ instance partition's tables.
3395
+ - The instance partition's new resource levels are readable via
3396
+ the API.
3397
+
3398
+ The returned long-running operation will have a name of the
3399
+ format ``<instance_partition_name>/operations/<operation_id>``
3400
+ and can be used to track the instance partition modification.
3401
+ The metadata field type is
3402
+ [UpdateInstancePartitionMetadata][google.spanner.admin.instance.v1.UpdateInstancePartitionMetadata].
3403
+ The response field type is
3404
+ [InstancePartition][google.spanner.admin.instance.v1.InstancePartition],
3405
+ if successful.
3406
+
3407
+ Authorization requires ``spanner.instancePartitions.update``
3408
+ permission on the resource
3409
+ [name][google.spanner.admin.instance.v1.InstancePartition.name].
3410
+
3411
+ .. code-block:: python
3412
+
3413
+ # This snippet has been automatically generated and should be regarded as a
3414
+ # code template only.
3415
+ # It will require modifications to work:
3416
+ # - It may require correct/in-range values for request initialization.
3417
+ # - It may require specifying regional endpoints when creating the service
3418
+ # client as shown in:
3419
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3420
+ from google.cloud import spanner_admin_instance_v1
3421
+
3422
+ def sample_update_instance_partition():
3423
+ # Create a client
3424
+ client = spanner_admin_instance_v1.InstanceAdminClient()
3425
+
3426
+ # Initialize request argument(s)
3427
+ instance_partition = spanner_admin_instance_v1.InstancePartition()
3428
+ instance_partition.node_count = 1070
3429
+ instance_partition.name = "name_value"
3430
+ instance_partition.config = "config_value"
3431
+ instance_partition.display_name = "display_name_value"
3432
+
3433
+ request = spanner_admin_instance_v1.UpdateInstancePartitionRequest(
3434
+ instance_partition=instance_partition,
3435
+ )
3436
+
3437
+ # Make the request
3438
+ operation = client.update_instance_partition(request=request)
3439
+
3440
+ print("Waiting for operation to complete...")
3441
+
3442
+ response = operation.result()
3443
+
3444
+ # Handle the response
3445
+ print(response)
3446
+
3447
+ Args:
3448
+ request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstancePartitionRequest, dict]):
3449
+ The request object. The request for
3450
+ [UpdateInstancePartition][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstancePartition].
3451
+ instance_partition (google.cloud.spanner_admin_instance_v1.types.InstancePartition):
3452
+ Required. The instance partition to update, which must
3453
+ always include the instance partition name. Otherwise,
3454
+ only fields mentioned in
3455
+ [field_mask][google.spanner.admin.instance.v1.UpdateInstancePartitionRequest.field_mask]
3456
+ need be included.
3457
+
3458
+ This corresponds to the ``instance_partition`` field
3459
+ on the ``request`` instance; if ``request`` is provided, this
3460
+ should not be set.
3461
+ field_mask (google.protobuf.field_mask_pb2.FieldMask):
3462
+ Required. A mask specifying which fields in
3463
+ [InstancePartition][google.spanner.admin.instance.v1.InstancePartition]
3464
+ should be updated. The field mask must always be
3465
+ specified; this prevents any future fields in
3466
+ [InstancePartition][google.spanner.admin.instance.v1.InstancePartition]
3467
+ from being erased accidentally by clients that do not
3468
+ know about them.
3469
+
3470
+ This corresponds to the ``field_mask`` field
3471
+ on the ``request`` instance; if ``request`` is provided, this
3472
+ should not be set.
3473
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3474
+ should be retried.
3475
+ timeout (float): The timeout for this request.
3476
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3477
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3478
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3479
+ be of type `bytes`.
3480
+
3481
+ Returns:
3482
+ google.api_core.operation.Operation:
3483
+ An object representing a long-running operation.
3484
+
3485
+ The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstancePartition` An isolated set of Cloud Spanner resources that databases can define
3486
+ placements on.
3487
+
3488
+ """
3489
+ # Create or coerce a protobuf request object.
3490
+ # - Quick check: If we got a request object, we should *not* have
3491
+ # gotten any keyword arguments that map to the request.
3492
+ flattened_params = [instance_partition, field_mask]
3493
+ has_flattened_params = (
3494
+ len([param for param in flattened_params if param is not None]) > 0
3495
+ )
3496
+ if request is not None and has_flattened_params:
3497
+ raise ValueError(
3498
+ "If the `request` argument is set, then none of "
3499
+ "the individual field arguments should be set."
3500
+ )
3501
+
3502
+ # - Use the request object if provided (there's no risk of modifying the input as
3503
+ # there are no flattened fields), or create one.
3504
+ if not isinstance(
3505
+ request, spanner_instance_admin.UpdateInstancePartitionRequest
3506
+ ):
3507
+ request = spanner_instance_admin.UpdateInstancePartitionRequest(request)
3508
+ # If we have keyword arguments corresponding to fields on the
3509
+ # request, apply these.
3510
+ if instance_partition is not None:
3511
+ request.instance_partition = instance_partition
3512
+ if field_mask is not None:
3513
+ request.field_mask = field_mask
3514
+
3515
+ # Wrap the RPC method; this adds retry and timeout information,
3516
+ # and friendly error handling.
3517
+ rpc = self._transport._wrapped_methods[
3518
+ self._transport.update_instance_partition
3519
+ ]
3520
+
3521
+ # Certain fields should be provided within the metadata header;
3522
+ # add these here.
3523
+ metadata = tuple(metadata) + (
3524
+ gapic_v1.routing_header.to_grpc_metadata(
3525
+ (("instance_partition.name", request.instance_partition.name),)
3526
+ ),
3527
+ )
3528
+
3529
+ # Validate the universe domain.
3530
+ self._validate_universe_domain()
3531
+
3532
+ # Send the request.
3533
+ response = rpc(
3534
+ request,
3535
+ retry=retry,
3536
+ timeout=timeout,
3537
+ metadata=metadata,
3538
+ )
3539
+
3540
+ # Wrap the response in an operation future.
3541
+ response = operation.from_gapic(
3542
+ response,
3543
+ self._transport.operations_client,
3544
+ spanner_instance_admin.InstancePartition,
3545
+ metadata_type=spanner_instance_admin.UpdateInstancePartitionMetadata,
3546
+ )
3547
+
3548
+ # Done; return the response.
3549
+ return response
3550
+
3551
+ def list_instance_partition_operations(
3552
+ self,
3553
+ request: Optional[
3554
+ Union[spanner_instance_admin.ListInstancePartitionOperationsRequest, dict]
3555
+ ] = None,
3556
+ *,
3557
+ parent: Optional[str] = None,
3558
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3559
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3560
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3561
+ ) -> pagers.ListInstancePartitionOperationsPager:
3562
+ r"""Lists instance partition long-running operations in the given
3563
+ instance. An instance partition operation has a name of the form
3564
+ ``projects/<project>/instances/<instance>/instancePartitions/<instance_partition>/operations/<operation>``.
3565
+ The long-running operation metadata field type
3566
+ ``metadata.type_url`` describes the type of the metadata.
3567
+ Operations returned include those that have
3568
+ completed/failed/canceled within the last 7 days, and pending
3569
+ operations. Operations returned are ordered by
3570
+ ``operation.metadata.value.start_time`` in descending order
3571
+ starting from the most recently started operation.
3572
+
3573
+ Authorization requires
3574
+ ``spanner.instancePartitionOperations.list`` permission on the
3575
+ resource
3576
+ [parent][google.spanner.admin.instance.v1.ListInstancePartitionOperationsRequest.parent].
3577
+
3578
+ .. code-block:: python
3579
+
3580
+ # This snippet has been automatically generated and should be regarded as a
3581
+ # code template only.
3582
+ # It will require modifications to work:
3583
+ # - It may require correct/in-range values for request initialization.
3584
+ # - It may require specifying regional endpoints when creating the service
3585
+ # client as shown in:
3586
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3587
+ from google.cloud import spanner_admin_instance_v1
3588
+
3589
+ def sample_list_instance_partition_operations():
3590
+ # Create a client
3591
+ client = spanner_admin_instance_v1.InstanceAdminClient()
3592
+
3593
+ # Initialize request argument(s)
3594
+ request = spanner_admin_instance_v1.ListInstancePartitionOperationsRequest(
3595
+ parent="parent_value",
3596
+ )
3597
+
3598
+ # Make the request
3599
+ page_result = client.list_instance_partition_operations(request=request)
3600
+
3601
+ # Handle the response
3602
+ for response in page_result:
3603
+ print(response)
3604
+
3605
+ Args:
3606
+ request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstancePartitionOperationsRequest, dict]):
3607
+ The request object. The request for
3608
+ [ListInstancePartitionOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstancePartitionOperations].
3609
+ parent (str):
3610
+ Required. The parent instance of the instance partition
3611
+ operations. Values are of the form
3612
+ ``projects/<project>/instances/<instance>``.
3613
+
3614
+ This corresponds to the ``parent`` field
3615
+ on the ``request`` instance; if ``request`` is provided, this
3616
+ should not be set.
3617
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3618
+ should be retried.
3619
+ timeout (float): The timeout for this request.
3620
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3621
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3622
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3623
+ be of type `bytes`.
3624
+
3625
+ Returns:
3626
+ google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancePartitionOperationsPager:
3627
+ The response for
3628
+ [ListInstancePartitionOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstancePartitionOperations].
3629
+
3630
+ Iterating over this object will yield results and
3631
+ resolve additional pages automatically.
3632
+
3633
+ """
3634
+ # Create or coerce a protobuf request object.
3635
+ # - Quick check: If we got a request object, we should *not* have
3636
+ # gotten any keyword arguments that map to the request.
3637
+ flattened_params = [parent]
3638
+ has_flattened_params = (
3639
+ len([param for param in flattened_params if param is not None]) > 0
3640
+ )
3641
+ if request is not None and has_flattened_params:
3642
+ raise ValueError(
3643
+ "If the `request` argument is set, then none of "
3644
+ "the individual field arguments should be set."
3645
+ )
3646
+
3647
+ # - Use the request object if provided (there's no risk of modifying the input as
3648
+ # there are no flattened fields), or create one.
3649
+ if not isinstance(
3650
+ request, spanner_instance_admin.ListInstancePartitionOperationsRequest
3651
+ ):
3652
+ request = spanner_instance_admin.ListInstancePartitionOperationsRequest(
3653
+ request
3654
+ )
3655
+ # If we have keyword arguments corresponding to fields on the
3656
+ # request, apply these.
3657
+ if parent is not None:
3658
+ request.parent = parent
3659
+
3660
+ # Wrap the RPC method; this adds retry and timeout information,
3661
+ # and friendly error handling.
3662
+ rpc = self._transport._wrapped_methods[
3663
+ self._transport.list_instance_partition_operations
3664
+ ]
3665
+
3666
+ # Certain fields should be provided within the metadata header;
3667
+ # add these here.
3668
+ metadata = tuple(metadata) + (
3669
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
3670
+ )
3671
+
3672
+ # Validate the universe domain.
3673
+ self._validate_universe_domain()
3674
+
3675
+ # Send the request.
3676
+ response = rpc(
3677
+ request,
3678
+ retry=retry,
3679
+ timeout=timeout,
3680
+ metadata=metadata,
3681
+ )
3682
+
3683
+ # This method is paged; wrap the response in a pager, which provides
3684
+ # an `__iter__` convenience method.
3685
+ response = pagers.ListInstancePartitionOperationsPager(
3686
+ method=rpc,
3687
+ request=request,
3688
+ response=response,
3689
+ retry=retry,
3690
+ timeout=timeout,
3691
+ metadata=metadata,
3692
+ )
3693
+
3694
+ # Done; return the response.
3695
+ return response
3696
+
3697
+ def move_instance(
3698
+ self,
3699
+ request: Optional[
3700
+ Union[spanner_instance_admin.MoveInstanceRequest, dict]
3701
+ ] = None,
3702
+ *,
3703
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
3704
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3705
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
3706
+ ) -> operation.Operation:
3707
+ r"""Moves an instance to the target instance configuration. You can
3708
+ use the returned long-running operation to track the progress of
3709
+ moving the instance.
3710
+
3711
+ ``MoveInstance`` returns ``FAILED_PRECONDITION`` if the instance
3712
+ meets any of the following criteria:
3713
+
3714
+ - Is undergoing a move to a different instance configuration
3715
+ - Has backups
3716
+ - Has an ongoing update
3717
+ - Contains any CMEK-enabled databases
3718
+ - Is a free trial instance
3719
+
3720
+ While the operation is pending:
3721
+
3722
+ - All other attempts to modify the instance, including changes
3723
+ to its compute capacity, are rejected.
3724
+
3725
+ - The following database and backup admin operations are
3726
+ rejected:
3727
+
3728
+ - ``DatabaseAdmin.CreateDatabase``
3729
+ - ``DatabaseAdmin.UpdateDatabaseDdl`` (disabled if
3730
+ default_leader is specified in the request.)
3731
+ - ``DatabaseAdmin.RestoreDatabase``
3732
+ - ``DatabaseAdmin.CreateBackup``
3733
+ - ``DatabaseAdmin.CopyBackup``
3734
+
3735
+ - Both the source and target instance configurations are
3736
+ subject to hourly compute and storage charges.
3737
+
3738
+ - The instance might experience higher read-write latencies and
3739
+ a higher transaction abort rate. However, moving an instance
3740
+ doesn't cause any downtime.
3741
+
3742
+ The returned long-running operation has a name of the format
3743
+ ``<instance_name>/operations/<operation_id>`` and can be used to
3744
+ track the move instance operation. The metadata field type is
3745
+ [MoveInstanceMetadata][google.spanner.admin.instance.v1.MoveInstanceMetadata].
3746
+ The response field type is
3747
+ [Instance][google.spanner.admin.instance.v1.Instance], if
3748
+ successful. Cancelling the operation sets its metadata's
3749
+ [cancel_time][google.spanner.admin.instance.v1.MoveInstanceMetadata.cancel_time].
3750
+ Cancellation is not immediate because it involves moving any
3751
+ data previously moved to the target instance configuration back
3752
+ to the original instance configuration. You can use this
3753
+ operation to track the progress of the cancellation. Upon
3754
+ successful completion of the cancellation, the operation
3755
+ terminates with ``CANCELLED`` status.
3756
+
3757
+ If not cancelled, upon completion of the returned operation:
3758
+
3759
+ - The instance successfully moves to the target instance
3760
+ configuration.
3761
+ - You are billed for compute and storage in target instance
3762
+ configuration.
3763
+
3764
+ Authorization requires the ``spanner.instances.update``
3765
+ permission on the resource
3766
+ [instance][google.spanner.admin.instance.v1.Instance].
3767
+
3768
+ For more details, see `Move an
3769
+ instance <https://cloud.google.com/spanner/docs/move-instance>`__.
3770
+
3771
+ .. code-block:: python
3772
+
3773
+ # This snippet has been automatically generated and should be regarded as a
3774
+ # code template only.
3775
+ # It will require modifications to work:
3776
+ # - It may require correct/in-range values for request initialization.
3777
+ # - It may require specifying regional endpoints when creating the service
3778
+ # client as shown in:
3779
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
3780
+ from google.cloud import spanner_admin_instance_v1
3781
+
3782
+ def sample_move_instance():
3783
+ # Create a client
3784
+ client = spanner_admin_instance_v1.InstanceAdminClient()
3785
+
3786
+ # Initialize request argument(s)
3787
+ request = spanner_admin_instance_v1.MoveInstanceRequest(
3788
+ name="name_value",
3789
+ target_config="target_config_value",
3790
+ )
3791
+
3792
+ # Make the request
3793
+ operation = client.move_instance(request=request)
3794
+
3795
+ print("Waiting for operation to complete...")
3796
+
3797
+ response = operation.result()
3798
+
3799
+ # Handle the response
3800
+ print(response)
3801
+
3802
+ Args:
3803
+ request (Union[google.cloud.spanner_admin_instance_v1.types.MoveInstanceRequest, dict]):
3804
+ The request object. The request for
3805
+ [MoveInstance][google.spanner.admin.instance.v1.InstanceAdmin.MoveInstance].
3806
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
3807
+ should be retried.
3808
+ timeout (float): The timeout for this request.
3809
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
3810
+ sent along with the request as metadata. Normally, each value must be of type `str`,
3811
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
3812
+ be of type `bytes`.
3813
+
3814
+ Returns:
3815
+ google.api_core.operation.Operation:
3816
+ An object representing a long-running operation.
3817
+
3818
+ The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.MoveInstanceResponse` The response for
3819
+ [MoveInstance][google.spanner.admin.instance.v1.InstanceAdmin.MoveInstance].
3820
+
3821
+ """
3822
+ # Create or coerce a protobuf request object.
3823
+ # - Use the request object if provided (there's no risk of modifying the input as
3824
+ # there are no flattened fields), or create one.
3825
+ if not isinstance(request, spanner_instance_admin.MoveInstanceRequest):
3826
+ request = spanner_instance_admin.MoveInstanceRequest(request)
3827
+
3828
+ # Wrap the RPC method; this adds retry and timeout information,
3829
+ # and friendly error handling.
3830
+ rpc = self._transport._wrapped_methods[self._transport.move_instance]
3831
+
3832
+ # Certain fields should be provided within the metadata header;
3833
+ # add these here.
3834
+ metadata = tuple(metadata) + (
3835
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3836
+ )
3837
+
3838
+ # Validate the universe domain.
3839
+ self._validate_universe_domain()
3840
+
3841
+ # Send the request.
3842
+ response = rpc(
3843
+ request,
3844
+ retry=retry,
3845
+ timeout=timeout,
3846
+ metadata=metadata,
3847
+ )
3848
+
3849
+ # Wrap the response in an operation future.
3850
+ response = operation.from_gapic(
3851
+ response,
3852
+ self._transport.operations_client,
3853
+ spanner_instance_admin.MoveInstanceResponse,
3854
+ metadata_type=spanner_instance_admin.MoveInstanceMetadata,
3855
+ )
3856
+
3857
+ # Done; return the response.
3858
+ return response
3859
+
3860
+ def __enter__(self) -> "InstanceAdminClient":
3861
+ return self
3862
+
3863
+ def __exit__(self, type, value, traceback):
3864
+ """Releases underlying transport's resources.
3865
+
3866
+ .. warning::
3867
+ ONLY use as a context manager if the transport is NOT shared
3868
+ with other clients! Exiting the with block will CLOSE the transport
3869
+ and may cause errors in other clients!
3870
+ """
3871
+ self.transport.close()
3872
+
3873
+
3874
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
3875
+ gapic_version=package_version.__version__
3876
+ )
3877
+
3878
+ if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
3879
+ DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
3880
+
3881
+ __all__ = ("InstanceAdminClient",)