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,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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 the Private Connections CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA)
class PrivateConnections(base.Group):
"""Manage Private Connections in Google Cloud VMware Engine."""
category = base.COMPUTE_CATEGORY

View File

@@ -0,0 +1,166 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""'vmware private-connections create' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.vmware.privateconnections import PrivateConnectionsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.vmware import flags
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""
Creates a new private connection to connect VMware Engine Network to the specified VPC network. This establishes private IP connectivity between the VPC network and all the VMware Private Clouds attached to the VMware Engine Network. Private connection creation is considered finished when the connection is in ACTIVE state. Check the progress of the private connection using `{parent_command} list`.
""",
'EXAMPLES':
"""
To create a Private Connection of type PRIVATE_SERVICE_ACCESS, first obtain the service-project by listing vpc-peerings, run:
$ gcloud compute networks peerings list --network=my-vpc --project=my-project
where my-vpc is the VPC on which a private service access connection is created and project is the one in which the private connection will be created.
The response will be of this format:
NAME NETWORK PEER_PROJECT \n
servicenetworking-googleapis-com my-vpc td096d594ece09650-tp
The PEER_PROJECT field in the output of the command will provide the value for the service-project required for creating the private connection.
To create a Private Connection called `my-private-connection` of type `PRIVATE_SERVICE_ACCESS` in project `my-project` and region `us-west1` with routing_mode `REGIONAL` to connect service networking VPC from project `td096d594ece09650-tp` to legacy VMware Engine Network `us-west1-default`, run:
$ {command} my-private-connection --location=us-west1 --project=my-project --vmware-engine-network=us-west1-default --description="A short description for the new private connection" --routing-mode=REGIONAL --service-project=td096d594ece09650-tp --type=PRIVATE_SERVICE_ACCESS
Or:
$ {command} my-private-connection --vmware-engine-network=us-west1-default --description="A short description for the new private connection" --routing-mode=REGIONAL --service-project=td096d594ece09650-tp --type=PRIVATE_SERVICE_ACCESS
In the second example, the project and location are taken from gcloud properties core/project and compute/region, respectively.
To create a Private Connection called `my-private-connection` of type `THIRD_PARTY_SERVICE` in project `my-project` and region `us-west1` to connect VPC `my-service-network` from project `td096d594ece09650-tp` to legacy VMware Engine Network `us-west1-default`, run:
$ {command} my-private-connection --location=us-west1 --project=my-project --vmware-engine-network=us-west1-default --description="A short description for the new private connection" --service-network=my-service-network --service-project=td096d594ece09650-tp --type=THIRD_PARTY_SERVICE
Or:
$ {command} my-private-connection --vmware-engine-network=us-west1-default --description="A short description for the new private connection" --service-network=my-service-network --service-project=td096d594ece09650-tp --type=THIRD_PARTY_SERVICE
In the above example, the project and location are taken from gcloud properties core/project and compute/region, respectively.
If you try to create a private connection of type=THIRD_PARTY_SERVICE, and do not provide the service-network field, an error will be thrown with the message:
Missing required argument [--service-network]: For private connection of type THIRD_PARTY_SERVICE, service-network field is required
"""
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Google Cloud Private Connection."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddPrivateConnectionToParser(parser, positional=True)
base.ASYNC_FLAG.AddToParser(parser)
base.ASYNC_FLAG.SetDefault(parser, True)
parser.display_info.AddFormat('yaml')
parser.add_argument(
'--description',
help="""\
Text describing the private connection.
""")
parser.add_argument(
'--routing-mode',
choices=['GLOBAL', 'REGIONAL'],
help="""\
Type of the routing mode. Default value is set to GLOBAL. For type=PRIVATE_SERVICE_ACCESS, this field can be set to GLOBAL or REGIONAL, for other types only GLOBAL is supported.
""")
parser.add_argument(
'--type',
required=True,
choices={
'PRIVATE_SERVICE_ACCESS':
'Peering connection used for establishing [private services access](https://cloud.google.com/vpc/docs/private-services-access).',
'NETAPP_CLOUD_VOLUMES':
'Peering connection used for connecting to NetApp Cloud Volumes.',
'DELL_POWERSCALE':
'Peering connection used for connecting to Dell PowerScale.',
'THIRD_PARTY_SERVICE':
'Peering connection used for connecting to third-party services. Most third-party services require manual setup of reverse peering on the VPC network associated with the third-party service.'
},
help="""\
Type of private connection.
""")
parser.add_argument(
'--service-network',
help="""\
Resource ID of the service network to connect with the VMware Engine network to create a private connection.
* For type=PRIVATE_SERVICE_ACCESS, this field represents service networking VPC. In this case the field value will be automatically set to `servicenetworking` and cannot be changed.
* For type=NETAPP_CLOUD_VOLUME, this field represents NetApp service VPC. In this case the field value will be automatically set to `netapp-tenant-vpc` and cannot be changed.
* For type=DELL_POWERSCALE, this field represents Dell service VPC. In this case the field value will be automatically set to `dell-tenant-vpc` and cannot be changed.
* For type=THIRD_PARTY_SERVICE, this field could represent a consumer VPC or any other producer VPC to which the VMware Engine Network needs to be connected. service-network field is required for this type.
""")
parser.add_argument(
'--service-project',
required=True,
help="""\
Project ID or project number of the service network.
""")
parser.add_argument(
'--vmware-engine-network',
required=True,
help="""\
Resource ID of the legacy VMware Engine network. Provide the {vmware_engine_network_id}, which will be in the form of {location}-default. The {location} is the same as the location specified in the private connection resource.
""")
def Run(self, args):
if args.type == 'THIRD_PARTY_SERVICE' and not args.service_network:
raise exceptions.RequiredArgumentException(
'--service-network',
'For private connection of type THIRD_PARTY_SERVICE, service-network field is required.'
)
private_connection = args.CONCEPTS.private_connection.Parse()
client = PrivateConnectionsClient()
is_async = args.async_
operation = client.Create(
private_connection,
vmware_engine_network=args.vmware_engine_network,
service_project=args.service_project,
private_connection_type=args.type,
routing_mode=args.routing_mode,
description=args.description,
service_network=args.service_network,
)
if is_async:
log.CreatedResource(
operation.name, kind='Private Connection', is_async=True)
return
resource = client.WaitForOperation(
operation_ref=client.GetOperationRef(operation),
message='waiting for private connection [{}] to be created'.format(
private_connection.RelativeName()
),
)
log.CreatedResource(
private_connection.RelativeName(), kind='Private Connection'
)
return resource

View File

@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""'vmware private-connections delete' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.vmware.privateconnections import PrivateConnectionsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.vmware import flags
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""
Delete a Private Connection. When a private connection is deleted for a VMware Engine network, the connected network becomes inaccessible to that VMware Engine network.
""",
'EXAMPLES':
"""
To delete a Private Connection resource called `my-private-connection` in project `my-project` and region `us-west1`, run:
$ {command} my-private-connection --location=us-west1 --project=my-project
Or:
$ {command} my-private-connection
In the second example, the project and the location is taken from gcloud properties core/project and compute/region, respectively.
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Delete a Google Cloud Private Connection."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddPrivateConnectionToParser(parser, positional=True)
base.ASYNC_FLAG.AddToParser(parser)
base.ASYNC_FLAG.SetDefault(parser, True)
def Run(self, args):
private_connection = args.CONCEPTS.private_connection.Parse()
client = PrivateConnectionsClient()
is_async = args.async_
operation = client.Delete(private_connection)
if is_async:
log.DeletedResource(
operation.name, kind='Private Connection', is_async=True)
return operation
return client.WaitForOperation(
operation_ref=client.GetOperationRef(operation),
message='waiting for private connection [{}] to be deleted'.format(
private_connection.RelativeName()),
has_result=False)

View File

@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""'vmware private-connections describe' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.vmware.privateconnections import PrivateConnectionsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.vmware import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Describe a Private Connection by its resource name. It contains details of the private connection, such as service_network, vmware_engine_network, routing_mode and state.
""",
'EXAMPLES':
"""
To get the information about a private connection resource called `my-private-connection` in project `my-project` and region `us-west1`, run:
$ {command} my-private-connection --location=us-west1 --project=my-project
Or:
$ {command} my-private-connection
In the second example, the project and location are taken from gcloud properties core/project and compute/region, respectively.
"""
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Google Cloud Private Connection."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddPrivateConnectionToParser(parser, positional=True)
def Run(self, args):
private_connection = args.CONCEPTS.private_connection.Parse()
client = PrivateConnectionsClient()
return client.Get(private_connection)

