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,51 @@
# -*- 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 command group for cloud dataproc operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Operations(base.Group):
"""View and manage Dataproc operations.
View and manage Dataproc operations.
## EXAMPLES
To cancel an active operation, run:
$ {command} cancel operation_id
To view the details of an operation, run:
$ {command} describe operation_id
To see the list of all operations, run:
$ {command} list
To delete the record of an inactive operation, run:
$ {command} delete operation_id
"""

View File

@@ -0,0 +1,63 @@
# -*- 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.
"""Cancel operation 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 import log
from googlecloudsdk.core.console import console_io
class Cancel(base.Command):
"""Cancel an active operation.
Cancel an active operation.
## EXAMPLES
To cancel an operation, run:
$ {command} operation_id
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddOperationResourceArg(parser, 'cancel', dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
operation_ref = args.CONCEPTS.operation.Parse()
request = dataproc.messages.DataprocProjectsRegionsOperationsCancelRequest(
name=operation_ref.RelativeName())
console_io.PromptContinue(
message="The operation '{0}' will be cancelled.".format(
args.operation),
cancel_on_no=True,
cancel_string='Cancellation aborted by user.')
dataproc.client.projects_regions_operations.Cancel(request)
# TODO(b/36050484) Check that operation was cancelled.
log.status.write('Cancelled [{0}].\n'.format(args.operation))

View File

@@ -0,0 +1,63 @@
# -*- 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.
"""Delete operation 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 import log
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete the record of an inactive operation.
Delete the record of an inactive operation.
## EXAMPLES
To delete the record of an operation, run:
$ {command} operation_id
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddOperationResourceArg(parser, 'delete', dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
operation_ref = args.CONCEPTS.operation.Parse()
request = dataproc.messages.DataprocProjectsRegionsOperationsDeleteRequest(
name=operation_ref.RelativeName())
console_io.PromptContinue(
message="The operation '{0}' will be deleted.".format(args.operation),
cancel_on_no=True,
cancel_string='Deletion aborted by user.')
dataproc.client.projects_regions_operations.Delete(request)
# TODO(b/36051082) Check that operation was deleted.
log.DeletedResource(args.operation)

View File

@@ -0,0 +1,53 @@
# -*- 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.
"""Describe operation 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):
"""View the details of an operation.
View the details of an operation.
## EXAMPLES
To view the details of an operation, run:
$ {command} operation_id
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddOperationResourceArg(parser, 'describe', dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
operation_ref = args.CONCEPTS.operation.Parse()
request = dataproc.messages.DataprocProjectsRegionsOperationsGetRequest(
name=operation_ref.RelativeName())
operation = dataproc.client.projects_regions_operations.Get(request)
return operation

View File

@@ -0,0 +1,65 @@
# -*- 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.
"""Get IAM operation 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.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class GetIamPolicy(base.ListCommand):
"""Get IAM policy for an operation.
Gets the IAM policy for an operation, given an operation ID.
## EXAMPLES
The following command prints the IAM policy for an operation with the ID
`example-operation`:
$ {command} example-operation
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddOperationResourceArg(parser, 'retrieve the policy for',
dataproc.api_version)
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
msgs = dataproc.messages
operation_ref = args.CONCEPTS.operation.Parse()
request = msgs.DataprocProjectsRegionsOperationsGetIamPolicyRequest(
resource=operation_ref.RelativeName(),
getIamPolicyRequest=msgs.GetIamPolicyRequest(
options=msgs.GetPolicyOptions(
requestedPolicyVersion=iam_helpers.MAX_LIBRARY_IAM_SUPPORTED_VERSION
)
),
)
return dataproc.client.projects_regions_operations.GetIamPolicy(request)

View File

@@ -0,0 +1,137 @@
# -*- 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.
"""List operation command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import json
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
from googlecloudsdk.core import properties
STATE_MATCHER_MAP = {'active': 'ACTIVE', 'inactive': 'NON_ACTIVE'}
STATE_MATCHER_FILTER = 'operation_state_matcher'
CLUSTER_NAME_FILTER = 'cluster_name'
PROJECT_FILTER = 'project_id'
class List(base.ListCommand):
"""View the list of all operations.
View a list of operations in a project. An optional filter can be used to
constrain the operations returned. Filters are case-sensitive and have the
following syntax:
field = value [AND [field = value]] ...
where `field` is either of `status.state` or `labels.[KEY]`, where `[KEY]` is
a label key. `value` can be ```*``` to match all values. `status.state` is
one of: `PENDING`, `ACTIVE`, `DONE`. Only the logical `AND` operator is
supported; space-separated items are treated as having an implicit `AND`
operator.
## EXAMPLES
To see the list of all operations in Dataproc's 'us-central1' region, run:
$ {command} --region='us-central1'
To see the list of all create cluster operations in Dataproc's 'global'
region, run:
$ {command} --region='global' --filter='operationType = CREATE'
To see the list of all active operations in a cluster named 'mycluster'
located in Dataproc's 'global' region, run:
$ {command} --region='global' --filter='status.state = RUNNING AND
clusterName = mycluster'
To see a list of all pending operations with the label `env=staging` on
cluster `mycluster` located in Dataproc's 'us-central1' region, run:
$ {command} --region='us-central1' --filter='status.state = PENDING
AND labels.env = staging AND clusterName = mycluster'
"""
@staticmethod
def Args(parser):
base.URI_FLAG.RemoveFromParser(parser)
base.PAGE_SIZE_FLAG.SetDefault(parser, constants.DEFAULT_PAGE_SIZE)
flags.AddRegionFlag(parser)
parser.add_argument(
'--cluster',
help=('Restrict to the operations of this Dataproc cluster. This flag '
'is ignored when --filter is specified. The equivalent term in '
'a --filter expression is: `clusterName = myclustername`'))
parser.add_argument(
'--state-filter',
choices=sorted(STATE_MATCHER_MAP.keys()),
help=('Filter by cluster state. This flag is ignored when --filter '
'is specified. The equivalent term in a --filter expression is: '
'`status.state = ACTIVE`'))
flags.AddListOperationsFormat(parser)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
region_callback = util.ResolveRegion
# Parse Operations endpoint.
project_callback = properties.VALUES.core.project.GetOrFail
operation_list_ref = dataproc.resources.Parse(
None,
params={'regionId': region_callback, 'projectId': project_callback},
collection='dataproc.projects.regions.operations_list')
filter_dict = dict()
if args.state_filter:
filter_dict[STATE_MATCHER_FILTER] = STATE_MATCHER_MAP[args.state_filter]
if args.cluster:
filter_dict[CLUSTER_NAME_FILTER] = args.cluster
op_filter = None
if args.filter:
# Prefer new filter argument if present
op_filter = args.filter
# Explicitly null out args.filter if present because by default
# args.filter also acts as a postfilter to the things coming back from the
# backend
args.filter = None
else:
op_filter = json.dumps(filter_dict)
request = dataproc.messages.DataprocProjectsRegionsOperationsListRequest(
name=operation_list_ref.RelativeName(), filter=op_filter)
return list_pager.YieldFromList(
dataproc.client.projects_regions_operations,
request,
limit=args.limit, field='operations',
batch_size=args.page_size,
batch_size_attribute='pageSize')

View File

@@ -0,0 +1,62 @@
# -*- 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.
"""Set IAM operation 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.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class SetIamPolicy(base.Command):
"""Set IAM policy for an operation.
Sets the IAM policy for an operation, given an operation ID and the policy.
"""
detailed_help = iam_util.GetDetailedHelpForSetIamPolicy('operation',
use_an=True)
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc(cls.ReleaseTrack())
flags.AddOperationResourceArg(parser, 'set the policy on',
dataproc.api_version)
iam_util.AddArgForPolicyFile(parser)
def Run(self, args):
dataproc = dp.Dataproc(self.ReleaseTrack())
msgs = dataproc.messages
policy = iam_util.ParsePolicyFile(args.policy_file, msgs.Policy)
policy.version = iam_helpers.MAX_LIBRARY_IAM_SUPPORTED_VERSION
set_iam_policy_request = msgs.SetIamPolicyRequest(policy=policy)
operation_ref = args.CONCEPTS.operation.Parse()
request = msgs.DataprocProjectsRegionsOperationsSetIamPolicyRequest(
resource=operation_ref.RelativeName(),
setIamPolicyRequest=set_iam_policy_request)
return dataproc.client.projects_regions_operations.SetIamPolicy(request)