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,29 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoint."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class IndexEndpoint(base.Group):
"""Manage Vertex AI index endpoints."""
category = base.VERTEX_AI_CATEGORY

View File

@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoints 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.index_endpoints 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 index_endpoints_util
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.command_lib.util.args import labels_util
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateV1(base.CreateCommand):
"""Create a new Vertex AI index endpoint.
## EXAMPLES
To create an index endpoint under project `example` with network
`projects/123/global/networks/test-network` in region
`us-central1`, run:
$ {command} --display-name=index-endpoint --description=test
--network=projects/123/global/networks/test-network
--project=example --region=us-central1
"""
@staticmethod
def Args(parser):
flags.AddRegionResourceArg(
parser,
'to create index endpoint',
prompt_func=region_util.GetPromptForRegionFunc(
constants.SUPPORTED_OP_REGIONS
),
)
flags.GetDisplayNameArg('index endpoint').AddToParser(parser)
flags.GetDescriptionArg('index endpoint').AddToParser(parser)
flags.GetNetworkArg().AddToParser(parser)
flags.GetPublicEndpointEnabledArg().AddToParser(parser)
labels_util.AddCreateLabelsFlags(parser)
flags.AddPrivateServiceConnectConfig(parser)
flags.GetEncryptionKmsKeyNameArg().AddToParser(parser)
def _Run(self, args, version):
validation.ValidateDisplayName(args.display_name)
validation.ValidateEndpointArgs(args.network, args.public_endpoint_enabled)
region_ref = args.CONCEPTS.region.Parse()
region = region_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
index_endpoint_client = client.IndexEndpointsClient(version=version)
if version == constants.GA_VERSION:
operation = index_endpoint_client.Create(region_ref, args)
else:
operation = index_endpoint_client.CreateBeta(region_ref, args)
response_msg = operations_util.WaitForOpMaybe(
operations_client=operations.OperationsClient(version=version),
op=operation,
op_ref=index_endpoints_util.ParseIndexEndpointOperation(
operation.name))
if response_msg is not None:
response = encoding.MessageToPyValue(response_msg)
if 'name' in response:
log.status.Print(('Created Vertex AI index endpoint: {}.').format(
response['name']))
return response_msg
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class CreateV1Beta1(CreateV1):
"""Create a new Vertex AI index endpoint.
## EXAMPLES
To create an index endpoint under project `example` with network
`projects/123/global/networks/test-network` in region
`us-central1`, run:
$ {command} --display-name=index-endpoint --description=test
--network=projects/123/global/networks/test-network
--project=example --region=us-central1
"""
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)

View File

@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoints 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.index_endpoints 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 index_endpoints_util
from googlecloudsdk.command_lib.ai import operations_util
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.GA)
class DeleteV1(base.DeleteCommand):
"""Delete an existing Vertex AI index endpoint.
## EXAMPLES
To delete an index endpoint `123` of project `example` in region
`us-central1`, run:
$ {command} 123 --project=example --region=us-central1
"""
@staticmethod
def Args(parser):
flags.AddIndexEndpointResourceArg(parser, 'to delete')
def _Run(self, args, version):
index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
region = index_endpoint_ref.AsDict()['locationsId']
index_endpoint_id = index_endpoint_ref.AsDict()['indexEndpointsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
console_io.PromptContinue(
'This will delete index endpoint [{}]...'.format(index_endpoint_id),
cancel_on_no=True)
operation = client.IndexEndpointsClient(
version=version).Delete(index_endpoint_ref)
return operations_util.WaitForOpMaybe(
operations_client=operations.OperationsClient(version=version),
op=operation,
op_ref=index_endpoints_util.ParseIndexEndpointOperation(
operation.name))
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DeleteV1Beta1(DeleteV1):
"""Delete an existing Vertex AI index endpoint.
## EXAMPLES
To delete an index endpoint `123` of project `example` in region
`us-central1`, run:
$ {command} 123 --project=example --region=us-central1
"""
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)

View File

