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,31 @@
# -*- 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 group for Vertex AI deployment resource pools."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
# deployment resource pool not yet ready for v1 API
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.UniverseCompatible
class DeploymentResourcePools(base.Group):
"""Manage Vertex AI deployment resource pools."""
category = base.VERTEX_AI_CATEGORY

View File

@@ -0,0 +1,122 @@
# -*- 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.
"""Vertex AI deployment resource pools create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import encoding
from googlecloudsdk.api_lib.ai import operations
from googlecloudsdk.api_lib.ai.deployment_resource_pools import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ai import constants
from googlecloudsdk.command_lib.ai import deployment_resource_pools_util
from googlecloudsdk.command_lib.ai import endpoint_util
from googlecloudsdk.command_lib.ai import flags
from googlecloudsdk.command_lib.ai import operations_util
from googlecloudsdk.command_lib.ai import region_util
from googlecloudsdk.command_lib.ai import validation
from googlecloudsdk.core import log
def _AddArgsBeta(parser):
"""Adding deployment resource pool arguments from CLI.
Args:
parser: argparse.ArgumentParser, cli argument parser
Returns:
None
"""
version = constants.BETA_VERSION
parser.add_argument(
'deployment_resource_pool_id',
help='The ID to use for the DeploymentResourcePool, which will become ' +
'the final component of the DeploymentResourcePool\'s resource name. ' +
'The maximum length is 63 characters, and valid characters are ' +
'/^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/.')
flags.AddPredictionResourcesArgs(parser, version, drp=True)
flags.GetAutoscalingMetricSpecsArg().AddToParser(parser)
flags.AddRegionResourceArg(
parser,
'to create deployment resource pool',
prompt_func=region_util.PromptForDeploymentResourcePoolSupportedRegion)
def _RunBeta(args):
"""Create a new Vertex AI deployment resource pool."""
validation.ValidateRequiredReplicaCount(args.required_replica_count,
args.min_replica_count)
version = constants.BETA_VERSION
region_ref = args.CONCEPTS.region.Parse()
args.region = region_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=args.region):
deployment_resource_pools_client = client.DeploymentResourcePoolsClient(
version=version)
op = deployment_resource_pools_client.CreateBeta(
region_ref,
args.deployment_resource_pool_id,
autoscaling_metric_specs=args.autoscaling_metric_specs,
accelerator_dict=args.accelerator,
min_replica_count=args.min_replica_count,
max_replica_count=args.max_replica_count,
machine_type=args.machine_type,
tpu_topology=args.tpu_topology,
multihost_gpu_node_count=args.multihost_gpu_node_count,
reservation_affinity=args.reservation_affinity,
spot=args.spot,
required_replica_count=args.required_replica_count,
)
response_msg = operations_util.WaitForOpMaybe(
operations.OperationsClient(), op,
deployment_resource_pools_util.ParseOperation(op.name))
if response_msg is not None:
response = encoding.MessageToPyValue(response_msg)
if 'name' in response:
log.status.Print(
('Created Vertex AI deployment resource pool: {}.')
.format(response['name']))
return response_msg
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.UniverseCompatible
class CreateV1Beta1(base.CreateCommand):
"""Create a new Vertex AI deployment resource pool.
This command creates a new deployment resource pool with a provided deployment
resource pool id (name) in a provided region (assuming that region provides
support for this api). You can choose to simply provide the resource pool
name and create an instance with default arguments, or you can pass in your
own preferences, such as the accelerator and machine specs. Please note this
functionality is not yet available in the GA track and is currently only
part of the v1beta1 API version.
## EXAMPLES
To create a deployment resource pool with name ``example'' in region
``us-central1'', run:
$ {command} example --region=us-central1
"""
@staticmethod
def Args(parser):
return _AddArgsBeta(parser)
def Run(self, args):
return _RunBeta(args)

View File

@@ -0,0 +1,91 @@
# -*- 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.
"""Vertex AI deployment resource pools delete command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai import operations
from googlecloudsdk.api_lib.ai.deployment_resource_pools import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ai import constants
from googlecloudsdk.command_lib.ai import deployment_resource_pools_util
from googlecloudsdk.command_lib.ai import endpoint_util
from googlecloudsdk.command_lib.ai import flags
from googlecloudsdk.command_lib.ai import operations_util
from googlecloudsdk.command_lib.ai import region_util
from googlecloudsdk.core.console import console_io
def _ArgsBeta(parser):
"""Adding deployment resource pool arguments from CLI.
Args:
parser: argparse.ArgumentParser, cli argument parser
Returns:
None
"""
flags.AddDeploymentResourcePoolArg(
parser,
'to delete',
prompt_func=region_util.PromptForDeploymentResourcePoolSupportedRegion)
def _RunBeta(args):
"""Delete a Vertex AI deployment resource pool."""
version = constants.BETA_VERSION
deployment_resource_pool_ref = args.CONCEPTS.deployment_resource_pool.Parse()
args.region = deployment_resource_pool_ref.AsDict()['locationsId']
deployment_resource_pool_id = deployment_resource_pool_ref.AsDict(
)['deploymentResourcePoolsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=args.region):
deployment_resource_pools_client = client.DeploymentResourcePoolsClient(
version=version)
operation_client = operations.OperationsClient()
console_io.PromptContinue(
'This will delete deployment resource pool [{}]...'.format(
deployment_resource_pool_id),
cancel_on_no=True)
op = deployment_resource_pools_client.DeleteBeta(
deployment_resource_pool_ref)
return operations_util.WaitForOpMaybe(
operation_client,
op,
deployment_resource_pools_util.ParseOperation(op.name),
log_method='delete')
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.UniverseCompatible
class DeleteV1Beta1(base.DeleteCommand):
"""Delete an existing Vertex AI deployment resource pool.
## EXAMPLES
To delete a deployment resource pool ``123'' under project ``example'' in
region ``us-central1'', run:
$ {command} 123 --project=example --region=us-central1
"""
@staticmethod
def Args(parser):
return _ArgsBeta(parser)
def Run(self, args):
return _RunBeta(args)

View File

@@ -0,0 +1,73 @@
# -*- 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.
"""Vertex AI deployment resource pools describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai.deployment_resource_pools import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ai import constants
from googlecloudsdk.command_lib.ai import endpoint_util
from googlecloudsdk.command_lib.ai import flags
from googlecloudsdk.command_lib.ai import region_util
def _ArgsBeta(parser):
flags.AddDeploymentResourcePoolArg(
parser,
'to describe',
prompt_func=region_util.PromptForDeploymentResourcePoolSupportedRegion)
def _RunBeta(args):
"""Describe a Vertex AI deployment resource pool."""
version = constants.BETA_VERSION
deployment_resource_pool_ref = args.CONCEPTS.deployment_resource_pool.Parse()
args.region = deployment_resource_pool_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=args.region):
deployment_resource_pools_client = client.DeploymentResourcePoolsClient(
version=version)
describe_response = deployment_resource_pools_client.DescribeBeta(
deployment_resource_pool_ref)
return describe_response
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.UniverseCompatible
class DescribeV1Beta1(base.DescribeCommand):
"""Describe a Vertex AI deployment resource pool.
This command describes a deployment resource pool with a provided deployment
resource pool.
## EXAMPLES
To describe a deployment resource pool with name ''example'' in region
''us-central1'', run:
$ {command} example --region=us-central1
"""
@staticmethod
def Args(parser):
return _ArgsBeta(parser)
def Run(self, args):
return _RunBeta(args)

View File

@@ -0,0 +1,89 @@
# -*- 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.
"""Vertex AI deployment resource pools list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai.deployment_resource_pools import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ai import constants
from googlecloudsdk.command_lib.ai import endpoint_util
from googlecloudsdk.command_lib.ai import flags
from googlecloudsdk.command_lib.ai import region_util
from googlecloudsdk.core import resources
_DEFAULT_FORMAT = """
table(
name.basename():label=DEPLOYMENT_RESOURCE_POOL_ID
)
"""
def _GetUri(deployment_resource_pool):
ref = resources.REGISTRY.ParseRelativeName(
deployment_resource_pool.name,
constants.DEPLOYMENT_RESOURCE_POOLS_COLLECTION)
return ref.SelfLink()
def _AddArgsBeta(parser):
"""Adding deployment resource pool arguments from CLI.
Args:
parser: argparse.ArgumentParser, cli argument parser
Returns:
None
"""
parser.display_info.AddFormat(_DEFAULT_FORMAT)
parser.display_info.AddUriFunc(_GetUri)
flags.AddRegionResourceArg(
parser,
'to list deployment resource pools',
prompt_func=region_util.PromptForDeploymentResourcePoolSupportedRegion)
def _RunBeta(args):
"""List Vertex AI deployment resource pools."""
version = constants.BETA_VERSION
region_ref = args.CONCEPTS.region.Parse()
args.region = region_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=args.region):
return client.DeploymentResourcePoolsClient(
version=version).ListBeta(region_ref)
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.UniverseCompatible
class ListV1Beta1(base.ListCommand):
"""List existing Vertex AI deployment resource pools.
## EXAMPLES
To list the deployment resource pools under project ``example'' in region
``us-central1'', run:
$ {command} --project=example --region=us-central1
"""
@staticmethod
def Args(parser):
return _AddArgsBeta(parser)
def Run(self, args):
return _RunBeta(args)

