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,479 @@
# -*- 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.
"""Utils for VMware Engine private-clouds clusters commands.
Provides helpers for parsing the autoscaling settings and node type configs and
for combining settings from many sources together.
"""
from __future__ import absolute_import
from __future__ import annotations
from __future__ import division
from __future__ import unicode_literals
import collections
import dataclasses
from typing import Any, Dict, List, Union
from googlecloudsdk.core import exceptions
@dataclasses.dataclass(frozen=True)
class ScalingThresholds:
"""Scaling thresholds for a single condition. Uses None for empty values.
Attributes:
scale_in: The threshold for scaling in.
scale_out: The threshold for scaling out.
"""
scale_in: int
scale_out: int
def _MergeFields(left, right):
"""Merges two fields, favoring right one.
Args:
left: First field.
right: Second field.
Returns:
Merged field.
"""
return right if right is not None else left
def _MergeScalingThresholds(
left: ScalingThresholds | None, right: ScalingThresholds | None
) -> ScalingThresholds | None:
"""Merges two ScalingThresholds objects, favoring right one.
Args:
left: First ScalingThresholds object.
right: Second ScalingThresholds object.
Returns:
Merged ScalingThresholds - It contains the updated scale_in and scale_out
values, favoring the right one.
None - It indicates removal of threshold from autoscaling policy, favoring
right one. Therefore, if right is None, return None.
"""
if left is None:
return right
if right is None:
return None
return ScalingThresholds(
scale_in=_MergeFields(left.scale_in, right.scale_in),
scale_out=_MergeFields(left.scale_out, right.scale_out),
)
@dataclasses.dataclass(frozen=True)
class AutoscalingPolicy:
"""Represents the autoscaling policy for a single node type.
Uses None for empty settings.
Attributes:
node_type_id: The node type id.
scale_out_size: The size of a single scale out operation.
min_node_count: The minimum number of nodes of this type in the cluster.
max_node_count: The maximum number of nodes of this type in the cluster.
cpu_thresholds: The CPU thresholds.
granted_memory_thresholds: The granted memory thresholds.
consumed_memory_thresholds: The consumed memory thresholds.
storage_thresholds: The storage thresholds.
"""
node_type_id: str
scale_out_size: int
min_node_count: int
max_node_count: int
cpu_thresholds: ScalingThresholds
granted_memory_thresholds: ScalingThresholds
consumed_memory_thresholds: ScalingThresholds
storage_thresholds: ScalingThresholds
def _MergeAutoscalingPolicies(
left: AutoscalingPolicy,
right: AutoscalingPolicy,
) -> AutoscalingPolicy:
"""Merges two AutoscalingPolicy objects, favoring right one.
Args:
left: First AutoscalingPolicy object.
right: Second AutoscalingPolicy object.
Returns:
Merged AutoscalingPolicy.
"""
if left is None:
return right
if right is None:
return left
return AutoscalingPolicy(
node_type_id=_MergeFields(left.node_type_id, right.node_type_id),
scale_out_size=_MergeFields(left.scale_out_size, right.scale_out_size),
min_node_count=_MergeFields(left.min_node_count, right.min_node_count),
max_node_count=_MergeFields(left.max_node_count, right.max_node_count),
cpu_thresholds=_MergeScalingThresholds(
left.cpu_thresholds, right.cpu_thresholds
),
granted_memory_thresholds=_MergeScalingThresholds(
left.granted_memory_thresholds, right.granted_memory_thresholds
),
consumed_memory_thresholds=_MergeScalingThresholds(
left.consumed_memory_thresholds, right.consumed_memory_thresholds
),
storage_thresholds=_MergeScalingThresholds(
left.storage_thresholds, right.storage_thresholds
),
)
@dataclasses.dataclass(frozen=True)
class AutoscalingSettings:
"""Represents the autoscaling settings for a private-cloud cluster.
Uses None for empty settings.
Attributes:
min_cluster_node_count: The minimum number of nodes in the cluster.
max_cluster_node_count: The maximum number of nodes in the cluster.
cool_down_period: The cool down period for autoscaling.
autoscaling_policies: The autoscaling policies for each node type.
"""
min_cluster_node_count: int
max_cluster_node_count: int
cool_down_period: str
autoscaling_policies: Dict[str, AutoscalingPolicy]
def MergeAutoscalingSettings(
left: AutoscalingSettings, right: AutoscalingSettings
) -> AutoscalingSettings:
"""Merges two AutoscalingSettings objects, favoring right one.
Args:
left: First AutoscalingSettings object.
right: Second AutoscalingSettings object.
Returns:
Merged AutoscalingSettings.
"""
if left is None:
return right
if right is None:
return left
policies = {}
for policy_name, policy in left.autoscaling_policies.items():
if policy_name in right.autoscaling_policies:
policies[policy_name] = _MergeAutoscalingPolicies(
policy, right.autoscaling_policies[policy_name]
)
else:
policies[policy_name] = policy
for policy_name, policy in right.autoscaling_policies.items():
if policy_name not in left.autoscaling_policies:
policies[policy_name] = policy
return AutoscalingSettings(
min_cluster_node_count=_MergeFields(
left.min_cluster_node_count, right.min_cluster_node_count
),
max_cluster_node_count=_MergeFields(
left.max_cluster_node_count, right.max_cluster_node_count
),
cool_down_period=_MergeFields(
left.cool_down_period, right.cool_down_period
),
autoscaling_policies=policies,
)
class InvalidNodeConfigsProvidedError(exceptions.Error):
def __init__(self, details):
super(InvalidNodeConfigsProvidedError, self).__init__(
f'INVALID_ARGUMENT: {details}'
)
class InvalidAutoscalingSettingsProvidedError(exceptions.Error):
def __init__(self, details):
super(InvalidAutoscalingSettingsProvidedError, self).__init__(
f'INVALID_ARGUMENT: {details}'
)
NodeTypeConfig = collections.namedtuple(
typename='NodeTypeConfig',
field_names=['type', 'count', 'custom_core_count'],
)
def FindDuplicatedTypes(types):
type_counts = collections.Counter(types)
return [node_type for node_type, count in type_counts.items() if count > 1]
def ParseNodesConfigsParameters(nodes_configs):
requested_node_types = [config['type'] for config in nodes_configs]
duplicated_types = FindDuplicatedTypes(requested_node_types)
if duplicated_types:
raise InvalidNodeConfigsProvidedError(
'types: {} provided more than once.'.format(duplicated_types)
)
return [
NodeTypeConfig(
config['type'], config['count'], config.get('custom-core-count', 0)
)
for config in nodes_configs
]
def ParseAutoscalingSettingsFromInlinedFormat(
min_cluster_node_count: int,
max_cluster_node_count: int,
cool_down_period: str,
autoscaling_policies: List[Dict[str, Union[str, int]]],
) -> AutoscalingSettings:
"""Parses inlined autoscaling settings (passed as CLI arguments).
The resulting object can later be passed to
googlecloudsdk.api_lib.vmware.util.ConstructAutoscalingSettingsMessage.
Args:
min_cluster_node_count: autoscaling-min-cluster-node-count CLI argument.
max_cluster_node_count: autoscaling-max-cluster-node-count CLI argument.
cool_down_period: autoscaling-cool-down-period CLI argument.
autoscaling_policies: list of update-autoscaling-policy CLI arguments.
Returns:
Equivalent AutoscalingSettings instance.
"""
parsed_settings = AutoscalingSettings(
min_cluster_node_count=min_cluster_node_count,
max_cluster_node_count=max_cluster_node_count,
cool_down_period=cool_down_period,
autoscaling_policies={},
)
for policy in autoscaling_policies:
parsed_policy = AutoscalingPolicy(
node_type_id=policy.get('node-type-id'),
scale_out_size=policy.get('scale-out-size'),
min_node_count=policy.get('min-node-count'),
max_node_count=policy.get('max-node-count'),
cpu_thresholds=_AutoscalingThresholdsFromPolicy(
policy, 'cpu-thresholds'
),
granted_memory_thresholds=_AutoscalingThresholdsFromPolicy(
policy, 'granted-memory-thresholds'
),
consumed_memory_thresholds=_AutoscalingThresholdsFromPolicy(
policy, 'consumed-memory-thresholds'
),
storage_thresholds=_AutoscalingThresholdsFromPolicy(
policy, 'storage-thresholds'
),
)
parsed_settings.autoscaling_policies[policy['name']] = parsed_policy
return parsed_settings
def _AutoscalingThresholdsFromPolicy(
policy: Dict[str, Union[str, int]], threshold: str
) -> ScalingThresholds:
scale_in = policy.get(f'{threshold}-scale-in')
scale_out = policy.get(f'{threshold}-scale-out')
if scale_in is None and scale_out is None:
return None
return ScalingThresholds(scale_in=scale_in, scale_out=scale_out)
def _ValidateIfOnlySupportedKeysArePassed(
keys: List[str], supported_keys: List[str]
):
for key in keys:
if key not in supported_keys:
raise InvalidAutoscalingSettingsProvidedError(
'unsupported key: {key}, supported keys are: {supported_keys}'.format(
key=key, supported_keys=supported_keys
)
)
def ParseAutoscalingSettingsFromFileFormat(
cluster: Dict[str, Any]
) -> AutoscalingSettings:
"""Parses the autoscaling settings from the format returned by the describe command.
The resulting object can later be passed to
googlecloudsdk.api_lib.vmware.util.ConstructAutoscalingSettingsMessage.
Args:
cluster: dictionary with the settings. Parsed from a file provided by user.
Returns:
Equivalent AutoscalingSettings instance.
Raises:
InvalidAutoscalingSettingsProvidedError: if the file format was wrong.
"""
def _ParseThresholds(thresholds_dict):
if thresholds_dict is None:
return None
_ValidateIfOnlySupportedKeysArePassed(
thresholds_dict.keys(), ['scaleIn', 'scaleOut']
)
return ScalingThresholds(
scale_in=thresholds_dict.get('scaleIn'),
scale_out=thresholds_dict.get('scaleOut'),
)
_ValidateIfOnlySupportedKeysArePassed(cluster.keys(), ['autoscalingSettings'])
if 'autoscalingSettings' not in cluster:
raise InvalidAutoscalingSettingsProvidedError(
'autoscalingSettings not provided in the file'
)
autoscaling_settings = cluster['autoscalingSettings']
_ValidateIfOnlySupportedKeysArePassed(
autoscaling_settings.keys(),
[
'minClusterNodeCount',
'maxClusterNodeCount',
'coolDownPeriod',
'autoscalingPolicies',
],
)
parsed_settings = AutoscalingSettings(
min_cluster_node_count=autoscaling_settings.get('minClusterNodeCount'),
max_cluster_node_count=autoscaling_settings.get('maxClusterNodeCount'),
cool_down_period=autoscaling_settings.get('coolDownPeriod'),
autoscaling_policies={},
)
if 'autoscalingPolicies' not in autoscaling_settings:
return parsed_settings
for policy_name, policy_settings in autoscaling_settings[
'autoscalingPolicies'
].items():
_ValidateIfOnlySupportedKeysArePassed(
policy_settings.keys(),
[
'nodeTypeId',
'scaleOutSize',
'minNodeCount',
'maxNodeCount',
'cpuThresholds',
'grantedMemoryThresholds',
'consumedMemoryThresholds',
'storageThresholds',
],
)
parsed_policy = AutoscalingPolicy(
node_type_id=policy_settings.get('nodeTypeId'),
scale_out_size=policy_settings.get('scaleOutSize'),
min_node_count=policy_settings.get('minNodeCount'),
max_node_count=policy_settings.get('maxNodeCount'),
cpu_thresholds=_ParseThresholds(policy_settings.get('cpuThresholds')),
granted_memory_thresholds=_ParseThresholds(
policy_settings.get('grantedMemoryThresholds')
),
consumed_memory_thresholds=_ParseThresholds(
policy_settings.get('consumedMemoryThresholds')
),
storage_thresholds=_ParseThresholds(
policy_settings.get('storageThresholds')
),
)
parsed_settings.autoscaling_policies[policy_name] = parsed_policy
return parsed_settings
def ParseAutoscalingSettingsFromApiFormat(
cluster_message,
) -> AutoscalingSettings:
"""Parses the autoscaling settings from the format returned by the describe command.
The resulting object can later be passed to
googlecloudsdk.api_lib.vmware.util.ConstructAutoscalingSettingsMessage.
Args:
cluster_message: cluster object with the autoscaling settings.
Returns:
Equivalent AutoscalingSettings istance.
"""
if cluster_message.autoscalingSettings is None:
return None
autoscaling_settings = cluster_message.autoscalingSettings
parsed_settings = AutoscalingSettings(
min_cluster_node_count=autoscaling_settings.minClusterNodeCount,
max_cluster_node_count=autoscaling_settings.maxClusterNodeCount,
cool_down_period=autoscaling_settings.coolDownPeriod,
autoscaling_policies={},
)
for item in autoscaling_settings.autoscalingPolicies.additionalProperties:
policy_name, policy_settings = item.key, item.value
def _ParseThresholds(thresholds):
if thresholds is None:
return None
return ScalingThresholds(
scale_in=thresholds.scaleIn,
scale_out=thresholds.scaleOut,
)
parsed_policy = AutoscalingPolicy(
node_type_id=policy_settings.nodeTypeId,
scale_out_size=policy_settings.scaleOutSize,
min_node_count=policy_settings.minNodeCount,
max_node_count=policy_settings.maxNodeCount,
cpu_thresholds=_ParseThresholds(policy_settings.cpuThresholds),
granted_memory_thresholds=_ParseThresholds(
policy_settings.grantedMemoryThresholds
),
consumed_memory_thresholds=_ParseThresholds(
policy_settings.consumedMemoryThresholds
),
storage_thresholds=_ParseThresholds(policy_settings.storageThresholds),
)
parsed_settings.autoscaling_policies[policy_name] = parsed_policy
return parsed_settings

