def register_folded_cli_argument( scope, base_name, resource_type, parent_name=None, # pylint: disable=too-many-arguments parent_type=None, type_field=None, existing_id_flag_value='existingId', new_flag_value='new', none_flag_value='none', **kwargs): type_field_name = type_field or base_name + '_type' fold_validator = _name_id_fold(base_name, resource_type, type_field_name, existing_id_flag_value, new_flag_value, none_flag_value, parent_name, parent_type) custom_validator = kwargs.pop('validator', None) if custom_validator: def wrapped(namespace): fold_validator(namespace) custom_validator(namespace) validator = wrapped else: validator = fold_validator register_cli_argument(scope, base_name, validator=validator, **kwargs) register_cli_argument(scope, type_field_name, help=argparse.SUPPRESS, default=None)
def register_folded_cli_argument(scope, base_name, resource_type, parent_name=None, # pylint: disable=too-many-arguments parent_type=None, type_field=None, existing_id_flag_value='existingId', new_flag_value='new', none_flag_value='none', **kwargs): type_field_name = type_field or base_name + '_type' fold_validator = _name_id_fold(base_name, resource_type, type_field_name, existing_id_flag_value, new_flag_value, none_flag_value, parent_name, parent_type) custom_validator = kwargs.pop('validator', None) if custom_validator: def wrapped(namespace): fold_validator(namespace) custom_validator(namespace) validator = wrapped else: validator = fold_validator register_cli_argument(scope, base_name, validator=validator, **kwargs) register_cli_argument(scope, type_field_name, help=argparse.SUPPRESS, default=None)
def test_override_using_register_cli_argument(self): def sample_sdk_method(param_a): # pylint: disable=unused-argument pass def test_validator_completer(): pass command_table.clear() cli_command('override_using_register_cli_argument foo', sample_sdk_method, None) register_cli_argument('override_using_register_cli_argument', 'param_a', options_list=('--overridden', '-r'), validator=test_validator_completer, completer=test_validator_completer, required=False) _update_command_definitions(command_table) command_metadata = command_table[ 'override_using_register_cli_argument foo'] self.assertEqual(len(command_metadata.arguments), 1, 'We expected exactly 1 arguments') actual_arg = command_metadata.arguments['param_a'] self.assertEqual(actual_arg.options_list, ('--overridden', '-r')) self.assertEqual(actual_arg.validator, test_validator_completer) self.assertEqual(actual_arg.completer, test_validator_completer) self.assertFalse(actual_arg.options['required']) command_table.clear()
def test_register_cli_argument(self): command_table.clear() cli_command('test register sample-vm-get', Test_command_registration.sample_vm_get) register_cli_argument( 'test register sample-vm-get', 'vm_name', CliArgumentType(options_list=('--wonky-name', '-n'), metavar='VMNAME', help='Completely WONKY name...', required=False)) _update_command_definitions(command_table) self.assertEqual(len(command_table), 1, 'We expect exactly one command in the command table') command_metadata = command_table['test register sample-vm-get'] self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments') some_expected_arguments = { 'resource_group_name': CliArgumentType(dest='resource_group_name', required=True), 'vm_name': CliArgumentType(dest='vm_name', required=False), } for probe in some_expected_arguments: existing = next(arg for arg in command_metadata.arguments if arg == probe) self.assertDictContainsSubset( some_expected_arguments[existing].settings, command_metadata.arguments[existing].options) self.assertEqual(command_metadata.arguments['vm_name'].options_list, ('--wonky-name', '-n'))
def register_path_argument(scope, default_file_param=None, options_list=None): path_help = 'The path to the file within the file share.' if default_file_param: path_help = '{} If the file name is omitted, the source file name will be used.'.format(path_help) register_extra_cli_argument(scope, 'path', options_list=options_list or ('--path', '-p'), required=default_file_param is None, help=path_help, validator=get_file_path_validator(default_file_param=default_file_param), completer=file_path_completer) register_cli_argument(scope, 'file_name', IGNORE_TYPE) register_cli_argument(scope, 'directory_name', IGNORE_TYPE)
def test_override_using_register_cli_argument(self): def sample_sdk_method(param_a): # pylint: disable=unused-argument pass def test_validator_completer(): pass command_table.clear() cli_command('override_using_register_cli_argument foo', sample_sdk_method, None) register_cli_argument('override_using_register_cli_argument', 'param_a', options_list=('--overridden', '-r'), validator=test_validator_completer, completer=test_validator_completer, required=False) _update_command_definitions(command_table) command_metadata = command_table['override_using_register_cli_argument foo'] self.assertEqual(len(command_metadata.arguments), 1, 'We expected exactly 1 arguments') actual_arg = command_metadata.arguments['param_a'] self.assertEqual(actual_arg.options_list, ('--overridden', '-r')) self.assertEqual(actual_arg.validator, test_validator_completer) self.assertEqual(actual_arg.completer, test_validator_completer) self.assertFalse(actual_arg.options['required'])
def test_generic_update_ids(self): my_objs = [ { 'prop': 'val', 'list': [ 'a', 'b', ['c', {'d': 'e'}] ] }, { 'prop': 'val', 'list': [ 'a', 'b', ['c', {'d': 'e'}] ] }] def my_get(name, resource_group): #pylint:disable=unused-argument # name is None when tests are run in a batch on Python <=2.7.9 if sys.version_info < (2, 7, 10): return my_objs[0] return my_objs[int(name)] def my_set(**kwargs): #pylint:disable=unused-argument return my_objs register_cli_argument('gencommand', 'name', CliArgumentType(options_list=('--name', '-n'), metavar='NAME', id_part='name')) register_generic_update('gencommand', my_get, my_set) config = Configuration([]) APPLICATION.initialize(config) id_str = ('/subscriptions/00000000-0000-0000-0000-0000000000000/resourceGroups/rg/' 'providers/Microsoft.Compute/virtualMachines/') APPLICATION.execute('gencommand --ids {0}0 {0}1 --resource-group bar --set prop=newval' .format(id_str).split()) self.assertEqual(my_objs[0]['prop'], 'newval', 'first object updated') # name is None when tests are run in a batch on Python <=2.7.9 if not sys.version_info < (2, 7, 10): self.assertEqual(my_objs[1]['prop'], 'newval', 'second object updated')
def test_register_cli_argument_with_overrides(self): command_table.clear() global_vm_name_type = CliArgumentType( options_list=('--foo', '-f'), metavar='FOO', help='foo help' ) derived_vm_name_type = CliArgumentType(base_type=global_vm_name_type, help='first modification') cli_command('test vm-get', Test_command_registration.sample_vm_get, None) cli_command('test command vm-get-1', Test_command_registration.sample_vm_get, None) cli_command('test command vm-get-2', Test_command_registration.sample_vm_get, None) register_cli_argument('test', 'vm_name', global_vm_name_type) register_cli_argument('test command', 'vm_name', derived_vm_name_type) register_cli_argument('test command vm-get-2', 'vm_name', derived_vm_name_type, help='second modification') _update_command_definitions(command_table) self.assertEqual(len(command_table), 3, 'We expect exactly three commands in the command table') command1 = command_table['test vm-get'].arguments['vm_name'] command2 = command_table['test command vm-get-1'].arguments['vm_name'] command3 = command_table['test command vm-get-2'].arguments['vm_name'] self.assertTrue(command1.options['help'] == 'foo help') self.assertTrue(command2.options['help'] == 'first modification') self.assertTrue(command3.options['help'] == 'second modification')
def register_folded_cli_argument(scope, base_name, resource_type, parent_name=None, # pylint: disable=too-many-arguments parent_type=None, type_field=None, existing_id_flag_value='existingId', new_flag_value='new', none_flag_value='none', default_value_flag='new', allow_none=True, **kwargs): type_field_name = type_field or base_name + '_type' fold_validator = _name_id_fold(base_name, resource_type, type_field_name, existing_id_flag_value, new_flag_value, none_flag_value, allow_none, parent_name, parent_type) custom_validator = kwargs.pop('validator', None) if custom_validator: def wrapped(namespace): fold_validator(namespace) custom_validator(namespace) validator = wrapped else: validator = fold_validator quotes = '""' if platform.system() == 'Windows' else "''" quote_text = ' Use {} for none.'.format(quotes) if allow_none else '' flag_texts = { new_flag_value: ' Creates new by default.{}'.format(quote_text), existing_id_flag_value: ' Uses existing by default or creates if none found.{}' .format(quote_text), none_flag_value: ' None by default.' } help_text = 'Name or ID of the resource.' + flag_texts[default_value_flag] register_cli_argument(scope, base_name, validator=validator, help=help_text, **kwargs) register_cli_argument(scope, type_field_name, help=argparse.SUPPRESS, default=None)
def test_register_cli_argument(self): command_table.clear() cli_command('test register sample-vm-get', Test_command_registration.sample_vm_get) register_cli_argument('test register sample-vm-get', 'vm_name', CliArgumentType( options_list=('--wonky-name', '-n'), metavar='VMNAME', help='Completely WONKY name...', required=False )) _update_command_definitions(command_table) self.assertEqual(len(command_table), 1, 'We expect exactly one command in the command table') command_metadata = command_table['test register sample-vm-get'] self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments') some_expected_arguments = { 'resource_group_name': CliArgumentType(dest='resource_group_name', required=True), 'vm_name': CliArgumentType(dest='vm_name', required=False), } for probe in some_expected_arguments: existing = next(arg for arg in command_metadata.arguments if arg == probe) self.assertDictContainsSubset(some_expected_arguments[existing].settings, command_metadata.arguments[existing].options) self.assertEqual(command_metadata.arguments['vm_name'].options_list, ('--wonky-name', '-n'))
def test_register_cli_argument_with_overrides(self): command_table.clear() global_vm_name_type = CliArgumentType(options_list=('--foo', '-f'), metavar='FOO', help='foo help') derived_vm_name_type = CliArgumentType(base_type=global_vm_name_type, help='first modification') cli_command('test vm-get', Test_command_registration.sample_vm_get, None) cli_command('test command vm-get-1', Test_command_registration.sample_vm_get, None) cli_command('test command vm-get-2', Test_command_registration.sample_vm_get, None) register_cli_argument('test', 'vm_name', global_vm_name_type) register_cli_argument('test command', 'vm_name', derived_vm_name_type) register_cli_argument('test command vm-get-2', 'vm_name', derived_vm_name_type, help='second modification') _update_command_definitions(command_table) self.assertEqual( len(command_table), 3, 'We expect exactly three commands in the command table') command1 = command_table['test vm-get'].arguments['vm_name'] command2 = command_table['test command vm-get-1'].arguments['vm_name'] command3 = command_table['test command vm-get-2'].arguments['vm_name'] self.assertTrue(command1.options['help'] == 'foo help') self.assertTrue(command2.options['help'] == 'first modification') self.assertTrue(command3.options['help'] == 'second modification') command_table.clear()
subscription_name_or_id_type = CliArgumentType( options_list=('--subscription-name-or-id', '-n'), metavar='SUBSCRIPTION_NAME_OR_ID', help='Subscription id. Unique name also works.', completer=get_subscription_id_list) tenant_type = CliArgumentType( options_list=('--tenant', '-t'), help='The tenant associated with the service principal.') username_type = CliArgumentType(options_list=('--username', '-u'), help='Organization id or service principal') sp_name_type = CliArgumentType(options_list=('--name', '-n')) register_cli_argument('login', 'password', password_type) register_cli_argument('login', 'service_principal', service_principal_type) register_cli_argument('login', 'username', username_type) register_cli_argument('login', 'tenant', tenant_type) register_cli_argument( 'logout', 'username', username_type, help='account user, if missing, logout the current active account') register_cli_argument('account', 'subscription_name_or_id', subscription_name_or_id_type) register_cli_argument('account create-sp', 'name', sp_name_type) register_cli_argument('account reset-sp-credentials', 'name', sp_name_type)
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- import azure.cli.commands.parameters #pylint: disable=unused-import from azure.cli.commands import register_cli_argument register_cli_argument('ad app', 'application_object_id', options_list=('--object-id', )) register_cli_argument('ad app', 'app_id', help='application id') register_cli_argument('ad', 'display_name', help='object\'s display name or its prefix') register_cli_argument( 'ad', 'identifier_uri', help='graph application identifier, must be in uri format') register_cli_argument('ad', 'spn', help='service principal name') register_cli_argument('ad', 'upn', help='user principal name, e.g. [email protected]') register_cli_argument('ad', 'query_filter', options_list=('--filter', ), help='OData filter') register_cli_argument('role assignment', 'role_assignment_name', options_list=('--role-assignment-name', '-n'))
action='store_true', help='The credential representing a service principal.' ) subscription_name_or_id_type = CliArgumentType( options_list=('--subscription-name-or-id', '-n'), metavar='SUBSCRIPTION_NAME_OR_ID', help='Subscription id. Unique name also works.', completer=get_subscription_id_list ) tenant_type = CliArgumentType( options_list=('--tenant', '-t'), help='The tenant associated with the service principal.' ) username_type = CliArgumentType( options_list=('--username', '-u'), help='Organization id or service principal' ) register_cli_argument('login', 'password', password_type) register_cli_argument('login', 'service_principal', service_principal_type) register_cli_argument('login', 'username', username_type) register_cli_argument('login', 'tenant', tenant_type) register_cli_argument('logout', 'username', username_type, help='account user, if missing, logout the current active account') register_cli_argument('account', 'subscription_name_or_id', subscription_name_or_id_type)
] choices_upgrade_mode = [e.value.lower() for e in UpgradeMode] choices_ip_allocation_method = [e.value.lower() for e in IPAllocationMethod] name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') multi_ids_type = CliArgumentType(nargs='+') admin_username_type = CliArgumentType(options_list=('--admin-username', ), default=getpass.getuser(), required=False) existing_vm_name = CliArgumentType(overrides=name_arg_type, help='The name of the virtual machine', completer=get_resource_name_completion_list( 'Microsoft.Compute/virtualMachines'), id_part='name') register_cli_argument('vm', 'vm_name', existing_vm_name) register_cli_argument('vm', 'size', CliArgumentType(completer=get_vm_size_completion_list)) register_cli_argument('vm', 'tags', tags_type) register_cli_argument('vm', 'name', arg_type=name_arg_type) register_cli_argument('vmss', 'vm_scale_set_name', name_arg_type, completer=get_resource_name_completion_list( 'Microsoft.Compute/virtualMachineScaleSets'), id_part='name') register_cli_argument('vmss', 'virtual_machine_scale_set_name', name_arg_type) register_cli_argument('vmss', 'instance_ids', multi_ids_type) register_cli_argument('vmss', 'tags', tags_type) register_cli_argument('vmss', 'name', arg_type=name_arg_type)
) timeout_type = CliArgumentType( help='timeout in seconds', type=int ) use_http_type = CliArgumentType( help='specifies that http should be the default endpoint protocol', action='store_const', const='http' ) # PARAMETER SCOPE REGISTRATIONS register_cli_argument('storage', 'metadata', metadata_type) register_cli_argument('storage', 'container_name', container_name_type) register_cli_argument('storage', 'copy_source', copy_source_type) register_cli_argument('storage', 'directory_name', directory_type) register_cli_argument('storage', 'share_name', share_name_type) register_cli_argument('storage', 'expiry', expiry_type) register_cli_argument('storage', 'if_modified_since', if_modified_since_type) register_cli_argument('storage', 'if_unmodified_since', if_unmodified_since_type) register_cli_argument('storage', 'ip', ip_type) register_cli_argument('storage', 'lease_break_period', lease_break_period_type) register_cli_argument('storage', 'lease_duration', lease_duration_type) register_cli_argument('storage', 'lease_id', lease_id_type) register_cli_argument('storage', 'permission', permission_type) register_cli_argument('storage', 'start', start_type) register_cli_argument('storage', 'timeout', timeout_type)
get_resource_group_completion_list) from .custom import get_policy_completion_list, get_policy_assignment_completion_list from ._validators import validate_resource_type, validate_parent, resolve_resource_parameters # BASIC PARAMETER CONFIGURATION choices_deployment_mode = [e.value.lower() for e in DeploymentMode] resource_type_type = CliArgumentType( help='The resource type in <namespace>/<type> format.', type=validate_resource_type, validator=resolve_resource_parameters ) resource_name_type = CliArgumentType(options_list=('--name', '-n')) register_cli_argument('resource', 'resource_name', resource_name_type) register_cli_argument('resource', 'api_version', CliArgumentType(help='The api version of the resource (omit for latest)', required=False)) register_cli_argument('resource', 'resource_provider_namespace', CliArgumentType(help=argparse.SUPPRESS, required=False)) register_cli_argument('resource', 'resource_type', resource_type_type) register_cli_argument('resource', 'parent_resource_path', CliArgumentType(help='The parent resource type in <type>/<name> format.', type=validate_parent, required=False, options_list=('--parent',))) register_cli_argument('resource', 'tag', tag_type) register_cli_argument('resource', 'tags', tags_type) register_cli_argument('resource list', 'name', resource_name_type) register_cli_argument('resource move', 'ids', nargs='+') _PROVIDER_HELP_TEXT = 'the resource namespace, aka \'provider\'' register_cli_argument('resource provider', 'top', CliArgumentType(help=argparse.SUPPRESS)) register_cli_argument('resource provider', 'resource_provider_namespace', CliArgumentType(options_list=('--namespace', '-n'), help=_PROVIDER_HELP_TEXT)) register_cli_argument('resource feature', 'resource_provider_namespace', CliArgumentType(options_list=('--namespace',), required=True, help=_PROVIDER_HELP_TEXT)) register_cli_argument('resource feature list', 'resource_provider_namespace', CliArgumentType(options_list=('--namespace',), required=False, help=_PROVIDER_HELP_TEXT))
# BASIC PARAMETER CONFIGURATION name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') nsg_name_type = CliArgumentType(options_list=('--nsg-name',), metavar='NSG', help='Name of the network security group.') virtual_network_name_type = CliArgumentType(options_list=('--vnet-name',), metavar='VNET_NAME', help='The virtual network (VNET) name.', completer=get_resource_name_completion_list('Microsoft.Network/virtualNetworks')) subnet_name_type = CliArgumentType(options_list=('--subnet-name',), metavar='SUBNET_NAME', help='The subnet name.') load_balancer_name_type = CliArgumentType(options_list=('--lb-name',), metavar='LB_NAME', help='The load balancer name.', completer=get_resource_name_completion_list('Microsoft.Network/loadBalancers'), id_part='name') private_ip_address_type = CliArgumentType(help='Static private IP address to use.', validator=validate_private_ip_address) cookie_based_affinity_type = CliArgumentType(type=str.lower, completer=get_enum_type_completion_list(ApplicationGatewayCookieBasedAffinity)) http_protocol_type = CliArgumentType(type=str.lower, completer=get_enum_type_completion_list(ApplicationGatewayProtocol)) choices_ip_allocation_method = [e.value.lower() for e in IPAllocationMethod] choices_private_ip_address_version = [e.value.lower() for e in privateIpAddressVersion] register_cli_argument('network', 'subnet_name', subnet_name_type) register_cli_argument('network', 'virtual_network_name', virtual_network_name_type, id_part='name') register_cli_argument('network', 'network_security_group_name', nsg_name_type, id_part='name') register_cli_argument('network', 'private_ip_address', private_ip_address_type) register_cli_argument('network', 'private_ip_address_allocation', help=argparse.SUPPRESS) register_cli_argument('network', 'private_ip_address_version', choices=choices_private_ip_address_version, type=str.lower) register_cli_argument('network', 'tags', tags_type) for item in ['lb', 'nic']: register_cli_argument('network {}'.format(item), 'subnet', validator=validate_subnet_name_or_id, help='Name or ID of an existing subnet.') register_cli_argument('network {}'.format(item), 'virtual_network_name', help='The virtual network (VNet) associated with the provided subnet name (Omit if supplying a subnet id).') register_cli_argument('network {}'.format(item), 'public_ip_address', validator=validate_public_ip_name_or_id) register_cli_argument('network application-gateway', 'application_gateway_name', name_arg_type, completer=get_resource_name_completion_list('Microsoft.Network/applicationGateways'), id_part='name') register_cli_argument('network application-gateway', 'sku_name', completer=get_enum_type_completion_list(ApplicationGatewaySkuName)) register_cli_argument('network application-gateway', 'sku_tier', completer=get_enum_type_completion_list(ApplicationGatewayTier))
help='Location.', metavar='LOCATION') deployment_name_type = CliArgumentType( help=argparse.SUPPRESS, required=False, validator=generate_deployment_name ) quotes = '""' if platform.system() == 'Windows' else "''" quote_text = 'Use {} for none.'.format(quotes) tags_type = CliArgumentType( type=validate_tags, help='multiple semicolon separated tags in \'key[=value]\' format. {}'.format(quote_text), nargs='?', const='' ) tag_type = CliArgumentType( type=validate_tag, help='a single tag in \'key[=value]\' format. {}'.format(quote_text), nargs='?', const='' ) register_cli_argument('', 'resource_group_name', resource_group_name_type) register_cli_argument('', 'location', location_type) register_cli_argument('', 'deployment_name', deployment_name_type)
from azure.cli.commands.parameters import (resource_group_name_type, tag_type, tags_type, get_resource_group_completion_list) from ._validators import validate_resource_type, validate_parent, resolve_resource_parameters # BASIC PARAMETER CONFIGURATION choices_deployment_mode = [e.value.lower() for e in DeploymentMode] resource_type_type = CliArgumentType( help='The resource type in <namespace>/<type> format.', type=validate_resource_type, validator=resolve_resource_parameters) register_cli_argument('resource', 'resource_name', CliArgumentType(options_list=('--name', '-n'))) register_cli_argument( 'resource', 'api_version', CliArgumentType(help='The api version of the resource (omit for latest)', required=False)) register_cli_argument('resource', 'resource_provider_namespace', CliArgumentType(help=argparse.SUPPRESS, required=False)) register_cli_argument('resource', 'resource_type', resource_type_type) register_cli_argument( 'resource', 'parent_resource_path', CliArgumentType(help='The parent resource type in <type>/<name> format.', type=validate_parent, required=False, options_list=('--parent', ))) register_cli_argument('resource', 'tag', tag_type) register_cli_argument('resource', 'tags', tags_type)
options_list=('--start', ), type=validate_datetime_as_string, help= 'start UTC datetime of SAS token (Y-m-d\'T\'H:M\'Z\'). Defaults to time of request.' ) timeout_type = CliArgumentType(help='timeout in seconds', type=int) use_http_type = CliArgumentType( help='specifies that http should be the default endpoint protocol', action='store_const', const='http') # PARAMETER SCOPE REGISTRATIONS register_cli_argument('storage', 'metadata', metadata_type) register_cli_argument('storage', 'container_name', container_name_type) register_cli_argument('storage', 'copy_source', copy_source_type) register_cli_argument('storage', 'directory_name', directory_type) register_cli_argument('storage', 'share_name', share_name_type) register_cli_argument('storage', 'expiry', expiry_type) register_cli_argument('storage', 'if_modified_since', if_modified_since_type) register_cli_argument('storage', 'if_unmodified_since', if_unmodified_since_type) register_cli_argument('storage', 'ip', ip_type) register_cli_argument('storage', 'lease_break_period', lease_break_period_type) register_cli_argument('storage', 'lease_duration', lease_duration_type) register_cli_argument('storage', 'lease_id', lease_id_type) register_cli_argument('storage', 'permission', permission_type) register_cli_argument('storage', 'start', start_type) register_cli_argument('storage', 'timeout', timeout_type)
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- from azure.cli.commands import register_cli_argument, CliArgumentType # BASIC PARAMETER CONFIGURATION register_cli_argument( 'component', 'component_name', CliArgumentType(options_list=('--name', '-n'), help='Name of component')) register_cli_argument( 'component', 'force', CliArgumentType(options_list=('--force', '-f'), help='Supress delete confirmation prompt', action='store_true')) register_cli_argument( 'component', 'link', CliArgumentType( options_list=('--link', '-l'), help= 'If a url or path to an html file, parse for links to archives. If local path or file://' 'url that\'s a directory, then look for archives in the directory listing.' )) register_cli_argument( 'component', 'private', CliArgumentType(options_list=('--private', '-p'), help='Get from the project PyPI server', action='store_true')) register_cli_argument(
options_list=('--lb-name', ), metavar='LB_NAME', help='The load balancer name.', completer=get_resource_name_completion_list( 'Microsoft.Network/loadBalancers'), id_part='name') private_ip_address_type = CliArgumentType( help='Static private IP address to use.', validator=validate_private_ip_address) choices_ip_allocation_method = [e.value.lower() for e in IPAllocationMethod] choices_private_ip_address_version = [ e.value.lower() for e in privateIpAddressVersion ] register_cli_argument('network', 'subnet_name', subnet_name_type) register_cli_argument('network', 'virtual_network_name', virtual_network_name_type, id_part='name') register_cli_argument('network', 'network_security_group_name', nsg_name_type, id_part='name') register_cli_argument('network', 'private_ip_address', private_ip_address_type) register_cli_argument('network', 'private_ip_address_allocation', help=argparse.SUPPRESS) register_cli_argument('network', 'private_ip_address_version', choices=choices_private_ip_address_version,
storage_account_key_options = {'both': ['key1', 'key2'], 'primary': ['key1'], 'secondary': ['key2']} # ARGUMENT TYPES account_name_type = CliArgumentType(options_list=('--account-name', '-n'), help='The storage account name.', completer=get_resource_name_completion_list('Microsoft.Storage/storageAccounts'), id_part='name') blob_name_type = CliArgumentType(options_list=('--blob-name', '-b'), help='The blob name.', completer=get_storage_name_completion_list(BaseBlobService, 'list_blobs', parent='container_name')) container_name_type = CliArgumentType(options_list=('--container-name', '-c'), help='The container name.', completer=get_storage_name_completion_list(BaseBlobService, 'list_containers')) directory_type = CliArgumentType(options_list=('--directory-name', '-d'), help='The directory name.', completer=get_storage_name_completion_list(FileService, 'list_directories_and_files', parent='share_name')) file_name_type = CliArgumentType(options_list=('--file-name', '-f'), completer=get_storage_name_completion_list(FileService, 'list_directories_and_files', parent='share_name')) share_name_type = CliArgumentType(options_list=('--share-name', '-s'), help='The file share name.', completer=get_storage_name_completion_list(FileService, 'list_shares')) table_name_type = CliArgumentType(options_list=('--table-name', '-t'), completer=get_storage_name_completion_list(TableService, 'list_tables')) queue_name_type = CliArgumentType(options_list=('--queue-name', '-q'), help='The queue name.', completer=get_storage_name_completion_list(QueueService, 'list_queues')) # PARAMETER REGISTRATIONS register_cli_argument('storage', 'directory_name', directory_type) register_cli_argument('storage', 'share_name', share_name_type) register_cli_argument('storage', 'table_name', table_name_type) register_cli_argument('storage', 'if_modified_since', help='Alter only if modified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')', type=validate_datetime) register_cli_argument('storage', 'if_unmodified_since', help='Alter only if unmodified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')', type=validate_datetime) register_cli_argument('storage', 'metadata', nargs='+', help='Metadata in space-separated key=value pairs.', validator=validate_metadata) register_cli_argument('storage', 'timeout', help='Request timeout in seconds. Applies to each call to the service.', type=int) register_cli_argument('storage', 'container_name', container_name_type) register_cli_argument('storage', 'content_cache_control', help='The cache control string.') register_cli_argument('storage', 'content_disposition', help='Conveys additional information about how to process the response payload, and can also be used to attach additional metadata.') register_cli_argument('storage', 'content_encoding', help='The content encoding type.') register_cli_argument('storage', 'content_language', help='The content language.') register_cli_argument('storage', 'content_md5', help='The content\'s MD5 hash.') register_cli_argument('storage', 'content_type', help='The content MIME type.')
super(ScheduleEntryList, self).__init__() import json if value[0] in ("'", '"') and value[-1] == value[0]: # Remove leading and trailing quotes for dos/cmd.exe users value = value[1:-1] dictval = json.loads(value) self.extend([ ScheduleEntry(row['dayOfWeek'], int(row['startHourUtc']), row.get('maintenanceWindow', None)) for row in dictval ]) register_cli_argument( 'redis', 'name', arg_type=name_type, completer=get_resource_name_completion_list('Microsoft.Cache/redis'), id_part='name') register_cli_argument('redis', 'redis_configuration', type=JsonString) register_cli_argument('redis', 'reboot_type', completer=get_enum_type_completion_list(RebootType)) register_cli_argument('redis', 'key_type', choices=[e.value for e in RedisKeyType]) register_cli_argument('redis', 'shard_id', type=int) register_cli_argument('redis import-method', 'files', nargs='+') register_cli_argument('redis patch-schedule set', 'schedule_entries', type=ScheduleEntryList)
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- import azure.cli.commands.parameters #pylint: disable=unused-import from azure.cli.commands import register_cli_argument register_cli_argument('ad app', 'application_object_id', options_list=('--object-id',)) register_cli_argument('ad app', 'app_id', help='application id') register_cli_argument('ad', 'display_name', help='object\'s display name or its prefix') register_cli_argument('ad', 'identifier_uri', help='graph application identifier, must be in uri format') register_cli_argument('ad', 'spn', help='service principal name') register_cli_argument('ad', 'upn', help='user principal name, e.g. [email protected]') register_cli_argument('ad', 'query_filter', options_list=('--filter',), help='OData filter') register_cli_argument('role assignment', 'role_assignment_name', options_list=('--role-assignment-name', '-n')) register_cli_argument('role assignment', 'role', help='role name or id') register_cli_argument('ad user', 'mail_nickname', help='mail alias. Defaults to user principal name') register_cli_argument('ad user', 'force_change_password_next_login', action='store_true')
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- from azure.cli.commands import register_cli_argument, CliArgumentType # BASIC PARAMETER CONFIGURATION register_cli_argument('component', 'component_name', CliArgumentType( options_list=('--name', '-n'), help='Name of component' )) register_cli_argument('component', 'force', CliArgumentType( options_list=('--force', '-f'), help='Supress delete confirmation prompt', action='store_true' )) register_cli_argument('component', 'link', CliArgumentType( options_list=('--link', '-l'), help='If a url or path to an html file, parse for links to archives. If local path or file://' 'url that\'s a directory, then look for archives in the directory listing.' )) register_cli_argument('component', 'private', CliArgumentType( options_list=('--private', '-p'), help='Get from the project PyPI server', action='store_true' )) register_cli_argument('component', 'version', CliArgumentType( help='Component version (otherwise latest)' ))
return [r.name for r in result] # BASIC PARAMETER CONFIGURATION choices_caching_types = [e.value for e in CachingTypes] choices_container_service_orchestrator_types = [e.value for e in ContainerServiceOchestratorTypes] choices_upgrade_mode = [e.value.lower() for e in UpgradeMode] choices_ip_allocation_method = [e.value.lower() for e in IPAllocationMethod] name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') multi_ids_type = CliArgumentType( nargs='+' ) admin_username_type = CliArgumentType(options_list=('--admin-username',), default=getpass.getuser(), required=False) existing_vm_name = CliArgumentType(overrides=name_arg_type, help='The name of the virtual machine', completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines'), id_part='name') register_cli_argument('vm', 'vm_name', existing_vm_name) register_cli_argument('vm', 'size', CliArgumentType(completer=get_vm_size_completion_list)) register_cli_argument('vm', 'tags', tags_type) register_cli_argument('vm', 'name', arg_type=name_arg_type) register_cli_argument('vmss', 'vm_scale_set_name', name_arg_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'), id_part='name') register_cli_argument('vmss', 'virtual_machine_scale_set_name', name_arg_type) register_cli_argument('vmss', 'instance_ids', multi_ids_type) register_cli_argument('vmss', 'tags', tags_type) register_cli_argument('vmss', 'name', arg_type=name_arg_type) register_cli_argument('vm disk', 'vm_name', arg_type=existing_vm_name, options_list=('--vm-name',)) register_cli_argument('vm disk', 'disk_name', CliArgumentType(options_list=('--name', '-n'), help='The data disk name. If missing, will retrieve from vhd uri')) register_cli_argument('vm disk', 'disk_size', CliArgumentType(help='Size of disk (GiB)', default=1023, type=int)) register_cli_argument('vm disk', 'lun', CliArgumentType( type=int, help='0-based logical unit number (LUN). Max value depends on the Virutal Machine size.')) register_cli_argument('vm disk', 'vhd', CliArgumentType(type=VirtualHardDisk, help='virtual hard disk\'s uri. For example:https://mystorage.blob.core.windows.net/vhds/d1.vhd'))
help='Name of resource group') name_type = CliArgumentType(options_list=('--name', '-n'), help='the primary resource name') location_type = CliArgumentType(options_list=('--location', '-l'), completer=get_location_completion_list, help='Location.', metavar='LOCATION') deployment_name_type = CliArgumentType(help=argparse.SUPPRESS, required=False, validator=generate_deployment_name) tags_type = CliArgumentType( type=validate_tags, help= 'multiple semicolon separated tags in \'key[=value]\' format. Omit value to clear tags.', nargs='?', const='') tag_type = CliArgumentType( type=validate_tag, help='a single tag in \'key[=value]\' format. Omit value to clear tags.', nargs='?', const='') register_cli_argument('', 'resource_group_name', resource_group_name_type) register_cli_argument('', 'location', location_type) register_cli_argument('', 'deployment_name', deployment_name_type)
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- # pylint: disable=line-too-long from azure.mgmt.keyvault.models.key_vault_management_client_enums import (SkuName) from azure.cli.commands.parameters import ( get_resource_name_completion_list, name_type) from azure.cli.commands import register_cli_argument import azure.cli.commands.arm # pylint: disable=unused-import from azure.cli.command_modules.keyvault._validators import (process_policy_namespace, process_set_policy_perms_namespace) register_cli_argument('keyvault', 'vault_name', arg_type=name_type, completer=get_resource_name_completion_list('Microsoft.KeyVault/vaults'), id_part='name') register_cli_argument('keyvault', 'object_id', help='a GUID that identifies the principal that will receive permissions') register_cli_argument('keyvault', 'spn', help='name of a service principal that will receive permissions') register_cli_argument('keyvault', 'upn', help='name of a user principal that will receive permissions') register_cli_argument('keyvault create', 'vault_name', completer=None) register_cli_argument('keyvault create', 'sku', choices=[e.value for e in SkuName]) register_cli_argument('keyvault create', 'no_self_perms', action='store_true', help="If specified, don't add permissions for the current user in the new vault") register_cli_argument('keyvault set-policy', 'object_id', validator=process_policy_namespace) register_cli_argument('keyvault delete-policy', 'object_id', validator=process_policy_namespace) # TODO Validate perms_to_keys and perms_to_secrets when enums are added in keyvault SDK register_cli_argument('keyvault set-policy', 'perms_to_keys', nargs='*', validator=process_set_policy_perms_namespace, help='Permissions to keys') register_cli_argument('keyvault set-policy', 'perms_to_secrets', nargs='*', help='Permissions to secrets')
tags_type, get_resource_group_completion_list) from ._validators import validate_resource_type, validate_parent, resolve_resource_parameters # BASIC PARAMETER CONFIGURATION choices_deployment_mode = [e.value.lower() for e in DeploymentMode] resource_type_type = CliArgumentType( help='The resource type in <namespace>/<type> format.', type=validate_resource_type, validator=resolve_resource_parameters ) register_cli_argument('resource', 'resource_name', CliArgumentType(options_list=('--name', '-n'))) register_cli_argument('resource', 'api_version', CliArgumentType(help='The api version of the resource (omit for latest)', required=False)) register_cli_argument('resource', 'resource_provider_namespace', CliArgumentType(help=argparse.SUPPRESS, required=False)) register_cli_argument('resource', 'resource_type', resource_type_type) register_cli_argument('resource', 'parent_resource_path', CliArgumentType(help='The parent resource type in <type>/<name> format.', type=validate_parent, required=False, options_list=('--parent',))) register_cli_argument('resource', 'tag', tag_type) register_cli_argument('resource', 'tags', tags_type) register_cli_argument('resource move', 'ids', nargs='+') register_cli_argument('resource provider', 'top', CliArgumentType(help=argparse.SUPPRESS)) register_cli_argument('resource provider', 'resource_provider_namespace', CliArgumentType(options_list=('--namespace', '-n'), help='the resource provider name, aka \'namespace\'')) register_cli_argument('resource group', 'resource_group_name', resource_group_name_type, options_list=('--name', '-n')) register_cli_argument('resource group deployment', 'resource_group_name', arg_type=resource_group_name_type, completer=get_resource_group_completion_list) register_cli_argument('resource group deployment', 'deployment_name', CliArgumentType(options_list=('--name', '-n'), required=True, help='The deployment name.')) register_cli_argument('resource group deployment', 'parameters_file_path', completer=FilesCompleter())
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- from azure.cli.commands import CliArgumentType, register_cli_argument from azure.cli.commands.parameters import tags_type from azure.mgmt.web import WebSiteManagementClient from azure.cli.commands.client_factory import get_mgmt_service_client from azure.cli.commands.template_create import register_folded_cli_argument # FACTORIES def _web_client_factory(**_): return get_mgmt_service_client(WebSiteManagementClient) # PARAMETER REGISTRATION register_cli_argument('webapp', 'name', CliArgumentType(options_list=('--name', '-n'))) register_cli_argument('webapp', 'tags', tags_type) register_folded_cli_argument('webapp create', 'hosting_plan', 'Microsoft.Web/serverfarms')
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- from azure.cli.commands import CliArgumentType, register_cli_argument from azure.cli.commands.parameters import tags_type from azure.mgmt.web import WebSiteManagementClient from azure.cli.commands.client_factory import get_mgmt_service_client from azure.cli.commands.template_create import register_folded_cli_argument # FACTORIES def _web_client_factory(**_): return get_mgmt_service_client(WebSiteManagementClient) # PARAMETER REGISTRATION register_cli_argument('webapp', 'name', CliArgumentType(options_list=('--name', '-n'))) register_cli_argument('webapp', 'tags', tags_type) register_folded_cli_argument('webapp create', 'hosting_plan', 'Microsoft.Web/serverfarms', help='Name or ID of the web application\'s hosting plan.' ' Creates if resource doesn\'t exist.')
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- #pylint: disable=line-too-long import azure.cli.commands.parameters #pylint: disable=unused-import from azure.cli.commands import CliArgumentType from azure.cli.commands import register_cli_argument register_cli_argument('ad app', 'application_object_id', options_list=('--object-id',)) register_cli_argument('ad app', 'display_name', help=' the display name of the application') register_cli_argument('ad app', 'homepage', help='the url where users can sign in and use your app.') register_cli_argument('ad app', 'identifier', options_list=('--id',), help='identifier uri, application id, or object id') register_cli_argument('ad app', 'identifier_uris', nargs='+', help='space separated unique URIs that Azure AD can use for this app.') register_cli_argument('ad app', 'reply_urls', nargs='+', help='space separated URIs to which Azure AD will redirect in response to an OAuth 2.0 request. The value does not need to be a physical endpoint, but must be a valid URI.') register_cli_argument('ad app', 'start_date', help='the start date after which password or key would be valid. Default value is current time') register_cli_argument('ad app', 'end_date', help='the end date till which password or key is valid. Default value is one year after current time') register_cli_argument('ad app', 'key_value', help='the value for the key credentials associated with the application') register_cli_argument('ad app', 'key_type', choices=['AsymmetricX509Cert', 'Password', 'Symmetric'], default='AsymmetricX509Cert', help='the type of the key credentials associated with the application') register_cli_argument('ad app', 'key_usage', choices=['Sign', 'Verify'], default='Verify', help='the usage of the key credentials associated with the application.') sp_name_type = CliArgumentType( options_list=('--name', '-n') ) register_cli_argument('ad sp', 'identifier', options_list=('--id',), help='service principal name, or object id') register_cli_argument('ad sp create', 'identifier', options_list=('--id',), help='identifier uri, application id, or object id of the associated application') register_cli_argument('ad sp create-for-rbac', 'name', sp_name_type) register_cli_argument('ad sp reset-credentials', 'name', sp_name_type)
#--------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- #pylint: disable=line-too-long import azure.cli.commands.parameters #pylint: disable=unused-import from azure.cli.commands import register_cli_argument register_cli_argument('ad app', 'application_object_id', options_list=('--object-id',)) register_cli_argument('ad app', 'app_id', help='application id') register_cli_argument('ad', 'display_name', help='object\'s display name or its prefix') register_cli_argument('ad', 'identifier_uri', help='graph application identifier, must be in uri format') register_cli_argument('ad', 'spn', help='service principal name') register_cli_argument('ad', 'upn', help='user principal name, e.g. [email protected]') register_cli_argument('ad', 'query_filter', options_list=('--filter',), help='OData filter') register_cli_argument('ad user', 'mail_nickname', help='mail alias. Defaults to user principal name') register_cli_argument('ad user', 'force_change_password_next_login', action='store_true') register_cli_argument('role assignment', 'role_assignment_name', options_list=('--role-assignment-name', '-n')) register_cli_argument('role assignment', 'role', help='role name or id') register_cli_argument('role assignment', 'show_all', options_list=('--all',), action='store_true', help='show all assignments under the current subscription') register_cli_argument('role assignment', 'include_inherited', action='store_true', help='include assignments applied on parent scopes') register_cli_argument('role assignment', 'assignee', help='represent a user, group, or service principal. supported format: object id, user sign-in name, or service principal name') register_cli_argument('role assignment', 'ids', nargs='+', help='space separated role assignment ids') register_cli_argument('role', 'role_id', help='the role id') register_cli_argument('role', 'resource_group_name', options_list=('--resource-group', '-g'),