feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command group for spanner instances."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Instances(base.Group):
"""Manage Cloud Spanner instances."""
pass

View File

@@ -0,0 +1,34 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Add IAM policy binding to a Cloud Spanner instance.
description: |
Add an IAM policy binding to a Cloud Spanner instance. One binding consists of a member,
a role, and an optional condition.
examples: |
To add an IAM policy binding for the role of 'roles/editor' for the user 'test-user@gmail.com'
with instance 'my-instance', run:
$ {command} my-instance --member='user:test-user@gmail.com' --role='roles/editor'
To add an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/spanner.admin' and the user 'test-user@gmail.com' with instance 'my-instance', run:
$ {command} my-instance --member='user:test-user@gmail.com' --role='roles/spanner.admin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: spanner.projects.instances
arguments:
resource:
help_text: The Cloud Spanner instance to which to add the IAM policy binding.
spec: !REF googlecloudsdk.command_lib.spanner.resources:instance
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command group for managing Spanner instance configurations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Config(base.Group):
"""Manage Spanner instance configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Spanner instance.
description: |
*{command}* exports the configuration for a Spanner instance.
Instance configurations can be exported in
Kubernetes Resource Model (krm) or Terraform HCL formats. The
default format is `krm`.
Specifying `--all` allows you to export the configurations for all
instances within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for an instance, run:
$ {command} my-instance
To export the configuration for an instance to a file, run:
$ {command} my-instance --path=/path/to/dir/
To export the configuration for an instance in Terraform
HCL format, run:
$ {command} my-instance --resource-format=terraform
To export the configurations for all instances within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Instance to export the configuration for.
spec: !REF googlecloudsdk.command_lib.spanner.resources:instance

View File

@@ -0,0 +1,340 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for spanner instances create."""
import textwrap
from googlecloudsdk.api_lib.spanner import instance_operations
from googlecloudsdk.api_lib.spanner import instances
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.spanner import flags
from googlecloudsdk.command_lib.spanner import resource_args
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Cloud Spanner instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To create a Cloud Spanner instance, run:
$ {command} my-instance-id --config=regional-us-east1 --description=my-instance-display-name --nodes=3
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Please add arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.Instance().AddToParser(parser)
flags.Config().AddToParser(parser)
flags.Description().AddToParser(parser)
flags.Edition(
choices={
'STANDARD': 'Standard edition',
'ENTERPRISE': 'Enterprise edition',
'ENTERPRISE_PLUS': 'Enterprise Plus edition',
'EDITION_UNSPECIFIED': (
"Spanner's legacy pricing model. For more information, see the"
' [Spanner editions overview]'
'(https://cloud.google.com/spanner/docs/editions-overview)'
),
},
).AddToParser(parser)
flags.DefaultBackupScheduleType(
choices={
'DEFAULT_BACKUP_SCHEDULE_TYPE_UNSPECIFIED': 'Not specified.',
'NONE': (
'No default backup schedule is created automatically when a new'
' database is created in an instance.'
),
'AUTOMATIC': (
'A default backup schedule is created automatically when a new'
' database is created in an instance. You can edit or delete'
" the default backup schedule once it's created. The default"
' backup schedule creates a full backup every 24 hours. These'
' full backups are retained for 7 days.'
),
},
).AddToParser(parser)
resource_args.AddExpireBehaviorArg(parser)
resource_args.AddInstanceTypeArg(parser)
flags.AddCapacityArgsForInstance(
require_all_autoscaling_args=True,
parser=parser,
add_asymmetric_option_flag=True,
autoscaling_cpu_target_group=True,
add_asymmetric_total_cpu_target_flag=True,
add_asymmetric_disable_autoscaling_flags=True,
)
base.ASYNC_FLAG.AddToParser(parser)
parser.display_info.AddCacheUpdater(flags.InstanceCompleter)
flags.AddTags(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
instance_type = resource_args.GetInstanceType(args)
expire_behavior = resource_args.GetExpireBehavior(args)
op = instances.Create(
instance=args.instance,
config=args.config,
description=args.description,
nodes=args.nodes,
processing_units=args.processing_units,
autoscaling_min_nodes=args.autoscaling_min_nodes,
autoscaling_max_nodes=args.autoscaling_max_nodes,
autoscaling_min_processing_units=args.autoscaling_min_processing_units,
autoscaling_max_processing_units=args.autoscaling_max_processing_units,
autoscaling_high_priority_cpu_target=args.autoscaling_high_priority_cpu_target,
autoscaling_total_cpu_target=args.autoscaling_total_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target,
asymmetric_autoscaling_options=args.asymmetric_autoscaling_option,
instance_type=instance_type,
expire_behavior=expire_behavior,
edition=args.edition,
default_backup_schedule_type=args.default_backup_schedule_type,
tags=args.tags,
)
if args.async_:
return op
instance_operations.Await(op, 'Creating instance')
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaCreate(base.CreateCommand):
"""Create a Cloud Spanner instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To create a Cloud Spanner instance, run:
$ {command} my-instance-id --config=regional-us-east1 --description=my-instance-display-name --nodes=3
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Please add arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.Instance().AddToParser(parser)
flags.Config().AddToParser(parser)
flags.Description().AddToParser(parser)
flags.Edition(
choices={
'STANDARD': 'Standard edition',
'ENTERPRISE': 'Enterprise edition',
'ENTERPRISE_PLUS': 'Enterprise Plus edition',
'EDITION_UNSPECIFIED': (
"Spanner's legacy pricing model. For more information, see the"
' [Spanner editions overview]'
'(https://cloud.google.com/spanner/docs/editions-overview)'
),
},
).AddToParser(parser)
flags.DefaultBackupScheduleType(
choices={
'DEFAULT_BACKUP_SCHEDULE_TYPE_UNSPECIFIED': 'Not specified.',
'NONE': (
'No default backup schedule is created automatically when a new'
' database is created in an instance.'
),
'AUTOMATIC': (
'A default backup schedule is created automatically when a new'
' database is created in an instance. You can edit or delete'
" the default backup schedule once it's created. The default"
' backup schedule creates a full backup every 24 hours. These'
' full backups are retained for 7 days.'
),
},
).AddToParser(parser)
resource_args.AddExpireBehaviorArg(parser)
resource_args.AddInstanceTypeArg(parser)
flags.AddCapacityArgsForInstance(
require_all_autoscaling_args=True,
parser=parser,
add_asymmetric_option_flag=True,
autoscaling_cpu_target_group=True,
add_asymmetric_total_cpu_target_flag=True,
add_asymmetric_disable_autoscaling_flags=True,
add_disable_downscaling_flag=True,
)
base.ASYNC_FLAG.AddToParser(parser)
parser.display_info.AddCacheUpdater(flags.InstanceCompleter)
flags.AddTags(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
instance_type = resource_args.GetInstanceType(args)
expire_behavior = resource_args.GetExpireBehavior(args)
op = instances.Create(
instance=args.instance,
config=args.config,
description=args.description,
nodes=args.nodes,
processing_units=args.processing_units,
autoscaling_min_nodes=args.autoscaling_min_nodes,
autoscaling_max_nodes=args.autoscaling_max_nodes,
autoscaling_min_processing_units=args.autoscaling_min_processing_units,
autoscaling_max_processing_units=args.autoscaling_max_processing_units,
autoscaling_high_priority_cpu_target=args.autoscaling_high_priority_cpu_target,
autoscaling_total_cpu_target=args.autoscaling_total_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target,
asymmetric_autoscaling_options=args.asymmetric_autoscaling_option,
disable_downscaling=args.disable_downscaling,
instance_type=instance_type,
expire_behavior=expire_behavior,
edition=args.edition,
default_backup_schedule_type=args.default_backup_schedule_type,
tags=args.tags,
)
if args.async_:
return op
instance_operations.Await(op, 'Creating instance')
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaCreate(Create):
"""Create a Cloud Spanner instance with ALPHA features."""
__doc__ = Create.__doc__
@staticmethod
def Args(parser):
"""See base class."""
flags.Instance().AddToParser(parser)
flags.Config().AddToParser(parser)
flags.Description().AddToParser(parser)
flags.SsdCache().AddToParser(parser)
flags.Edition(
choices={
'STANDARD': 'Standard edition',
'ENTERPRISE': 'Enterprise edition',
'ENTERPRISE_PLUS': 'Enterprise Plus edition',
'EDITION_UNSPECIFIED': (
"Spanner's legacy pricing model. For more information, see the"
' [Spanner editions overview]'
'(https://cloud.google.com/spanner/docs/editions-overview)'
),
},
).AddToParser(parser)
flags.DefaultBackupScheduleType(
choices={
'DEFAULT_BACKUP_SCHEDULE_TYPE_UNSPECIFIED': 'Not specified.',
'NONE': (
'No default backup schedule is created automatically when a new'
' database is created in an instance.'
),
'AUTOMATIC': (
'A default backup schedule is created automatically when a new'
' database is created in an instance. You can edit or delete'
" the default backup schedule once it's created. The default"
' backup schedule creates a full backup every 24 hours. These'
' full backups are retained for 7 days.'
),
},
).AddToParser(parser)
resource_args.AddExpireBehaviorArg(parser)
resource_args.AddInstanceTypeArg(parser)
resource_args.AddDefaultStorageTypeArg(parser)
flags.AddCapacityArgsForInstance(
require_all_autoscaling_args=True,
parser=parser,
add_asymmetric_option_flag=True,
asymmetric_options_group=False,
autoscaling_cpu_target_group=True,
add_asymmetric_total_cpu_target_flag=True,
add_asymmetric_disable_autoscaling_flags=True,
add_disable_downscaling_flag=True,
)
base.ASYNC_FLAG.AddToParser(parser)
parser.display_info.AddCacheUpdater(flags.InstanceCompleter)
flags.AddTags(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
instance_type = resource_args.GetInstanceType(args)
expire_behavior = resource_args.GetExpireBehavior(args)
default_storage_type = resource_args.GetDefaultStorageTypeArg(args)
op = instances.Create(
instance=args.instance,
config=args.config,
description=args.description,
nodes=args.nodes,
processing_units=args.processing_units,
autoscaling_min_nodes=args.autoscaling_min_nodes,
autoscaling_max_nodes=args.autoscaling_max_nodes,
autoscaling_min_processing_units=args.autoscaling_min_processing_units,
autoscaling_max_processing_units=args.autoscaling_max_processing_units,
autoscaling_high_priority_cpu_target=args.autoscaling_high_priority_cpu_target,
autoscaling_total_cpu_target=args.autoscaling_total_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target,
asymmetric_autoscaling_options=args.asymmetric_autoscaling_option,
disable_downscaling=args.disable_downscaling,
instance_type=instance_type,
expire_behavior=expire_behavior,
default_storage_type=default_storage_type,
ssd_cache=args.ssd_cache,
edition=args.edition,
default_backup_schedule_type=args.default_backup_schedule_type,
tags=args.tags,
)
if args.async_:
return op
instance_operations.Await(op, 'Creating instance')

View File

@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for spanner instances delete."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.spanner import instances
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.spanner import flags
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete a Cloud Spanner instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To delete a Cloud Spanner instance, run:
$ {command} my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Please add arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.Instance().AddToParser(parser)
parser.display_info.AddCacheUpdater(flags.InstanceCompleter)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
console_io.PromptContinue(
message='Delete instance [{0}]. Are you sure?'.format(args.instance),
cancel_on_no=True)
return instances.Delete(args.instance)

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for spanner instances describe."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.spanner import instances
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.spanner import flags
class Describe(base.DescribeCommand):
"""Describe a Cloud Spanner instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To describe a Cloud Spanner instance, run:
$ {command} my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Please add arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.Instance().AddToParser(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
return instances.Get(args.instance)

View File

@@ -0,0 +1,27 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get the IAM policy for a Cloud Spanner instance.
description: |
*{command}* displays the IAM policy associated with a Cloud Spanner
instance. If formatted as JSON, the output can be edited and used as
a policy file for *set-iam-policy*. The output includes an "etag"
field identifying the version emitted and allowing detection of
concurrent policy updates; see
$ {parent} set-iam-policy for additional details.
examples: |
To print the IAM policy for a given Cloud Spanner instance, run:
$ {command} my-instance
request:
collection: spanner.projects.instances
arguments:
resource:
help_text: The Cloud Spanner instance for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.spanner.resources:instance
iam:
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for spanner instances get-locations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.spanner import instances
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.spanner import flags
@base.UniverseCompatible
class GetLocations(base.Command):
"""Get the location of every replica in a Cloud Spanner instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To get the location of every replica in a Cloud Spanner instance in this project, run:
$ {command} my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
For `get-locations` command, we have one positional argument, `instanceId`
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
flags.Instance().AddToParser(parser)
parser.add_argument(
'--verbose',
required=False,
action='store_true',
help='Indicates that both regions and types of replicas be returned.')
parser.display_info.AddFormat("""table(location:sort=1,type.if(verbose))""")
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. From `Args`, we extract command line
arguments
Returns:
List of dict values for locations of instance
"""
return instances.GetLocations(args.instance, args.verbose)

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for spanner instances list."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.spanner import instances
from googlecloudsdk.calliope import base
class List(base.ListCommand):
"""List the Cloud Spanner instances in this project."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To list all Cloud Spanner instances in this project, run:
$ {command}
"""),
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat("""
table(
name.basename(),
displayName,
config.basename(),
nodeCount,
processing_units,
state,
instance_type
)
""")
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
return instances.List()

View File

@@ -0,0 +1,206 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for spanner instances get-locations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.spanner import instances
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.spanner import flags
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Move(base.Command):
"""Move the Cloud Spanner instance to the specified instance configuration."""
detailed_help = {
'EXAMPLES': textwrap.dedent("""\
To move the Cloud Spanner instance, which has two CMEK-enabled
databases db1 and db2 and a database db3 with Google-managed
encryption keys, to the target instance configuration nam3
(us-east4, us-east1, us-central1), run:
$ gcloud spanner instances move my-instance-id
--target-config=nam3
--target-database-move-configs=^:^database-id=db1:kms-key-names=projects/myproject/locations/us-east4/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-east1/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-central1/keyRings/mykeyring/cryptoKeys/cmek-key
--target-database-move-configs=^:^database-id=db2:kms-key-names=projects/myproject/locations/us-east4/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-east1/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-central1/keyRings/mykeyring/cryptoKeys/cmek-key
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
For `move` command, we have one positional argument, `instanceId`
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
flags.Instance().AddToParser(parser)
flags.TargetConfig().AddToParser(parser)
parser.add_argument(
'--target-database-move-configs',
metavar='^:^database-id=DATABASE_ID:kms-key-names=KEY1,KEY2',
type=arg_parsers.ArgObject(
spec={
'database-id': str,
'kms-key-names': str,
},
required_keys=['database-id'],
repeated=True,
),
action=arg_parsers.FlattenAction(),
help=(
'Database level configurations for each database to be moved.'
' Currently only used for CMEK-enabled databases to specificy the'
' target database KMS keys.'
),
)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. From `Args`, we extract command line
arguments
"""
instances.Move(
args.instance, args.target_config, args.target_database_move_configs
)
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaMove(base.Command):
"""Move the Cloud Spanner instance to the specified instance configuration."""
detailed_help = {
'EXAMPLES': textwrap.dedent("""\
To move the Cloud Spanner instance, which has two CMEK-enabled
databases db1 and db2 and a database db3 with Google-managed
encryption keys, to the target instance configuration nam3
(us-east4, us-east1, us-central1), run:
$ gcloud beta spanner instances move my-instance-id
--target-config=nam3
--target-database-move-configs=^:^database-id=db1:kms-key-names=projects/myproject/locations/us-east4/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-east1/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-central1/keyRings/mykeyring/cryptoKeys/cmek-key
--target-database-move-configs=^:^database-id=db2:kms-key-names=projects/myproject/locations/us-east4/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-east1/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-central1/keyRings/mykeyring/cryptoKeys/cmek-key
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
For `move` command, we have one positional argument, `instanceId`
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
flags.Instance().AddToParser(parser)
flags.TargetConfig().AddToParser(parser)
parser.add_argument(
'--target-database-move-configs',
metavar='^:^database-id=DATABASE_ID:kms-key-names=KEY1,KEY2',
type=arg_parsers.ArgObject(
spec={
'database-id': str,
'kms-key-names': str,
},
required_keys=['database-id'],
repeated=True,
),
action=arg_parsers.FlattenAction(),
help=(
'Database level configurations for each database to be moved.'
' Currently only used for CMEK-enabled databases to specificy the'
' target database KMS keys.'
),
)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. From `Args`, we extract command line
arguments
"""
instances.Move(
args.instance, args.target_config, args.target_database_move_configs
)
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaMove(base.Command):
"""Move the Cloud Spanner instance to the specified instance configuration."""
detailed_help = {
'EXAMPLES': textwrap.dedent("""\
To move the Cloud Spanner instance, which has two CMEK-enabled
databases db1 and db2 and a database db3 with Google-managed
encryption keys, to the target instance configuration nam3
(us-east4, us-east1, us-central1), run:
$ gcloud alpha spanner instances move my-instance-id
--target-config=nam3
--target-database-move-configs=^:^database-id=db1:kms-key-names=projects/myproject/locations/us-east4/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-east1/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-central1/keyRings/mykeyring/cryptoKeys/cmek-key
--target-database-move-configs=^:^database-id=db2:kms-key-names=projects/myproject/locations/us-east4/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-east1/keyRings/mykeyring/cryptoKeys/cmek-key,projects/myproject/locations/us-central1/keyRings/mykeyring/cryptoKeys/cmek-key
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
For `move` command, we have one positional argument, `instanceId`
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
flags.Instance().AddToParser(parser)
flags.TargetConfig().AddToParser(parser)
parser.add_argument(
'--target-database-move-configs',
metavar='^:^database-id=DATABASE_ID:kms-key-names=KEY1,KEY2',
type=arg_parsers.ArgObject(
spec={
'database-id': str,
'kms-key-names': str,
},
required_keys=['database-id'],
repeated=True,
),
action=arg_parsers.FlattenAction(),
help=(
'Database level configurations for each database to be moved.'
' Currently only used for CMEK-enabled databases to specificy the'
' target database KMS keys.'
),
)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. From `Args`, we extract command line
arguments
"""
instances.Move(
args.instance, args.target_config, args.target_database_move_configs
)

View File

@@ -0,0 +1,33 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Remove IAM policy binding of a Cloud Spanner instance.
description: |
Remove an IAM policy binding of a Cloud Spanner instance. One binding consists of a member,
a role, and an optional condition.
examples: |
To remove an IAM policy binding for the role of 'roles/editor' for the user 'test-user@gmail.com'
with instance 'my-instance', run:
$ {command} my-instance --member='user:test-user@gmail.com' --role='roles/editor'
To remove an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/spanner.admin' and the user 'test-user@gmail.com' with instance 'my-instance', run:
$ {command} my-instance --member='user:test-user@gmail.com' --role='roles/spanner.admin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: spanner.projects.instances
arguments:
resource:
help_text: The Cloud Spanner instance to remove the IAM policy binding from.
spec: !REF googlecloudsdk.command_lib.spanner.resources:instance
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,26 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Set the IAM policy for a Cloud Spanner instance.
description: |
Set the IAM policy for a Cloud Spanner instance given a instance ID and
a file encoded in JSON or YAML that contains the IAM policy.
examples: |
The following command reads an IAM policy defined in a JSON file
`policy.json` and sets it for a spanner instance with the ID
`example-instance`:
$ {command} example-instance policy.json
See https://cloud.google.com/iam/docs/managing-policies for details of the
policy file format and contents.
request:
collection: spanner.projects.instances
arguments:
resource:
help_text: The Spanner instance to set the IAM policy for.
spec: !REF googlecloudsdk.command_lib.spanner.resources:instance
iam:
policy_version: 3

View File

@@ -0,0 +1,324 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for spanner instances update."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.spanner import instance_operations
from googlecloudsdk.api_lib.spanner import instances
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.spanner import flags
from googlecloudsdk.command_lib.spanner import resource_args
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.Command):
"""Update a Cloud Spanner instance."""
detailed_help = {
'EXAMPLES': textwrap.dedent("""\
To update the display name of a Cloud Spanner instance, run:
$ {command} my-instance-id --description=my-new-display-name
To update the node count of a Cloud Spanner instance, run:
$ {command} my-instance-id --nodes=1
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Please add arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
flags.Instance().AddToParser(parser)
flags.Description(required=False).AddToParser(parser)
base.ASYNC_FLAG.AddToParser(parser)
resource_args.AddExpireBehaviorArg(parser)
resource_args.AddInstanceTypeArg(parser)
flags.AddCapacityArgsForInstance(
require_all_autoscaling_args=False,
parser=parser,
add_asymmetric_option_flag=True,
asymmetric_options_group=True,
add_asymmetric_total_cpu_target_flag=True,
add_asymmetric_disable_autoscaling_flags=True,
autoscaling_cpu_target_group=True,
)
flags.Edition(None, True).AddToParser(parser)
flags.DefaultBackupScheduleType(
choices={
'DEFAULT_BACKUP_SCHEDULE_TYPE_UNSPECIFIED': 'Not specified.',
'NONE': (
'No default backup schedule is created automatically when a new'
' database is created in an instance.'
),
'AUTOMATIC': (
'A default backup schedule is created automatically when a new'
' database is created in an instance. You can edit or delete'
" the default backup schedule once it's created. The default"
' backup schedule creates a full backup every 24 hours. These'
' full backups are retained for 7 days.'
),
},
).AddToParser(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
instance_type = resource_args.GetInstanceType(args)
expire_behavior = resource_args.GetExpireBehavior(args)
op = instances.Patch(
args.instance,
description=args.description,
nodes=args.nodes,
processing_units=args.processing_units,
autoscaling_min_nodes=args.autoscaling_min_nodes,
autoscaling_max_nodes=args.autoscaling_max_nodes,
autoscaling_min_processing_units=args.autoscaling_min_processing_units,
autoscaling_max_processing_units=args.autoscaling_max_processing_units,
autoscaling_high_priority_cpu_target=args.autoscaling_high_priority_cpu_target,
autoscaling_total_cpu_target=args.autoscaling_total_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target,
asymmetric_autoscaling_options=args.asymmetric_autoscaling_option,
clear_asymmetric_autoscaling_options=args.clear_asymmetric_autoscaling_option,
instance_type=instance_type,
expire_behavior=expire_behavior,
edition=args.edition,
default_backup_schedule_type=args.default_backup_schedule_type,
)
if args.async_:
return op
instance_operations.Await(op, 'Updating instance')
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaUpdate(base.Command):
"""Update a Cloud Spanner instance."""
detailed_help = {
'EXAMPLES': textwrap.dedent("""\
To update the display name of a Cloud Spanner instance, run:
$ {command} my-instance-id --description=my-new-display-name
To update the node count of a Cloud Spanner instance, run:
$ {command} my-instance-id --nodes=1
"""),
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Please add arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
flags.Instance().AddToParser(parser)
flags.Description(required=False).AddToParser(parser)
base.ASYNC_FLAG.AddToParser(parser)
resource_args.AddExpireBehaviorArg(parser)
resource_args.AddInstanceTypeArg(parser)
flags.AddCapacityArgsForInstance(
require_all_autoscaling_args=False,
parser=parser,
add_asymmetric_option_flag=True,
asymmetric_options_group=True,
add_asymmetric_total_cpu_target_flag=True,
add_asymmetric_disable_autoscaling_flags=True,
autoscaling_cpu_target_group=True,
add_disable_downscaling_flag=True,
)
flags.Edition(None, True).AddToParser(parser)
flags.DefaultBackupScheduleType(
choices={
'DEFAULT_BACKUP_SCHEDULE_TYPE_UNSPECIFIED': 'Not specified.',
'NONE': (
'No default backup schedule is created automatically when a new'
' database is created in an instance.'
),
'AUTOMATIC': (
'A default backup schedule is created automatically when a new'
' database is created in an instance. You can edit or delete'
" the default backup schedule once it's created. The default"
' backup schedule creates a full backup every 24 hours. These'
' full backups are retained for 7 days.'
),
},
).AddToParser(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
instance_type = resource_args.GetInstanceType(args)
expire_behavior = resource_args.GetExpireBehavior(args)
op = instances.Patch(
args.instance,
description=args.description,
nodes=args.nodes,
processing_units=args.processing_units,
autoscaling_min_nodes=args.autoscaling_min_nodes,
autoscaling_max_nodes=args.autoscaling_max_nodes,
autoscaling_min_processing_units=args.autoscaling_min_processing_units,
autoscaling_max_processing_units=args.autoscaling_max_processing_units,
autoscaling_high_priority_cpu_target=args.autoscaling_high_priority_cpu_target,
autoscaling_total_cpu_target=args.autoscaling_total_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target,
asymmetric_autoscaling_options=args.asymmetric_autoscaling_option,
disable_downscaling=args.disable_downscaling,
clear_asymmetric_autoscaling_options=args.clear_asymmetric_autoscaling_option,
instance_type=instance_type,
expire_behavior=expire_behavior,
edition=args.edition,
default_backup_schedule_type=args.default_backup_schedule_type,
)
if args.async_:
return op
instance_operations.Await(op, 'Updating instance')
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaUpdate(base.Command):
"""Update a Cloud Spanner instance with ALPHA features."""
detailed_help = {
'EXAMPLES': textwrap.dedent("""\
To update the display name of a Cloud Spanner instance, run:
$ {command} my-instance-id --description=my-new-display-name
To update the node count of a Cloud Spanner instance, run:
$ {command} my-instance-id --nodes=1
"""),
}
__doc__ = Update.__doc__
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Please add arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
flags.Instance().AddToParser(parser)
flags.Description(required=False).AddToParser(parser)
base.ASYNC_FLAG.AddToParser(parser)
resource_args.AddExpireBehaviorArg(parser)
resource_args.AddInstanceTypeArg(parser)
flags.AddCapacityArgsForInstance(
require_all_autoscaling_args=False,
parser=parser,
add_asymmetric_option_flag=True,
asymmetric_options_group=True,
autoscaling_cpu_target_group=True,
add_asymmetric_total_cpu_target_flag=True,
add_asymmetric_disable_autoscaling_flags=True,
add_disable_downscaling_flag=True,
)
flags.SsdCache().AddToParser(parser)
flags.Edition(None, True).AddToParser(parser)
flags.DefaultBackupScheduleType(
choices={
'DEFAULT_BACKUP_SCHEDULE_TYPE_UNSPECIFIED': 'Not specified.',
'NONE': (
'No default backup schedule is created automatically when a new'
' database is created in an instance.'
),
'AUTOMATIC': (
'A default backup schedule is created automatically when a new'
' database is created in an instance. You can edit or delete'
" the default backup schedule once it's created. The default"
' backup schedule creates a full backup every 24 hours. These'
' full backups are retained for 7 days.'
),
},
).AddToParser(parser)
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Returns:
Some value that we want to have printed later.
"""
instance_type = resource_args.GetInstanceType(args)
expire_behavior = resource_args.GetExpireBehavior(args)
op = instances.Patch(
args.instance,
description=args.description,
nodes=args.nodes,
processing_units=args.processing_units,
autoscaling_min_nodes=args.autoscaling_min_nodes,
autoscaling_max_nodes=args.autoscaling_max_nodes,
autoscaling_min_processing_units=args.autoscaling_min_processing_units,
autoscaling_max_processing_units=args.autoscaling_max_processing_units,
autoscaling_high_priority_cpu_target=args.autoscaling_high_priority_cpu_target,
autoscaling_total_cpu_target=args.autoscaling_total_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target,
asymmetric_autoscaling_options=args.asymmetric_autoscaling_option,
disable_downscaling=args.disable_downscaling,
clear_asymmetric_autoscaling_options=args.clear_asymmetric_autoscaling_option,
instance_type=instance_type,
expire_behavior=expire_behavior,
ssd_cache_id=args.ssd_cache,
edition=args.edition,
default_backup_schedule_type=args.default_backup_schedule_type,
)
if args.async_:
return op
instance_operations.Await(op, 'Updating instance')