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 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
class Clusters(base.Group):
"""Manage Cloud Bigtable clusters."""

View File

@@ -0,0 +1,119 @@
# -*- 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 clusters create."""
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.command_lib.bigtable import arguments
from googlecloudsdk.command_lib.util.apis import arg_utils
from googlecloudsdk.core import log
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA
)
class CreateCluster(base.CreateCommand):
"""Create a bigtable cluster."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To add a cluster in zone `us-east1-c` to the instance with id
`my-instance-id`, run:
$ {command} my-cluster-id --instance=my-instance-id --zone=us-east1-c
To add a cluster with `10` nodes, run:
$ {command} my-cluster-id --instance=my-instance-id --zone=us-east1-c --num-nodes=10
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddClusterResourceArg(parser, 'to describe')
arguments.ArgAdder(
parser
).AddClusterZone().AddAsync().AddScalingArgsForClusterCreate().AddClusterNodeScalingFactor()
arguments.AddKmsKeyResourceArg(parser, 'cluster')
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.
"""
cluster = self._Cluster(args)
cluster_ref = args.CONCEPTS.cluster.Parse()
operation = clusters.Create(cluster_ref, cluster)
operation_ref = util.GetOperationRef(operation)
if args.async_:
log.CreatedResource(
operation_ref.RelativeName(),
kind='bigtable cluster {0}'.format(cluster_ref.Name()),
is_async=True)
return
return util.AwaitCluster(
operation_ref,
'Creating bigtable cluster {0}'.format(cluster_ref.Name()))
def _Cluster(self, args):
msgs = util.GetAdminMessages()
storage_type = (
msgs.Cluster.DefaultStorageTypeValueValuesEnum.STORAGE_TYPE_UNSPECIFIED
)
node_scaling_factor = arg_utils.ChoiceToEnum(
args.node_scaling_factor,
msgs.Cluster.NodeScalingFactorValueValuesEnum,
)
cluster = msgs.Cluster(
serveNodes=args.num_nodes,
nodeScalingFactor=node_scaling_factor,
location=util.LocationUrl(args.zone),
defaultStorageType=storage_type)
kms_key = arguments.GetAndValidateKmsKeyName(args)
if kms_key:
cluster.encryptionConfig = msgs.EncryptionConfig(kmsKeyName=kms_key)
if (args.autoscaling_min_nodes is not None or
args.autoscaling_max_nodes is not None or
args.autoscaling_cpu_target is not None or
args.autoscaling_storage_target is not None):
cluster.clusterConfig = clusters.BuildClusterConfig(
autoscaling_min=args.autoscaling_min_nodes,
autoscaling_max=args.autoscaling_max_nodes,
autoscaling_cpu_target=args.autoscaling_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target)
# serveNodes must be set to None or 0 to enable Autoscaling.
# go/cbt-autoscaler-api
cluster.serveNodes = None
return cluster

View File

@@ -0,0 +1,65 @@
# -*- 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 clusters delete."""
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.calliope import base
from googlecloudsdk.command_lib.bigtable import arguments
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
class DeleteCluster(base.DeleteCommand):
"""Delete a bigtable cluster."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To delete a cluster, run:
$ {command} my-cluster-id --instance=my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddClusterResourceArg(parser, 'to delete')
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.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
console_io.PromptContinue(
'You are about to delete cluster: [{0}]'.format(cluster_ref.Name()),
throw_if_unattended=True,
cancel_on_no=True)
response = clusters.Delete(cluster_ref)
log.DeletedResource(cluster_ref.Name(), 'cluster')
return response

View File

@@ -0,0 +1,61 @@
# -*- 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 clusters 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
class DescribeCluster(base.DescribeCommand):
"""Describe an existing Bigtable cluster."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To view a cluster's description, run:
$ {command} my-cluster-id --instance=my-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddClusterResourceArg(parser, 'to describe')
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()
cluster_ref = args.CONCEPTS.cluster.Parse()
msg = util.GetAdminMessages(
).BigtableadminProjectsInstancesClustersGetRequest(
name=cluster_ref.RelativeName())
return cli.projects_instances_clusters.Get(msg)

View File

@@ -0,0 +1,94 @@
# -*- 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 clusters 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.command_lib.bigtable import arguments
from googlecloudsdk.core import resources
def _GetUriFunction(resource):
return resources.REGISTRY.ParseRelativeName(
resource.name,
collection='bigtableadmin.projects.instances.clusters').SelfLink()
class ListClusters(base.ListCommand):
"""List existing Bigtable clusters."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To list all clusters in an instance, run:
$ {command} --instances=my-instance-id
To list all clusters in multiple instances, run:
$ {command} --instances=my-instance-id,my-other-instance-id
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddInstancesResourceArg(parser, 'to list clusters for')
parser.display_info.AddFormat("""
table(
name.segment(3):sort=1:label=INSTANCE,
name.basename():sort=2:label=NAME,
location.basename():label=ZONE,
serveNodes:label=NODES,
defaultStorageType:label=STORAGE,
state
)
""")
parser.display_info.AddUriFunc(_GetUriFunction)
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.
Yields:
Some value that we want to have printed later.
"""
cli = util.GetAdminClient()
instance_refs = args.CONCEPTS.instances.Parse()
if not args.IsSpecified('instances'):
instance_refs = [util.GetInstanceRef('-')]
for instance_ref in instance_refs:
msg = (
util.GetAdminMessages()
.BigtableadminProjectsInstancesClustersListRequest(
parent=instance_ref.RelativeName()))
for cluster in list_pager.YieldFromList(
cli.projects_instances_clusters,
msg,
field='clusters',
batch_size_attribute=None):
yield cluster

View File

@@ -0,0 +1,82 @@
# -*- 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 clusters update 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.command_lib.bigtable import arguments
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class UpdateCluster(base.UpdateCommand):
"""Update a Bigtable cluster's number of nodes."""
detailed_help = {
'EXAMPLES':
textwrap.dedent("""\
To update a cluster to `10` nodes, run:
$ {command} my-cluster-id --instance=my-instance-id --num-nodes=10
"""),
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
arguments.AddClusterResourceArg(parser, 'to update')
(arguments.ArgAdder(parser).AddAsync().AddScalingArgsForClusterUpdate())
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:
None
"""
return self._Run(args)
def _Run(self, args):
"""Implements Run() with different possible features flags."""
cluster_ref = args.CONCEPTS.cluster.Parse()
operation = clusters.PartialUpdate(
cluster_ref,
nodes=args.num_nodes,
autoscaling_min=args.autoscaling_min_nodes,
autoscaling_max=args.autoscaling_max_nodes,
autoscaling_cpu_target=args.autoscaling_cpu_target,
autoscaling_storage_target=args.autoscaling_storage_target,
disable_autoscaling=args.disable_autoscaling)
if not args.async_:
operation_ref = util.GetOperationRef(operation)
return util.AwaitCluster(
operation_ref,
'Updating bigtable cluster {0}'.format(cluster_ref.Name()))
log.UpdatedResource(
cluster_ref.Name(), kind='cluster', is_async=args.async_)
return None