View File

@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""'vmware private-connections list' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.vmware.privateconnections import PrivateConnectionsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.vmware import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Lists VMware Engine private connections.
""",
'EXAMPLES':
"""
To list private connections in project `my-project` and region `us-west1` sorted from oldest to newest, run:
$ {command} --location=us-west1 --project=my-project --sort-by=~create_time
Or:
$ {command} --sort-by=~create_time
In the second example, the project and the location are taken from gcloud properties core/project and compute/region, respectively.
To list private connections in project `my-project` from all regions, run:
$ {command} --location=- --project=my-project
Or:
$ {command} --location=-
In the last example, the project is taken from gcloud properties core/project.
"""
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Google Cloud Private Connections."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddLocationArgToParser(parser, regional=True)
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,'
'name.segment(-3):label=LOCATION,'
'serviceNetwork.segment(-4):label=SERVICE_PROJECT_ID,'
'type, state)')
def Run(self, args):
location = args.CONCEPTS.location.Parse()
client = PrivateConnectionsClient()
return client.List(location)

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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 the private connection peering routes CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA)
class PrivateConnectionRoutes(base.Group):
"""Manage private connection peering routes in Google Cloud VMware Engine."""
category = base.COMPUTE_CATEGORY

View File

@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""private connection peering routes list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.vmware.privateconnectionroutes import PrivateConnectionPeeringRoutesClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.vmware import flags
from googlecloudsdk.core.resource import resource_projector
DETAILED_HELP = {
'DESCRIPTION':
"""
Lists the private connection routes exchanged over a peering connection.
""",
'EXAMPLES':
"""
To list all the peering routes of private connection called `my-private-connection` in project `my-project` and region `us-west1`, run:
$ {command} --private-connection=my-private-connection --location=us-west1 --project=my-project
Or:
$ {command} --private-connection=my-private-connection
In the last example, the project and the location are taken from gcloud properties core/project and compute/region, respectively.
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Google Cloud private connection peering routes."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddPrivateConnectionToParser(parser)
parser.display_info.AddFormat("""\
table(
dest_range,
type,
next_hop_region,
status,
direction)
""")
def Run(self, args):
privateconnection = args.CONCEPTS.private_connection.Parse()
client = PrivateConnectionPeeringRoutesClient()
items = client.List(privateconnection)
def _TransformStatus(direction, imported):
"""Create customized status field based on direction and imported."""
if imported:
if direction == 'INCOMING':
return 'accepted'
return 'accepted by peer'
if direction == 'INCOMING':
return 'rejected by config'
return 'rejected by peer config'
for item in items:
route = resource_projector.MakeSerializable(item)
# Set "status" to "Imported" or "Imported by peer" based on direction.
route['status'] = _TransformStatus(
route['direction'], route.get('imported', False)
)
yield route