View File

@@ -0,0 +1,367 @@
# -*- 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.
"""Flags for data-catalog commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import argparse
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.command_lib.util.apis import yaml_data
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
def AddPrivatecloudArgToParser(parser, positional=False):
"""Sets up an argument for the privatecloud resource."""
name = '--private-cloud'
if positional:
name = 'private_cloud'
privatecloud_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.private_cloud'
)
resource_spec = concepts.ResourceSpec.FromYaml(privatecloud_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='private_cloud.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddOperationArgToParser(parser):
"""Sets up an argument for the operation resource."""
operation_data = yaml_data.ResourceYAMLData.FromPath('vmware.operation')
resource_spec = concepts.ResourceSpec.FromYaml(operation_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='operation',
concept_spec=resource_spec,
required=True,
group_help='operation.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddSubnetArgToParser(parser):
"""Sets up an argument for the subnet resource."""
address_data = yaml_data.ResourceYAMLData.FromPath('vmware.subnet')
resource_spec = concepts.ResourceSpec.FromYaml(address_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='subnet',
concept_spec=resource_spec,
required=True,
group_help='subnet.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddClusterArgToParser(
parser, positional=False, hide_resource_argument_flags=False
):
"""Sets up an argument for the cluster resource."""
if positional:
name = 'cluster'
else:
name = '--cluster'
cluster_data = yaml_data.ResourceYAMLData.FromPath('vmware.cluster')
resource_spec = concepts.ResourceSpec.FromYaml(cluster_data.GetData())
flag_name_overrides = None
if hide_resource_argument_flags:
flag_name_overrides = {'location': '', 'private-cloud': ''}
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='cluster.',
flag_name_overrides=flag_name_overrides,
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddExternalAddressArgToParser(parser):
"""Sets up an argument for the external address resource."""
address_data = yaml_data.ResourceYAMLData.FromPath('vmware.external_address')
resource_spec = concepts.ResourceSpec.FromYaml(address_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='external_address',
concept_spec=resource_spec,
required=True,
group_help='external_address.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddManagementDnsZoneBindingArgToParser(parser):
"""Sets up an argument for the management DNS zone binding resource."""
path = 'vmware.management_dns_zone_binding'
address_data = yaml_data.ResourceYAMLData.FromPath(path)
resource_spec = concepts.ResourceSpec.FromYaml(address_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='management_dns_zone_binding',
concept_spec=resource_spec,
required=True,
group_help='management_dns_zone_binding.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddHcxActivationKeyArgToParser(parser):
"""Sets up an argument for the HCX activation key resource."""
hcx_activation_key_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.hcx_activation_key'
)
resource_spec = concepts.ResourceSpec.FromYaml(
hcx_activation_key_data.GetData()
)
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='hcx_activation_key',
concept_spec=resource_spec,
required=True,
group_help='hcxactivationkey.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddLocationArgToParser(parser, regional=False, positional=False):
"""Parses location flag."""
location_data = yaml_data.ResourceYAMLData.FromPath('vmware.location')
if regional:
location_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.regional_location'
)
resource_spec = concepts.ResourceSpec.FromYaml(location_data.GetData())
name = '--location'
if positional:
name = 'location'
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='location.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddNodeTypeArgToParser(parser, positional=False):
"""Parses node type flag."""
if positional:
name = 'node_type'
flag_name_overrides = None
else:
name = '--node-type'
flag_name_overrides = {'location': ''}
location_data = yaml_data.ResourceYAMLData.FromPath('vmware.node_type')
resource_spec = concepts.ResourceSpec.FromYaml(location_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='node_type.',
flag_name_overrides=flag_name_overrides,
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddProjectArgToParser(parser, positional=False):
"""Parses project flag."""
name = '--project'
if positional:
name = 'project'
project_data = yaml_data.ResourceYAMLData.FromPath('vmware.project')
resource_spec = concepts.ResourceSpec.FromYaml(project_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='project.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddPrivateConnectionToParser(parser, positional=False):
"""Sets up an argument for the Private Connection resource."""
name = '--private-connection'
if positional:
name = 'private_connection'
private_connection_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.private_connection'
)
resource_spec = concepts.ResourceSpec.FromYaml(
private_connection_data.GetData()
)
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='private_connection.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddLoggingServerArgToParser(parser):
"""Sets up an argument for the Logging Server resource."""
logging_server_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.logging_server'
)
resource_spec = concepts.ResourceSpec.FromYaml(logging_server_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='logging_server',
concept_spec=resource_spec,
required=True,
group_help='logging_server.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddIdentitySourceArgToParser(parser):
"""Sets up an argument for the Identity Source resource."""
resource_data = yaml_data.ResourceYAMLData.FromPath('vmware.identity_source')
resource_spec = concepts.ResourceSpec.FromYaml(resource_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='identity_source',
concept_spec=resource_spec,
required=True,
group_help='identity_source.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddNodeArgToParser(parser):
"""Sets up an argument for the node resource."""
node_data = yaml_data.ResourceYAMLData.FromPath('vmware.node')
resource_spec = concepts.ResourceSpec.FromYaml(node_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='node', concept_spec=resource_spec, required=True, group_help='node.'
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddAutoscalingSettingsFlagsToParser(parser):
"""Sets up autoscaling settings flags.
There are two mutually exclusive options to pass the autoscaling settings:
through command line arguments or as a yaml file.
Args:
parser: arg_parser instance that will have the flags added.
"""
autoscaling_settings_group = parser.add_mutually_exclusive_group(
required=False, hidden=True
)
inlined_autoscaling_settings_group = autoscaling_settings_group.add_group()
inlined_autoscaling_settings_group.add_argument(
'--autoscaling-min-cluster-node-count',
type=int,
help='Minimum number of nodes in the cluster',
)
inlined_autoscaling_settings_group.add_argument(
'--autoscaling-max-cluster-node-count',
type=int,
help='Maximum number of nodes in the cluster',
)
inlined_autoscaling_settings_group.add_argument(
'--autoscaling-cool-down-period',
type=str,
help=(
'Cool down period (in minutes) between consecutive cluster'
' expansions/contractions'
),
)
inlined_autoscaling_settings_group.add_argument(
'--autoscaling-policy',
type=arg_parsers.ArgDict(
spec={
'name': str,
'node-type-id': str,
'scale-out-size': int,
'min-node-count': int,
'max-node-count': int,
'cpu-thresholds-scale-in': int,
'cpu-thresholds-scale-out': int,
'granted-memory-thresholds-scale-in': int,
'granted-memory-thresholds-scale-out': int,
'consumed-memory-thresholds-scale-in': int,
'consumed-memory-thresholds-scale-out': int,
'storage-thresholds-scale-in': int,
'storage-thresholds-scale-out': int,
},
required_keys=['name', 'node-type-id', 'scale-out-size'],
),
action='append',
default=list(),
help='Autoscaling policy to be applied to the cluster',
)
autoscaling_settings_group.add_argument(
'--autoscaling-settings-from-file',
type=arg_parsers.YAMLFileContents(),
help=(
'A YAML file containing the autoscaling settings to be applied to'
' the cluster'
),
)
def AddDatastoreArgToParser(parser, positional=False):
"""Sets up an argument for the datastore resource."""
name = '--datastore'
if positional:
name = 'datastore'
datastore_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.datastore'
)
resource_spec = concepts.ResourceSpec.FromYaml(datastore_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='datastore.',
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddUpgradeArgToParser(
parser: argparse.ArgumentParser,
) -> None:
"""Sets up an argument for the upgrade resource."""
upgrade_data = yaml_data.ResourceYAMLData.FromPath('vmware.upgrade')
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='upgrade',
concept_spec=concepts.ResourceSpec.FromYaml(upgrade_data.GetData()),
required=True,
group_help='upgrade.',
flag_name_overrides=None,
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)

View File

@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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.
"""Flags for VMware Engine network peering commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.command_lib.util.apis import yaml_data
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
def AddNetworkPeeringToParser(parser, positional=False):
"""Sets up an argument for the VMware Engine VPC network peering resource."""
name = '--network-peering'
if positional:
name = 'network_peering'
peering_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.network_peerings.network_peering')
resource_spec = concepts.ResourceSpec.FromYaml(peering_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='network_peering.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddLocationArgToParser(parser, positional=False):
"""Parses location flag."""
location_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.network_peerings.location')
resource_spec = concepts.ResourceSpec.FromYaml(location_data.GetData())
name = '--location'
if positional:
name = 'location'
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='location.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)

View File

@@ -0,0 +1,49 @@
project:
name: project
collection: vmwareengine.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Project ID.
property: core/project
disable_auto_completers: false
location:
name: location
collection: vmwareengine.projects.locations
attributes:
- *project
- &location
parameter_name: locationsId
attribute_name: location
help: The resource name of the location.
fallthroughs:
- hook: googlecloudsdk.command_lib.vmware.networks.util:DefaultToGlobal
hint: set location as 'global' (default)
disable_auto_completers: false
network_peering:
name: VMware Engine VPC network peering
collection: vmwareengine.projects.locations.networkPeerings
attributes:
- *project
- *location
- &network_peering
parameter_name: networkPeeringsId
attribute_name: network-peering
help: VMware Engine VPC network peering
disable_auto_completers: false
network_peering_routes:
name: VMware Engine VPC network peering routes
collection: vmwareengine.projects.locations.networkPeerings.peeringRoutes
attributes:
- *project
- *location
- *network_peering
- &network_peering_routes
parameter_name: networkPeeringsRoutesId
attribute_name: network-peering-routes
help: VMware Engine VPC network peering routes
disable_auto_completers: false

View File

@@ -0,0 +1,90 @@
# -*- 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.
"""Flags for VMware Engine network policies commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.command_lib.util.apis import yaml_data
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
# Needs to be indented to show up correctly in help text
LIST_WITH_CUSTOM_FIELDS_FORMAT = """\
table(
name.segment(-1):label=NAME,,
priority,
ipProtocol,
sourceIpRanges.flatten(show='values'),
sourcePorts.list(),
destinationIpRanges.flatten(show='values'),
destinationPorts.list(),
action
)"""
LIST_NOTICE = """\
To show all fields, please show in JSON format: --format=json
To show custom set of fields in table format, please see the examples in --help.
"""
def AddExternalAccessRuleToParser(parser, positional=False):
"""Sets up an argument for the VMware Engine external access rule resource."""
name = '--external-access-rule'
if positional:
name = 'external_access_rule'
peering_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.network_policies.external_access_rule')
resource_spec = concepts.ResourceSpec.FromYaml(peering_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='external_access_rule.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddNetworkPolicyToParser(parser, positional=False):
"""Sets up an argument for the VMware Engine network policy resource."""
name = '--network-policy'
if positional:
name = 'network_policy'
network_policy_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.network_policies.network_policy')
resource_spec = concepts.ResourceSpec.FromYaml(network_policy_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='network_policy.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddLocationArgToParser(parser, positional=False):
"""Parses location flag."""
location_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.network_policies.location')
resource_spec = concepts.ResourceSpec.FromYaml(location_data.GetData())
name = '--location'
if positional:
name = 'location'
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='location.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)

View File

@@ -0,0 +1,47 @@
project:
name: project
collection: vmwareengine.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Project ID or project number.
property: core/project
disable_auto_completers: false
location:
name: location
collection: vmwareengine.projects.locations
attributes:
- *project
- &location
parameter_name: locationsId
attribute_name: location
help: The resource name of the location.
property: compute/region
disable_auto_completers: false
network_policy:
name: VMware Engine Network Policy
collection: vmwareengine.projects.locations.networkPolicies
attributes:
- *project
- *location
- &network_policy
parameter_name: networkPoliciesId
attribute_name: network-policy
help: VMware Engine network policy
disable_auto_completers: false
external_access_rule:
name: VMware Engine External Access Rule
collection: vmwareengine.projects.locations.networkPolicies.externalAccessRules
attributes:
- *project
- *location
- *network_policy
- &external_access_rule
parameter_name: externalAccessRulesId
attribute_name: external-access-rule
help: VMware Engine external access rule
disable_auto_completers: false

View File

@@ -0,0 +1,66 @@
# -*- 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.
"""Flags for VMware Engine networks commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.command_lib.util.apis import yaml_data
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
def AddNetworkToParser(parser, positional=False):
"""Sets up an argument for the VMware Engine network resource."""
name = '--vmware-engine-network'
if positional:
name = 'vmware_engine_network'
network_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.networks.vmware_engine_network')
resource_spec = concepts.ResourceSpec.FromYaml(network_data.GetData())
if positional:
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='vmware_engine_network.'
)
else:
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='vmware_engine_network.',
flag_name_overrides={'location': '--network-location'}
)
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddLocationArgToParser(parser, positional=False):
"""Parses location flag."""
location_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.networks.location')
resource_spec = concepts.ResourceSpec.FromYaml(location_data.GetData())
name = '--location'
if positional:
name = 'location'
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='location.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)