@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoints deploy-index command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai.index_endpoints 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 index_endpoints_util
from googlecloudsdk.command_lib.ai import validation
from googlecloudsdk.core import log
DETAILED_HELP = {
'EXAMPLES':
"""\
To deploy index ``345'' to an index endpoint ``456'' with 2 min replica count and 10 max replica count under project ``example'' in region ``us-central1'', within reserved ip ranges
``vertex-ai-ip-range-1'' and ``vertex-ai-ip-range-2'' run:
$ {command} 456 --project=example --region=us-central1 --index=345 --deployed-index-id=deployed-index-345 --display-name=deployed-index-345 --min-replica-count=2 --max-replica-count=10 --reserved-ip-ranges=vertex-ai-ip-range-1,vertex-ai-ip-range-2
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class DeployIndexV1(base.Command):
"""Deploy an index to a Vertex AI index endpoint."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
flags.AddIndexEndpointResourceArg(parser, 'to deploy an index')
flags.GetDeployedIndexId().AddToParser(parser)
flags.GetIndexIdArg().AddToParser(parser)
flags.GetDisplayNameArg('deployed index').AddToParser(parser)
flags.AddDeploymentResourcesArgs(parser, 'deployed index')
flags.AddReservedIpRangesArgs(parser, 'deployed index')
flags.AddDeploymentTierArgs(parser, 'deployed index')
flags.AddDeploymentGroupArg(parser)
flags.AddAuthConfigArgs(parser, 'deployed index')
flags.GetEnableAccessLoggingArg().AddToParser(parser)
flags.AddPscAutomationConfigsArgs(parser)
def _Run(self, args, version):
validation.ValidateDisplayName(args.display_name)
index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
project_id = index_endpoint_ref.AsDict()['projectsId']
region = index_endpoint_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
index_endpoint_client = client.IndexEndpointsClient(version=version)
if version == constants.GA_VERSION:
operation = index_endpoint_client.DeployIndex(index_endpoint_ref, args)
else:
operation = index_endpoint_client.DeployIndexBeta(
index_endpoint_ref, args)
op_ref = index_endpoints_util.ParseIndexEndpointOperation(operation.name)
# TODO(b/208506223): Support `--async` flag.
index_endpoint_id = op_ref.AsDict()['indexEndpointsId']
log.status.Print(
constants.OPERATION_CREATION_DISPLAY_MESSAGE.format(
name=operation.name,
verb='deploy index',
id=op_ref.Name(),
sub_commands='--index-endpoint={} --region={} [--project={}]'
.format(index_endpoint_id, region, project_id)))
return operation
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DeployIndexV1Beta1(DeployIndexV1):
"""Deploy an index to a Vertex AI index endpoint."""
detailed_help = DETAILED_HELP
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)

View File

@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoints describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai.index_endpoints 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
@base.ReleaseTracks(base.ReleaseTrack.GA)
class DescribeV1(base.DescribeCommand):
"""Gets detailed index endpoint information about the given index endpoint id.
## EXAMPLES
Describe an index endpoint `123` of project `example` in region `us-central1`,
run:
$ {command} 123 --project=example --region=us-central1
"""
@staticmethod
def Args(parser):
flags.AddIndexEndpointResourceArg(parser, 'to describe')
def _Run(self, args, version):
index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
region = index_endpoint_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
return client.IndexEndpointsClient(
version=version).Get(index_endpoint_ref)
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DescribeV1Beta1(DescribeV1):
"""Gets detailed index endpoint information about the given index endpoint id.
## EXAMPLES
Describe an index endpoint `123` of project `example` in region `us-central1`,
run:
$ {command} 123 --project=example --region=us-central1
"""
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)

View File

@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoints list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai.index_endpoints 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
@base.ReleaseTracks(base.ReleaseTrack.GA)
class ListV1(base.ListCommand):
"""Lists the index endpoints of the given project and region.
## EXAMPLES
Lists the index endpoints of project `example` in region `us-central1`, run:
$ {command} --project=example --region=us-central1
"""
@staticmethod
def Args(parser):
flags.AddRegionResourceArg(
parser,
'to list index endpoints',
prompt_func=region_util.GetPromptForRegionFunc(
constants.SUPPORTED_OP_REGIONS
),
)
def _Run(self, args, version):
region_ref = args.CONCEPTS.region.Parse()
region = region_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
return client.IndexEndpointsClient(version=version).List(
region_ref=region_ref)
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class ListV1Beta1(ListV1):
"""Lists the index endpoints of the given project and region.
## EXAMPLES
Lists the index endpoints of project `example` in region `us-central1`, run:
$ {command} --project=example --region=us-central1
"""
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)

View File

