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,35 @@
# -*- 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.
"""Commands for reading and manipulating packet mirroring resources."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class PacketMirrorings(base.Group):
"""Manage Compute Engine packet mirroring resources."""
PacketMirrorings.detailed_help = {
'brief': 'Manage Compute Engine packet mirroring resources.',
'DESCRIPTION': 'Manage Compute Engine packet mirroring resources.',
}
PacketMirrorings.category = base.NETWORKING_CATEGORY

View File

@@ -0,0 +1,128 @@
# -*- 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.
"""Command for creating packet mirroring resources."""
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.packet_mirrorings import client
from googlecloudsdk.command_lib.compute.packet_mirrorings import flags
from googlecloudsdk.command_lib.compute.packet_mirrorings import utils
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Compute Engine packet mirroring policy."""
PACKET_MIRRORING_ARG = None
@classmethod
def Args(cls, parser):
base.ASYNC_FLAG.AddToParser(parser)
cls.PACKET_MIRRORING_ARG = flags.PacketMirroringArgument()
cls.PACKET_MIRRORING_ARG.AddArgument(parser, operation_type='create')
flags.AddCreateArgs(parser)
def Collection(self):
return 'compute.packetMirrorings'
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
messages = holder.client.messages
pm_ref = self.PACKET_MIRRORING_ARG.ResolveAsResource(args, holder.resources)
def _MakeInstanceInfo(instance):
return messages.PacketMirroringMirroredResourceInfoInstanceInfo(
url=utils.ResolveInstanceURI(pm_ref.project, instance,
holder.resources))
def _MakeMirroredSubnetInfo(subnet):
return messages.PacketMirroringMirroredResourceInfoSubnetInfo(
url=utils.ResolveSubnetURI(pm_ref.project, pm_ref.region, subnet,
holder.resources))
mirrored_instance_infos = [
_MakeInstanceInfo(instance) for instance in args.mirrored_instances
] if args.mirrored_instances else []
mirrored_subnet_infos = [
_MakeMirroredSubnetInfo(subnet) for subnet in args.mirrored_subnets
] if args.mirrored_subnets else []
pm_filter = messages.PacketMirroringFilter()
if args.filter_cidr_ranges or args.filter_protocols:
if args.filter_cidr_ranges:
pm_filter.cidrRanges.extend(args.filter_cidr_ranges)
if args.filter_protocols:
pm_filter.IPProtocols.extend(args.filter_protocols)
if args.filter_direction:
pm_filter.direction = messages.PacketMirroringFilter.DirectionValueValuesEnum(
args.filter_direction.upper())
mirrored_resources_info = messages.PacketMirroringMirroredResourceInfo(
subnetworks=mirrored_subnet_infos,
instances=mirrored_instance_infos,
tags=args.mirrored_tags or [])
template = messages.PacketMirroring(
name=pm_ref.Name(),
description=args.description,
network=messages.PacketMirroringNetworkInfo(
url=utils.ResolveNetworkURI(pm_ref.project, args.network,
holder.resources)),
collectorIlb=messages.PacketMirroringForwardingRuleInfo(
url=utils.ResolveForwardingRuleURI(pm_ref.project, pm_ref.region,
args.collector_ilb,
holder.resources)),
mirroredResources=mirrored_resources_info,
filter=pm_filter,
enable=messages.PacketMirroring.EnableValueValuesEnum.TRUE if
args.enable else messages.PacketMirroring.EnableValueValuesEnum.FALSE)
packet_mirroring = client.PacketMirroring(
pm_ref, compute_client=holder.client, registry=holder.resources)
return packet_mirroring.Create(template, is_async=args.async_ or False)
Create.detailed_help = {
'DESCRIPTION': 'Create a Compute Engine packet mirroring policy.',
'EXAMPLES':
"""\
Mirror all tcp traffic to/from all instances in subnet my-subnet in
us-central1, and send the mirrored traffic to the collector-fr
Forwarding Rule.
$ {command} my-pm
--network my-network --region us-central1
--mirrored-subnets my-subnet --collector-ilb collector-fr
--filter-protocols tcp
Mirror all traffic between instances with tag t1 and external server with IP
11.22.33.44 in us-central1, and send the mirrored traffic to the
collector-fr Forwarding Rule.
$ {command} my-pm
--network my-network --region us-central1
--mirrored-tags t1 --collector-ilb collector-fr
--filter-cidr-ranges 11.22.33.44/32
""",
}

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.
"""Command for deleting packet mirroring resources."""
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.packet_mirrorings import client
from googlecloudsdk.command_lib.compute.packet_mirrorings import flags
class Delete(base.DeleteCommand):
"""Delete a Compute Engine packet mirroring policy."""
PACKET_MIRRORING_ARG = None
@classmethod
def Args(cls, parser):
cls.PACKET_MIRRORING_ARG = flags.PacketMirroringArgument(plural=True)
cls.PACKET_MIRRORING_ARG.AddArgument(parser, operation_type='delete')
parser.display_info.AddCacheUpdater(flags.PacketMirroringCompleter)
def Collection(self):
return 'compute.packetMirrorings'
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
refs = self.PACKET_MIRRORING_ARG.ResolveAsResource(args, holder.resources)
utils.PromptForDeletion(refs)
requests = []
for ref in refs:
packet_mirroring = client.PacketMirroring(
ref, compute_client=holder.client)
requests.append(packet_mirroring.MakeDeleteRequestTuple())
return holder.client.MakeRequests(requests)
Delete.detailed_help = {
'DESCRIPTION': 'Delete a Compute Engine Packet Mirroring policy.',
'EXAMPLES':
"""\
Delete the Packet Mirroring policy pm-1 in region us-central1.
$ {command} pm-1
--region us-central1
"""
}