View File

@@ -0,0 +1,73 @@
# -*- 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.
"""Vertex AI deployment resource pools query command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai.deployment_resource_pools import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ai import constants
from googlecloudsdk.command_lib.ai import endpoint_util
from googlecloudsdk.command_lib.ai import flags
from googlecloudsdk.command_lib.ai import region_util
def _ArgsBeta(parser):
flags.AddDeploymentResourcePoolArg(
parser,
'to query',
prompt_func=region_util.PromptForDeploymentResourcePoolSupportedRegion)
def _RunBeta(args):
"""Queries Vertex AI deployed models sharing a specified deployment resource pool."""
version = constants.BETA_VERSION
deployment_resource_pool_ref = args.CONCEPTS.deployment_resource_pool.Parse()
args.region = deployment_resource_pool_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=args.region):
deployment_resource_pools_client = client.DeploymentResourcePoolsClient(
version=version)
query_response = deployment_resource_pools_client.QueryDeployedModelsBeta(
deployment_resource_pool_ref)
return query_response
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
@base.UniverseCompatible
class QueryDeployedModelsV1Beta1(base.ListCommand):
"""Queries Vertex AI deployed models sharing a specified deployment resource pool.
This command queries deployed models sharing the specified deployment resource
pool.
## EXAMPLES
To query a deployment resource pool with name ''example'' in region
''us-central1'', run:
$ {command} example --region=us-central1
"""
@staticmethod
def Args(parser):
return _ArgsBeta(parser)
def Run(self, args):
return _RunBeta(args)