View File

@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""'vmware private-connections update' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.vmware.privateconnections import PrivateConnectionsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.vmware import flags
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""
Updates a VMware Engine private connection. Only description and routing-mode can be updated.
""",
'EXAMPLES':
"""
To update a private connection named `my-private-connection` in project `my-project` and region `us-west1` by changing its description to `Updated description for the private connection` and routing-mode to `GLOBAL`, run:
$ {command} my-private-connection --location=us-west1 --project=my-project --description="Updated description for the private connection" --routing-mode=GLOBAL
Or:
$ {command} my-private-connection --description="Updated description for the private connection" --routing-mode=GLOBAL
In the second example, the project and location are taken from gcloud properties core/project and compute/regions, respectively.
"""
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Google Cloud Private Connection."""
detailed_help = DETAILED_HELP
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddPrivateConnectionToParser(parser, positional=True)
base.ASYNC_FLAG.AddToParser(parser)
base.ASYNC_FLAG.SetDefault(parser, True)
parser.display_info.AddFormat('yaml')
parser.add_argument(
'--description',
help="""\
Updated description for this Private Connection.
""")
parser.add_argument(
'--routing-mode',
choices=['GLOBAL', 'REGIONAL'],
help="""\
Updated routing mode for this Private Connection.
""")
def Run(self, args):
private_connection = args.CONCEPTS.private_connection.Parse()
client = PrivateConnectionsClient()
is_async = args.async_
operation = client.Update(private_connection, args.description,
args.routing_mode)
if is_async:
log.UpdatedResource(
operation.name, kind='Private Connection', is_async=True)
return
resource = client.WaitForOperation(
operation_ref=client.GetOperationRef(operation),
message='waiting for private connection [{}] to be updated'.format(
private_connection.RelativeName()
),
)
log.UpdatedResource(
private_connection.RelativeName(), kind='Private Connection'
)
return resource