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,42 @@
# -*- 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 target instances."""
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 TargetInstances(base.Group):
"""Read and manipulate Compute Engine virtual target instances."""
TargetInstances.category = base.INSTANCES_CATEGORY
TargetInstances.detailed_help = {
'DESCRIPTION': """
Read and manipulate Compute Engine virtual target instances.
For more information about target instances, see the
[target instances documentation](https://cloud.google.com/compute/docs/protocol-forwarding#targetinstances).
See also: [Target instances API](https://cloud.google.com/compute/docs/reference/rest/v1/targetInstances).
""",
}

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 instance 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 instance 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 instance.
description: |
*{command}* exports the configuration for a Compute Engine target instance.
Target instance 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 instances within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a target instance, run:
$ {command} my-target-instance
To export the configuration for a target instance to a file, run:
$ {command} my-target-instance --path=/path/to/dir/
To export the configuration for a target instance in Terraform
HCL format, run:
$ {command} my-target-instance --resource-format=terraform
To export the configurations for all target instances within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Target instance to export the configuration for.
spec: !REF googlecloudsdk.command_lib.compute.resources:target_instance

View File

@@ -0,0 +1,133 @@
# -*- 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 instances."""
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 exceptions as compute_exceptions
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.instances import (flags as
instance_flags)
from googlecloudsdk.command_lib.compute.target_instances import flags
class CreateHelper(object):
"""Helper class to creat a target instance."""
INSTANCE_ARG = None
TARGET_INSTANCE_ARG = None
@classmethod
def Args(cls, parser):
"""Add flags to create a target instance to the parser."""
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
cls.INSTANCE_ARG = instance_flags.InstanceArgumentForTargetInstance()
cls.INSTANCE_ARG.AddArgument(parser)
cls.TARGET_INSTANCE_ARG = flags.TargetInstanceArgument()
cls.TARGET_INSTANCE_ARG.AddArgument(parser)
flags.AddNetwork(parser)
parser.add_argument(
'--description',
help='An optional, textual description of the target instance.')
parser.display_info.AddCacheUpdater(flags.TargetInstancesCompleter)
def __init__(self):
pass
def Run(self, args, holder):
"""Issues request necessary to create a target instance."""
client = holder.client
target_instance_ref = self.TARGET_INSTANCE_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client))
if target_instance_ref.zone and not args.instance_zone:
args.instance_zone = target_instance_ref.zone
instance_ref = self.INSTANCE_ARG.ResolveAsResource(args, holder.resources)
if target_instance_ref.zone != instance_ref.zone:
raise compute_exceptions.ArgumentError(
'Target instance zone must match the virtual machine instance zone.')
target_instance = client.messages.TargetInstance(
description=args.description,
name=target_instance_ref.Name(),
instance=instance_ref.SelfLink())
if args.IsSpecified('network'):
target_instance.network = flags.NETWORK_ARG.ResolveAsResource(
args, holder.resources).SelfLink()
request = client.messages.ComputeTargetInstancesInsertRequest(
targetInstance=target_instance,
project=target_instance_ref.project,
zone=target_instance_ref.zone)
return client.MakeRequests([(client.apitools_client.targetInstances,
'Insert', request)])
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateGA(base.CreateCommand):
"""Create a target instance for handling traffic from a forwarding rule.
*{command}* is used to create a target instance for handling
traffic from one or more forwarding rules. Target instances
are ideal for traffic that should be managed by a single
source. For more information on target instances, see
[](https://cloud.google.com/compute/docs/protocol-forwarding/#targetinstances)
"""
@classmethod
def Args(cls, parser):
CreateHelper.Args(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
return CreateHelper().Run(args, holder)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(CreateGA):
"""Create a target instance for handling traffic from a forwarding rule.
*{command}* is used to create a target instance for handling
traffic from one or more forwarding rules. Target instances
are ideal for traffic that should be managed by a single
source. For more information on target instances, see
[](https://cloud.google.com/compute/docs/protocol-forwarding/#targetinstances)
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(CreateBeta):
"""Create a target instance for handling traffic from a forwarding rule.
*{command}* is used to create a target instance for handling
traffic from one or more forwarding rules. Target instances
are ideal for traffic that should be managed by a single
source. For more information on target instances, see
[](https://cloud.google.com/compute/docs/protocol-forwarding/#targetinstances)
"""

View File

@@ -0,0 +1,62 @@
# -*- 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 instances."""
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_instances import flags
class Delete(base.DeleteCommand):
"""Delete target instances.
*{command}* deletes one or more Compute Engine target
instances. Target instances can be deleted only if they are
not being used by any other resources like forwarding rules.
"""
TARGET_INSTANCE_ARG = None
@staticmethod
def Args(parser):
Delete.TARGET_INSTANCE_ARG = flags.TargetInstanceArgument(plural=True)
Delete.TARGET_INSTANCE_ARG.AddArgument(parser, operation_type='delete')
parser.display_info.AddCacheUpdater(flags.TargetInstancesCompleter)
def Run(self, args):
"""Issues requests necessary to delete Target Instances."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
target_instance_refs = Delete.TARGET_INSTANCE_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client))
utils.PromptForDeletion(target_instance_refs, 'zone')
requests = []
for target_instance_ref in target_instance_refs:
requests.append((client.apitools_client.targetInstances, 'Delete',
client.messages.ComputeTargetInstancesDeleteRequest(
**target_instance_ref.AsDict())))
return client.MakeRequests(requests)

View File

@@ -0,0 +1,54 @@
# -*- 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 instances."""
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_instances import flags
class Describe(base.DescribeCommand):
"""Describe a target instance.
*{command}* displays all data associated with a Compute
Engine target instance in a project.
"""
TARGET_INSTANCE_ARG = None
@staticmethod
def Args(parser):
Describe.TARGET_INSTANCE_ARG = flags.TargetInstanceArgument()
Describe.TARGET_INSTANCE_ARG.AddArgument(parser, operation_type='describe')
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
target_instance_ref = self.TARGET_INSTANCE_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client))
request = client.messages.ComputeTargetInstancesGetRequest(
**target_instance_ref.AsDict())
return client.MakeRequests([(client.apitools_client.targetInstances, 'Get',
request)])[0]