View File

@@ -0,0 +1,37 @@
project:
name: project
collection: vmwareengine.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Project ID.
property: core/project
disable_auto_completers: false
location:
name: location
collection: vmwareengine.projects.locations
attributes:
- *project
- &location
parameter_name: locationsId
attribute_name: location
help: The resource name of the location.
fallthroughs:
- hook: googlecloudsdk.command_lib.vmware.networks.util:DefaultToGlobal
hint: set location as 'global' (default) or a region
disable_auto_completers: false
vmware_engine_network:
name: VMware Engine network
collection: vmwareengine.projects.locations.vmwareEngineNetworks
attributes:
- *project
- *location
- &vmware_engine_network
parameter_name: vmwareEngineNetworksId
attribute_name: vmware-engine-network
help: VMware Engine network
disable_auto_completers: false

View File

@@ -0,0 +1,25 @@
# -*- 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.
"""Utils for VMware Engine networks commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
def DefaultToGlobal():
"""Returns 'global' to be used as a fallthrough hook in resources.yaml."""
return 'global'

View File

@@ -0,0 +1,214 @@
project:
name: project
collection: vmwareengine.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Project ID.
property: core/project
disable_auto_completers: false
location:
name: location
collection: vmwareengine.projects.locations
attributes:
- *project
- &location
parameter_name: locationsId
attribute_name: location
help: Location of the private cloud or cluster.
property: compute/zone
disable_auto_completers: false
private_cloud:
name: private cloud
collection: vmwareengine.projects.locations.privateClouds
attributes:
- *project
- *location
- &private_cloud
parameter_name: privateCloudsId
attribute_name: private-cloud
help: VMware Engine private cloud.
disable_auto_completers: false
cluster:
name: cluster
collection: vmwareengine.projects.locations.privateClouds.clusters
attributes:
- *project
- *location
- *private_cloud
- &cluster
parameter_name: clustersId
attribute_name: cluster
help: Resource ID of the cluster
disable_auto_completers: false
hcx_activation_key:
name: HCX activation key
collection: vmwareengine.projects.locations.privateClouds.hcxActivationKeys
attributes:
- *project
- *location
- *private_cloud
- &hcx_activation_key
parameter_name: hcxActivationKeysId
attribute_name: hcx-activation-key
help: Resource ID of the HCX activation key
disable_auto_completers: false
operation:
name: operation
collection: vmwareengine.projects.locations.operations
attributes:
- *project
- *location
- parameter_name: operationsId
attribute_name: operation
help: |
The name of the VMware Engine operation.
disable_auto_completers: false
node_type:
name: node type
collection: vmwareengine.projects.locations.nodeTypes
attributes:
- *project
- *location
- &node_type
parameter_name: nodeTypesId
attribute_name: node-type
help: |
Node Type in a VMware Engine cluster.
disable_auto_completers: false
external_address:
name: external address
collection: vmwareengine.projects.locations.privateClouds.externalAddresses
attributes:
- *project
- *location
- *private_cloud
- &external_address
parameter_name: externalAddressesId
attribute_name: external-address
help: Resource ID of the ExternalAddress
disable_auto_completers: false
subnet:
name: subnet
collection: vmwareengine.projects.locations.privateClouds.subnets
attributes:
- *project
- *location
- *private_cloud
- &subnet
parameter_name: subnetsId
attribute_name: subnet
help: Resource ID of the Subnet
disable_auto_completers: false
management_dns_zone_binding:
name: management DNS zone binding
collection: vmwareengine.projects.locations.privateClouds.managementDnsZoneBindings
attributes:
- *project
- *location
- *private_cloud
- &management_dns_zone_binding
parameter_name: managementDnsZoneBindingsId
attribute_name: management-dns-zone-binding
help: Resource ID of the Management DNS zone binding
disable_auto_completers: false
regional_location:
name: regional location
collection: vmwareengine.projects.locations
attributes:
- *project
- &regional_location
parameter_name: locationsId
attribute_name: location
help: The resource name of the location.
property: compute/region
disable_auto_completers: false
private_connection:
name: Private Connection
collection: vmwareengine.projects.locations.privateConnections
attributes:
- *project
- *regional_location
- &private_connection
parameter_name: privateConnectionsId
attribute_name: private-connection
help: Private Connection
disable_auto_completers: false
logging_server:
name: Logging Server
collection: vmwareengine.projects.locations.privateClouds.loggingServers
attributes:
- *project
- *location
- *private_cloud
- &logging_server
parameter_name: loggingServersId
attribute_name: logging-server
help: Resource ID of the Logging Server
disable_auto_completers: false
identity_source:
name: Identity Source
collection: vmwareengine.projects.locations.privateClouds.identitySources
attributes:
- *project
- *location
- *private_cloud
- &identity_source
parameter_name: identitySourcesId
attribute_name: identity-source
help: Resource ID of the Identity Source
disable_auto_completers: false
node:
name: node
collection: vmwareengine.projects.locations.privateClouds.clusters.nodes
attributes:
- *project
- *location
- *private_cloud
- *cluster
- &node
parameter_name: nodesId
attribute_name: node
help: Resource ID of the Node
disable_auto_completers: false
upgrade:
name: upgrade
collection: vmwareengine.projects.locations.privateClouds.upgrades
attributes:
- *project
- *location
- *private_cloud
- &upgrade
parameter_name: upgradesId
attribute_name: upgrade
help: Resource ID of the upgrade
disable_auto_completers: false
datastore:
name: datastore
plural_name: datastores
collection: vmwareengine.projects.locations.datastores
attributes:
- *project
- *location
- &datastore
parameter_name: datastoresId
attribute_name: datastore
help: The datastore id of the {resource} resource.
disable_auto_completers: false

View File

@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Flags for data-catalog commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.command_lib.util.apis import yaml_data
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
def AddPrivatecloudArgToParser(parser, positional=False):
"""Sets up an argument for the privatecloud resource."""
if positional:
name = 'privatecloud'
else:
name = '--privatecloud'
privatecloud_data = yaml_data.ResourceYAMLData.FromPath(
'vmware.sddc.privatecloud')
resource_spec = concepts.ResourceSpec.FromYaml(privatecloud_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='privatecloud.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddIPArgToParser(parser):
ip_address_id = yaml_data.ResourceYAMLData.FromPath('vmware.sddc.ip_address')
resource_spec = concepts.ResourceSpec.FromYaml(ip_address_id.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='name',
concept_spec=resource_spec,
required=True,
group_help='ip_address.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddClusterArgToParser(parser):
cluster_data = yaml_data.ResourceYAMLData.FromPath('vmware.sddc.cluster')
resource_spec = concepts.ResourceSpec.FromYaml(cluster_data.GetData())
presentation_spec = presentation_specs.ResourcePresentationSpec(
name='cluster',
concept_spec=resource_spec,
required=True,
group_help='cluster.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddRegionArgToParser(parser, positional=False):
"""Parses region flag."""
region_data = yaml_data.ResourceYAMLData.FromPath('vmware.sddc.region')
resource_spec = concepts.ResourceSpec.FromYaml(region_data.GetData())
if positional:
name = 'region'
else:
name = '--region'
presentation_spec = presentation_specs.ResourcePresentationSpec(
name=name,
concept_spec=resource_spec,
required=True,
group_help='region.')
return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
def AddLabelsToMessage(labels, message):
"""Parses labels into a specific message."""
# set up for call to ParseCreateArgs, which expects labels as an
# attribute on an object.
class LabelHolder(object):
def __init__(self, labels):
self.labels = labels
message.labels = labels_util.ParseCreateArgs(
LabelHolder(labels),
type(message).LabelsValue)

View File

@@ -0,0 +1,60 @@
project:
name: project
collection: sddc.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Project ID.
property: core/project
disable_auto_completers: false
region:
name: region
collection: sddc.projects.locations
attributes:
- *project
- &region
parameter_name: locationsId
attribute_name: region
help: Region of the private cloud or cluster.
property: vmware/region
disable_auto_completers: false
privatecloud:
name: privatecloud
collection: sddc.projects.locations.clusterGroups
attributes:
- *project
- *region
- &privatecloud
parameter_name: clusterGroupsId
attribute_name: privatecloud
help: VMware Engine private cloud.
disable_auto_completers: false
cluster:
name: cluster
collection: sddc.projects.locations.clusterGroups.clusters
attributes:
- *project
- *region
- *privatecloud
- &cluster
parameter_name: clustersId
attribute_name: cluster
help: Cluster in a VMware Engine private cloud.
disable_auto_completers: false
ip_address:
name: ip_address
collection: sddc.projects.locations.clusterGroups.ipAddresses
attributes:
- *project
- *region
- *privatecloud
- &ip_address
parameter_name: ipAddressesId
attribute_name: name
help: IP address name in a VMware Engine private cloud.
disable_auto_completers: false