Skip to content

Commit

Permalink
{AKS} Sort out parameter declarations (#22863)
Browse files Browse the repository at this point in the history
  • Loading branch information
FumingZhang authored Jun 14, 2022
1 parent 6ca46e9 commit e266dbd
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 224 deletions.
36 changes: 14 additions & 22 deletions src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
validate_priority, validate_snapshot_id, validate_snapshot_name,
validate_spot_max_price, validate_ssh_key, validate_taints,
validate_vm_set_type, validate_vnet_subnet_id,
validate_disable_and_enable_parameters, validate_defender_config_parameter)
validate_defender_disable_and_enable_parameters, validate_defender_config_parameter)
from azure.cli.core.commands.parameters import (
edge_zone_type, file_type, get_enum_type,
get_resource_name_completion_list, get_three_state_flag, name_type,
Expand Down Expand Up @@ -220,10 +220,8 @@ def load_arguments(self, _):
c.argument('disable_local_accounts', action='store_true')
c.argument('disable_rbac', action='store_true')
c.argument('edge_zone', edge_zone_type)
c.argument('admin_username', options_list=[
'--admin-username', '-u'], default='azureuser')
c.argument('generate_ssh_keys', action='store_true',
validator=validate_create_parameters)
c.argument('admin_username', options_list=['--admin-username', '-u'], default='azureuser')
c.argument('generate_ssh_keys', action='store_true', validator=validate_create_parameters)
c.argument('ssh_key_value', required=False, type=file_type, default=os.path.join('~', '.ssh', 'id_rsa.pub'),
completer=FilesCompleter(), validator=validate_ssh_key)
c.argument('no_ssh_key', options_list=['--no-ssh-key', '-x'])
Expand All @@ -237,10 +235,8 @@ def load_arguments(self, _):
c.argument('load_balancer_outbound_ip_prefixes', validator=validate_load_balancer_outbound_ip_prefixes)
c.argument('load_balancer_outbound_ports', type=int, validator=validate_load_balancer_outbound_ports)
c.argument('load_balancer_idle_timeout', type=int, validator=validate_load_balancer_idle_timeout)
c.argument('nat_gateway_managed_outbound_ip_count', type=int,
validator=validate_nat_gateway_managed_outbound_ip_count)
c.argument('nat_gateway_idle_timeout', type=int,
validator=validate_nat_gateway_idle_timeout)
c.argument('nat_gateway_managed_outbound_ip_count', type=int, validator=validate_nat_gateway_managed_outbound_ip_count)
c.argument('nat_gateway_idle_timeout', type=int, validator=validate_nat_gateway_idle_timeout)
c.argument('outbound_type', arg_type=get_enum_type(outbound_types))
c.argument('network_plugin', arg_type=get_enum_type(network_plugins))
c.argument('network_policy')
Expand Down Expand Up @@ -274,6 +270,8 @@ def load_arguments(self, _):
c.argument('attach_acr', acr_arg_type)
c.argument('skip_subnet_role_assignment', action='store_true')
c.argument('node_resource_group')
c.argument('enable_defender', action='store_true')
c.argument('defender_config', validator=validate_defender_config_parameter)
# addons
c.argument('enable_addons', options_list=['--enable-addons', '-a'])
c.argument('workspace_resource_id')
Expand Down Expand Up @@ -315,10 +313,7 @@ def load_arguments(self, _):
c.argument('enable_fips_image', action='store_true')
c.argument('kubelet_config')
c.argument('linux_os_config')
c.argument('enable_defender', action='store_true')
c.argument('defender_config', validator=validate_defender_config_parameter)
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

with self.argument_context('aks update') as c:
# managed cluster paramerters
Expand Down Expand Up @@ -355,6 +350,9 @@ def load_arguments(self, _):
c.argument('gmsa_root_domain_name')
c.argument('attach_acr', acr_arg_type, validator=validate_acr)
c.argument('detach_acr', acr_arg_type, validator=validate_acr)
c.argument('disable_defender', action='store_true', validator=validate_defender_disable_and_enable_parameters)
c.argument('enable_defender', action='store_true')
c.argument('defender_config', validator=validate_defender_config_parameter)
# addons
c.argument('enable_secret_rotation', action='store_true')
c.argument('disable_secret_rotation', action='store_true')
Expand All @@ -370,11 +368,7 @@ def load_arguments(self, _):
c.argument('max_count', type=int, validator=validate_nodes_count)
c.argument('nodepool_labels', nargs='*', validator=validate_nodepool_labels,
help='space-separated labels: key[=value] [key[=value] ...]. See https://aka.ms/node-labels for syntax of labels.')
c.argument('disable_defender', action='store_true', validator=validate_disable_and_enable_parameters)
c.argument('enable_defender', action='store_true')
c.argument('defender_config', validator=validate_defender_config_parameter)
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

with self.argument_context('aks disable-addons', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('addons', options_list=['--addons', '-a'])
Expand Down Expand Up @@ -429,10 +423,8 @@ def load_arguments(self, _):
c.argument('aad_tenant_id')

with self.argument_context('aks upgrade', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('kubernetes_version',
completer=get_k8s_upgrades_completion_list)
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
c.argument('kubernetes_version', completer=get_k8s_upgrades_completion_list)
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

with self.argument_context('aks scale', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('nodepool_name', validator=validate_nodepool_name, help='Node pool name, up to 12 alphanumeric characters.')
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/acs/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,6 @@ def validate_defender_config_parameter(namespace):
raise RequiredArgumentMissingError("Please specify --enable-defnder")


def validate_disable_and_enable_parameters(namespace):
def validate_defender_disable_and_enable_parameters(namespace):
if namespace.disable_defender and namespace.enable_defender:
raise ArgumentUsageError('Providing both --disable-defender and --enable-defender flags is invalid')
Loading

0 comments on commit e266dbd

Please sign in to comment.