View File

@@ -0,0 +1,50 @@
# -*- 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 instances."""
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.api_lib.compute import utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.target_instances import flags
class List(base.ListCommand):
"""List target instances."""
@staticmethod
def Args(parser):
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
parser.display_info.AddUriFunc(utils.MakeGetUriFunc())
parser.display_info.AddCacheUpdater(flags.TargetInstancesCompleter)
lister.AddZonalListerArgs(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
request_data = lister.ParseZonalFlags(args, holder.resources)
list_implementation = lister.ZonalLister(
client, client.apitools_client.targetInstances)
return lister.Invoke(request_data, list_implementation)
List.detailed_help = base_classes.GetZonalListerHelp('target instances')

View File

@@ -0,0 +1,92 @@
# -*- 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.
"""Command for updating target instances."""
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.calliope import exceptions
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.security_policies import (
flags as security_policy_flags,
)
from googlecloudsdk.command_lib.compute.target_instances import flags
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Update(base.UpdateCommand):
r"""Update a Compute Engine target instance.
*{command}* updates a Compute Engine target instance.
## EXAMPLES
To update the security policy run this:
$ {command} TARGET_INSTANCE --security-policy='my-policy'
"""
TARGET_INSTANCE_ARG = None
SECURITY_POLICY_ARG = None
@classmethod
def Args(cls, parser):
cls.TARGET_INSTANCE_ARG = flags.TargetInstanceArgument()
cls.TARGET_INSTANCE_ARG.AddArgument(parser, operation_type='update')
cls.SECURITY_POLICY_ARG = (
security_policy_flags.SecurityPolicyRegionalArgumentForTargetResource(
resource='target instance'
)
)
cls.SECURITY_POLICY_ARG.AddArgument(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
target_instance_ref = self.TARGET_INSTANCE_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(client),
)
# Empty string is a valid value.
if getattr(args, 'security_policy', None) is not None:
if getattr(args, 'security_policy', None):
security_policy_ref = self.SECURITY_POLICY_ARG.ResolveAsResource(
args, holder.resources).SelfLink()
# If security policy is an empty string we should clear the current policy
else:
security_policy_ref = None
request = client.messages.ComputeTargetInstancesSetSecurityPolicyRequest(
project=target_instance_ref.project,
targetInstance=target_instance_ref.Name(),
zone=target_instance_ref.zone,
securityPolicyReference=client.messages.SecurityPolicyReference(
securityPolicy=security_policy_ref
)
)
return client.MakeRequests([(client.apitools_client.targetInstances,
'SetSecurityPolicy', request)])
parameter_names = ['--security-policy']
raise exceptions.MinimumArgumentException(
parameter_names, 'Please specify at least one property to update'
)