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,25 @@
# -*- 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.
"""The instances command group for bigtable."""
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 Bigtable instances."""

View File

@@ -0,0 +1,33 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Add an IAM policy binding to a Cloud Bigtable instance.
description: |
Add an IAM policy binding to a Cloud Bigtable 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/bigtable.admin` and the user `test-user@gmail.com` with instance `my-instance`, run:
$ {command} my-instance --member=`user:test-user@gmail.com` --role=`roles/bigtable.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: bigtableadmin.projects.instances
arguments:
resource:
help_text: The Cloud Bigtable instance to which to add the IAM policy binding.
spec: !REF googlecloudsdk.command_lib.bigtable.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 Cloud Bigtable 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 Cloud Bigtable instance configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Cloud Bigtable instance.
description: |
*{command}* exports the configuration for a Cloud Bigtable 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.bigtable.resources:instance

View File

@@ -0,0 +1,279 @@
# -*- 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.
"""bigtable instances create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.bigtable import clusters
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA)
class CreateInstance(base.CreateCommand):
"""Create a new Bigtable instance."""
_support_tags = False
detailed_help = {
'EXAMPLES': textwrap.dedent("""\
To create an instance with id `my-instance-id` with a cluster located
in `us-east1-c`, run:
$ {command} my-instance-id --display-name="My Instance" --cluster-config=id=my-cluster-id,zone=us-east1-c
To create an instance with multiple clusters, run:
$ {command} my-instance-id --display-name="My Instance" --cluster-config=id=my-cluster-id-1,zone=us-east1-c --cluster-config=id=my-cluster-id-2,zone=us-west1-c,nodes=3
To create an instance with `HDD` storage and `10` nodes, run:
$ {command} my-hdd-instance --display-name="HDD Instance" --cluster-storage-type=HDD --cluster-config=id=my-cluster-id,zone=us-east1-c,nodes=10
"""),
}
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
(
arguments.ArgAdder(parser)
.AddInstanceDisplayName(required=True)
.AddClusterConfig()
.AddDeprecatedCluster()
.AddDeprecatedClusterZone()
.AddDeprecatedClusterNodes()
.AddClusterStorage()
.AddAsync()
.AddDeprecatedInstanceType()
)
if cls._support_tags:
arguments.ArgAdder(parser).AddTags()
arguments.AddInstanceResourceArg(parser, 'to create', positional=True)
parser.display_info.AddCacheUpdater(arguments.InstanceCompleter)
def Run(self, args):
"""Executes the instances create 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 self._Run(args)
def _Run(self, args):
"""Implements Run() with different possible features flags."""
cli = util.GetAdminClient()
ref = args.CONCEPTS.instance.Parse()
# TODO(b/153576330): This is a workaround for inconsistent collection names.
parent_ref = resources.REGISTRY.Create(
'bigtableadmin.projects', projectId=ref.projectsId)
msgs = util.GetAdminMessages()
instance_type = msgs.Instance.TypeValueValuesEnum(args.instance_type)
new_clusters = self._Clusters(args)
clusters_properties = []
for cluster_id, cluster in sorted(new_clusters.items()):
clusters_properties.append(
msgs.CreateInstanceRequest.ClustersValue.AdditionalProperty(
key=cluster_id, value=cluster))
msg = msgs.CreateInstanceRequest(
instanceId=ref.Name(),
parent=parent_ref.RelativeName(),
instance=msgs.Instance(
displayName=args.display_name,
type=instance_type,
tags=self._Tags(args),
),
clusters=msgs.CreateInstanceRequest.ClustersValue(
additionalProperties=clusters_properties
),
)
result = cli.projects_instances.Create(msg)
operation_ref = util.GetOperationRef(result)
if args.async_:
log.CreatedResource(
operation_ref.RelativeName(),
kind='bigtable instance {0}'.format(ref.Name()),
is_async=True)
return result
return util.AwaitInstance(
operation_ref, 'Creating bigtable instance {0}'.format(ref.Name()))
def _Clusters(self, args):
"""Get the clusters configs from command arguments.
Args:
args: the argparse namespace from Run().
Returns:
A dict mapping from cluster id to msg.Cluster.
"""
msgs = util.GetAdminMessages()
storage_type = msgs.Cluster.DefaultStorageTypeValueValuesEnum(
args.cluster_storage_type.upper())
if args.cluster_config is not None:
if (args.cluster is not None
or args.cluster_zone is not None
or args.cluster_num_nodes is not None):
raise exceptions.InvalidArgumentException(
'--cluster-config --cluster --cluster-zone --cluster-num-nodes',
'Use --cluster-config or the combination of --cluster, '
'--cluster-zone and --cluster-num-nodes to specify cluster(s), not '
'both.')
self._ValidateClusterConfigArgs(args.cluster_config)
new_clusters = {}
for cluster_dict in args.cluster_config:
nodes = cluster_dict.get('nodes', 1)
node_scaling_factor = cluster_dict.get(
'node-scaling-factor',
msgs.Cluster.NodeScalingFactorValueValuesEnum(
msgs.Cluster.NodeScalingFactorValueValuesEnum.NODE_SCALING_FACTOR_1X
),
)
cluster = msgs.Cluster(
serveNodes=nodes,
nodeScalingFactor=node_scaling_factor,
defaultStorageType=storage_type,
# TODO(b/36049938): switch location to resource
# when b/29566669 is fixed on API
location=util.LocationUrl(cluster_dict['zone']))
if 'kms-key' in cluster_dict:
cluster.encryptionConfig = msgs.EncryptionConfig(
kmsKeyName=cluster_dict['kms-key'])
if ('autoscaling-min-nodes' in cluster_dict or
'autoscaling-max-nodes' in cluster_dict or
'autoscaling-cpu-target' in cluster_dict):
# autoscaling-storage-target is optional.
if 'autoscaling-storage-target' in cluster_dict:
storage_target = cluster_dict['autoscaling-storage-target']
else:
storage_target = None
cluster.clusterConfig = clusters.BuildClusterConfig(
autoscaling_min=cluster_dict['autoscaling-min-nodes'],
autoscaling_max=cluster_dict['autoscaling-max-nodes'],
autoscaling_cpu_target=cluster_dict['autoscaling-cpu-target'],
autoscaling_storage_target=storage_target)
# serveNodes must be set to None or 0 to enable Autoscaling.
# go/cbt-autoscaler-api
cluster.serveNodes = None
new_clusters[cluster_dict['id']] = cluster
return new_clusters
elif args.cluster is not None:
if args.cluster_zone is None:
raise exceptions.InvalidArgumentException(
'--cluster-zone', '--cluster-zone must be specified.')
cluster = msgs.Cluster(
serveNodes=arguments.ProcessInstanceTypeAndNodes(args),
# nodeScalingFactor is not supported in deprecated workflow
defaultStorageType=storage_type,
nodeScalingFactor=msgs.Cluster.NodeScalingFactorValueValuesEnum(
msgs.Cluster.NodeScalingFactorValueValuesEnum.NODE_SCALING_FACTOR_1X
),
# TODO(b/36049938): switch location to resource
# when b/29566669 is fixed on API
location=util.LocationUrl(args.cluster_zone))
return {args.cluster: cluster}
else:
raise exceptions.InvalidArgumentException(
'--cluster --cluster-config',
'Use --cluster-config to specify cluster(s).',
)
def _ValidateClusterConfigArgs(self, cluster_config):
"""Validates arguments in cluster-config as a repeated dict."""
# Validate cluster-config of each cluster.
for cluster_dict in cluster_config:
if ('autoscaling-min-nodes' in cluster_dict or
'autoscaling-max-nodes' in cluster_dict or
'autoscaling-cpu-target' in cluster_dict or
'autoscaling-storage-target' in cluster_dict):
# nodes and autoscaling args are mutual exclusive.
if 'nodes' in cluster_dict:
raise exceptions.InvalidArgumentException(
'--autoscaling-min-nodes --autoscaling-max-nodes '
'--autoscaling-cpu-target --autoscaling-storage-target',
'At most one of nodes | autoscaling-min-nodes '
'autoscaling-max-nodes autoscaling-cpu-target '
'autoscaling-storage-target may be specified in --cluster-config')
# To enable autoscaling, all related args must be set.
if ('autoscaling-min-nodes' not in cluster_dict or
'autoscaling-max-nodes' not in cluster_dict or
'autoscaling-cpu-target' not in cluster_dict):
raise exceptions.InvalidArgumentException(
'--autoscaling-min-nodes --autoscaling-max-nodes '
'--autoscaling-cpu-target', 'All of --autoscaling-min-nodes '
'--autoscaling-max-nodes --autoscaling-cpu-target must be set to '
'enable Autoscaling.')
@classmethod
def _Tags(cls, args, tags_arg_name='tags'):
"""Get the tags from command arguments.
Args:
args: the argparse namespace from Run().
tags_arg_name: the name of the tags argument.
Returns:
A dict mapping from tag key to tag value.
"""
if not cls._support_tags:
return None
tags = getattr(args, tags_arg_name)
if not tags:
return None
tags_message = util.GetAdminMessages().Instance.TagsValue
# Sorted for test stability.
return tags_message(
additionalProperties=[
tags_message.AdditionalProperty(key=key, value=value)
for key, value in sorted(tags.items())
]
)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateInstanceAlpha(CreateInstance):
"""Create a new Bigtable instance."""
_support_tags = True

View File

@@ -0,0 +1,69 @@
# -*- 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.
"""bigtable instances delete command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core.console import console_io
class DeleteInstance(base.DeleteCommand):
"""Delete an existing Bigtable instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To delete an instance, run:
$ {command} my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddInstancesResourceArg(parser, 'to delete', positional=True)
parser.display_info.AddCacheUpdater(arguments.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.
"""
cli = util.GetAdminClient()
msgs = util.GetAdminMessages()
for instance in args.instance:
should_continue = console_io.PromptContinue(
message='Delete instance {}. Are you sure?'.format(instance))
if should_continue:
ref = util.GetInstanceRef(instance)
msg = msgs.BigtableadminProjectsInstancesDeleteRequest(
name=ref.RelativeName())
cli.projects_instances.Delete(msg)
return None

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.
"""bigtable instances describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
class DescribeInstance(base.DescribeCommand):
"""Describe an existing Bigtable instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To view an instance's description, run:
$ {command} my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddInstanceResourceArg(parser, 'to describe', positional=True)
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.
"""
cli = util.GetAdminClient()
ref = resources.REGISTRY.Parse(
args.instance,
params={
'projectsId': properties.VALUES.core.project.GetOrFail,
},
collection='bigtableadmin.projects.instances')
msg = util.GetAdminMessages().BigtableadminProjectsInstancesGetRequest(
name=ref.RelativeName())
instance = cli.projects_instances.Get(msg)
return instance

View File

@@ -0,0 +1,60 @@
# -*- 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 bigtable instances get-iam-policy."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.bigtable import instances
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
class GetIamPolicy(base.ListCommand):
"""Get the IAM policy for a Cloud Bigtable instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To print the IAM policy for an instance, run:
$ {command} my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddInstanceResourceArg(
parser, 'to get the IAM policy for', positional=True)
base.URI_FLAG.RemoveFromParser(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:
A IAM policy message.
"""
instance_ref = util.GetInstanceRef(args.instance)
return instances.GetIamPolicy(instance_ref)

View File

@@ -0,0 +1,78 @@
# -*- 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.
"""bigtable instances list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
def _GetUriFunction(resource):
return util.GetInstanceRef(resource.name).SelfLink()
class ListInstances(base.ListCommand):
"""List existing Bigtable instances."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To list all instances, run:
$ {command}
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.display_info.AddFormat("""
table(
name.basename():sort=1,
displayName,
state
)
""")
parser.display_info.AddUriFunc(_GetUriFunction)
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.
"""
cli = util.GetAdminClient()
project_ref = resources.REGISTRY.Parse(
properties.VALUES.core.project.Get(required=True),
collection='bigtableadmin.projects')
msg = util.GetAdminMessages().BigtableadminProjectsInstancesListRequest(
parent=project_ref.RelativeName())
return list_pager.YieldFromList(
cli.projects_instances,
msg,
field='instances',
batch_size_attribute=None)

View File

@@ -0,0 +1,33 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Remove an IAM policy binding from a Cloud Bigtable instance.
description: |
Remove an IAM policy binding from a Cloud Bigtable 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/bigtable.admin` and the user `test-user@gmail.com` with instance `my-instance`, run:
$ {command} my-instance --member=`user:test-user@gmail.com` --role=`roles/bigtable.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: bigtableadmin.projects.instances
arguments:
resource:
help_text: The Cloud Bigtable instance to remove the IAM policy binding from.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:instance
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,54 @@
# -*- 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 bigtable instances set-iam-policy."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.command_lib.bigtable import iam
from googlecloudsdk.command_lib.iam import iam_util
class SetIamPolicy(base.Command):
"""Set the IAM policy for a Cloud Bigtable instance."""
detailed_help = iam_util.GetDetailedHelpForSetIamPolicy(
'instance', example_id='my-instance-id', use_an=True)
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddInstanceResourceArg(
parser, 'to set the IAM policy for', positional=True)
iam_util.AddArgForPolicyFile(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:
A IAM policy message.
"""
instance_ref = util.GetInstanceRef(args.instance)
result = iam.SetInstanceIamPolicy(instance_ref, args.policy_file)
iam_util.LogSetIamPolicy(instance_ref.Name(), 'instance')
return result

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""The main command group for bigtable."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Tables(base.Group):
"""Query Cloud Bigtable tables."""

View File

@@ -0,0 +1,33 @@
release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Add an IAM policy binding to a Cloud Bigtable table.
description: |
Add an IAM policy binding to a Cloud Bigtable table. 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 table `my-table` in instance `my-instance`, run:
$ {command} my-table --instance=`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 2019 for the role of
`roles/bigtable.admin` and the user `test-user@gmail.com` with table `my-table` in instance `my-instance`, run:
$ {command} my-table --instance=`my-instance` --member=`user:test-user@gmail.com` --role=`roles/bigtable.admin` --condition=`expression=request.time < timestamp("2020-01-01T00:00:00Z"),title=expires_end_of_2019,description=Expires at midnight on 2019-12-31`
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion
request:
collection: bigtableadmin.projects.instances.tables
arguments:
resource:
help_text: Cloud Bigtable table to add the IAM policy binding to.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table

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 Cloud Bigtable table 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 Cloud Bigtable table configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Cloud Bigtable table.
description: |
*{command}* exports the configuration for a Cloud Bigtable table.
Table 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
tables within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a table, run:
$ {command} my-table
To export the configuration for a table to a file, run:
$ {command} my-table --path=/path/to/dir/
To export the configuration for a table in Terraform
HCL format, run:
$ {command} my-table --resource-format=terraform
To export the configurations for all tables within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Table to export the configuration for.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table

View File

@@ -0,0 +1,125 @@
- release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Create a new Cloud Bigtable table.
description: Create a new Cloud Bigtable table.
examples: |
To create a table `my-table` in instance `my-instance` with a column family `my-family`, run:
$ {command} my-table --instance=my-instance --column-families="my-family"
To create a table that has a column family named `my-instance`, a garbage collection policy
that lets data expire after 864,000 seconds, and initial table splits on row keys `car` and `key`, run:
$ {command} my-table --instance=my-instance --column-families="my-family:maxage=864000s" --splits=car,key
To create a table `my-table` in instance `my-instance` that lets data in column family `my-family1`
expire after 10 days and keeps a maximum of 5 cells per column in column family `my-family-2` if the data is less than 5 days old, run:
$ {command} my-table --instance=my-instance --column-families="my-family-1:maxage=10d,my-family-2:maxversions=5||maxage=5d"
To create a table `my-table` that has one column family `my-family` that lets data expire after 10 days, and to enable a change stream
for the table to be kept for 7 days, run:
$ {command} my-table --instance=my-instance --column-families="my-family:maxage=10d" --change-stream-retention-period=7d
To create a deletion-protected table `my-table` in instance `my-instance` with a column family `my-family`, run:
$ {command} my-table --instance=my-instance --column-families="my-family" --deletion-protection
To create a table `my-table` without deletion protection in instance `my-instance` with a column family `my-family`, run:
$ {command} my-table --instance=my-instance --column-families="my-family" --no-deletion-protection
To create a table `my-table` with the default automated backup policy (retention_period=7d, frequency=1d) enabled in instance `my-instance` with a column family `my-family`, run:
$ {command} my-table --instance=my-instance --column-families="my-family" --enable-automated-backup
To create a table `my-table` with a custom automated backup policy configured to retain backups for 30 days in instance `my-instance` with a column family `my-family`, run:
$ {command} my-table --instance=my-instance --column-families="my-family" --automated-backup-retention_period=30d
request:
collection: bigtableadmin.projects.instances.tables
modify_request_hooks:
- googlecloudsdk.api_lib.bigtable.tables:UpdateRequestWithInput
- googlecloudsdk.api_lib.bigtable.tables:HandleAutomatedBackupPolicyCreateTableArgs
- googlecloudsdk.api_lib.bigtable.tables:HandleRowKeySchemaCreateTableArgs
arguments:
resource:
help_text: Cloud Bigtable table to create.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table
additional_arguments_hook: googlecloudsdk.api_lib.bigtable.tables:AddAutomatedBackupPolicyCreateTableArgs
params:
- api_field: createTableRequest.table.columnFamilies
arg_name: column-families
required: true
type: "arg_list"
help_text: |
A double-quote (`"`) wrapped list of family name and corresponding garbage collection rules
concatenated by `:`, where the rules are optional. For example:
`"family_1,family_2:maxage=5d&&maxversions=2,family_3:maxage=10d||maxversions=5"`
processor: googlecloudsdk.api_lib.bigtable.tables:ParseColumnFamilies
- api_field: createTableRequest.initialSplits
arg_name: splits
help_text: |
Row keys where the table should initially be split. For example: `car,key`
type: "arg_list"
processor: googlecloudsdk.api_lib.bigtable.tables:MakeSplits
- api_field: createTableRequest.table.changeStreamConfig.retentionPeriod
arg_name: change-stream-retention-period
help_text: |
The length of time to retain change stream data for the table, in the range of
[1 day, 7 days]. Acceptable units are days (d), hours (h), minutes (m), and seconds (s).
Passing in a value for this option enables a change stream for the table. Examples: `5d` or
`48h`.
processor: googlecloudsdk.api_lib.bigtable.tables:ParseChangeStreamRetentionPeriod
- api_field: createTableRequest.table.tieredStorageConfig.infrequentAccess.includeIfOlderThan
arg_name: tiered-storage-infrequent-access-older-than
release_tracks: [ALPHA, BETA]
help_text: |
The age at which data should be moved to infrequent access storage.
See `$ gcloud topic datetimes` for information on absolute duration formats.
processor: googlecloudsdk.api_lib.bigtable.tables:ParseTieredStorageConfigDuration
- api_field: createTableRequest.table.deletionProtection
arg_name: deletion-protection
type: bool
help_text: |
Once specified, the table is deletion protected.
- arg_name: row-key-schema-definition-file
required: false
help_text: |
The row key schema for the table. The schema is defined in a YAML or JSON file, equivalent
to the StructType protobuf message.
Example YAML:
```yaml
encoding:
delimitedBytes:
delimiter: '#'
fields:
- fieldName: field1
type:
bytesType:
encoding:
raw: {}
- fieldName: field2
type:
bytesType:
encoding:
raw: {}
```
- arg_name: row-key-schema-pre-encoded-bytes
type: bool
default: false
required: false
help_text: |
By default, Base64 encoding is applied to all binary fields in the YAML/JSON file (for
example, `encoding.delimitedBytes.delimiter`).
Use this to indicate that all binary fields are already encoded in the YAML/JSON file and
should not be encoded again.

View File

@@ -0,0 +1,17 @@
- release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Delete a Cloud Bigtable table.
description: Delete a Cloud Bigtable table.
examples: |
To delete the table `my-table` in instance `my-instance`, run:
$ {command} my-table --instance=my-instance
request:
collection: bigtableadmin.projects.instances.tables
method: delete
arguments:
resource:
help_text: Cloud Bigtable table to delete.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table

View File

@@ -0,0 +1,41 @@
- release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Retrieve information about a table.
description: Retrieve information about a table.
examples: |
To describe a table, run:
$ {command} TABLE_NAME --instance=INSTANCE_NAME
request:
collection: bigtableadmin.projects.instances.tables
arguments:
resource:
help_text: Cloud Bigtable table to describe.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table
params:
- api_field: view
arg_name: view
help_text: The view to be applied to the returned table's fields.
default: schema
choices: # Enum is mapped to keep VIEW_UNSPECIFIED invisible from user.
- arg_value: name
enum_value: NAME_ONLY
help_text: Only populates `name`.
- arg_value: schema
enum_value: SCHEMA_VIEW
help_text: Only populates `name` and fields related to the table's schema.
- arg_value: replication
enum_value: REPLICATION_VIEW
help_text: Only populates `name` and fields related to the table's replication.
- arg_value: encryption
enum_value: ENCRYPTION_VIEW
help_text: Only populates `name` and fields related to the table's encryption status.
- arg_value: stats
enum_value: STATS_VIEW
help_text: Only populates `name` and fields related to the table's statistics (e.g. TableStats and ColumnFamilyStats).
- arg_value: full
enum_value: FULL
help_text: Populates all fields.

View File

@@ -0,0 +1,24 @@
release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Get an IAM policy on a Cloud Bigtable table.
description: |
Get an IAM policy on a Cloud Bigtable table.
examples: |
To get the IAM policy on the table `my-table` in instance `my-instance`, run:
$ {command} my-table --instance=`my-instance`
See https://cloud.google.com/iam/docs/managing-policies for more information.
request:
collection: bigtableadmin.projects.instances.tables
arguments:
resource:
help_text: Cloud Bigtable table to get the IAM policy for.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table
iam:
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""bigtable tables list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
def _GetUriFunction(resource):
table_ref = resources.REGISTRY.ParseRelativeName(
resource.name,
collection='bigtableadmin.projects.instances.tables')
return table_ref.SelfLink()
class ListInstances(base.ListCommand):
"""List existing Bigtable instance tables.
## EXAMPLES
To list all tables in an instance, run:
$ {command} --instances=INSTANCE_NAME
To list all tables in several instances, run:
$ {command} --instances=INSTANCE_NAME1,INSTANCE_NAME2
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
parser.display_info.AddFormat("""
table(
name.basename():sort=1
)
""")
parser.display_info.AddUriFunc(_GetUriFunction)
arguments.ArgAdder(parser).AddInstance(
positional=False, required=True, multiple=True)
def Run(self, args):
cli = util.GetAdminClient()
msgs = util.GetAdminMessages()
instances = args.instances
results = []
for instance in instances:
instance_ref = resources.REGISTRY.Parse(
instance,
params={'projectsId': properties.VALUES.core.project.GetOrFail},
collection='bigtableadmin.projects.instances')
request = msgs.BigtableadminProjectsInstancesTablesListRequest(
parent=instance_ref.RelativeName(),)
for table in list_pager.YieldFromList(
cli.projects_instances_tables,
request,
field='tables',
batch_size_attribute=None):
results.append(table)
return results

View File

@@ -0,0 +1,33 @@
release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Remove an IAM policy binding from a Cloud Bigtable table.
description: |
Remove an IAM policy binding from a Cloud Bigtable table. 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 table `my-table` in instance `my-instance`, run:
$ {command} my-table --instance=`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 2019 for the role of
`roles/bigtable.admin` and the user `test-user@gmail.com` with table `my-table` in instance `my-instance`, run:
$ {command} my-table --instance=`my-instance` --member=`user:test-user@gmail.com` --role=`roles/bigtable.admin` --condition=`expression=request.time < timestamp("2020-01-01T00:00:00Z"),title=expires_end_of_2019,description=Expires at midnight on 2019-12-31`
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion
request:
collection: bigtableadmin.projects.instances.tables
arguments:
resource:
help_text: Cloud Bigtable table to remove the IAM policy binding from.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table

View File

@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google Inc. 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.
"""bigtable tables restore command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core import log
class RestoreTables(base.RestoreCommand):
"""Restore a Cloud Bigtable backup to a new table."""
detailed_help = {
'DESCRIPTION':
textwrap.dedent("""
This command restores a Cloud Bigtable backup to a new table.
"""),
'EXAMPLES':
textwrap.dedent("""
To restore table 'table2' from backup 'backup1', run:
$ {command} --source-instance=instance1 --source-cluster=cluster1 --source=backup1 --destination-instance=instance1 --destination=table2
To restore table 'table2' from backup 'backup1' in a different project, run:
$ {command} --source=projects/project1/instances/instance1/clusters/cluster1/backups/backup1 --destination=projects/project2/instances/instance2/tables/table2
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddTableRestoreResourceArg(parser)
arguments.ArgAdder(parser).AddAsync()
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.
"""
cli = util.GetAdminClient()
msgs = util.GetAdminMessages()
backup_ref = args.CONCEPTS.source.Parse() # backup
table_ref = args.CONCEPTS.destination.Parse() # table
restore_request = msgs.RestoreTableRequest(
# Full backup name.
backup=backup_ref.RelativeName(),
# Table id
tableId=table_ref.Name())
msg = (msgs.BigtableadminProjectsInstancesTablesRestoreRequest(
# The name of the instance in which to create the restored table.
parent=table_ref.Parent().RelativeName(),
restoreTableRequest=restore_request))
operation = cli.projects_instances_tables.Restore(msg)
operation_ref = util.GetOperationRef(operation)
if args.async_:
log.CreatedResource(
operation_ref.RelativeName(),
kind='bigtable table {0}'.format(table_ref.Name()),
is_async=True)
return
return util.AwaitTable(
operation_ref,
'Creating bigtable table {0}'.format(table_ref.Name()))

View File

@@ -0,0 +1,27 @@
release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Set an IAM policy on a Cloud Bigtable table.
description: |
Set an IAM policy on a Cloud Bigtable table.
examples: |
To set the IAM policy from file `my-policy` on the table `my-table` in
instance `my-instance`, run:
$ {command} my-table --instance=`my-instance` my-policy
See https://cloud.google.com/iam/docs/managing-policies for more information.
request:
collection: bigtableadmin.projects.instances.tables
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=setIamPolicyRequest.policy.version
- googlecloudsdk.command_lib.iam.hooks:AddVersionToUpdateMaskIfNotPresent:update_mask_path=setIamPolicyRequest.updateMask
arguments:
resource:
help_text: Cloud Bigtable table to set the IAM policy on.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table
iam:
policy_version: 3

View File

@@ -0,0 +1,20 @@
- release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Undelete a previously deleted Cloud Bigtable table.
description: Undelete a previously deleted Cloud Bigtable table.
examples: |
To undelete the table `my-table` in instance `my-instance`, run:
$ {command} my-table --instance=my-instance
request:
collection: bigtableadmin.projects.instances.tables
method: undelete
arguments:
resource:
help_text: Cloud Bigtable table to undelete.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table
async:
collection: bigtableadmin.operations

View File

@@ -0,0 +1,106 @@
- release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Update an existing Cloud Bigtable table.
description: Update an existing new Cloud Bigtable table with the specified configuration.
examples: |
To enable deletion protection, run:
$ {command} my-table --instance=my-instance --deletion-protection
To disable deletion protection, run:
$ {command} my-table --instance=my-instance --no-deletion-protection
To enable a change stream with a retention period of 1 day, or to update your table's change stream retention period to 1 day, run:
$ {command} my-table --instance=my-instance --change-stream-retention-period=1d
To disable a change stream, run:
$ {command} my-table --instance=my-instance --clear-change-stream-retention-period
To enable the default automated backup policy on a table, or update a table to use the default policy (retention_period=7d, frequency=1d), run:
$ {command} my-table --instance=my-instance --enable-automated-backup
To disable automated backup: run:
$ {command} my-table --instance=my-instance --disable-automated-backup
To enable or update a custom automated backup policy and configure it to retain backups for 30 days, run:
$ {command} my-table --instance=my-instance --automated-backup-retention_period=30d
request:
collection: bigtableadmin.projects.instances.tables
method: patch
modify_request_hooks:
- googlecloudsdk.api_lib.bigtable.tables:HandleChangeStreamArgs
- googlecloudsdk.api_lib.bigtable.tables:HandleAutomatedBackupPolicyUpdateTableArgs
- googlecloudsdk.api_lib.bigtable.tables:HandleTieredStorageArgs
- googlecloudsdk.api_lib.bigtable.tables:RefreshUpdateMask
- googlecloudsdk.api_lib.bigtable.tables:HandleRowKeySchemaUpdateTableArgs
arguments:
resource:
help_text: Cloud Bigtable table to update.
spec: !REF googlecloudsdk.command_lib.bigtable.resources:table
additional_arguments_hook: googlecloudsdk.api_lib.bigtable.tables:AddAdditionalArgsAlphaBeta
GA:
additional_arguments_hook: googlecloudsdk.api_lib.bigtable.tables:AddAdditionalArgs
params:
- api_field: table.deletionProtection
arg_name: deletion-protection
type: bool
help_text: |
Once specified, the table is deletion protected.
- arg_name: row-key-schema-pre-encoded-bytes
type: bool
help_text: |
By default, Base64 encoding is applied to all binary fields in the YAML/JSON file (for example,
`encoding.delimitedBytes.delimiter`).
Use this to indicate that all binary fields are already encoded in the YAML/JSON file and
should not be encoded again.
This field is only used when `row-key-schema-definition-file` is set. It is ignored if
`clear-row-key-schema` is set.
- group:
help_text: |
Whether to update or clear the row key schema in the updated table. Only one of these
flags can be set.
required: false
mutex: true
params:
- arg_name: row-key-schema-definition-file
help_text: |
The row key schema for the table. The schema is defined in a YAML or JSON file, equivalent
to the StructType protobuf message.
Example YAML:
```yaml
encoding:
delimitedBytes:
delimiter: '#'
fields:
- fieldName: field1
type:
bytesType:
encoding:
raw: {}
- fieldName: field2
type:
bytesType:
encoding:
raw: {}
```
- arg_name: clear-row-key-schema
type: bool
help_text: |
Whether to clear the row key schema in the updated table.
async:
collection: bigtableadmin.operations

View File

@@ -0,0 +1,70 @@
# -*- 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.
"""bigtable instances update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.bigtable import util as bigtable_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core import log
class UpdateInstance(base.UpdateCommand):
"""Modify an existing Bigtable instance."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To update the display name for an instance, run:
$ {command} my-instance-id --display-name="Updated Instance Name"
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.ArgAdder(parser).AddInstanceDisplayName()
arguments.AddInstanceResourceArg(parser, 'to update', positional=True)
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.
"""
cli = bigtable_util.GetAdminClient()
ref = bigtable_util.GetInstanceRef(args.instance)
msgs = bigtable_util.GetAdminMessages()
instance = cli.projects_instances.Get(
msgs.BigtableadminProjectsInstancesGetRequest(name=ref.RelativeName()))
instance.state = None # must be unset when calling Update
if args.display_name:
instance.displayName = args.display_name
instance = cli.projects_instances.Update(instance)
log.UpdatedResource(instance.name, kind='instance')
return instance

View File

@@ -0,0 +1,70 @@
# -*- 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.
"""bigtable instances upgrade command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.bigtable import instances
from googlecloudsdk.api_lib.bigtable import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
class UpgradeInstance(base.UpdateCommand):
"""Upgrade an existing instance's type from development to production."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To upgrade a `DEVELOPMENT` instance to `PRODUCTION`, run:
$ {command} my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.ArgAdder(parser).AddAsync()
arguments.AddInstanceResourceArg(parser, 'to upgrade', positional=True)
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.
"""
op = instances.Upgrade(args.instance)
if args.async_:
result = op
else:
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='bigtableadmin.operations')
message = 'Upgrading bigtable instance {0}'.format(args.instance)
result = util.AwaitInstance(op_ref, message)
log.UpdatedResource(args.instance, kind='instance', is_async=args.async_)
return result