@@ -0,0 +1,99 @@
# -*- 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.
"""AI Platform index endpoints mutate-deployed-index 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.index_endpoints 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 index_endpoints_util
from googlecloudsdk.command_lib.ai import operations_util
from googlecloudsdk.core import log
DETAILED_HELP = {
'EXAMPLES':
"""\
To mutated a deployed index ``deployed-index-123'' from an index
endpoint ``456'' with 2 min replica count and 10 max replica count under
project ``example'' in region ``us-central1'', within
``vertex-ai-ip-ranges-1'' and ``vertex-ai-ip-ranges-2'', within
deployment group ``test'', enabling access logging, with JWT audiences
``aud1'' and ``aud2'', JWT issuers ``issuer1'' and ``issuer2'' run:
$ {command} 456 --project=example --region=us-central1 --deployed-index-id=deployed-index-123 --min-replica-count=2 --max-replica-count=10 --reserved-ip-ranges=vertex-ai-ip-ranges-1,vertex-ai-ip-ranges-2 --enable-access-logging --audiences=aud1,aud2 --allowed-issuers=issuer1,issuer2 --deployment-group=test
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class MutateDeployedIndexV1(base.Command):
"""Mutate an existing deployed index from a Vertex AI index endpoint."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
flags.AddIndexEndpointResourceArg(parser, 'ID of the index endpoint.')
flags.GetDeployedIndexId().AddToParser(parser)
flags.AddDeploymentResourcesArgs(parser, 'deployed index')
flags.AddReservedIpRangesArgs(parser, 'deployed index')
flags.AddDeploymentGroupArg(parser)
flags.AddAuthConfigArgs(parser, 'deployed index')
flags.GetEnableAccessLoggingArg().AddToParser(parser)
def _Run(self, args, version):
index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
region = index_endpoint_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
index_endpoint_client = client.IndexEndpointsClient(version=version)
if version == constants.GA_VERSION:
operation = index_endpoint_client.MutateDeployedIndex(
index_endpoint_ref, args)
else:
operation = index_endpoint_client.MutateDeployedIndexBeta(
index_endpoint_ref, args)
response_msg = operations_util.WaitForOpMaybe(
operations_client=operations.OperationsClient(version=version),
op=operation,
op_ref=index_endpoints_util.ParseIndexEndpointOperation(
operation.name))
if response_msg is not None:
response = encoding.MessageToPyValue(response_msg)
if 'deployedIndex' in response and 'id' in response['deployedIndex']:
log.status.Print(('Id of the deployed index updated: {}.').format(
response['deployedIndex']['id']))
return response_msg
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class MutateDeployedIndexV1Beta1(MutateDeployedIndexV1):
"""Mutate an existing deployed index from a Vertex AI index endpoint."""
detailed_help = DETAILED_HELP
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)

View File

@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoints undeploy-index 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.index_endpoints 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 index_endpoints_util
from googlecloudsdk.command_lib.ai import operations_util
@base.ReleaseTracks(base.ReleaseTrack.GA)
class UndeployIndexV1(base.Command):
"""Undeploy an index from a Vertex AI index endpoint.
## EXAMPLES
To undeploy the deployed-index ``deployed-index-345'' from an index endpoint
``456'' under project ``example'' in region ``us-central1'', run:
$ {command} 456 --project=example --region=us-central1
--deployed-index-id=deployed-index-345
"""
@staticmethod
def Args(parser):
flags.AddIndexEndpointResourceArg(parser, 'to undeploy an index')
flags.GetDeployedIndexId().AddToParser(parser)
def _Run(self, args, version):
index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
region = index_endpoint_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
index_endpoint_client = client.IndexEndpointsClient(version=version)
if version == constants.GA_VERSION:
operation = index_endpoint_client.UndeployIndex(index_endpoint_ref,
args)
else:
operation = index_endpoint_client.UndeployIndexBeta(
index_endpoint_ref, args)
return operations_util.WaitForOpMaybe(
operations_client=operations.OperationsClient(version=version),
op=operation,
op_ref=index_endpoints_util.ParseIndexEndpointOperation(
operation.name))
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class UndeployIndexV1Beta1(UndeployIndexV1):
"""Undeploy an index from a Vertex AI index endpoint.
## EXAMPLES
To undeploy the deployed-index ``deployed-index-345'' from an index endpoint
``456'' under project ``example'' in region ``us-central1'', run:
$ {command} 456 --project=example --region=us-central1
--deployed-index-id=deployed-index-345
"""
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)

View File

@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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 index endpoints update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ai.index_endpoints 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 errors
from googlecloudsdk.command_lib.ai import flags
from googlecloudsdk.command_lib.ai import validation
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.GA)
class UpdateV1(base.UpdateCommand):
"""Update an Vertex AI index endpoint.
## EXAMPLES
To update display name of index endpoint `123` under project `example` in
region `us-central1`, run:
$ {command} --display-name=new-name --project=example --region=us-central1
"""
@staticmethod
def Args(parser):
flags.AddIndexEndpointResourceArg(parser, 'to update')
flags.GetDisplayNameArg(
'index endpoint', required=False).AddToParser(parser)
flags.GetDescriptionArg('index endpoint').AddToParser(parser)
labels_util.AddUpdateLabelsFlags(parser)
def _Run(self, args, version):
validation.ValidateDisplayName(args.display_name)
index_endpoint_ref = args.CONCEPTS.index_endpoint.Parse()
region = index_endpoint_ref.AsDict()['locationsId']
with endpoint_util.AiplatformEndpointOverrides(version, region=region):
index_endpoint_client = client.IndexEndpointsClient(version=version)
try:
if version == constants.GA_VERSION:
result = index_endpoint_client.Patch(index_endpoint_ref, args)
else:
result = index_endpoint_client.PatchBeta(index_endpoint_ref, args)
except errors.NoFieldsSpecifiedError:
available_update_args = [
'display_name', 'description', 'update_labels', 'clear_labels',
'remove_labels'
]
if not any(args.IsSpecified(arg) for arg in available_update_args):
raise
log.status.Print('No update to perform.')
return None
else:
log.UpdatedResource(result.name, kind='Vertex AI index endpoint')
return result
def Run(self, args):
return self._Run(args, constants.GA_VERSION)
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class UpdateV1Beta1(UpdateV1):
"""Update an Vertex AI index endpoint.
## EXAMPLES
To update display name of index endpoint `123` under project `example` in
region `us-central1`, run:
$ {command} --display-name=new-name --project=example --region=us-central1
"""
def Run(self, args):
return self._Run(args, constants.BETA_VERSION)