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,53 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 session templates."""
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.BETA)
class SessionTemplates(base.Group):
"""Create and manage Dataproc session templates.
Create and manage Dataproc session templates.
## EXAMPLES
To see the list of all session templates, run:
$ {command} list
To view the details of a session template, run:
$ {command} describe my-template
To view just the non-output only fields of a session template, run:
$ {command} export my-template --destination template-file.yaml
To create or update a session template, run:
$ {command} import my-template --source template-file.yaml
To delete a session template, run:
$ {command} delete my-template
"""
pass

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 session template 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
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class Delete(base.DeleteCommand):
"""Delete a session template.
## EXAMPLES
The following command deletes the session template
`example-session-template`:
$ {command} example-session-template
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc()
flags.AddSessionTemplateResourceArg(parser, 'delete',
dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc()
messages = dataproc.messages
template_ref = args.CONCEPTS.session_template.Parse()
request = messages.DataprocProjectsLocationsSessionTemplatesDeleteRequest(
name=template_ref.RelativeName())
console_io.PromptContinue(
message="The session template '[{0}]' will be deleted.".format(
template_ref.Name()),
cancel_on_no=True)
dataproc.client.projects_locations_sessionTemplates.Delete(request)
log.DeletedResource(template_ref.RelativeName())

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 session template 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
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class Describe(base.DescribeCommand):
"""Describe a session template.
## EXAMPLES
The following command prints out the session template
`example-session-template`:
$ {command} example-session-template
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc()
flags.AddSessionTemplateResourceArg(parser, 'describe',
dataproc.api_version)
def Run(self, args):
dataproc = dp.Dataproc()
messages = dataproc.messages
template_ref = args.CONCEPTS.session_template.Parse()
request = messages.DataprocProjectsLocationsSessionTemplatesGetRequest(
name=template_ref.RelativeName())
return dataproc.client.projects_locations_sessionTemplates.Get(request)

View File

@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 session template 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
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class Export(base.Command):
"""Export a session template.
Exporting a session template is similar to describing one, except that export
omits output only fields, such as the template 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 session template
`example-session-template` to a file so that it can be imported later:
$ {command} example-session-template --destination=saved-template.yaml
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc()
flags.AddSessionTemplateResourceArg(parser, 'export', dataproc.api_version)
export_util.AddExportFlags(parser)
def Run(self, args):
dataproc = dp.Dataproc()
messages = dataproc.messages
template_ref = args.CONCEPTS.session_template.Parse()
request = messages.DataprocProjectsLocationsSessionTemplatesGetRequest(
name=template_ref.RelativeName())
template = dataproc.client.projects_locations_sessionTemplates.Get(request)
# Filter out OUTPUT_ONLY fields and resource identifying fields. Note this
# needs to be kept in sync with v1 session_templates.proto.
template.name = None
template.createTime = None
template.creator = None
template.updateTime = None
template.uuid = None
if args.destination:
with files.FileWriter(args.destination) as stream:
export_util.Export(message=template, stream=stream)
else:
# Print to stdout
export_util.Export(message=template, stream=sys.stdout)

View File

@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 session template 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
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class Import(base.Command):
"""Import a session template.
If the specified session template already exists, it will be overwritten.
Otherwise, a new session template will be created.
To edit an existing session template, you can export the session template
to a file, edit its configuration, and then import the new configuration.
This command does not allow output only fields, such as template 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 session template
`example-session-template` based on a yaml file:
$ {command} example-session-template --source=saved-template.yaml
"""
@classmethod
def Args(cls, parser):
dataproc = dp.Dataproc()
flags.AddSessionTemplateResourceArg(parser, 'import',
dataproc.api_version)
export_util.AddImportFlags(parser)
def Run(self, args):
dataproc = dp.Dataproc()
template_ref = args.CONCEPTS.session_template.Parse()
template = util.ReadSessionTemplate(
dataproc=dataproc,
template_file_name=args.source)
try:
return util.CreateSessionTemplate(dataproc, template_ref.RelativeName(),
template)
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 template
console_io.PromptContinue(
message=('Session template [{0}] will be overwritten.').format(
template.name),
cancel_on_no=True)
return util.UpdateSessionTemplate(dataproc, template_ref.RelativeName(),
template)

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 session templates 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
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class List(base.ListCommand):
"""List session templates.
## EXAMPLES
The following command lists all session templates in Dataproc's
'us-central1' region:
$ {command} --location=us-central1
"""
@staticmethod
def Args(parser):
flags.AddLocationFlag(parser)
base.PAGE_SIZE_FLAG.SetDefault(parser, constants.DEFAULT_PAGE_SIZE)
parser.display_info.AddFormat("""
table(
name.basename():label=NAME
)
""")
# 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()
messages = dataproc.messages
location = util.ParseProjectsLocationsForSession(dataproc)
request = messages.DataprocProjectsLocationsSessionTemplatesListRequest(
parent=location.RelativeName())
return list_pager.YieldFromList(
dataproc.client.projects_locations_sessionTemplates,
request,
limit=args.limit,
field='sessionTemplates',
batch_size=args.page_size,
batch_size_attribute='pageSize')