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,46 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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.
"""Commands for reading and manipulating VPN Gateways."""
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 TargetVpnGateways(base.Group):
"""Read and manipulate classic VPN gateways."""
# Placeholder to indicate that a detailed_help field exists and should
# be set outside the class definition.
detailed_help = None
TargetVpnGateways.category = base.NETWORKING_CATEGORY
TargetVpnGateways.detailed_help = {
'DESCRIPTION': """
Read and manipulate Classic VPN gateways for Cloud VPN.
For more information about Classic VPN gateways, see the
[Classic VPN gateways documentation](https://cloud.google.com/network-connectivity/docs/vpn/concepts/overview#classic-vpn).
See also: [Classic VPN gateways API](https://cloud.google.com/compute/docs/reference/rest/v1/targetVpnGateways).
""",
}

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 managing Compute Engine target vpn gateway configurations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Config(base.Group):
"""Manage Compute Engine target vpn gateway configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Compute Engine target vpn gateway.
description: |
*{command}* exports the configuration for a Compute Engine target vpn gateway.
Target vpn gateway configurations can be exported in
Kubernetes Resource Model (krm) or Terraform HCL formats. The
default format is `krm`.
Specifying `--all` allows you to export the configurations for all
target vpn gateways within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a target vpn gateway, run:
$ {command} my-target-vpn-gateway
To export the configuration for a target vpn gateway to a file, run:
$ {command} my-target-vpn-gateway --path=/path/to/dir/
To export the configuration for a target vpn gateway in Terraform
HCL format, run:
$ {command} my-target-vpn-gateway --resource-format=terraform
To export the configurations for all target vpn gateways within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Target vpn gateway to export the configuration for.
spec: !REF googlecloudsdk.command_lib.compute.resources:target_vpn_gateway

View File

@@ -0,0 +1,193 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for creating target VPN Gateways."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import resource_manager_tags_utils
from googlecloudsdk.command_lib.compute.networks import flags as network_flags
from googlecloudsdk.command_lib.compute.target_vpn_gateways import flags
import six
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.UniverseCompatible
class Create(base.CreateCommand):
"""Create a Cloud VPN Classic Target VPN Gateway.
*{command}* is used to create a Cloud VPN Classic Target VPN Gateway. A
Target VPN Gateway can reference one or more VPN tunnels that connect it to
the remote tunnel endpoint. A Target VPN Gateway may also be referenced by
one or more forwarding rules that define which packets the
gateway is responsible for routing.
"""
NETWORK_ARG = None
TARGET_VPN_GATEWAY_ARG = None
_support_tagging_at_creation = False
@classmethod
def Args(cls, parser):
"""Adds arguments to the supplied parser."""
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
"""\
A reference to a network in this project to
contain the VPN Gateway.
""")
cls.NETWORK_ARG.AddArgument(parser)
cls.TARGET_VPN_GATEWAY_ARG = flags.TargetVpnGatewayArgument()
cls.TARGET_VPN_GATEWAY_ARG.AddArgument(parser, operation_type='create')
parser.add_argument(
'--description',
help='An optional, textual description for the target VPN Gateway.')
if cls._support_tagging_at_creation:
parser.add_argument(
'--resource-manager-tags',
type=arg_parsers.ArgDict(),
metavar='KEY=VALUE',
help="""\
A comma-separated list of Resource Manager tags to apply to the target VPN gateway.
""",
)
parser.display_info.AddCacheUpdater(flags.TargetVpnGatewaysCompleter)
def _Run(self, args):
"""Issues API requests to construct Target VPN Gateways.
Args:
args: argparse.Namespace, The arguments received by this command.
Returns:
[protorpc.messages.Message], A list of responses returned
by the compute API.
"""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
messages = client.messages
# helper = target_vpn_gateways_utils.TargetVpnGatewayHelper(holder)
target_vpn_gateway_ref = self.TARGET_VPN_GATEWAY_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client))
network_ref = self.NETWORK_ARG.ResolveAsResource(args, holder.resources)
params = None
if self._support_tagging_at_creation:
if args.resource_manager_tags is not None:
params = self._CreateTargetVpnGatewayParams(
messages, args.resource_manager_tags
)
if self._support_tagging_at_creation and params is not None:
request = client.messages.ComputeTargetVpnGatewaysInsertRequest(
project=target_vpn_gateway_ref.project,
region=target_vpn_gateway_ref.region,
targetVpnGateway=client.messages.TargetVpnGateway(
description=args.description,
name=target_vpn_gateway_ref.Name(),
network=network_ref.SelfLink(),
params=params,
),
)
else:
request = client.messages.ComputeTargetVpnGatewaysInsertRequest(
project=target_vpn_gateway_ref.project,
region=target_vpn_gateway_ref.region,
targetVpnGateway=client.messages.TargetVpnGateway(
description=args.description,
name=target_vpn_gateway_ref.Name(),
network=network_ref.SelfLink(),
),
)
return client.MakeRequests(
[(client.apitools_client.targetVpnGateways, 'Insert', request)]
)
def _CreateTargetVpnGatewayParams(self, messages, resource_manager_tags):
resource_manager_tags_map = (
resource_manager_tags_utils.GetResourceManagerTags(
resource_manager_tags
)
)
params = messages.TargetVpnGatewayParams
additional_properties = [
params.ResourceManagerTagsValue.AdditionalProperty(key=key, value=value)
for key, value in sorted(six.iteritems(resource_manager_tags_map))
]
return params(
resourceManagerTags=params.ResourceManagerTagsValue(
additionalProperties=additional_properties
)
)
def Run(self, args):
"""Issues API requests to construct Target VPN gateways."""
return self._Run(args)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(Create):
"""Create a Cloud VPN Classic Target VPN Gateway.
*{command}* is used to create a Cloud VPN Classic Target VPN Gateway. A
Target VPN Gateway can reference one or more VPN tunnels that connect it to
the remote tunnel endpoint. A Target VPN Gateway may also be referenced by
one or more forwarding rules that define which packets the
gateway is responsible for routing.
"""
_support_tagging_at_creation = False
@classmethod
def Args(cls, parser):
"""Set up arguments for this command."""
super(CreateBeta, cls).Args(parser)
def Run(self, args):
"""See base.CreateCommand."""
return self._Run(args)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(Create):
"""Create a Cloud VPN Classic Target VPN Gateway.
*{command}* is used to create a Cloud VPN Classic Target VPN Gateway. A
Target VPN Gateway can reference one or more VPN tunnels that connect it to
the remote tunnel endpoint. A Target VPN Gateway may also be referenced by
one or more forwarding rules that define which packets the
gateway is responsible for routing.
"""
_support_tagging_at_creation = True
@classmethod
def Args(cls, parser):
"""Set up arguments for this command."""
super(CreateAlpha, cls).Args(parser)
def Run(self, args):
"""See base.CreateCommand."""
return self._Run(args)

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for deleting target vpn gateways."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.target_vpn_gateways import flags
class Delete(base.DeleteCommand):
"""Delete Cloud VPN Classic Target VPN Gateways.
*{command}* deletes one or more Compute Engine Cloud VPN Classic
Target VPN Gateways.
"""
TARGET_VPN_GATEWAY_ARG = None
@staticmethod
def Args(parser):
Delete.TARGET_VPN_GATEWAY_ARG = flags.TargetVpnGatewayArgument(plural=True)
Delete.TARGET_VPN_GATEWAY_ARG.AddArgument(parser, operation_type='delete')
parser.display_info.AddCacheUpdater(flags.TargetVpnGatewaysCompleter)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
target_vpn_gateway_refs = Delete.TARGET_VPN_GATEWAY_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client))
utils.PromptForDeletion(target_vpn_gateway_refs, 'region')
requests = []
for target_vpn_gateway_ref in target_vpn_gateway_refs:
requests.append((client.apitools_client.targetVpnGateways, 'Delete',
client.messages.ComputeTargetVpnGatewaysDeleteRequest(
**target_vpn_gateway_ref.AsDict())))
return client.MakeRequests(requests)

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for describing target vpn gateways."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.target_vpn_gateways import flags
class Describe(base.DescribeCommand):
"""Describe a Compute Engine Cloud VPN Classic Target VPN Gateway.
*{command}* displays all data associated with a Compute Engine
Cloud VPN Target VPN Gateway in a project.
"""
TARGET_VPN_GATEWAY_ARG = None
@staticmethod
def Args(parser):
"""Adds arguments to the supplied parser."""
Describe.TARGET_VPN_GATEWAY_ARG = flags.TargetVpnGatewayArgument()
Describe.TARGET_VPN_GATEWAY_ARG.AddArgument(
parser, operation_type='describe')
def Run(self, args):
"""Issues the request necessary for describing a target VPN gateway."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
target_vpn_gateway_ref = self.TARGET_VPN_GATEWAY_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client))
request = client.messages.ComputeTargetVpnGatewaysGetRequest(
**target_vpn_gateway_ref.AsDict())
return client.MakeRequests([(client.apitools_client.targetVpnGateways,
'Get', request)])[0]

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for listing target VPN gateways."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import lister
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.target_vpn_gateways import flags
class List(base.ListCommand):
"""List Cloud VPN Classic Target VPN Gateways."""
# Placeholder to indicate that a detailed_help field exists and should
# be set outside the class definition.
detailed_help = None
@staticmethod
def Args(parser):
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
lister.AddRegionsArg(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
request_data = lister.ParseRegionalFlags(args, holder.resources)
list_implementation = lister.RegionalLister(
client, client.apitools_client.targetVpnGateways)
return lister.Invoke(request_data, list_implementation)
List.detailed_help = base_classes.GetRegionalListerHelp(
'Cloud VPN Classic Target VPN Gateways')

View File

@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 update labels for target VPN gateways."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute.operations import poller
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions as calliope_exceptions
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.target_vpn_gateways import flags as target_vpn_gateway_flags
from googlecloudsdk.command_lib.util.args import labels_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Update(base.UpdateCommand):
r"""Update a Compute Engine Cloud VPN Classic Target VPN Gateway.
*{command}* updates labels for a Compute Engine Cloud VPN Classic
Target VPN gateway. For example:
$ {command} example-gateway --region us-central1 \
--update-labels=k0=value1,k1=value2 --remove-labels=k3
will add/update labels ``k0'' and ``k1'' and remove labels with key ``k3''.
Labels can be used to identify the target VPN gateway and to filter them as in
$ {parent_command} list --filter='labels.k1:value2'
To list existing labels
$ {parent_command} describe example-gateway --format="default(labels)"
"""
TARGET_VPN_GATEWAY_ARG = None
@classmethod
def Args(cls, parser):
"""Adds arguments to the supplied parser.
Args:
parser: The argparse parser to add arguments to.
"""
cls.TARGET_VPN_GATEWAY_ARG = (
target_vpn_gateway_flags.TargetVpnGatewayArgument())
cls.TARGET_VPN_GATEWAY_ARG.AddArgument(parser)
labels_util.AddUpdateLabelsFlags(parser)
def _CreateRegionalSetLabelsRequest(self, messages, target_vpn_gateway_ref,
target_vpn_gateway, replacement):
"""Creates the API request to update labels on a Target VPN Gateway.
Args:
messages: Module with request messages.
target_vpn_gateway_ref: Resource reference for the target VPN gateway.
target_vpn_gateway: The target_vpn_gateway being updated.
replacement: A new labels request proto representing the update and remove
edits.
Returns:
Request to be sent to update the target VPN gateway's labels.
"""
return messages.ComputeTargetVpnGatewaysSetLabelsRequest(
project=target_vpn_gateway_ref.project,
resource=target_vpn_gateway_ref.Name(),
region=target_vpn_gateway_ref.region,
regionSetLabelsRequest=messages.RegionSetLabelsRequest(
labelFingerprint=target_vpn_gateway.labelFingerprint,
labels=replacement))
def Run(self, args):
"""Issues API requests to update a Target VPN Gateway.
Args:
args: argparse.Namespace, The arguments received by this command.
Returns:
[protorpc.messages.Message], A list of responses returned
by the compute API.
"""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client.apitools_client
messages = holder.client.messages
target_vpn_gateway_ref = self.TARGET_VPN_GATEWAY_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
labels_diff = labels_util.Diff.FromUpdateArgs(args)
if not labels_diff.MayHaveUpdates():
raise calliope_exceptions.RequiredArgumentException(
'LABELS', 'At least one of --update-labels or '
'--remove-labels must be specified.')
target_vpn_gateway = client.targetVpnGateways.Get(
messages.ComputeTargetVpnGatewaysGetRequest(
**target_vpn_gateway_ref.AsDict()))
labels_value = messages.RegionSetLabelsRequest.LabelsValue
labels_update = labels_diff.Apply(labels_value, target_vpn_gateway.labels)
if not labels_update.needs_update:
return target_vpn_gateway
request = self._CreateRegionalSetLabelsRequest(
messages, target_vpn_gateway_ref, target_vpn_gateway,
labels_update.labels)
operation = client.targetVpnGateways.SetLabels(request)
operation_ref = holder.resources.Parse(
operation.selfLink, collection='compute.regionOperations')
operation_poller = poller.Poller(client.targetVpnGateways)
return waiter.WaitFor(operation_poller, operation_ref,
'Updating labels of target VPN gateway [{0}]'.format(
target_vpn_gateway_ref.Name()))