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,36 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 ai-platform models."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Models(base.Group):
"""AI Platform Models commands.
An AI Platform model is a container representing an ML application or
service. A model may contain multiple versions which act as the
implementation of the service. See also:
$ {parent_command} versions --help.
For more information, please see
https://cloud.google.com/ml/docs/concepts/technical-overview#model
"""
pass

View File

@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 to add IAM policy binding for a model."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.ml_engine import region_util
def _AddIamPolicyBindingFlags(parser, add_condition=False):
flags.GetModelName().AddToParser(parser)
flags.GetRegionArg(include_global=True).AddToParser(parser)
iam_util.AddArgsForAddIamPolicyBinding(
parser, flags.MlEngineIamRolesCompleter, add_condition=add_condition)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
return models_util.AddIamPolicyBinding(models.ModelsClient(), args.model,
args.member, args.role)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class AddIamPolicyBinding(base.Command):
"""Add IAM policy binding to a model."""
detailed_help = iam_util.GetDetailedHelpForAddIamPolicyBinding(
'model', 'my_model', role='roles/ml.admin', condition=False)
@staticmethod
def Args(parser):
_AddIamPolicyBindingFlags(parser)
def Run(self, args):
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class AddIamPolicyBindingBeta(AddIamPolicyBinding):
"""Add IAM policy binding to a model."""
detailed_help = iam_util.GetDetailedHelpForAddIamPolicyBinding(
'model', 'my_model', role='roles/ml.admin', condition=False)
@staticmethod
def Args(parser):
_AddIamPolicyBindingFlags(parser)
def Run(self, args):
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AddIamPolicyBindingAlpha(base.Command):
"""Adds IAM policy binding to a model.
Adds a policy binding to the IAM policy of a ML engine model, given a model ID
and the binding. One binding consists of a member, a role, and an optional
condition.
"""
detailed_help = iam_util.GetDetailedHelpForAddIamPolicyBinding(
'model', 'my_model', role='roles/ml.admin', condition=True)
@staticmethod
def Args(parser):
_AddIamPolicyBindingFlags(parser, add_condition=True)
def Run(self, args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
condition = iam_util.ValidateAndExtractCondition(args)
iam_util.ValidateMutexConditionAndPrimitiveRoles(condition, args.role)
return models_util.AddIamPolicyBindingWithCondition(
models.ModelsClient(),
args.model,
args.member,
args.role,
condition)

View File

@@ -0,0 +1,125 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 models create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml_engine import constants
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
_REGION_FLAG_HELPTEXT = """\
Google Cloud region of the regional endpoint to use for this command.
If you specify this flag, do not specify `--regions`.
If you specify `--region=global`, the model will be deployed to 'us-central1'
by default using the global endpoint. Please use `--regions` only if you want
to change the region where the model will be deployed against the global
endpoint.
If both flags are unspecified and you don't set ``ai_platform/region'', you will
be prompted for region of the regional endpoint.
Learn more about regional endpoints and see a list of available regions:
https://cloud.google.com/ai-platform/prediction/docs/regional-endpoints
"""
def _AddCreateArgs(parser,
support_console_logging=False):
"""Get arguments for the `ai-platform models create` command."""
flags.GetModelName().AddToParser(parser)
flags.GetDescriptionFlag('model').AddToParser(parser)
region_group = parser.add_mutually_exclusive_group()
region_group.add_argument(
'--region',
choices=constants.SUPPORTED_REGIONS_WITH_GLOBAL,
help=_REGION_FLAG_HELPTEXT)
region_group.add_argument(
'--regions',
metavar='REGION',
type=arg_parsers.ArgList(min_length=1),
help="""\
The Google Cloud region where the model will be deployed (currently only a
single region is supported) against the global endpoint.
If you specify this flag, do not specify `--region`.
Defaults to 'us-central1' while using the global endpoint.
""")
parser.add_argument(
'--enable-logging',
action='store_true',
help='If set, enables StackDriver Logging for online prediction. These '
'logs are like standard server access logs, containing information '
'such as timestamps and latency for each request.')
if support_console_logging:
parser.add_argument(
'--enable-console-logging',
action='store_true',
help='If set, enables StackDriver Logging of stderr and stdout streams '
'for online prediction. These logs are more verbose than the '
'standard access logs and can be helpful for debugging.')
labels_util.AddCreateLabelsFlags(parser)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a new AI Platform model."""
@staticmethod
def Args(parser):
_AddCreateArgs(parser)
def _Run(self, args, support_console_logging=False):
region, model_regions = models_util.GetModelRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
models_client = models.ModelsClient()
labels = models_util.ParseCreateLabels(models_client, args)
enable_console_logging = (
support_console_logging and args.enable_console_logging)
model = models_util.Create(
models_client,
args.model,
model_regions,
enable_logging=args.enable_logging,
enable_console_logging=enable_console_logging,
labels=labels,
description=args.description)
log.CreatedResource(model.name, kind='ai platform model')
def Run(self, args):
self._Run(args)
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class CreateBeta(Create):
"""Create a new AI Platform model."""
@staticmethod
def Args(parser):
_AddCreateArgs(parser, support_console_logging=True)
def Run(self, args):
self._Run(args, support_console_logging=True)

View File

@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 models delete command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.api_lib.ml_engine import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.ml_engine import region_util
def _AddDeleteArgs(parser):
flags.GetModelName().AddToParser(parser)
flags.GetRegionArg(include_global=True).AddToParser(parser)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
models_client = models.ModelsClient()
operations_client = operations.OperationsClient()
return models_util.Delete(models_client, operations_client, args.model)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
r"""Delete an existing AI Platform model.
## EXAMPLES
To delete all models matching the regular expression `vision[0-9]+`, run:
$ {parent_command} list --uri \
--filter 'name ~ vision[0-9]+' |
xargs -n 1 {command}
"""
@staticmethod
def Args(parser):
_AddDeleteArgs(parser)
def Run(self, args):
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class DeleteBeta(Delete):
r"""Delete an existing AI Platform model.
## EXAMPLES
To delete all models matching the regular expression `vision[0-9]+`, run:
$ {parent_command} list --uri \
--filter 'name ~ vision[0-9]+' |
xargs -n 1 {command}
"""
@staticmethod
def Args(parser):
_AddDeleteArgs(parser)
def Run(self, args):
return _Run(args)

View File

@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 models describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import region_util
_COLLECTION = 'ml.models'
def _AddDescribeArgs(parser):
flags.GetModelName().AddToParser(parser)
flags.GetRegionArg(include_global=True).AddToParser(parser)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
return models.ModelsClient().Get(args.model)
# TODO(b/62998601): don't repeat the first sentence due. Also if b/62998171 is
# resolved this should be obsolete.
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe an existing AI Platform model.
Describe an existing AI Platform model.
If you would like to see all versions of a model, use
`gcloud ai-platform versions list`.
"""
@staticmethod
def Args(parser):
_AddDescribeArgs(parser)
def Run(self, args):
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class DescribeBeta(base.DescribeCommand):
"""Describe an existing AI Platform model.
Describe an existing AI Platform model.
If you would like to see all versions of a model, use
`gcloud ai-platform versions list`.
"""
@staticmethod
def Args(parser):
_AddDescribeArgs(parser)
def Run(self, args):
return _Run(args)

View File

@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Fetch the IAM policy for a model."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.ml_engine import region_util
def _AddGetIamPolicyArgs(parser):
flags.GetModelResourceArg(
positional=True, required=True,
verb='to set IAM policy for').AddToParser(parser)
flags.GetRegionArg(include_global=True).AddToParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
return models_util.GetIamPolicy(models.ModelsClient(), args.model)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class GetIamPolicyBeta(base.ListCommand):
"""Get the IAM policy for a model.
Gets the IAM policy for the given model.
Returns an empty policy if the resource does not have a policy set.
## EXAMPLES
The following command gets the IAM policy for the model `my_model`:
$ {command} my_model
"""
@staticmethod
def Args(parser):
_AddGetIamPolicyArgs(parser)
def Run(self, args):
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class GetIamPolicy(base.ListCommand):
"""Get the IAM policy for a model.
Gets the IAM policy for the given model.
Returns an empty policy if the resource does not have a policy set.
## EXAMPLES
The following command gets the IAM policy for the model `my_model`:
$ {command} my_model
"""
@staticmethod
def Args(parser):
_AddGetIamPolicyArgs(parser)
def Run(self, args):
return _Run(args)

View File

@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 models list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.ml_engine import region_util
from googlecloudsdk.core import resources
_COLLECTION = 'ml.models'
_DEFAULT_FORMAT = """
table(
name.basename(),
defaultVersion.name.basename()
)
"""
def _GetUri(model):
ref = resources.REGISTRY.ParseRelativeName(
model.name, models_util.MODELS_COLLECTION)
return ref.SelfLink()
def _AddListArgs(parser):
parser.display_info.AddFormat(_DEFAULT_FORMAT)
parser.display_info.AddUriFunc(_GetUri)
flags.GetRegionArg(include_global=True).AddToParser(parser)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
return models_util.List(models.ModelsClient())
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List existing AI Platform models."""
@staticmethod
def Args(parser):
_AddListArgs(parser)
def Run(self, args):
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class ListBeta(base.ListCommand):
"""List existing AI Platform models."""
@staticmethod
def Args(parser):
_AddListArgs(parser)
def Run(self, args):
return _Run(args)

View File

@@ -0,0 +1,160 @@
# -*- 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.
"""Remove IAM Policy Binding."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.ml_engine import region_util
def _GetRemoveIamPolicyBindingArgs(parser, add_condition=False):
iam_util.AddArgsForRemoveIamPolicyBinding(parser, add_condition=add_condition)
flags.GetModelResourceArg(
required=True,
verb='for which to remove IAM policy binding from').AddToParser(parser)
flags.GetRegionArg(include_global=True).AddToParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
client = models.ModelsClient()
return models_util.RemoveIamPolicyBinding(client, args.model, args.member,
args.role)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class RemoveIamPolicyBinding(base.Command):
"""Removes IAM policy binding from an AI Platform Model resource.
Removes a policy binding from an AI Platform Model. One
binding consists of a member, a role and an optional condition.
See $ {parent_command} get-iam-policy for examples of how to
specify a model resource.
"""
description = 'remove IAM policy binding from an AI Platform model'
detailed_help = iam_util.GetDetailedHelpForRemoveIamPolicyBinding(
'model', 'my_model', role='roles/ml.admin', condition=False)
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order
to capture some information, but behaves like an ArgumentParser.
"""
_GetRemoveIamPolicyBindingArgs(parser, add_condition=False)
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:
The specified function with its description and configured filter.
"""
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class RemoveIamPolicyBindingBeta(base.Command):
"""Removes IAM policy binding from an AI Platform Model resource.
Removes a policy binding from an AI Platform Model. One
binding consists of a member, a role and an optional condition.
See $ {parent_command} get-iam-policy for examples of how to
specify a model resource.
"""
description = 'remove IAM policy binding from an AI Platform model'
detailed_help = iam_util.GetDetailedHelpForRemoveIamPolicyBinding(
'model', 'my_model', role='roles/ml.admin', condition=False)
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order
to capture some information, but behaves like an ArgumentParser.
"""
_GetRemoveIamPolicyBindingArgs(parser, add_condition=False)
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:
The specified function with its description and configured filter.
"""
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class RemoveIamPolicyBindingAlpha(base.Command):
r"""Removes IAM policy binding from an AI Platform Model resource.
Remove an IAM policy binding from the IAM policy of a ML model. One binding
consists of a member, a role, and an optional condition.
See $ {parent_command} get-iam-policy for examples of how to
specify a model resource.
"""
description = 'remove IAM policy binding from an AI Platform model'
detailed_help = iam_util.GetDetailedHelpForRemoveIamPolicyBinding(
'model', 'my_model', role='roles/ml.admin', condition=False)
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order
to capture some information, but behaves like an ArgumentParser.
"""
_GetRemoveIamPolicyBindingArgs(parser, add_condition=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:
The specified function with its description and configured filter.
"""
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
condition = iam_util.ValidateAndExtractCondition(args)
iam_util.ValidateMutexConditionAndPrimitiveRoles(condition, args.role)
return models_util.RemoveIamPolicyBindingWithCondition(
models.ModelsClient(), args.model, args.member, args.role, condition)

View File

@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Set the IAM policy for a model."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.ml_engine import region_util
def _AddSetIamPolicyArgs(parser):
flags.GetModelResourceArg(
positional=True, required=True,
verb='to set IAM policy for').AddToParser(parser)
flags.GetRegionArg(include_global=True).AddToParser(parser)
iam_util.AddArgForPolicyFile(parser)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
return models_util.SetIamPolicy(models.ModelsClient(), args.model,
args.policy_file)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class SetIamPolicyGA(base.Command):
"""Set the IAM policy for a model.
Sets the IAM policy for the given model as defined in a JSON or YAML file.
See https://cloud.google.com/iam/docs/managing-policies for details of
the policy file format and contents.
## EXAMPLES
The following command will read am IAM policy defined in a JSON file
'policy.json' and set it for the model `my_model`:
$ {command} my_model policy.json
"""
@staticmethod
def Args(parser):
_AddSetIamPolicyArgs(parser)
def Run(self, args):
return _Run(args)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class SetIamPolicyBeta(base.Command):
"""Set the IAM policy for a model.
Sets the IAM policy for the given model as defined in a JSON or YAML file.
See https://cloud.google.com/iam/docs/managing-policies for details of
the policy file format and contents.
## EXAMPLES
The following command will read am IAM policy defined in a JSON file
'policy.json' and set it for the model `my_model`:
$ {command} my_model policy.json
"""
@staticmethod
def Args(parser):
_AddSetIamPolicyArgs(parser)
def Run(self, args):
return _Run(args)

View File

@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 models update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml_engine import models
from googlecloudsdk.api_lib.ml_engine import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml_engine import endpoint_util
from googlecloudsdk.command_lib.ml_engine import flags
from googlecloudsdk.command_lib.ml_engine import models_util
from googlecloudsdk.command_lib.ml_engine import region_util
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
def _AddUpdateArgs(parser):
"""Get arguments for the `ai-platform models update` command."""
flags.GetModelName().AddToParser(parser)
flags.GetRegionArg(include_global=True).AddToParser(parser)
flags.GetDescriptionFlag('model').AddToParser(parser)
labels_util.AddUpdateLabelsFlags(parser)
def _Run(args):
region = region_util.GetRegion(args)
with endpoint_util.MlEndpointOverrides(region=region):
models_client = models.ModelsClient()
operations_client = operations.OperationsClient()
models_util.Update(models_client, operations_client, args)
log.UpdatedResource(args.model, kind='ai platform model')
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class UpdateBeta(base.UpdateCommand):
"""Update an existing AI Platform model."""
@staticmethod
def Args(parser):
_AddUpdateArgs(parser)
def Run(self, args):
_Run(args)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update an existing AI Platform model."""
@staticmethod
def Args(parser):
_AddUpdateArgs(parser)
def Run(self, args):
_Run(args)