View File

@@ -0,0 +1,63 @@
# -*- 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.
"""Command for describing packet mirroring resources."""
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.packet_mirrorings import client
from googlecloudsdk.command_lib.compute.packet_mirrorings import flags
class Describe(base.DescribeCommand):
"""Describe a Compute Engine packet mirroring policy.
*{command}* displays all data associated with Compute Engine packet
mirroring in a project.
"""
PACKET_MIRRORING_ARG = None
@classmethod
def Args(cls, parser):
cls.PACKET_MIRRORING_ARG = flags.PacketMirroringArgument()
cls.PACKET_MIRRORING_ARG.AddArgument(parser, operation_type='describe')
def Collection(self):
return 'compute.packetMirrorings'
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
ref = self.PACKET_MIRRORING_ARG.ResolveAsResource(args, holder.resources)
packet_mirroring = client.PacketMirroring(ref, compute_client=holder.client)
return packet_mirroring.Describe()
Describe.detailed_help = {
'DESCRIPTION': 'Describe a Compute Engine Packet Mirroring policy.',
'EXAMPLES':
"""\
Describe the Packet Mirroring policy pm-1 in region us-central1.
$ {command} pm-1
--region us-central1
"""
}

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.
"""Command for listing security policies."""
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
class List(base.ListCommand):
"""List packet mirroring policies."""
@staticmethod
def Args(parser):
parser.display_info.AddFormat("""
table(
name,
region.basename(),
network.url.basename():label=NETWORK,
enable
)
""")
lister.AddRegionsArg(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
request_data = lister.ParseRegionalFlags(args, holder.resources)
compute_client = holder.client
list_implementation = lister.RegionalLister(
compute_client, compute_client.apitools_client.packetMirrorings)
return lister.Invoke(request_data, list_implementation)
List.detailed_help = base_classes.GetRegionalListerHelp(
'packet mirroring policies')

View File

@@ -0,0 +1,227 @@
# -*- 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.
"""Command for creating packet mirroring resources."""
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.packet_mirrorings import client
from googlecloudsdk.command_lib.compute.packet_mirrorings import flags
from googlecloudsdk.command_lib.compute.packet_mirrorings import utils
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.UniverseCompatible
class Update(base.UpdateCommand):
"""Update a Compute Engine packet mirroring policy."""
PACKET_MIRRORING_ARG = None
@classmethod
def Args(cls, parser):
base.ASYNC_FLAG.AddToParser(parser)
cls.PACKET_MIRRORING_ARG = flags.PacketMirroringArgument()
cls.PACKET_MIRRORING_ARG.AddArgument(parser, operation_type='update')
flags.AddUpdateArgs(parser)
def Collection(self):
return 'compute.packetMirrorings'
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
messages = holder.client.messages
pm_ref = self.PACKET_MIRRORING_ARG.ResolveAsResource(args, holder.resources)
packet_mirroring = client.PacketMirroring(
pm_ref, compute_client=holder.client, registry=holder.resources)
resource = packet_mirroring.Describe()[0]
cleared_fields = []
self._UpdateResource(pm_ref, resource, cleared_fields, holder, args,
messages)
packet_mirroring.Update(
resource, is_async=args.async_ or False, cleared_fields=cleared_fields)
def _UpdateResource(self, pm_ref, resource, cleared_fields, holder, args,
messages):
if args.enable is not None:
resource.enable = (
messages.PacketMirroring.EnableValueValuesEnum.TRUE if args.enable
else messages.PacketMirroring.EnableValueValuesEnum.FALSE)
if args.collector_ilb is not None:
resource.collectorIlb = messages.PacketMirroringForwardingRuleInfo(
url=utils.ResolveForwardingRuleURI(pm_ref.project, pm_ref.region, args
.collector_ilb, holder.resources))
if args.description is not None:
resource.description = args.description
if args.clear_mirrored_tags:
resource.mirroredResources.tags[:] = []
cleared_fields.append('mirroredResources.tags')
elif args.add_mirrored_tags:
resource.mirroredResources.tags.extend(args.add_mirrored_tags)
elif args.set_mirrored_tags:
resource.mirroredResources.tags[:] = args.set_mirrored_tags
elif args.remove_mirrored_tags:
for tag in args.remove_mirrored_tags:
if tag not in resource.mirroredResources.tags:
raise exceptions.InvalidArgumentException(
'Tag %s not found in this packet mirroring.' % tag)
resource.mirroredResources.tags[:] = [
x for x in resource.mirroredResources.tags
if x not in args.remove_mirrored_tags
]
def _MakeSubnetInfo(subnet):
return messages.PacketMirroringMirroredResourceInfoSubnetInfo(
url=utils.ResolveSubnetURI(pm_ref.project, pm_ref.region, subnet,
holder.resources))
if args.clear_mirrored_subnets:
resource.mirroredResources.subnetworks[:] = []
cleared_fields.append('mirroredResources.subnetworks')
elif args.add_mirrored_subnets:
resource.mirroredResources.subnetworks.extend(
[_MakeSubnetInfo(subnet) for subnet in args.add_mirrored_subnets])
elif args.set_mirrored_subnets:
resource.mirroredResources.subnetworks[:] = [
_MakeSubnetInfo(subnet) for subnet in args.set_mirrored_subnets
]
elif args.remove_mirrored_subnets:
urls = [
utils.ResolveSubnetURI(pm_ref.project, pm_ref.region, subnet,
holder.resources)
for subnet in args.remove_mirrored_subnets
]
for url in urls:
if next(
(x for x in resource.mirroredResources.subnetworks if x.url == url),
None) is None:
raise exceptions.InvalidArgumentException(
'Subnet %s not found in this packet mirroring.' % url)
resource.mirroredResources.subnetworks = [
x for x in resource.mirroredResources.subnetworks if x.url not in urls
]
def _MakeInstanceInfo(instance):
return messages.PacketMirroringMirroredResourceInfoInstanceInfo(
url=utils.ResolveInstanceURI(pm_ref.project, instance,
holder.resources))
if args.clear_mirrored_instances:
resource.mirroredResources.instances[:] = []
cleared_fields.append('mirroredResources.instances')
elif args.add_mirrored_instances:
resource.mirroredResources.instances.extend([
_MakeInstanceInfo(instance)
for instance in args.add_mirrored_instances
])
elif args.set_mirrored_instances:
resource.mirroredResources.instances[:] = [
_MakeInstanceInfo(instance)
for instance in args.set_mirrored_instances
]
elif args.remove_mirrored_instances:
urls = [
utils.ResolveInstanceURI(pm_ref.project, instance, holder.resources)
for instance in args.remove_mirrored_instances
]
for url in urls:
if next(
(x for x in resource.mirroredResources.instances if x.url == url),
None) is None:
raise exceptions.InvalidArgumentException(
'Instance %s not found in this packet mirroring.' % url)
resource.mirroredResources.instances = [
x for x in resource.mirroredResources.instances if x.url not in urls
]
if args.clear_filter_protocols:
resource.filter.IPProtocols[:] = []
cleared_fields.append('filter.IPProtocols')
elif args.add_filter_protocols:
resource.filter.IPProtocols.extend(args.add_filter_protocols)
elif args.set_filter_protocols:
resource.filter.IPProtocols[:] = args.set_filter_protocols
elif args.remove_filter_protocols:
for protocol in args.remove_filter_protocols:
if protocol not in resource.filter.IPProtocols:
raise exceptions.InvalidArgumentException(
'Protocol %s not found in this packet mirroring.' % protocol)
resource.filter.IPProtocols[:] = [
x for x in resource.filter.IPProtocols
if x not in args.remove_filter_protocols
]
if args.clear_filter_cidr_ranges:
resource.filter.cidrRanges[:] = []
cleared_fields.append('filter.cidrRanges')
elif args.add_filter_cidr_ranges:
resource.filter.cidrRanges.extend(args.add_filter_cidr_ranges)
elif args.set_filter_cidr_ranges:
resource.filter.cidrRanges[:] = args.set_filter_cidr_ranges
elif args.remove_filter_cidr_ranges:
for cidr in args.remove_filter_cidr_ranges:
if cidr not in resource.filter.cidrRanges:
raise exceptions.InvalidArgumentException(
'CIDR Range %s not found in this packet mirroring.' % cidr)
resource.filter.cidrRanges[:] = [
x for x in resource.filter.cidrRanges
if x not in args.remove_filter_cidr_ranges
]
if args.filter_direction:
resource.filter.direction = messages.PacketMirroringFilter.DirectionValueValuesEnum(
args.filter_direction.upper())
Update.detailed_help = {
'DESCRIPTION':
'Update a Compute Engine packet mirroring policy.',
'EXAMPLES':
"""\
Stop mirroring by tags, add subnet-1 as a mirrored subnet.
$ {command} my-pm
--region us-central1 --clear-mirrored-tags
--add-mirrored-subnets subnet-1
Change the load-balancer to send mirrored traffic to.
$ {command} my-pm
--region us-central1 --collector-ilb new-forwarding-rule
Disable a Packet Mirroring policy.
$ {command} my-pm
--region us-central1 --no-enable
Re-enable a disabled Packet Mirroring policy.
$ {command} my-pm
--region us-central1 --enable
""",
}