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,47 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Cloud vmware Announcements client."""
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.vmware import util
class AnnouncementsClient(util.VmwareClientBase):
"""cloud vmware Announcements client."""
def __init__(self):
super(AnnouncementsClient, self).__init__()
self.service = self.client.projects_locations_announcements
def List(self, location, announcement_type):
request = (
self.messages.VmwareengineProjectsLocationsAnnouncementsListRequest(
parent=location.RelativeName()
)
)
# At the moment we only support active announcements of a given type.
request.filter = f'state:ACTIVE AND code:{announcement_type}'
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='announcements',
)

View File

@@ -0,0 +1,176 @@
# -*- 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.
"""Cloud vmware Clusters client."""
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.vmware import util
class ClustersClient(util.VmwareClientBase):
"""cloud vmware Clusters client."""
def __init__(self):
super(ClustersClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_clusters
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersGetRequest(
name=resource.RelativeName())
return self.service.Get(request)
def Create(self, resource, nodes_configs, autoscaling_settings=None):
parent = resource.Parent().RelativeName()
cluster_id = resource.Name()
node_type_configs = util.ConstructNodeParameterConfigMessage(
self.messages.Cluster.NodeTypeConfigsValue,
self.messages.NodeTypeConfig, nodes_configs)
cluster = self.messages.Cluster(nodeTypeConfigs=node_type_configs)
cluster.autoscalingSettings = util.ConstructAutoscalingSettingsMessage(
self.messages.AutoscalingSettings,
self.messages.AutoscalingPolicy,
self.messages.Thresholds,
autoscaling_settings,
)
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersCreateRequest(
parent=parent,
cluster=cluster,
clusterId=cluster_id)
return self.service.Create(request)
def Delete(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersDeleteRequest(
name=resource.RelativeName())
return self.service.Delete(request)
def List(self, private_cloud_resource):
private_cloud = private_cloud_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersListRequest(
parent=private_cloud
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='clusters')
def Update(self, resource, nodes_configs, autoscaling_settings):
node_type_configs, node_type_configs_update_mask = None, []
if nodes_configs is not None:
node_type_configs = util.ConstructNodeParameterConfigMessage(
self.messages.Cluster.NodeTypeConfigsValue,
self.messages.NodeTypeConfig,
nodes_configs,
)
node_type_configs_update_mask = ['node_type_configs.*.node_count']
if autoscaling_settings is not None:
autoscaling_settings_update_mask = ['autoscaling_settings']
else:
autoscaling_settings_update_mask = []
# If a customer removes the last policy from the settings, the settings do
# not provide any additional value. So, in this case, we are removing the
# entire setting.
if (
autoscaling_settings is not None
and autoscaling_settings.autoscaling_policies
):
autoscaling_settings_message = util.ConstructAutoscalingSettingsMessage(
self.messages.AutoscalingSettings,
self.messages.AutoscalingPolicy,
self.messages.Thresholds,
autoscaling_settings,
)
else:
autoscaling_settings_message = None
cluster = self.messages.Cluster(
nodeTypeConfigs=node_type_configs,
autoscalingSettings=autoscaling_settings_message,
)
update_mask = ','.join(
node_type_configs_update_mask + autoscaling_settings_update_mask
)
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersPatchRequest(
name=resource.RelativeName(), cluster=cluster, updateMask=update_mask
)
return self.service.Patch(request)
def MountDatastore(
self,
cluster_ref,
datastore,
subnet,
mtu,
connection_count,
access_mode,
nfs_version,
ignore_colocation,
):
"""Mounts a datastore to a cluster."""
datastore_network = self.messages.DatastoreNetwork(
subnet=cluster_ref.Parent().RelativeName() + '/subnets/' + subnet
)
if mtu is not None:
datastore_network.mtu = mtu
if connection_count is not None:
datastore_network.connectionCount = connection_count
datastore_mount_config = self.messages.DatastoreMountConfig(
datastore=datastore,
datastoreNetwork=datastore_network,
)
if access_mode:
datastore_mount_config.accessMode = (
self.messages.DatastoreMountConfig.AccessModeValueValuesEnum(
access_mode
)
)
if nfs_version:
if nfs_version == 'NFS_V4':
nfs_version_enum_str = 'NFS_V41'
else:
nfs_version_enum_str = nfs_version
datastore_mount_config.nfsVersion = (
self.messages.DatastoreMountConfig.NfsVersionValueValuesEnum(
nfs_version_enum_str
)
)
mount_datastore_request = self.messages.MountDatastoreRequest(
datastoreMountConfig=datastore_mount_config,
ignoreColocation=ignore_colocation,
)
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersMountDatastoreRequest(
name=cluster_ref.RelativeName(),
mountDatastoreRequest=mount_datastore_request,
)
return self.service.MountDatastore(request)
def UnmountDatastore(self, cluster_ref, datastore):
"""Unmounts a datastore from a cluster."""
unmount_datastore_request = self.messages.UnmountDatastoreRequest(
datastore=datastore
)
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersUnmountDatastoreRequest(
name=cluster_ref.RelativeName(),
unmountDatastoreRequest=unmount_datastore_request,
)
return self.service.UnmountDatastore(request)

View File

@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Cloud vmware datastores client."""
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.vmware import util
class DatastoresClient(util.VmwareClientBase):
"""Cloud vmware datastores client."""
def __init__(self):
super(DatastoresClient, self).__init__()
self.service = self.client.projects_locations_datastores
def Get(self, resource):
"""Gets a datastore."""
request = self.messages.VmwareengineProjectsLocationsDatastoresGetRequest(
name=resource.RelativeName()
)
return self.service.Get(request)
def List(self, location_resource):
"""Lists datastores in a given location."""
location = location_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsDatastoresListRequest(
parent=location
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='datastores',
)
def Delete(self, resource, etag=None):
request = (
self.messages.VmwareengineProjectsLocationsDatastoresDeleteRequest(
name=resource.RelativeName(), etag=etag
)
)
return self.service.Delete(request)
def Update(self, resource, description=None):
datastore = self.Get(resource)
update_mask = []
if description is not None:
datastore.description = description
update_mask.append('description')
request = self.messages.VmwareengineProjectsLocationsDatastoresPatchRequest(
datastore=datastore,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
return self.service.Patch(request)
def Create(
self,
resource,
description=None,
netapp_volume=None,
filestore_instance=None,
third_party_nfs_network=None,
third_party_nfs_file_share=None,
third_party_nfs_servers=None,
):
"""Creates a datastore."""
parent = resource.Parent().RelativeName()
datastore_id = resource.Name()
datastore = self.messages.Datastore(description=description)
nfs_datastore = self.messages.NfsDatastore()
if netapp_volume:
nfs_datastore.googleFileService = (
self.messages.GoogleFileService(
netappVolume=netapp_volume
)
)
elif filestore_instance:
nfs_datastore.googleFileService = (
self.messages.GoogleFileService(
filestoreInstance=filestore_instance
)
)
elif third_party_nfs_servers:
nfs_datastore.thirdPartyFileService = (
self.messages.ThirdPartyFileService(
servers=third_party_nfs_servers,
fileShare=third_party_nfs_file_share,
network=third_party_nfs_network,
)
)
datastore.nfsDatastore = nfs_datastore
request = (
self.messages.VmwareengineProjectsLocationsDatastoresCreateRequest(
parent=parent,
datastoreId=datastore_id,
datastore=datastore,
)
)
return self.service.Create(request)

View File

@@ -0,0 +1,83 @@
# -*- 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.
"""Google Cloud DNS Bind Permission client."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.vmware import util
class DNSBindPermissionClient(util.VmwareClientBase):
"""cloud vmware dns bind permission client."""
def __init__(self):
super(DNSBindPermissionClient, self).__init__()
self.service = self.client.projects_locations_dnsBindPermission
self.describe_service = self.client.projects_locations
def GetPrincipal(self, dns_bind_permission, user=None, service_account=None):
if user is not None:
dns_bind_permission.principal = self.messages.Principal(user=user)
else:
dns_bind_permission.principal = self.messages.Principal(
serviceAccount=service_account
)
def Grant(self, project_resource, user=None, service_account=None):
dns_bind_permission = self.messages.GrantDnsBindPermissionRequest()
self.GetPrincipal(
dns_bind_permission, user=user, service_account=service_account
)
dns_bind_permission_name = (
'{project}/locations/global/dnsBindPermission'.format(
project=project_resource.RelativeName()
)
)
request = self.messages.VmwareengineProjectsLocationsDnsBindPermissionGrantRequest(
grantDnsBindPermissionRequest=dns_bind_permission,
name=dns_bind_permission_name,
)
return self.service.Grant(request)
def Revoke(self, project_resource, user=None, service_account=None):
dns_bind_permission = self.messages.RevokeDnsBindPermissionRequest()
self.GetPrincipal(
dns_bind_permission, user=user, service_account=service_account
)
dns_bind_permission_name = (
'{project}/locations/global/dnsBindPermission'.format(
project=project_resource.RelativeName()
)
)
request = self.messages.VmwareengineProjectsLocationsDnsBindPermissionRevokeRequest(
revokeDnsBindPermissionRequest=dns_bind_permission,
name=dns_bind_permission_name,
)
return self.service.Revoke(request)
def Get(self, project_resource):
dns_bind_permission_name = (
'{project}/locations/global/dnsBindPermission'.format(
project=project_resource.RelativeName()
)
)
request = (
self.messages.VmwareengineProjectsLocationsGetDnsBindPermissionRequest(
name=dns_bind_permission_name
)
)
return self.describe_service.GetDnsBindPermission(request)

View File

@@ -0,0 +1,163 @@
# -*- 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 Engine external access rules client."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import re
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.vmware import util
class ExternalAccessRulesClient(util.VmwareClientBase):
"""VMware Engine network policy client."""
def __init__(self):
super(ExternalAccessRulesClient, self).__init__()
self.service = self.client.projects_locations_networkPolicies_externalAccessRules
self.ip_regex = re.compile(r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$')
self.ip_ranges_regex = re.compile(
r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/\d{1,2}$')
def parse_ip_range(self, ip_range):
if self.ip_regex.match(ip_range) is not None:
return self.messages.IpRange(ipAddress=ip_range)
if self.ip_ranges_regex.match(ip_range) is not None:
return self.messages.IpRange(ipAddressRange=ip_range)
return self.messages.IpRange(externalAddress=ip_range)
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsNetworkPoliciesExternalAccessRulesGetRequest(
name=resource.RelativeName())
response = self.service.Get(request)
return response
def Create(self,
resource,
priority,
ip_protocol,
source_ranges,
destination_ranges,
source_ports,
destination_ports,
description=None,
action=None):
parent = resource.Parent().RelativeName()
external_access_rule_id = resource.Name()
external_access_rule = self.messages.ExternalAccessRule(
description=description,
priority=priority,
ipProtocol=ip_protocol)
if source_ports is None:
external_access_rule.sourcePorts = []
else:
external_access_rule.sourcePorts = source_ports
if destination_ports is None:
external_access_rule.destinationPorts = []
else:
external_access_rule.destinationPorts = destination_ports
if action is None or action.strip().upper() == 'ALLOW':
external_access_rule.action = self.messages.ExternalAccessRule.ActionValueValuesEnum.ALLOW
elif action.strip().upper() == 'DENY':
external_access_rule.action = self.messages.ExternalAccessRule.ActionValueValuesEnum.DENY
external_access_rule.sourceIpRanges = [
self.parse_ip_range(ip) for ip in source_ranges
]
external_access_rule.destinationIpRanges = [
self.parse_ip_range(ip) for ip in destination_ranges
]
request = self.messages.VmwareengineProjectsLocationsNetworkPoliciesExternalAccessRulesCreateRequest(
parent=parent,
externalAccessRule=external_access_rule,
externalAccessRuleId=external_access_rule_id,
)
return self.service.Create(request)
def Update(self,
resource,
priority=None,
ip_protocol=None,
source_ranges=None,
destination_ranges=None,
source_ports=None,
destination_ports=None,
description=None,
action=None):
external_access_rule = self.Get(resource)
update_mask = []
if description is not None:
external_access_rule.description = description
update_mask.append('description')
if priority is not None:
external_access_rule.priority = priority
update_mask.append('priority')
if ip_protocol is not None:
external_access_rule.ipProtocol = ip_protocol
update_mask.append('ip_protocol')
if source_ports is not None:
external_access_rule.sourcePorts = source_ports
update_mask.append('source_ports')
if destination_ports is not None:
external_access_rule.destinationPorts = destination_ports
update_mask.append('destination_ports')
if action is not None:
if action.strip().upper() == 'ALLOW':
external_access_rule.action = self.messages.ExternalAccessRule.ActionValueValuesEnum.ALLOW
elif action.strip().upper() == 'DENY':
external_access_rule.action = self.messages.ExternalAccessRule.ActionValueValuesEnum.DENY
update_mask.append('action')
if source_ranges is not None and source_ranges:
external_access_rule.sourceIpRanges = [
self.parse_ip_range(ip) for ip in source_ranges
]
update_mask.append('source_ip_ranges')
if destination_ranges is not None and destination_ranges:
external_access_rule.destinationIpRanges = [
self.parse_ip_range(ip) for ip in destination_ranges
]
update_mask.append('destination_ip_ranges')
request = self.messages.VmwareengineProjectsLocationsNetworkPoliciesExternalAccessRulesPatchRequest(
externalAccessRule=external_access_rule,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
return self.service.Patch(request)
def Delete(self, resource):
return self.service.Delete(
self.messages.VmwareengineProjectsLocationsNetworkPoliciesExternalAccessRulesDeleteRequest(
name=resource.RelativeName()
)
)
def List(self, network_policy_resource):
network_policy = network_policy_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsNetworkPoliciesExternalAccessRulesListRequest(
parent=network_policy
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='externalAccessRules')

View File

@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# 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.
"""Cloud vmware External Addresses client."""
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.vmware import util
class ExternalAddressesClient(util.VmwareClientBase):
"""cloud vmware external addresses client."""
def __init__(self):
super(ExternalAddressesClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_externalAddresses
def Create(self, resource, internal_ip, description=None):
external_address = self.messages.ExternalAddress(
internalIp=internal_ip, description=description
)
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsExternalAddressesCreateRequest(
externalAddress=external_address,
externalAddressId=resource.Name(),
parent=resource.Parent().RelativeName())
return self.service.Create(request)
def Update(self, resource, internal_ip=None, description=None):
external_address = self.Get(resource)
update_mask = []
if description is not None:
external_address.description = description
update_mask.append('description')
if internal_ip is not None:
external_address.internalIp = internal_ip
update_mask.append('internal_ip')
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsExternalAddressesPatchRequest(
externalAddress=external_address,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
return self.service.Patch(request)
def Delete(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsExternalAddressesDeleteRequest(
name=resource.RelativeName())
return self.service.Delete(request)
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsExternalAddressesGetRequest(
name=resource.RelativeName())
return self.service.Get(request)
def List(self, resource):
address_name = resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsExternalAddressesListRequest(
parent=address_name
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='externalAddresses')

View File

@@ -0,0 +1,50 @@
# -*- 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.
"""Cloud vmware hcx activation keys client."""
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.vmware import util
class HcxActivationKeysClient(util.VmwareClientBase):
"""cloud vmware hcx activation keys client."""
def __init__(self):
super(HcxActivationKeysClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_hcxActivationKeys
def Create(self, hcx_activation_key):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsHcxActivationKeysCreateRequest(
parent=hcx_activation_key.Parent().RelativeName(),
hcxActivationKeyId=hcx_activation_key.Name())
return self.service.Create(request)
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsHcxActivationKeysGetRequest(
name=resource.RelativeName())
return self.service.Get(request)
def List(self, private_cloud_resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsHcxActivationKeysListRequest(
parent=private_cloud_resource.RelativeName())
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='hcxActivationKeys')

View File

@@ -0,0 +1,136 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# 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.
"""Google Cloud Identity Sources client."""
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.vmware import util
from googlecloudsdk.command_lib.util.apis import arg_utils
class IdentitySourcesClient(util.VmwareClientBase):
"""Identity Sources client."""
def __init__(self):
super(IdentitySourcesClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_identitySources
def Create(
self,
resource,
domain,
base_users_dn,
base_groups_dn,
domain_user,
domain_password,
protocol,
primary_server,
domain_alias=None,
secondary_server=None,
ssl_certificates=None,
):
protocol_enum_value = arg_utils.ChoiceEnumMapper(
arg_name='protocol',
message_enum=self.messages.IdentitySource.ProtocolValueValuesEnum,
include_filter=lambda x: 'PROTOCOL_UNSPECIFIED' not in x,
).GetEnumForChoice(arg_utils.EnumNameToChoice(protocol))
source = self.messages.IdentitySource(
domain=domain,
baseUsersDn=base_users_dn,
baseGroupsDn=base_groups_dn,
domainUser=domain_user,
domainPassword=domain_password,
protocol=protocol_enum_value,
specificDomainControllers=self.messages.SpecificDomainControllers(
primaryServerUri=primary_server,
secondaryServerUri=secondary_server,
),
domainAlias=domain_alias,
sslCertificates=ssl_certificates,
applianceType=self.messages.IdentitySource.ApplianceTypeValueValuesEnum.VCENTER,
)
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsIdentitySourcesCreateRequest(
identitySource=source,
identitySourceId=resource.Name(),
parent=resource.Parent().RelativeName(),
)
return self.service.Create(request)
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsIdentitySourcesGetRequest(
name=resource.RelativeName()
)
return self.service.Get(request)
def List(self, resource):
address_name = resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsIdentitySourcesListRequest(
parent=address_name
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='identitySources',
)
def Update(
self,
resource,
base_users_dn=None,
base_groups_dn=None,
domain_user=None,
domain_password=None,
ssl_certificates=None,
):
source = self.messages.IdentitySource()
update_mask = []
if base_users_dn is not None:
source.baseUsersDn = base_users_dn
update_mask.append('base_users_dn')
if base_groups_dn is not None:
source.baseGroupsDn = base_groups_dn
update_mask.append('base_groups_dn')
if domain_user is not None:
source.domainUser = domain_user
update_mask.append('domain_user')
if domain_password is not None:
source.domainPassword = domain_password
update_mask.append('domain_password')
if ssl_certificates:
source.sslCertificates = ssl_certificates
update_mask.append('ssl_certificates')
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsIdentitySourcesPatchRequest(
identitySource=source,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
return self.service.Patch(request)
def Delete(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsIdentitySourcesDeleteRequest(
name=resource.RelativeName()
)
return self.service.Delete(request)

View File

@@ -0,0 +1,40 @@
# -*- 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.
"""Cloud vmware locations client."""
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.vmware import util
class LocationsClient(util.VmwareClientBase):
"""cloud vmware locations client."""
def __init__(self):
super(LocationsClient, self).__init__()
self.service = self.client.projects_locations
def List(self, project_resource):
request = self.messages.VmwareengineProjectsLocationsListRequest(
name=project_resource.RelativeName()
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='locations')

View File

@@ -0,0 +1,109 @@
# -*- 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.
"""Cloud vmware LoggingServers client."""
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.vmware import util
from googlecloudsdk.command_lib.util.apis import arg_utils
class LoggingServersClient(util.VmwareClientBase):
"""Cloud VMware LoggingServers client."""
def __init__(self):
super(LoggingServersClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_loggingServers
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsLoggingServersGetRequest(
name=resource.RelativeName()
)
return self.service.Get(request)
def Create(self, resource, hostname, source_type, protocol, port):
parent = resource.Parent().RelativeName()
logging_server = self.messages.LoggingServer(hostname=hostname)
logging_server.sourceType = self.GetSourceType(source_type)
logging_server.protocol = self.GetProtocol(protocol)
logging_server.port = port
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsLoggingServersCreateRequest(
parent=parent,
loggingServer=logging_server,
loggingServerId=resource.Name(),
)
return self.service.Create(request)
def Delete(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsLoggingServersDeleteRequest(
name=resource.RelativeName(),
)
return self.service.Delete(request)
def List(self, private_cloud_resource):
private_cloud = private_cloud_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsLoggingServersListRequest(
parent=private_cloud
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='loggingServers',
)
def Update(
self, resource, hostname=None, source_type=None, protocol=None, port=None
):
logging_server = self.Get(resource)
update_mask = []
if hostname is not None:
logging_server.hostname = hostname
update_mask.append('hostname')
if source_type is not None:
logging_server.sourceType = self.GetSourceType(source_type)
update_mask.append('source_type')
if protocol is not None:
logging_server.protocol = self.GetProtocol(protocol)
update_mask.append('protocol')
if port is not None:
logging_server.port = port
update_mask.append('port')
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsLoggingServersPatchRequest(
loggingServer=logging_server,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
return self.service.Patch(request)
def GetSourceType(self, source_type):
source_type_enum = arg_utils.ChoiceEnumMapper(
arg_name='source_type',
message_enum=self.messages.LoggingServer.SourceTypeValueValuesEnum,
include_filter=lambda x: 'SOURCE_TYPE_UNSPECIFIED' not in x,
).GetEnumForChoice(arg_utils.EnumNameToChoice(source_type))
return source_type_enum
def GetProtocol(self, protocol):
protocol_enum = arg_utils.ChoiceEnumMapper(
arg_name='protocol',
message_enum=self.messages.LoggingServer.ProtocolValueValuesEnum,
include_filter=lambda x: 'PROTOCOL_UNSPECIFIED' not in x,
).GetEnumForChoice(arg_utils.EnumNameToChoice(protocol))
return protocol_enum

View File

@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# 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.
# pylint: disable=locally-disabled, line-too-long
"""Cloud vmware Management DNS zone binding client."""
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.vmware import util
class ManagementDNSZoneBindingClient(util.VmwareClientBase):
"""cloud vmware management dns zone binding client."""
def __init__(self):
super(ManagementDNSZoneBindingClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_managementDnsZoneBindings
def Create(self, resource,
vpc_network=None,
vmware_engine_network=None,
description=None):
mgmt_dns_zone_binding = self.messages.ManagementDnsZoneBinding()
if vpc_network is not None:
mgmt_dns_zone_binding.vpcNetwork = vpc_network
else:
mgmt_dns_zone_binding.vmwareEngineNetwork = vmware_engine_network
if description is not None:
mgmt_dns_zone_binding.description = description
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsManagementDnsZoneBindingsCreateRequest(
managementDnsZoneBinding=mgmt_dns_zone_binding,
managementDnsZoneBindingId=resource.Name(),
parent=resource.Parent().RelativeName())
return self.service.Create(request)
def Update(self, resource,
description):
mgmt_dns_zone_binding = self.Get(resource)
update_mask = []
mgmt_dns_zone_binding.description = description
update_mask.append('description')
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsManagementDnsZoneBindingsPatchRequest(
managementDnsZoneBinding=mgmt_dns_zone_binding,
name=resource.RelativeName(),
updateMask=','.join(update_mask))
return self.service.Patch(request)
def Delete(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsManagementDnsZoneBindingsDeleteRequest(
name=resource.RelativeName())
return self.service.Delete(request)
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsManagementDnsZoneBindingsGetRequest(
name=resource.RelativeName())
return self.service.Get(request)
def List(self, resource, filter_expression=None,
limit=None, page_size=None):
address_name = resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsManagementDnsZoneBindingsListRequest(
parent=address_name, filter=filter_expression)
if page_size:
request.page_size = page_size
return list_pager.YieldFromList(
self.service,
request,
limit=limit,
batch_size_attribute='pageSize',
batch_size=page_size,
field='managementDnsZoneBindings')
def Repair(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsManagementDnsZoneBindingsRepairRequest(
name=resource.RelativeName()
)
return self.service.Repair(request)

View File

@@ -0,0 +1,148 @@
# -*- 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 Engine VPC network peering client."""
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.vmware import util
from googlecloudsdk.api_lib.vmware import networks
from googlecloudsdk.command_lib.util.apis import arg_utils
from googlecloudsdk.core import resources
class NetworkPeeringClient(util.VmwareClientBase):
"""VMware Engine VPC network peering client."""
def __init__(self):
super(NetworkPeeringClient, self).__init__()
self.service = self.client.projects_locations_networkPeerings
self.networks_client = networks.NetworksClient()
def Get(self, resource):
request = (
self.messages.VmwareengineProjectsLocationsNetworkPeeringsGetRequest(
name=resource.RelativeName()
)
)
response = self.service.Get(request)
return response
def Create(
self,
resource,
vmware_engine_network_id,
peer_network_id,
peer_network_type,
description=None,
peer_project=None,
peer_mtu=None,
export_custom_routes=True,
import_custom_routes=True,
export_custom_routes_with_public_ip=True,
import_custom_routes_with_public_ip=True,
exchange_subnet_routes=True,
vmware_engine_network_project=None,
):
project = resource.Parent().Parent().Name()
if peer_project is None:
peer_project = project
parent = resource.Parent().RelativeName()
peering_id = resource.Name()
# TODO(b/265135446) : pass the values as arguments into the constructor
peering = self.messages.NetworkPeering(description=description)
peer_network_type_enum = arg_utils.ChoiceEnumMapper(
arg_name='peer-network-type',
message_enum=self.messages.NetworkPeering
.PeerNetworkTypeValueValuesEnum,
include_filter=lambda x: 'UNSPECIFIED' not in x).GetEnumForChoice(
arg_utils.EnumNameToChoice(peer_network_type))
peering.peerNetworkType = peer_network_type_enum
peering.vmwareEngineNetwork = resources.REGISTRY.Parse(
line=None,
collection='vmwareengine.projects.locations.vmwareEngineNetworks',
params={
'projectsId': (
vmware_engine_network_project
if vmware_engine_network_project
else project
),
'locationsId': 'global',
'vmwareEngineNetworksId': vmware_engine_network_id,
},
).RelativeName()
if (
peer_network_type_enum
== self.messages.NetworkPeering.PeerNetworkTypeValueValuesEnum.VMWARE_ENGINE_NETWORK
):
peering.peerNetwork = 'projects/{project}/locations/global/vmwareEngineNetworks/{network_id}'.format(
project=peer_project, network_id=peer_network_id
)
else:
peering.peerNetwork = (
'projects/{project}/global/networks/{network_id}'.format(
project=peer_project, network_id=peer_network_id
)
)
if peer_mtu:
peering.peer_mtu = peer_mtu
peering.exportCustomRoutes = export_custom_routes
peering.importCustomRoutes = import_custom_routes
peering.exportCustomRoutesWithPublicIp = export_custom_routes_with_public_ip
peering.importCustomRoutesWithPublicIp = import_custom_routes_with_public_ip
peering.exchangeSubnetRoutes = exchange_subnet_routes
request = (
self.messages.VmwareengineProjectsLocationsNetworkPeeringsCreateRequest(
parent=parent, networkPeering=peering, networkPeeringId=peering_id
)
)
return self.service.Create(request)
def Update(self, resource, description):
peering = self.Get(resource)
update_mask = []
peering.description = description
update_mask.append('description')
request = (
self.messages.VmwareengineProjectsLocationsNetworkPeeringsPatchRequest(
networkPeering=peering,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
)
return self.service.Patch(request)
def Delete(self, resource):
return self.service.Delete(
self.messages.VmwareengineProjectsLocationsNetworkPeeringsDeleteRequest(
name=resource.RelativeName()
)
)
def List(self, location_resource):
location = location_resource.RelativeName()
request = (
self.messages.VmwareengineProjectsLocationsNetworkPeeringsListRequest(
parent=location
)
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='networkPeerings')

View File

@@ -0,0 +1,41 @@
# -*- 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 Engine VPC network peering client."""
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.vmware import util
class NetworkPeeringRoutesClient(util.VmwareClientBase):
"""VMware Engine VPC network peering routes client."""
def __init__(self):
super(NetworkPeeringRoutesClient, self).__init__()
self.service = self.client.projects_locations_networkPeerings_peeringRoutes
def List(self, network_peering):
networkpeering = network_peering.RelativeName()
request = self.messages.VmwareengineProjectsLocationsNetworkPeeringsPeeringRoutesListRequest(
parent=networkpeering
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='peeringRoutes')

View File

@@ -0,0 +1,121 @@
# -*- 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 Engine network policy client."""
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.vmware import util
from googlecloudsdk.api_lib.vmware.networks import NetworksClient
class NetworkPoliciesClient(util.VmwareClientBase):
"""VMware Engine network policy client."""
def __init__(self):
super(NetworkPoliciesClient, self).__init__()
self.service = self.client.projects_locations_networkPolicies
self.networks_client = NetworksClient()
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsNetworkPoliciesGetRequest(
name=resource.RelativeName())
response = self.service.Get(request)
return response
def Create(
self,
resource,
vmware_engine_network_id,
edge_services_cidr,
description=None,
internet_access=None,
external_ip_access=None,
):
parent = resource.Parent().RelativeName()
project = resource.Parent().Parent().Name()
network_policy_id = resource.Name()
network_policy = self.messages.NetworkPolicy(description=description)
internet_access_obj = self.messages.NetworkService(enabled=internet_access)
external_ip_access_obj = self.messages.NetworkService(
enabled=external_ip_access)
ven = self.networks_client.GetByID(project, vmware_engine_network_id)
network_policy.vmwareEngineNetwork = ven.name
network_policy.edgeServicesCidr = edge_services_cidr
network_policy.internetAccess = internet_access_obj
network_policy.externalIp = external_ip_access_obj
request = (
self.messages.VmwareengineProjectsLocationsNetworkPoliciesCreateRequest(
parent=parent,
networkPolicy=network_policy,
networkPolicyId=network_policy_id,
)
)
return self.service.Create(request)
def Update(self,
resource,
description=None,
edge_services_cidr=None,
internet_access=None,
external_ip_access=None):
network_policy = self.Get(resource)
update_mask = []
if description is not None:
network_policy.description = description
update_mask.append('description')
if edge_services_cidr is not None:
network_policy.edgeServicesCidr = edge_services_cidr
update_mask.append('edge_services_cidr')
if internet_access is not None:
internet_access_obj = self.messages.NetworkService(
enabled=internet_access)
network_policy.internetAccess = internet_access_obj
update_mask.append('internet_access.enabled')
if external_ip_access is not None:
external_ip_access_obj = self.messages.NetworkService(
enabled=external_ip_access)
network_policy.externalIp = external_ip_access_obj
update_mask.append('external_ip.enabled')
request = (
self.messages.VmwareengineProjectsLocationsNetworkPoliciesPatchRequest(
networkPolicy=network_policy,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
)
return self.service.Patch(request)
def Delete(self, resource):
return self.service.Delete(
self.messages.VmwareengineProjectsLocationsNetworkPoliciesDeleteRequest(
name=resource.RelativeName()
)
)
def List(self, location_resource):
location = location_resource.RelativeName()
request = (
self.messages.VmwareengineProjectsLocationsNetworkPoliciesListRequest(
parent=location
)
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='networkPolicies')

View File

@@ -0,0 +1,120 @@
# -*- 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.
"""Google Cloud VMware Engine network client."""
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.vmware import util
from googlecloudsdk.command_lib.util.apis import arg_utils
from googlecloudsdk.core.exceptions import Error
from googlecloudsdk.core.resources import REGISTRY
class NetworkNotFoundError(Error):
def __init__(self, network_id):
super(NetworkNotFoundError, self).__init__(
'FAILED_PRECONDITION: The VMware Engine network `{network_id}` doesn\'t exist. Operation on the resource can\'t be fulfilled.'
.format(network_id=network_id))
class MultipleNetworksFoundError(Error):
def __init__(self, network_id):
super(MultipleNetworksFoundError, self).__init__(
'Multiple VMware Engine networks `{network_id}` exist. Operation on the resource can\'t be fulfilled.'
.format(network_id=network_id))
class NetworksClient(util.VmwareClientBase):
"""Google Cloud VMware Engine network client."""
def __init__(self):
super(NetworksClient, self).__init__()
self.service = self.client.projects_locations_vmwareEngineNetworks
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsVmwareEngineNetworksGetRequest(
name=resource.RelativeName())
response = self.service.Get(request)
return response
def GetByID(self, project, network_id):
parent_location = REGISTRY.Create(
'vmwareengine.projects.locations', projectsId=project, locationsId='-')
networks = list(
network for network in self.List(parent_location)
if util.GetResourceId(network.name) == network_id)
if len(networks) > 1:
raise MultipleNetworksFoundError(network_id)
if not networks:
raise NetworkNotFoundError(network_id)
return networks[0]
def Create(self, resource, network_type, description=None):
parent = resource.Parent().RelativeName()
network_id = resource.Name()
network = self.messages.VmwareEngineNetwork(description=description)
type_enum = arg_utils.ChoiceEnumMapper(
arg_name='type',
message_enum=self.messages.VmwareEngineNetwork.TypeValueValuesEnum,
include_filter=lambda x: 'TYPE_UNSPECIFIED' not in x).GetEnumForChoice(
arg_utils.EnumNameToChoice(network_type))
network.type = type_enum
request = self.messages.VmwareengineProjectsLocationsVmwareEngineNetworksCreateRequest(
parent=parent,
vmwareEngineNetwork=network,
vmwareEngineNetworkId=network_id,
)
return self.service.Create(request)
def Update(self, resource, description):
network = self.Get(resource)
update_mask = []
if description is not None:
network.description = description
update_mask.append('description')
request = self.messages.VmwareengineProjectsLocationsVmwareEngineNetworksPatchRequest(
vmwareEngineNetwork=network,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
return self.service.Patch(request)
def Delete(self, resource, delay_hours=None):
return self.service.Delete(
self.messages.VmwareengineProjectsLocationsVmwareEngineNetworksDeleteRequest(
name=resource.RelativeName()
)
)
def List(self, location_resource):
location = location_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsVmwareEngineNetworksListRequest(
parent=location
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='vmwareEngineNetworks')

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# 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.
"""VMware Engine cluster nodes client."""
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.vmware import util
class NodesClient(util.VmwareClientBase):
"""cloud vmware cluster nodes client."""
def __init__(self):
super(NodesClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_clusters_nodes
def List(self, cluster_resource):
cluster = cluster_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersNodesListRequest(
parent=cluster)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='nodes')
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsClustersNodesGetRequest(
name=resource.RelativeName())
return self.service.Get(request)

View File

@@ -0,0 +1,45 @@
# -*- 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.
"""Cloud vmware node types client."""
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.vmware import util
class NodeTypesClient(util.VmwareClientBase):
"""cloud vmware node types client."""
def __init__(self):
super(NodeTypesClient, self).__init__()
self.service = self.client.projects_locations_nodeTypes
def List(self, location_resource):
request = self.messages.VmwareengineProjectsLocationsNodeTypesListRequest(
parent=location_resource.RelativeName()
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='nodeTypes')
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsNodeTypesGetRequest(
name=resource.RelativeName())
return self.service.Get(request)

View File

@@ -0,0 +1,46 @@
# -*- 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.
"""Cloud vmware operations client."""
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.vmware import util
class OperationsClient(util.VmwareClientBase):
"""cloud vmware operations client."""
def __init__(self):
super(OperationsClient, self).__init__()
self.service = self.client.projects_locations_operations
def List(self, location_resource):
location = location_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsOperationsListRequest(
name=location
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='operations')
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsOperationsGetRequest(
name=resource.RelativeName())
return self.service.Get(request)

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# 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.
"""Cloud vmware private-clouds Subnets client."""
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.vmware import util
class SubnetsClient(util.VmwareClientBase):
"""cloud vmware private-clouds subnets client."""
def __init__(self):
super(SubnetsClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_subnets
def List(self, resource):
address_name = resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsSubnetsListRequest(
parent=address_name)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='subnets')
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsSubnetsGetRequest(
name=resource.RelativeName())
response = self.service.Get(request)
return response
def Update(self, resource, ip_cidr_range):
subnet = self.Get(resource)
subnet.ipCidrRange = ip_cidr_range
update_mask = ['ip_cidr_range']
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsSubnetsPatchRequest(
subnet=subnet,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
return self.service.Patch(request)

View File

@@ -0,0 +1,251 @@
# -*- 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.
"""Cloud vmware Privateclouds client."""
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.vmware import clusters
from googlecloudsdk.api_lib.vmware import networks
from googlecloudsdk.api_lib.vmware import util
from googlecloudsdk.command_lib.util.apis import arg_utils
from googlecloudsdk.core.exceptions import Error
class SecondaryZoneNotProvidedError(Error):
def __init__(self):
super(SecondaryZoneNotProvidedError, self).__init__(
'FAILED_PRECONDITION: Secondary Zone value is required for Stretched'
' Private Cloud.'
)
class PreferredZoneNotProvidedError(Error):
def __init__(self):
super(PreferredZoneNotProvidedError, self).__init__(
'FAILED_PRECONDITION: Preferred Zone value is required for Stretched'
' Private Cloud.'
)
class PrivateCloudsClient(util.VmwareClientBase):
"""cloud vmware privateclouds client."""
def __init__(self):
super(PrivateCloudsClient, self).__init__()
self.service = self.client.projects_locations_privateClouds
self.networks_client = networks.NetworksClient()
self.cluster_client = clusters.ClustersClient()
def Get(self, resource):
request = (
self.messages.VmwareengineProjectsLocationsPrivateCloudsGetRequest(
name=resource.RelativeName()
)
)
response = self.service.Get(request)
return response
def Create(
self,
resource,
cluster_id,
nodes_configs,
network_cidr,
vmware_engine_network_id,
private_cloud_type,
description=None,
secondary_zone=None,
preferred_zone=None,
autoscaling_settings=None,
service_subnet=None,
):
parent = resource.Parent().RelativeName()
project = resource.Parent().Parent().Name()
private_cloud_id = resource.Name()
private_cloud = self.messages.PrivateCloud(description=description)
private_cloud.type = self.GetPrivateCloudType(private_cloud_type)
ven = self.networks_client.GetByID(project, vmware_engine_network_id)
new_subnets = []
if service_subnet:
new_subnets = [
self.messages.Subnet(ipCidrRange=cidr) for cidr in service_subnet
]
network_config = self.messages.NetworkConfig(
managementCidr=network_cidr, vmwareEngineNetwork=ven.name,
serviceSubnets=new_subnets,
)
management_cluster = self.messages.ManagementCluster(clusterId=cluster_id)
management_cluster.nodeTypeConfigs = (
util.ConstructNodeParameterConfigMessage(
self.messages.ManagementCluster.NodeTypeConfigsValue,
self.messages.NodeTypeConfig,
nodes_configs,
)
)
if (
private_cloud.type
is self.messages.PrivateCloud.TypeValueValuesEnum.STRETCHED
):
if not preferred_zone:
raise PreferredZoneNotProvidedError()
if not secondary_zone:
raise SecondaryZoneNotProvidedError()
management_cluster.stretchedClusterConfig = (
self.messages.StretchedClusterConfig(
preferredLocation=preferred_zone, secondaryLocation=secondary_zone
)
)
management_cluster.autoscalingSettings = (
util.ConstructAutoscalingSettingsMessage(
self.messages.AutoscalingSettings,
self.messages.AutoscalingPolicy,
self.messages.Thresholds,
autoscaling_settings,
)
)
private_cloud.managementCluster = management_cluster
private_cloud.networkConfig = network_config
request = (
self.messages.VmwareengineProjectsLocationsPrivateCloudsCreateRequest(
parent=parent,
privateCloudId=private_cloud_id,
privateCloud=private_cloud,
)
)
return self.service.Create(request)
def Update(self, resource, description):
private_cloud = self.Get(resource)
update_mask = []
private_cloud.description = description
update_mask.append('description')
request = (
self.messages.VmwareengineProjectsLocationsPrivateCloudsPatchRequest(
privateCloud=private_cloud,
name=resource.RelativeName(),
updateMask=','.join(update_mask),
)
)
return self.service.Patch(request)
def UnDelete(self, resource):
request = (
self.messages.VmwareengineProjectsLocationsPrivateCloudsUndeleteRequest(
name=resource.RelativeName()
)
)
return self.service.Undelete(request)
def Delete(self, resource, delay_hours=None):
return self.service.Delete(
self.messages.VmwareengineProjectsLocationsPrivateCloudsDeleteRequest(
name=resource.RelativeName(), delayHours=delay_hours
)
)
def DeleteNow(self, resource):
request = (
self.messages.VmwareengineProjectsLocationsPrivateCloudsPrivateCloudDeletionNowRequest(
name=resource.RelativeName()
)
)
return self.service.PrivateCloudDeletionNow(request)
def List(self, location_resource):
location = location_resource.RelativeName()
request = (
self.messages.VmwareengineProjectsLocationsPrivateCloudsListRequest(
parent=location
)
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='privateClouds',
)
def GetDnsForwarding(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsGetDnsForwardingRequest(
name=resource.RelativeName() + '/dnsForwarding'
)
return self.service.GetDnsForwarding(request)
def UpdateDnsForwarding(self, resource, args_rules):
rules = self._ParseRules(args_rules)
dns_forwarding = self.messages.DnsForwarding(forwardingRules=rules)
update_mask = 'forwardingRules'
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsUpdateDnsForwardingRequest(
name=resource.RelativeName() + '/dnsForwarding',
dnsForwarding=dns_forwarding,
updateMask=update_mask,
)
return self.service.UpdateDnsForwarding(request)
def _ParseRules(self, args_rules):
return [self._ParseRule(rule) for rule in args_rules]
def _ParseRule(self, rule):
return self.messages.ForwardingRule(
domain=rule['domain'], nameServers=rule['name-servers']
)
def GetNsxCredentials(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsShowNsxCredentialsRequest(
privateCloud=resource.RelativeName()
)
return self.service.ShowNsxCredentials(request)
def ResetNsxCredentials(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsResetNsxCredentialsRequest(
privateCloud=resource.RelativeName()
)
return self.service.ResetNsxCredentials(request)
def GetVcenterCredentials(self, resource, username=None):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsShowVcenterCredentialsRequest(
privateCloud=resource.RelativeName(), username=username
)
return self.service.ShowVcenterCredentials(request)
def ResetVcenterCredentials(self, resource, username=None):
vcenter = self.messages.ResetVcenterCredentialsRequest()
vcenter.username = username
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsResetVcenterCredentialsRequest(
privateCloud=resource.RelativeName(),
resetVcenterCredentialsRequest=vcenter,
)
return self.service.ResetVcenterCredentials(request)
def GetPrivateCloudType(self, private_cloud_type):
type_enum = arg_utils.ChoiceEnumMapper(
arg_name='type',
default='STANDARD',
message_enum=self.messages.PrivateCloud.TypeValueValuesEnum,
).GetEnumForChoice(arg_utils.EnumNameToChoice(private_cloud_type))
return type_enum
def GetManagementCluster(self, resource):
for cluster in self.cluster_client.List(resource):
if cluster.management:
return cluster

View File

@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# 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.
"""Google Cloud private connections peering routes client."""
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.vmware import util
class PrivateConnectionPeeringRoutesClient(util.VmwareClientBase):
"""Google Cloud private connections peering routes client."""
def __init__(self):
super(PrivateConnectionPeeringRoutesClient, self).__init__()
self.service = self.client.projects_locations_privateConnections_peeringRoutes
def List(self, private_connection):
private_connection = private_connection.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateConnectionsPeeringRoutesListRequest(
parent=private_connection)
return list_pager.YieldFromList(
self.service,
request,
field='peeringRoutes',
batch_size_attribute='pageSize')

View File

@@ -0,0 +1,119 @@
# -*- 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.
"""Google Cloud Private Connections client."""
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.vmware import util
from googlecloudsdk.api_lib.vmware.networks import NetworksClient
from googlecloudsdk.command_lib.util.apis import arg_utils
class PrivateConnectionsClient(util.VmwareClientBase):
"""Private Connections client."""
def __init__(self):
super(PrivateConnectionsClient, self).__init__()
self.service = self.client.projects_locations_privateConnections
self.networks_client = NetworksClient()
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateConnectionsGetRequest(
name=resource.RelativeName())
response = self.service.Get(request)
return response
def Create(self,
resource,
vmware_engine_network,
service_project,
private_connection_type,
routing_mode=None,
description=None,
service_network=None):
parent = resource.Parent().RelativeName()
project = resource.Parent().Parent().Name()
private_connection_id = resource.Name()
private_connection = self.messages.PrivateConnection(
description=description)
if routing_mode is not None:
private_connection.routingMode = self.GetRoutingMode(routing_mode)
ven = self.networks_client.GetByID(project, vmware_engine_network)
private_connection.vmwareEngineNetwork = ven.name
type_enum = arg_utils.ChoiceEnumMapper(
arg_name='type',
message_enum=self.messages.PrivateConnection.TypeValueValuesEnum,
include_filter=lambda x: 'TYPE_UNSPECIFIED' not in x).GetEnumForChoice(
arg_utils.EnumNameToChoice(private_connection_type))
private_connection.type = type_enum
service_network = self.GetServiceNetwork(type_enum, service_network)
private_connection.serviceNetwork = 'projects/{project}/global/networks/{network_id}'.format(
project=service_project, network_id=service_network)
request = self.messages.VmwareengineProjectsLocationsPrivateConnectionsCreateRequest(
parent=parent,
privateConnection=private_connection,
privateConnectionId=private_connection_id)
return self.service.Create(request)
def Update(self, resource, description=None, routing_mode=None):
private_connection = self.Get(resource)
update_mask = []
if description is not None:
private_connection.description = description
update_mask.append('description')
if routing_mode is not None:
private_connection.routingMode = self.GetRoutingMode(routing_mode)
update_mask.append('routing_mode')
request = self.messages.VmwareengineProjectsLocationsPrivateConnectionsPatchRequest(
privateConnection=private_connection,
name=resource.RelativeName(),
updateMask=','.join(update_mask))
return self.service.Patch(request)
def Delete(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateConnectionsDeleteRequest(
name=resource.RelativeName())
return self.service.Delete(request)
def List(self, location_resource):
location = location_resource.RelativeName()
request = self.messages.VmwareengineProjectsLocationsPrivateConnectionsListRequest(
parent=location)
return list_pager.YieldFromList(
self.service,
request,
field='privateConnections',
batch_size_attribute='pageSize')
def GetServiceNetwork(self, type_enum, service_network=None):
if service_network:
return service_network
if type_enum == self.messages.PrivateConnection.TypeValueValuesEnum.PRIVATE_SERVICE_ACCESS:
return 'servicenetworking'
if type_enum == self.messages.PrivateConnection.TypeValueValuesEnum.DELL_POWERSCALE:
return 'dell-tenant-vpc'
if type_enum == self.messages.PrivateConnection.TypeValueValuesEnum.NETAPP_CLOUD_VOLUMES:
return 'netapp-tenant-vpc'
def GetRoutingMode(self, routing_mode):
routing_mode_enum = arg_utils.ChoiceEnumMapper(
arg_name='routing_mode',
message_enum=self.messages.PrivateConnection.RoutingModeValueValuesEnum,
include_filter=lambda x: 'ROUTING_MODE_UNSPECIFIED' not in x
).GetEnumForChoice(arg_utils.EnumNameToChoice(routing_mode))
return routing_mode_enum

View File

@@ -0,0 +1,85 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# Copyright 2020 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.
"""Cloud vmware sddc Clusters client."""
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.vmware.sddc import util
from googlecloudsdk.command_lib.vmware.sddc import flags
class ClustersClient(util.VmwareClientBase):
"""cloud vmware Clusters client."""
def __init__(self):
super(ClustersClient, self).__init__()
self.service = self.client.projects_locations_clusterGroups_clusters
def Get(self, resource):
request = self.messages.SddcProjectsLocationsClusterGroupsClustersGetRequest(
name=resource.RelativeName())
return self.service.Get(request)
def Create(self, resource, node_count, node_type, zone, labels=None):
parent = resource.Parent().RelativeName()
cluster_id = resource.Name()
cluster = self.messages.Cluster(
nodeCount=node_count, defaultZone=zone, nodeType=node_type)
flags.AddLabelsToMessage(labels, cluster)
request = self.messages.SddcProjectsLocationsClusterGroupsClustersCreateRequest(
parent=parent,
cluster=cluster,
clusterId=cluster_id,
managementCluster=True)
return self.service.Create(request)
def Delete(self, resource):
request = self.messages.SddcProjectsLocationsClusterGroupsClustersDeleteRequest(
name=resource.RelativeName())
return self.service.Delete(request)
def List(self, cluster_group_resource):
cluster_group = cluster_group_resource.RelativeName()
request = (
self.messages.SddcProjectsLocationsClusterGroupsClustersListRequest(
parent=cluster_group
)
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='clusters')
def AddNodes(self, resource, node_count):
cluster = self.Get(resource)
request = self.messages.SddcProjectsLocationsClusterGroupsClustersAddNodesRequest(
cluster=resource.RelativeName(),
addNodesRequest=self.messages.AddNodesRequest(
nodeCount=cluster.nodeCount + node_count))
return self.service.AddNodes(request)
def RemoveNodes(self, resource, node_count):
cluster = self.Get(resource)
request = self.messages.SddcProjectsLocationsClusterGroupsClustersRemoveNodesRequest(
cluster=resource.RelativeName(),
removeNodesRequest=self.messages.RemoveNodesRequest(
nodeCount=cluster.nodeCount - node_count))
return self.service.RemoveNodes(request)

View File

@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*- # # Copyright 2020 Google LLC. All Rights Reserved.
# Copyright 2020 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.
"""Cloud vmware IPAdresses client."""
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.vmware.sddc import util
from googlecloudsdk.command_lib.vmware.sddc import flags
import six.moves.urllib.parse
class IPAddressesClient(util.VmwareClientBase):
"""cloud vmware sddc ip addresses client."""
def __init__(self):
super(IPAddressesClient, self).__init__()
self.service = self.client.projects_locations_clusterGroups_ipAddresses
def Create(self, resource, internal_ip, labels=None):
ip_address = self.messages.IpAddress(internalIp=internal_ip)
flags.AddLabelsToMessage(labels, ip_address)
request = self.messages.SddcProjectsLocationsClusterGroupsIpAddressesCreateRequest(
ipAddress=ip_address,
ipAddressId=resource.Name(),
parent=self.GetResourcePath(
resource, resource_path=resource.Parent().RelativeName()))
return self.service.Create(request)
def Delete(self, resource):
request = self.messages.SddcProjectsLocationsClusterGroupsIpAddressesDeleteRequest(
name=self.GetResourcePath(
resource, resource_path=resource.RelativeName()))
return self.service.Delete(request)
def Get(self, resource):
request = self.messages.SddcProjectsLocationsClusterGroupsIpAddressesGetRequest(
name=self.GetResourcePath(
resource, resource_path=resource.RelativeName()))
return self.service.Get(request)
def GetResourcePath(self,
resource,
resource_path,
encoded_cluster_groups_id=False):
result = six.text_type(resource_path)
if '/' not in resource.clusterGroupsId:
return result
cluster_groups_id = resource.clusterGroupsId.split('/').pop()
cluster_groups_id_path = six.text_type(resource.clusterGroupsId)
if encoded_cluster_groups_id:
cluster_groups_id_path = six.moves.urllib.parse.quote(
cluster_groups_id_path, safe='')
return result.replace(cluster_groups_id_path, cluster_groups_id)
def List(self, resource):
ip_name = resource.RelativeName()
request = (
self.messages.SddcProjectsLocationsClusterGroupsIpAddressesListRequest(
parent=ip_name
)
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='ipAddresses')

View File

@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""Cloud vmware sddc Privateclouds client."""
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.vmware.sddc import util
from googlecloudsdk.command_lib.vmware.sddc import flags
class PrivatecloudsClient(util.VmwareClientBase):
"""cloud vmware privateclouds client."""
def __init__(self):
super(PrivatecloudsClient, self).__init__()
self.service = self.client.projects_locations_clusterGroups
def Get(self, resource):
request = self.messages.SddcProjectsLocationsClusterGroupsGetRequest(
name=resource.RelativeName())
return self.service.Get(request)
def Create(
self,
resource,
vpc_network,
management_ip_range,
workload_ip_range,
labels=None,
description=None,
):
parent = resource.Parent().RelativeName()
cluster_group_id = resource.Name()
cluster_group = self.messages.ClusterGroup(description=description)
flags.AddLabelsToMessage(labels, cluster_group)
network_config = self.messages.NetworkConfig(
network=vpc_network,
managementCidr=management_ip_range,
workloadCidr=workload_ip_range)
cluster_group.networkConfig = network_config
request = self.messages.SddcProjectsLocationsClusterGroupsCreateRequest(
parent=parent,
clusterGroup=cluster_group,
clusterGroupId=cluster_group_id)
return self.service.Create(request)
def Update(self,
resource,
labels=None,
description=None,
external_ip_access=None):
cluster_group = self.Get(resource)
update_mask = ['labels']
if labels is not None:
flags.AddLabelsToMessage(labels, cluster_group)
if description is not None:
cluster_group.description = description
update_mask.append('description')
if external_ip_access is not None:
cluster_group.networkConfig.externalIpAccess = external_ip_access
update_mask.append('network_config.external_ip_access')
request = self.messages.SddcProjectsLocationsClusterGroupsPatchRequest(
clusterGroup=cluster_group,
name=resource.RelativeName(),
updateMask=','.join(update_mask))
return self.service.Patch(request)
def Delete(self, resource):
request = self.messages.SddcProjectsLocationsClusterGroupsDeleteRequest(
name=resource.RelativeName())
return self.service.Delete(request)
def List(self, location_resource):
location = location_resource.RelativeName()
request = self.messages.SddcProjectsLocationsClusterGroupsListRequest(
parent=location
)
return list_pager.YieldFromList(
self.service,
request,
batch_size_attribute='pageSize',
field='clusterGroups')

View File

@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""Cloud vmware sddc API utilities."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.core import resources
_DEFAULT_API_VERSION = 'v1alpha1'
class VmwareClientBase(object):
"""Base class for vwmare API client wrappers."""
def __init__(self, api_version=_DEFAULT_API_VERSION):
self._client = apis.GetClientInstance('sddc', api_version)
self._messages = apis.GetMessagesModule('sddc', api_version)
self.service = None
self.operations_service = self.client.projects_locations_operations
@property
def client(self):
return self._client
@property
def messages(self):
return self._messages
def WaitForOperation(self, operation, message, is_delete=False):
operation_ref = resources.REGISTRY.Parse(
operation.name, collection='sddc.projects.locations.operations')
if is_delete:
poller = waiter.CloudOperationPollerNoResources(self.operations_service)
else:
poller = waiter.CloudOperationPoller(self.service,
self.operations_service)
return waiter.WaitFor(poller, operation_ref, message)

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Cloud vmware Upgrades client."""
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.vmware import util
class UpgradesClient(util.VmwareClientBase):
"""cloud vmware Upgrades client."""
def __init__(self):
super(UpgradesClient, self).__init__()
self.service = self.client.projects_locations_privateClouds_upgrades
def Get(self, resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsUpgradesGetRequest(
name=resource.RelativeName()
)
return self.service.Get(request)
def List(self, private_cloud_resource):
request = self.messages.VmwareengineProjectsLocationsPrivateCloudsUpgradesListRequest(
parent=private_cloud_resource.RelativeName()
)
return list_pager.YieldFromList(
self.service, request, batch_size_attribute='pageSize', field='upgrades'
)

View File

@@ -0,0 +1,190 @@
# -*- 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.
"""Cloud vmware API utilities."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import datetime
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.core import resources
_DEFAULT_API_VERSION = 'v1'
class VmwareClientBase(object):
"""Base class for vwmare API client wrappers."""
def __init__(self, api_version=_DEFAULT_API_VERSION):
self._client = apis.GetClientInstance('vmwareengine', api_version)
self._messages = apis.GetMessagesModule('vmwareengine', api_version)
self.service = None
self.operations_service = self.client.projects_locations_operations
@property
def client(self):
return self._client
@property
def messages(self):
return self._messages
def GetOperationRef(self, operation):
"""Converts an Operation to a Resource that can be used with `waiter.WaitFor`.
"""
return resources.REGISTRY.ParseRelativeName(
operation.name, collection='vmwareengine.projects.locations.operations')
def WaitForOperation(self,
operation_ref,
message,
has_result=True,
max_wait=datetime.timedelta(seconds=3600)):
"""Waits for an operation to complete.
Polls the IDS Operation service until the operation completes, fails, or
max_wait_seconds elapses.
Args:
operation_ref: a Resource created by GetOperationRef describing the
operation.
message: the message to display to the user while they wait.
has_result: if True, the function will return the target of the operation
when it completes. If False, nothing will be returned (useful for Delete
operations)
max_wait: The time to wait for the operation to succeed before returning.
Returns:
if has_result = True, an Endpoint entity.
Otherwise, None.
"""
if has_result:
poller = waiter.CloudOperationPoller(self.service,
self.operations_service)
else:
poller = waiter.CloudOperationPollerNoResources(self.operations_service)
return waiter.WaitFor(
poller, operation_ref, message, max_wait_ms=max_wait.seconds * 1000)
def GetResponse(self, operation):
poller = waiter.CloudOperationPoller(self.service, self.operations_service)
return poller.GetResult(operation)
def GetResourceId(resource_name):
return resource_name.split('/')[-1]
def ConstructNodeParameterConfigMessage(map_class, config_class, nodes_configs):
"""Constructs a node configs API message.
Args:
map_class: The map message class.
config_class: The config (map-entry) message class.
nodes_configs: The list of nodes configurations.
Returns:
The constructed message.
"""
properties = []
for nodes_config in nodes_configs:
if nodes_config.count == 0:
continue
node_type_config = config_class(nodeCount=nodes_config.count)
if nodes_config.custom_core_count > 0:
node_type_config.customCoreCount = nodes_config.custom_core_count
prop = map_class.AdditionalProperty(
key=nodes_config.type, value=node_type_config
)
properties.append(prop)
return map_class(additionalProperties=properties)
def ConstructAutoscalingSettingsMessage(
settings_message_class,
policy_message_class,
thresholds_message_class,
autoscaling_settings,
):
"""Constructs autoscaling settings API message.
Args:
settings_message_class: Top-level autoscaling settings message class.
policy_message_class: Autoscaling policy message class.
thresholds_message_class: Autoscaling policy thresholds message class.
autoscaling_settings: Desired autoscaling settings.
Returns:
The constructed message.
"""
if not autoscaling_settings:
return None
settings_message = settings_message_class()
settings_message.minClusterNodeCount = (
autoscaling_settings.min_cluster_node_count
)
settings_message.maxClusterNodeCount = (
autoscaling_settings.max_cluster_node_count
)
settings_message.coolDownPeriod = autoscaling_settings.cool_down_period
policy_messages = {}
for name, policy in autoscaling_settings.autoscaling_policies.items():
policy_message = policy_message_class()
policy_message.nodeTypeId = policy.node_type_id
policy_message.scaleOutSize = policy.scale_out_size
policy_message.minNodeCount = policy.min_node_count
policy_message.maxNodeCount = policy.max_node_count
policy_message.cpuThresholds = _ConstructThresholdsMessage(
policy.cpu_thresholds, thresholds_message_class
)
policy_message.grantedMemoryThresholds = _ConstructThresholdsMessage(
policy.granted_memory_thresholds, thresholds_message_class
)
policy_message.consumedMemoryThresholds = _ConstructThresholdsMessage(
policy.consumed_memory_thresholds, thresholds_message_class
)
policy_message.storageThresholds = _ConstructThresholdsMessage(
policy.storage_thresholds, thresholds_message_class
)
policy_messages[name] = policy_message
settings_message.autoscalingPolicies = settings_message_class.AutoscalingPoliciesValue(
additionalProperties=[
settings_message_class.AutoscalingPoliciesValue.AdditionalProperty(
key=name, value=policy_message
) for name, policy_message in policy_messages.items()
]
)
return settings_message
def _ConstructThresholdsMessage(thresholds, thresholds_message_class):
thresholds_message = thresholds_message_class()
if thresholds is None:
return None
thresholds_message.scaleIn = thresholds.scale_in
thresholds_message.scaleOut = thresholds.scale_out
return thresholds_message