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,55 @@
# -*- 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.
"""The command group for cloud dataproc autoscaling policies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class AutoscalingPolicies(base.Group):
"""Create and manage Dataproc autoscaling policies.
Create and manage Dataproc autoscaling policies.
## EXAMPLES
To see the list of all autoscaling policies, run:
$ {command} list
To view the details of an autoscaling policy, run:
$ {command} describe my_policy
To view just the non-output only fields of an autoscaling policy, run:
$ {command} export my_policy --destination policy-file.yaml
To create or update an autoscaling policy, run:
$ {command} import my_policy --source policy-file.yaml
To delete an autoscaling policy, run:
$ {command} delete my_policy
"""
pass

View File

@@ -0,0 +1,58 @@
# -*- 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.
"""Delete autoscaling policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataproc import dataproc as dp
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataproc import flags
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete an autoscaling policy.
## EXAMPLES
The following command deletes the autoscaling policy
`example-autoscaling-policy`:
$ {command} example-autoscaling-policy
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddAutoscalingPolicyResourceArg(parser, 'delete',
dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
messages = dataproc.messages
policy_ref = args.CONCEPTS.autoscaling_policy.Parse()
request = messages.DataprocProjectsRegionsAutoscalingPoliciesDeleteRequest(
name=policy_ref.RelativeName())
console_io.PromptContinue(
message="The autoscaling policy '[{0}]' will be deleted.".format(
policy_ref.Name()),
cancel_on_no=True)
dataproc.client.projects_regions_autoscalingPolicies.Delete(request)

View File

@@ -0,0 +1,51 @@
# -*- 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.
"""Describe autoscaling policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataproc import dataproc as dp
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataproc import flags
class Describe(base.DescribeCommand):
"""Describe an autoscaling policy.
## EXAMPLES
The following command prints out the autoscaling policy
`example-autoscaling-policy`:
$ {command} example-autoscaling-policy
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddAutoscalingPolicyResourceArg(parser, 'describe',
dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
messages = dataproc.messages
policy_ref = args.CONCEPTS.autoscaling_policy.Parse()
request = messages.DataprocProjectsRegionsAutoscalingPoliciesGetRequest(
name=policy_ref.RelativeName())
return dataproc.client.projects_regions_autoscalingPolicies.Get(request)

View File

@@ -0,0 +1,73 @@
# -*- 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.
"""Export autoscaling policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from googlecloudsdk.api_lib.dataproc import dataproc as dp
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataproc import flags
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core.util import files
class Export(base.Command):
"""Export an autoscaling policy.
Exporting an autoscaling policy is similar to describing one, except that
export omits output only fields, such as the policy id and resource name. This
is to allow piping the output of export directly into import, which requires
that output only fields are omitted.
## EXAMPLES
The following command saves the contents of autoscaling policy
`example-autoscaling-policy` to a file so that it can be imported later:
$ {command} example-autoscaling-policy --destination=saved-policy.yaml
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddAutoscalingPolicyResourceArg(parser, 'export',
dataproc.api_version)
export_util.AddExportFlags(parser)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
messages = dataproc.messages
policy_ref = args.CONCEPTS.autoscaling_policy.Parse()
request = messages.DataprocProjectsRegionsAutoscalingPoliciesGetRequest(
name=policy_ref.RelativeName())
policy = dataproc.client.projects_regions_autoscalingPolicies.Get(request)
# Filter out OUTPUT_ONLY fields and resource identifying fields. Note this
# needs to be kept in sync with v1 autoscaling_policies.proto.
policy.id = None
policy.name = None
if args.destination:
with files.FileWriter(args.destination) as stream:
export_util.Export(message=policy, stream=stream)
else:
# Print to stdout
export_util.Export(message=policy, stream=sys.stdout)

View File

@@ -0,0 +1,66 @@
# -*- 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.
"""Get IAM autoscaling policy policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataproc import dataproc as dp
from googlecloudsdk.api_lib.dataproc import iam_helpers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataproc import flags
@base.DefaultUniverseOnly
class GetIamPolicy(base.Command):
"""Get IAM policy for an autoscaling policy.
Gets the IAM policy for an autoscaling policy, given an autoscaling policy ID.
## EXAMPLES
The following command prints the IAM policy for an autoscaling policy with the
ID `example-autoscaling-policy`:
$ {command} example-autoscaling-policy
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddAutoscalingPolicyResourceArg(
parser, 'retrieve the IAM policy for', api_version=dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
messages = dataproc.messages
policy_ref = args.CONCEPTS.autoscaling_policy.Parse()
# pylint: disable=line-too-long
request = (
messages.DataprocProjectsRegionsAutoscalingPoliciesGetIamPolicyRequest(
resource=policy_ref.RelativeName(),
getIamPolicyRequest=messages.GetIamPolicyRequest(
options=messages.GetPolicyOptions(
requestedPolicyVersion=iam_helpers.MAX_LIBRARY_IAM_SUPPORTED_VERSION
)
),
)
)
# pylint: enable=line-too-long
return dataproc.client.projects_regions_autoscalingPolicies.GetIamPolicy(
request)

View File

@@ -0,0 +1,79 @@
# -*- 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.
"""Import autoscaling policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.dataproc import dataproc as dp
from googlecloudsdk.api_lib.dataproc import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataproc import flags
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core.console import console_io
class Import(base.Command):
"""Import an autoscaling policy.
If the specified autoscaling policy already exists, it will be overwritten.
Otherwise, a new autoscaling policy will be created.
To edit an existing autoscaling policy, you can export the autoscaling policy
to a file, edit its configuration, and then import the new configuration.
This command does not allow output only fields, such as policy id and resource
name. It populates the id field based on the resource name specified as the
first command line argument.
## EXAMPLES
The following command creates or updates the contents of autoscaling policy
`example-autoscaling-policy` based on a yaml file:
$ {command} example-autoscaling-policy --source=saved-policy.yaml
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddAutoscalingPolicyResourceArg(parser, 'import',
dataproc.api_version)
export_util.AddImportFlags(parser)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
policy_ref = args.CONCEPTS.autoscaling_policy.Parse()
policy = util.ReadAutoscalingPolicy(
dataproc=dataproc,
policy_id=policy_ref.Name(),
policy_file_name=args.source)
try:
return util.CreateAutoscalingPolicy(dataproc, policy_ref.RelativeName(),
policy)
except apitools_exceptions.HttpError as error:
# Catch ALREADY_EXISTS
if error.status_code != 409:
raise error
# Warn the user that they're going to overwrite an existing policy
console_io.PromptContinue(
message=('Autoscaling policy [{0}] will be overwritten.').format(
policy.id),
cancel_on_no=True)
return util.UpdateAutoscalingPolicy(dataproc, policy_ref.RelativeName(),
policy)

View File

@@ -0,0 +1,68 @@
# -*- 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.
"""List autoscaling policies 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.dataproc import constants
from googlecloudsdk.api_lib.dataproc import dataproc as dp
from googlecloudsdk.api_lib.dataproc import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataproc import flags
class List(base.ListCommand):
"""List autoscaling policies.
## EXAMPLES
The following command lists all autoscaling policies in Dataproc's
'us-central1' region:
$ {command} --region=us-central1
"""
@staticmethod
def Args(parser):
flags.AddRegionFlag(parser)
base.PAGE_SIZE_FLAG.SetDefault(parser, constants.DEFAULT_PAGE_SIZE)
parser.display_info.AddFormat("""
table(
id:label=ID
)
""")
# Implementation of --uri prints out "name" field for each entry
parser.display_info.AddUriFunc(lambda resource: resource.name)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
messages = dataproc.messages
region = util.ParseRegion(dataproc)
request = messages.DataprocProjectsRegionsAutoscalingPoliciesListRequest(
parent=region.RelativeName())
return list_pager.YieldFromList(
dataproc.client.projects_regions_autoscalingPolicies,
request,
limit=args.limit,
field='policies',
batch_size=args.page_size,
batch_size_attribute='pageSize')

View File

@@ -0,0 +1,71 @@
# -*- 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 IAM autoscaling policy policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataproc import dataproc as dp
from googlecloudsdk.api_lib.dataproc import iam_helpers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataproc import flags
from googlecloudsdk.command_lib.iam import iam_util
@base.DefaultUniverseOnly
class SetIamPolicy(base.Command):
r"""Set IAM policy for an autoscaling policy.
Sets the IAM policy for an autoscaling policy, given an autoscaling policy ID
and the IAM policy.
## EXAMPLES
The following command will read an IAM policy defined in a JSON file
'policy.json' and set it for an autoscaling-policy with identifier
'example-autoscaling-policy'
$ {command} autoscaling-policies set-iam-policy \
example-autoscaling-policy policy.json
See https://cloud.google.com/iam/docs/managing-policies for details of the
policy file format and contents.
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddAutoscalingPolicyResourceArg(parser, 'retrieve the IAM policy for',
dataproc.api_version)
iam_util.AddArgForPolicyFile(parser)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
messages = dataproc.messages
policy = iam_util.ParsePolicyFile(args.policy_file, messages.Policy)
policy.version = iam_helpers.MAX_LIBRARY_IAM_SUPPORTED_VERSION
set_iam_policy_request = messages.SetIamPolicyRequest(policy=policy)
policy_ref = args.CONCEPTS.autoscaling_policy.Parse()
# pylint: disable=line-too-long
request = messages.DataprocProjectsRegionsAutoscalingPoliciesSetIamPolicyRequest(
resource=policy_ref.RelativeName(),
setIamPolicyRequest=set_iam_policy_request)
# pylint: enable=line-too-long
return dataproc.client.projects_regions_autoscalingPolicies.SetIamPolicy(
request)