def test_register_cli_argument(self): command_table.clear() cli_command( None, 'test register sample-vm-get', '{}#Test_command_registration.sample_vm_get'.format(__name__)) register_cli_argument( 'test register sample-vm-get', 'vm_name', CliArgumentType(options_list=('--wonky-name', '-n'), metavar='VMNAME', help='Completely WONKY name...', required=False)) command_table['test register sample-vm-get'].load_arguments() _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_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() setattr(sys.modules[__name__], sample_sdk_method.__name__, sample_sdk_method) cli_command(None, 'override_using_register_cli_argument foo', '{}#{}'.format(__name__, sample_sdk_method.__name__), 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) command_table[ 'override_using_register_cli_argument foo'].load_arguments() _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 register_folded_cli_argument(scope, base_name, resource_type, parent_name=None, parent_option_flag=None, parent_type=None, type_field=None, existing_id_flag_value='existingId', new_flag_value='new', none_flag_value='none', default_value_flag='new', base_required=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, parent_name, parent_option_flag, parent_type, base_required) custom_validator = kwargs.pop('validator', None) custom_help = kwargs.pop('help', None) if custom_validator: def wrapped(namespace): fold_validator(namespace) custom_validator(namespace) validator = wrapped else: validator = fold_validator if not custom_help: quotes = '""' if platform.system() == 'Windows' else "''" quote_text = ' Use {} for none.'.format( quotes) if none_flag_value else '' parent_text = ' If name specified, must also specify {}.'.format( parent_option_flag or parent_name) if parent_name else '' flag_texts = { new_flag_value: ' Creates new by default.{}'.format(quote_text), existing_id_flag_value: ' Uses existing resource.{}{}'.format(quote_text, parent_text), none_flag_value: ' None by default.' } help_text = 'Name or ID of the resource.' + flag_texts[ default_value_flag] else: help_text = custom_help 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 register_resource_parameter(command, dest, arg_group=None, required=True): """ Helper method to add the extra parameters needed to support specifying name or ID for target resources. """ register_cli_argument(command, dest, options_list=['--{}'.format(dest)], arg_group=arg_group, required=required, validator=get_target_resource_validator(dest, required), help="Name or ID of the target resource.") register_extra_cli_argument(command, 'namespace', options_list=['--{}-namespace'.format(dest)], arg_group=arg_group, help="Target resource provider namespace.") register_extra_cli_argument(command, 'parent', options_list=['--{}-parent'.format(dest)], arg_group=arg_group, help="Target resource parent path, if applicable.") register_extra_cli_argument(command, 'resource_type', options_list=['--{}-type'.format(dest)], arg_group=arg_group, help="Target resource type. Can also accept namespace/type format (Ex: 'Microsoft.Compute/virtualMachines)')")
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() setattr(sys.modules[__name__], sample_sdk_method.__name__, sample_sdk_method) cli_command(None, 'override_using_register_cli_argument foo', '{}#{}'.format(__name__, sample_sdk_method.__name__), 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) command_table['override_using_register_cli_argument foo'].load_arguments() _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 register_attributes_argument(scope, name, attr_class, create=False): register_cli_argument(scope, '{}_attributes'.format(name), ignore_type, validator=get_attribute_validator( name, attr_class, create)) if create: register_extra_cli_argument( scope, 'disabled', action='store_true', help='Create {} in disabled state.'.format(name)) else: register_extra_cli_argument(scope, 'enabled', default=None, choices=['true', 'false'], help='Enable the {}.'.format(name)) register_extra_cli_argument( scope, 'expires', default=None, help='Expiration UTC datetime (Y-m-d\'T\'H:M\'Z\').', type=datetime_type) register_extra_cli_argument( scope, 'not_before', default=None, help= 'Key not usable before the provided UTC datetime (Y-m-d\'T\'H:M\'Z\').', type=datetime_type)
def register_content_settings_argument(scope, settings_class, update): register_cli_argument(scope, 'content_settings', ignore_type, validator=get_content_setting_validator( settings_class, update)) register_extra_cli_argument(scope, 'content_type', default=None, help='The content MIME type.') register_extra_cli_argument(scope, 'content_encoding', default=None, help='The content encoding type.') register_extra_cli_argument(scope, 'content_language', default=None, help='The content language.') register_extra_cli_argument( scope, 'content_disposition', default=None, help= 'Conveys additional information about how to process the response payload, and can also be used to attach additional metadata.' ) register_extra_cli_argument(scope, 'content_cache_control', default=None, help='The cache control string.') register_extra_cli_argument(scope, 'content_md5', default=None, help='The content\'s MD5 hash.')
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 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_register_cli_argument(self): command_table.clear() cli_command(None, 'test register sample-vm-get', '{}#Test_command_registration.sample_vm_get'.format(__name__)) register_cli_argument('test register sample-vm-get', 'vm_name', CliArgumentType( options_list=('--wonky-name', '-n'), metavar='VMNAME', help='Completely WONKY name...', required=False )) command_table['test register sample-vm-get'].load_arguments() _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_blob_source_uri_arguments(scope): register_cli_argument(scope, 'copy_source', options_list=('--source-uri', '-u'), validator=process_blob_source_uri, required=False, arg_group='Copy Source') register_extra_cli_argument(scope, 'source_sas', default=None, help='The shared access signature for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_container', default=None, help='The container name for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_blob', default=None, help='The blob name for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_snapshot', default=None, help='The blob snapshot for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_account_name', default=None, help='The storage account name of the source blob.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_account_key', default=None, help='The storage account key of the source blob.', arg_group='Copy Source')
def register_attributes_argument(scope, name, attr_class, create=False): register_cli_argument(scope, '{}_attributes'.format(name), ignore_type, validator=get_attribute_validator(name, attr_class, create)) if create: register_extra_cli_argument(scope, 'disabled', action='store_true', help='Create {} in disabled state.'.format(name)) else: register_extra_cli_argument(scope, 'enabled', default=None, choices=['true', 'false'], help='Enable the {}.'.format(name)) register_extra_cli_argument(scope, 'expires', default=None, help='Expiration UTC datetime (Y-m-d\'T\'H:M:S\'Z\').', type=datetime_type) register_extra_cli_argument(scope, 'not_before', default=None, help='Key not usable before the provided UTC datetime (Y-m-d\'T\'H:M:S\'Z\').', type=datetime_type)
def register_content_settings_argument(scope, settings_class, update, arg_group=None): register_cli_argument(scope, 'content_settings', ignore_type, validator=get_content_setting_validator(settings_class, update), arg_group=arg_group) register_extra_cli_argument(scope, 'content_type', default=None, help='The content MIME type.', arg_group=arg_group) register_extra_cli_argument(scope, 'content_encoding', default=None, help='The content encoding type.', arg_group=arg_group) register_extra_cli_argument(scope, 'content_language', default=None, help='The content language.', arg_group=arg_group) register_extra_cli_argument(scope, 'content_disposition', default=None, help='Conveys additional information about how to process the response payload, and can also be used to attach additional metadata.', arg_group=arg_group) register_extra_cli_argument(scope, 'content_cache_control', default=None, help='The cache control string.', arg_group=arg_group) register_extra_cli_argument(scope, 'content_md5', default=None, help='The content\'s MD5 hash.', arg_group=arg_group)
def register_source_uri_arguments(scope): register_cli_argument(scope, 'copy_source', options_list=('--source-uri', '-u'), validator=validate_source_uri, required=False, arg_group='Copy Source') register_extra_cli_argument(scope, 'source_sas', default=None, help='The shared access signature for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_share', default=None, help='The share name for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_path', default=None, help='The file path for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_container', default=None, help='The container name for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_blob', default=None, help='The blob name for the source storage account.', arg_group='Copy Source') register_extra_cli_argument(scope, 'source_snapshot', default=None, help='The blob snapshot for the source storage account.', arg_group='Copy Source')
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', **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 quotes = '""' if platform.system() == 'Windows' else "''" quote_text = ' Use {} for none.'.format(quotes) if none_flag_value else '' flag_texts = { new_flag_value: ' Creates new by default.{}'.format(quote_text), existing_id_flag_value: ' Uses existing resource.{}'.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 set_up_command_table(self, required_arg=False): command_table.clear() module_name = __name__ + '.' + self._testMethodName cli_command(module_name, 'test sample-vm-list', '{}#TestCommandWithConfiguredDefaults.sample_vm_list'.format(__name__)) register_cli_argument('test sample-vm-list', 'resource_group_name', CliArgumentType(options_list=('--resource-group-name', '-g'), configured_default='group', required=required_arg)) command_table['test sample-vm-list'].load_arguments() _update_command_definitions(command_table) self.argv = 'az test sample-vm-list'.split() config = Configuration() config.get_command_table = lambda argv: command_table self.application = Application(config)
def set_up_command_table(self, required_arg=False): command_table.clear() module_name = __name__ + '.' + self._testMethodName cli_command(module_name, 'test sample-vm-list', '{}#TestCommandWithConfiguredDefaults.sample_vm_list'.format(__name__)) register_cli_argument('test sample-vm-list', 'resource_group_name', CliArgumentType(options_list=('--resource-group-name', '-g'), configured_default='group', required=required_arg)) command_table['test sample-vm-list'].load_arguments() _update_command_definitions(command_table) self.argv = 'az test sample-vm-list'.split() config = Configuration(self.argv) config.get_command_table = lambda: command_table self.application = Application(config)
def register_folded_cli_argument(scope, base_name, resource_type, parent_name=None, # pylint: disable=too-many-arguments parent_option_flag=None, parent_type=None, type_field=None, existing_id_flag_value='existingId', new_flag_value='new', none_flag_value='none', default_value_flag='new', base_required=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, parent_name, parent_option_flag, parent_type, base_required) custom_validator = kwargs.pop('validator', None) custom_help = kwargs.pop('help', None) if custom_validator: def wrapped(namespace): fold_validator(namespace) custom_validator(namespace) validator = wrapped else: validator = fold_validator if not custom_help: quotes = '""' if platform.system() == 'Windows' else "''" quote_text = ' Use {} for none.'.format(quotes) if none_flag_value else '' parent_text = ' If name specified, must also specify {}.'.format( parent_option_flag or parent_name) if parent_name else '' flag_texts = { new_flag_value: ' Creates new by default.{}'.format(quote_text), existing_id_flag_value: ' Uses existing resource.{}{}' .format(quote_text, parent_text), none_flag_value: ' None by default.' } help_text = 'Name or ID of the resource.' + flag_texts[default_value_flag] else: help_text = custom_help 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_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')) cli_generic_update_command('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_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')) cli_generic_update_command('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 register_attributes_argument(scope, name, attr_class, create=False, ignore=None): ignore = ignore or [] register_cli_argument(scope, '{}_attributes'.format(name), ignore_type, validator=get_attribute_validator(name, attr_class, create)) if create: register_extra_cli_argument(scope, 'disabled', help='Create {} in disabled state.'.format(name), **three_state_flag()) else: register_extra_cli_argument(scope, 'enabled', help='Enable the {}.'.format(name), **three_state_flag()) if 'expires' not in ignore: register_extra_cli_argument(scope, 'expires', default=None, help='Expiration UTC datetime (Y-m-d\'T\'H:M:S\'Z\').', type=datetime_type) if 'not_before' not in ignore: register_extra_cli_argument(scope, 'not_before', default=None, help='Key not usable before the provided UTC datetime ' '(Y-m-d\'T\'H:M:S\'Z\').', type=datetime_type)
def register_attributes_argument(scope, name, attr_class, create=False, ignore=None): ignore = ignore or [] register_cli_argument(scope, '{}_attributes'.format(name), ignore_type, validator=get_attribute_validator(name, attr_class, create)) if create: register_extra_cli_argument(scope, 'disabled', help='Create {} in disabled state.'.format(name), **three_state_flag()) else: register_extra_cli_argument(scope, 'enabled', help='Enable the {}.'.format(name), **three_state_flag()) if 'expires' not in ignore: register_extra_cli_argument(scope, 'expires', default=None, help='Expiration UTC datetime (Y-m-d\'T\'H:M:S\'Z\').', type=datetime_type) if 'not_before' not in ignore: register_extra_cli_argument(scope, 'not_before', default=None, help='Key not usable before the provided UTC datetime ' '(Y-m-d\'T\'H:M:S\'Z\').', type=datetime_type)
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()
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( None, 'test vm-get', '{}#Test_command_registration.sample_vm_get'.format(__name__), None) cli_command( None, 'test command vm-get-1', '{}#Test_command_registration.sample_vm_get'.format(__name__), None) cli_command( None, 'test command vm-get-2', '{}#Test_command_registration.sample_vm_get'.format(__name__), 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') command_table['test vm-get'].load_arguments() command_table['test command vm-get-1'].load_arguments() command_table['test command vm-get-2'].load_arguments() _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()
for item in ns.locations: comps = item.split('=', 1) loc_dict.append( Location(location_name=comps[0], failover_priority=int(comps[1]))) ns.locations = loc_dict def validate_ip_range_filter(ns): if ns.ip_range_filter: ns.ip_range_filter = ",".join(ns.ip_range_filter) register_cli_argument('cosmosdb', 'account_name', arg_type=name_type, help='Name of the Cosmos DB database account', completer=get_resource_name_completion_list( 'Microsoft.DocumentDb/databaseAccounts'), id_part="name") register_cli_argument('cosmosdb regenerate-key', 'key_kind', **enum_choice_list(KeyKind)) register_cli_argument( 'cosmosdb failover-priority-change', 'failover_policies', validator=validate_failover_policies, help= "space separated failover policies in 'regionName=failoverPriority' format. E.g \"East US\"=0 \"West US\"=1", nargs='+') register_cli_argument('cosmosdb create', 'account_name', completer=None) register_cli_argument('cosmosdb create',
from azure.cli.command_modules.dls._validators import validate_resource_group_name from azure.mgmt.datalake.store.models.data_lake_store_account_management_client_enums \ import (FirewallState, TrustedIdProviderState, TierType, FirewallAllowAzureIpsState) from azure.mgmt.datalake.store.models import (EncryptionConfigType) # ARGUMENT DEFINITIONS # pylint: disable=line-too-long datalake_store_name_type = CliArgumentType(help='Name of the Data Lake Store account.', options_list=('--account_name',), completer=get_resource_name_completion_list('Microsoft.DataLakeStore/accounts'), id_part='name') # PARAMETER REGISTRATIONS # global params register_cli_argument('dls', 'account_name', datalake_store_name_type, options_list=('--account', '-n')) register_cli_argument('dls', 'top', help='Maximum number of items to return.', type=int) register_cli_argument('dls', 'skip', help='The number of items to skip over before returning elements.', type=int) register_cli_argument('dls', 'count', help='The Boolean value of true or false to request a count of the matching resources included with the resources in the response, e.g. Categories?$count=true.', type=bool) # global account params register_cli_argument('dls account', 'tags', tags_type) register_cli_argument('dls account', 'resource_group_name', resource_group_name_type, id_part=None, required=False, help='If not specified, will attempt to discover the resource group for the specified Data Lake Store account.', validator=validate_resource_group_name) # account params register_cli_argument('dls account show', 'name', datalake_store_name_type, options_list=('--account', '-n')) register_cli_argument('dls account delete', 'name', datalake_store_name_type, options_list=('--account', '-n')) register_cli_argument('dls account', 'tier', help='The desired commitment tier for this account to use.', **enum_choice_list(TierType)) register_cli_argument('dls account create', 'resource_group_name', resource_group_name_type, validator=None) register_cli_argument('dls account create', 'account_name', datalake_store_name_type, options_list=('--account', '-n'), completer=None) register_cli_argument('dls account create', 'encryption_type', help='Indicates what type of encryption to provision the account with. By default, encryption is ServiceManaged. If no encryption is desired, it must be explicitly set with the --disable-encryption flag.', **enum_choice_list(EncryptionConfigType)) register_cli_argument('dls account create', 'disable_encryption', help='Indicates that the account will not have any form of encryption applied to it.', action='store_true') register_cli_argument('dls account update', 'trusted_id_provider_state', help='Enable/disable the existing trusted ID providers.', **enum_choice_list(TrustedIdProviderState))
help=argparse.SUPPRESS, required=False, validator=generate_deployment_name ) quotes = '""' if platform.system() == 'Windows' else "''" quote_text = 'Use {} to clear existing tags.'.format(quotes) tags_type = CliArgumentType( validator=validate_tags, help="space separated tags in 'key[=value]' format. {}".format(quote_text), nargs='*' ) tag_type = CliArgumentType( type=validate_tag, help="a single tag in 'key[=value]' format. {}".format(quote_text), nargs='?', const='' ) no_wait_type = CliArgumentType( options_list=('--no-wait', ), help='do not wait for the long running operation to finish', action='store_true' ) register_cli_argument('', 'resource_group_name', resource_group_name_type) register_cli_argument('', 'location', location_type) register_cli_argument('', 'deployment_name', deployment_name_type)
name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') multi_ids_type = CliArgumentType(nargs='+') existing_vm_name = CliArgumentType(overrides=name_arg_type, configured_default='vm', help="The name of the Virtual Machine. You can configure the default using `az configure --defaults vm=<name>`", completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines'), id_part='name') vmss_name_type = CliArgumentType(name_arg_type, configured_default='vmss', completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'), help="Scale set name. You can configure the default using `az configure --defaults vmss=<name>`", id_part='name') disk_sku = CliArgumentType(required=False, help='underlying storage sku', **enum_choice_list(['Premium_LRS', 'Standard_LRS'])) # ARGUMENT REGISTRATION register_cli_argument('vm', 'vm_name', existing_vm_name) register_cli_argument('vm', 'size', completer=get_vm_size_completion_list) for scope in ['vm', 'disk', 'snapshot', 'image']: register_cli_argument(scope, 'tags', tags_type) register_cli_argument('vm', 'name', arg_type=name_arg_type) with VersionConstraint(ResourceType.MGMT_COMPUTE, min_api='2017-03-30') as c: c.register_cli_argument('vm', 'zone', zone_type) c.register_cli_argument('disk', 'zone', zone_type, options_list=['--zone']) # TODO: --size-gb currently has claimed -z. We can do a breaking change later if we want to. c.register_cli_argument('vmss', 'zones', zones_type) for item in ['show', 'list']: register_cli_argument('vm {}'.format(item), 'show_details', action='store_true', options_list=('--show-details', '-d'), help='show public ip address, FQDN, and power states. command will run slow') register_cli_argument('vm unmanaged-disk', 'vm_name', arg_type=existing_vm_name) register_cli_argument('vm unmanaged-disk attach', 'disk_name', options_list=('--name', '-n'), help='The data disk name(optional when create a new disk)')
#--------------------------------------------------------------------------------------------- # 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.core.commands import register_cli_argument from azure.cli.core.commands.parameters import ( resource_group_name_type, location_type, tags_type, get_resource_name_completion_list) from ._constants import (ACR_RESOURCE_TYPE, STORAGE_RESOURCE_TYPE) from ._validators import (validate_resource_group_name) register_cli_argument( 'acr', 'registry_name', options_list=('--name', '-n'), help='The name of the container registry', completer=get_resource_name_completion_list(ACR_RESOURCE_TYPE)) register_cli_argument( 'acr', 'storage_account_name', help='The name of an existing storage account', completer=get_resource_name_completion_list(STORAGE_RESOURCE_TYPE)) register_cli_argument('acr', 'resource_group_name', resource_group_name_type) register_cli_argument('acr', 'location', location_type) register_cli_argument('acr', 'tags', tags_type) register_cli_argument('acr', 'admin_enabled', help='Indicates whether the admin user is enabled', choices=['true', 'false'])
system = platform.system() if system == 'Windows': program_files = os.environ.get('ProgramFiles') if not program_files: return None install_location = '{}\\{}.exe'.format(program_files, exe_name) elif system == 'Linux' or system == 'Darwin': install_location = '/usr/local/bin/{}'.format(exe_name) else: install_location = None return install_location name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') register_cli_argument('acs', 'tags', tags_type) register_cli_argument('acs', 'name', arg_type=name_arg_type, configured_default='acs', help="ACS cluster name. You can configure the default using `az configure --defaults acs=<name>`", completer=get_resource_name_completion_list('Microsoft.ContainerService/ContainerServices')) register_cli_argument('acs', 'resource_group', arg_type=resource_group_name_type) register_cli_argument('acs', 'orchestrator_type', options_list=('--orchestrator-type', '-t'), **enum_choice_list(ContainerServiceOchestratorTypes)) # some admin names are prohibited in acs, such as root, admin, etc. Because we have no control on the orchestrators, so default to a safe name. register_cli_argument('acs', 'admin_username', options_list=('--admin-username',), default='azureuser', required=False) register_cli_argument('acs', 'dns_name_prefix', options_list=('--dns-prefix', '-d')) register_cli_argument('acs', 'container_service_name', options_list=('--name', '-n'), help='The name of the container service', completer=get_resource_name_completion_list('Microsoft.ContainerService/ContainerServices')) register_cli_argument('acs', 'ssh_key_value', required=False, help='SSH key file value or key file path.', type=file_type, default=os.path.join('~', '.ssh', 'id_rsa.pub'), completer=FilesCompleter()) register_cli_argument('acs create', 'name', arg_type=name_arg_type, validator=validate_ssh_key)
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', 'retry_wait', options_list=('--retry-interval', )) register_cli_argument('storage', 'progress_callback', ignore_type) register_cli_argument( 'storage', 'metadata', nargs='+', help= 'Metadata in space-separated key=value pairs. This overwrites any existing metadata.', validator=validate_metadata) register_cli_argument( 'storage',
def ignore(self, argument): return register_cli_argument(self._scope, argument, ignore_type)
from azure.cli.core.commands.parameters import ( ignore_type, resource_group_name_type, tag_type, tags_type, get_resource_group_completion_list, enum_choice_list, no_wait_type, file_type) from .custom import (get_policy_completion_list, get_policy_assignment_completion_list, get_resource_types_completion_list, get_providers_completion_list) from ._validators import validate_deployment_name # BASIC PARAMETER CONFIGURATION resource_name_type = CliArgumentType(options_list=('--name', '-n'), help='The resource name. (Ex: myC)') _PROVIDER_HELP_TEXT = 'the resource namespace, aka \'provider\'' register_cli_argument('resource', 'no_wait', no_wait_type) register_cli_argument('resource', 'resource_name', resource_name_type) register_cli_argument('resource', 'api_version', help='The api version of the resource (omit for latest)', required=False) register_cli_argument('resource', 'resource_id', options_list=('--id', ), help='Resource ID') register_cli_argument('resource', 'resource_provider_namespace', options_list=('--namespace', ), completer=get_providers_completion_list, help="Provider namespace (Ex: 'Microsoft.Provider')") register_cli_argument(
def argument(self, argument_name, arg_type=None, **kwargs): register_cli_argument(self._commmand, argument_name, arg_type=arg_type, **kwargs)
load_params('postgres', postgresql) ##### # register cli arguments ##### server_completers = { 'mysql': get_resource_name_completion_list('Microsoft.DBForMySQL/servers'), 'postgres': get_resource_name_completion_list('Microsoft.DBForPostgreSQL/servers') } for command_group_name in ['mysql', 'postgres']: register_cli_argument('{0}'.format(command_group_name), 'name', options_list=('--sku-name', )) register_cli_argument('{0}'.format(command_group_name), 'server_name', completer=server_completers[command_group_name], options_list=('--server-name', '-s')) register_cli_argument('{0} server'.format(command_group_name), 'server_name', options_list=('--name', '-n'), id_part='name', help='Name of the server.') register_cli_argument('{0} server'.format(command_group_name), 'administrator_login', options_list=('--admin-user', '-u')) register_cli_argument('{0} server'.format(command_group_name),
# ARGUMENT DEFINITIONS # pylint: disable=line-too-long datalake_analytics_name_type = CliArgumentType( help='Name of the Data Lake Analytics account.', options_list=('--account_name', ), completer=get_resource_name_completion_list( 'Microsoft.DataLakeAnalytics/accounts'), id_part='name') # PARAMETER REGISTRATIONS # data lake analytics common params register_cli_argument( 'dla', 'resource_group_name', resource_group_name_type, id_part=None, required=False, help= 'If not specified, will attempt to discover the resource group for the specified Data Lake Analytics account.', validator=validate_resource_group_name) register_cli_argument('dla', 'top', help='Maximum number of items to return.', type=int) register_cli_argument( 'dla', 'skip', help='The number of items to skip over before returning elements.', type=int) register_cli_argument( 'dla',
def ignore(self, argument): return register_cli_argument(self._scope, argument, ignore_type)
def get_device_id_completion_list(prefix, action, parsed_args, **kwargs): #pylint: disable=unused-argument client = iot_hub_service_factory(kwargs) return [ d.device_id for d in iot_device_list(client, parsed_args.hub_name, top=100) ] if parsed_args.hub_name else [] hub_name_type = CliArgumentType( completer=get_resource_name_completion_list('Microsoft.Devices/IotHubs'), help='IoT Hub name.') register_cli_argument('iot hub', 'hub_name', hub_name_type, options_list=('--name', '-n')) for subgroup in ['consumer-group', 'policy']: register_cli_argument('iot hub {}'.format(subgroup), 'hub_name', options_list=('--hub-name', )) register_cli_argument('iot device', 'hub_name', hub_name_type) register_cli_argument('iot', 'device_id', options_list=('--device-id', '-d'), help='Device Id.', completer=get_device_id_completion_list) # Arguments for 'iot hub consumer-group' group
def argument(self, argument_name, arg_type=None, **kwargs): register_cli_argument(self._commmand, argument_name, arg_type=arg_type, **kwargs)
table_payload_formats = {'none': TablePayloadFormat.JSON_NO_METADATA, 'minimal': TablePayloadFormat.JSON_MINIMAL_METADATA, 'full': TablePayloadFormat.JSON_FULL_METADATA} # 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', 'retry_wait', options_list=('--retry-interval',)) register_cli_argument('storage', 'progress_callback', ignore_type) register_cli_argument('storage', 'metadata', nargs='+', help='Metadata in space-separated key=value pairs. This overwrites any existing metadata.', 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', 'if_modified_since', help='Alter only if modified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')', type=datetime_type, arg_group='Pre-condition') register_cli_argument('storage', 'if_unmodified_since', help='Alter only if unmodified since supplied UTC datetime (Y-m-d\'T\'H:M\'Z\')', type=datetime_type, arg_group='Pre-condition') register_cli_argument('storage', 'if_match', arg_group='Pre-condition') register_cli_argument('storage', 'if_none_match', arg_group='Pre-condition') register_cli_argument('storage', 'container_name', container_name_type) for item in ['check-name', 'delete', 'list', 'show', 'show-usage', 'update', 'keys']:
def ignore(self, argument_name): register_cli_argument(self._commmand, argument_name, ignore_type)
# pylint: disable=line-too-long def get_cloud_name_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument return [c.name for c in get_clouds()] def get_custom_cloud_name_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument return [c.name for c in get_custom_clouds()] active_cloud_name = get_active_cloud_name() register_cli_argument('cloud', 'cloud_name', options_list=('--name', '-n'), help='Name of a registered cloud', completer=get_cloud_name_completion_list) register_cli_argument('cloud show', 'cloud_name', help='Name of a registered cloud.', default=active_cloud_name) register_cli_argument('cloud update', 'cloud_name', help='Name of a registered cloud.', default=active_cloud_name) register_cli_argument('cloud list-profiles', 'cloud_name', help='Name of a registered cloud.', default=active_cloud_name) register_cli_argument('cloud list-profiles', 'show_all', help='Show all available profiles supported in the CLI.', action='store_true') register_cli_argument('cloud register', 'cloud_name', completer=None) register_cli_argument('cloud unregister', 'cloud_name', completer=get_custom_cloud_name_completion_list)
from azure.cli.command_modules.batch._validators import \ (application_enabled, datetime_format, storage_account_id, application_package_reference_format, validate_pool_resize_parameters, metadata_item_format, certificate_reference_format, validate_json_file, validate_cert_file, keyvault_id, environment_setting_format, validate_cert_settings, resource_file_format, load_node_agent_skus) from azure.cli.command_modules.batch._command_type import validate_client_parameters # pylint: disable=line-too-long # ARGUMENT DEFINITIONS batch_name_type = CliArgumentType(help='Name of the Batch account.', options_list=('--account-name',), completer=get_resource_name_completion_list('Microsoft.Batch/batchAccounts'), id_part=None) # PARAMETER REGISTRATIONS register_cli_argument('batch', 'resource_group_name', resource_group_name_type, help='Name of the resource group', completer=None, validator=None) register_cli_argument('batch account', 'account_name', batch_name_type, options_list=('--name', '-n')) register_cli_argument('batch account create', 'location', location_type, help='The region in which to create the account.') register_cli_argument('batch account create', 'tags', tags_type, help="Space separated tags in 'key[=value]' format.") register_cli_argument('batch account create', 'storage_account', help='The storage account name or resource ID to be used for auto storage.', validator=storage_account_id) register_cli_argument('batch account create', 'keyvault', help='The KeyVault name or resource ID to be used for an account with a pool allocation mode of \'User Subscription\'.', validator=keyvault_id) register_cli_argument('batch account create', 'keyvault_url', ignore_type) register_cli_argument('batch account set', 'tags', tags_type) register_cli_argument('batch account set', 'storage_account', help='The storage account name or resource ID to be used for auto storage.', validator=storage_account_id) register_cli_argument('batch account keys renew', 'key_name', **enum_choice_list(AccountKeyType)) register_cli_argument('batch account login', 'shared_key_auth', action='store_true', help='Using Shared Key authentication, if not specified, it will use Azure Active Directory authentication.') register_cli_argument('batch application set', 'application_id', options_list=('--application-id',), help="The ID of the application.") register_cli_argument('batch application set', 'allow_updates', options_list=('--allow-updates',), help="Specify to indicate whether packages within the application may be overwritten using the same version string. Specify either 'true' or 'false' to update the property.") register_cli_argument('batch application create', 'allow_updates', options_list=('--allow-updates',), action="store_true", help="Specify to indicate whether packages within the application may be overwritten using the same version string. True if flag present.") register_cli_argument('batch application package create', 'package_file', type=file_type, help='The path of the application package in zip format', completer=FilesCompleter())
def reg_arg(self, *args, **kwargs): return register_cli_argument(self._scope, *args, **kwargs)
resource_name_type = CliArgumentType(options_list=('--name', '-n'), help='The resource name. (Ex: myC)') resource_type_type = CliArgumentType( help="The resource type (Ex: 'resC'). Can also accept namespace/type" " format (Ex: 'Microsoft.Provider/resC')") resource_namespace_type = CliArgumentType( options_list=('--namespace', ), completer=get_providers_completion_list, help="Provider namespace (Ex: 'Microsoft.Provider')") resource_parent_type = CliArgumentType( required=False, options_list=('--parent', ), help="The parent path (Ex: 'resA/myA/resB/myB')") _PROVIDER_HELP_TEXT = 'the resource namespace, aka \'provider\'' register_cli_argument('resource', 'no_wait', no_wait_type) register_cli_argument('resource', 'resource_name', resource_name_type) register_cli_argument('resource', 'api_version', help='The api version of the resource (omit for latest)', required=False) register_cli_argument('resource', 'resource_provider_namespace', resource_namespace_type) register_cli_argument('resource', 'resource_type', arg_type=resource_type_type, completer=get_resource_types_completion_list) register_cli_argument('resource', 'parent_resource_path', resource_parent_type) register_cli_argument('resource', 'tag', tag_type) register_cli_argument('resource', 'tags', tags_type) register_cli_argument(
def ignore(self, argument_name): register_cli_argument(self._commmand, argument_name, ignore_type)
FirewallAllowAzureIpsState, AADObjectType) from azure.mgmt.datalake.analytics.job.models.data_lake_analytics_job_management_client_enums \ import (CompileMode, JobState, JobResult) # ARGUMENT DEFINITIONS # pylint: disable=line-too-long datalake_analytics_name_type = CliArgumentType(help='Name of the Data Lake Analytics account.', options_list=('--account_name',), completer=get_resource_name_completion_list('Microsoft.DataLakeAnalytics/accounts'), id_part='name') # PARAMETER REGISTRATIONS # data lake analytics common params register_cli_argument('dla', 'resource_group_name', resource_group_name_type, id_part=None, required=False, help='If not specified, will attempt to discover the resource group for the specified Data Lake Analytics account.', validator=validate_resource_group_name) register_cli_argument('dla', 'top', help='Maximum number of items to return.', type=int) register_cli_argument('dla', 'skip', help='The number of items to skip over before returning elements.', type=int) register_cli_argument('dla', 'count', help='The Boolean value of true or false to request a count of the matching resources included with the resources in the response, e.g. Categories?$count=true.', type=bool) # account params register_cli_argument('dla', 'account_name', datalake_analytics_name_type, options_list=('--account', '-n')) register_cli_argument('dla account', 'tags', tags_type) register_cli_argument('dla account', 'tier', help='The desired commitment tier for this account to use.', **enum_choice_list(TierType)) register_cli_argument('dla account create', 'resource_group_name', resource_group_name_type, validator=None) register_cli_argument('dla account create', 'account_name', datalake_analytics_name_type, options_list=('--account', '-n'), completer=None) register_cli_argument('dla account update', 'firewall_state', help='Enable/disable existing firewall rules.', **enum_choice_list(FirewallState)) register_cli_argument('dla account update', 'allow_azure_ips', help='Allow/block Azure originating IPs through the firewall', **enum_choice_list(FirewallAllowAzureIpsState)) register_cli_argument('dla account update', 'max_job_count', help='The maximum supported jobs running under the account at the same time.', type=int) register_cli_argument('dla account update', 'max_degree_of_parallelism', help='The maximum supported degree of parallelism for this account.', type=int) register_cli_argument('dla account update', 'query_store_retention', help='The number of days that job metadata is retained.', type=int)
def register(self, argument_name, options_list, **kwargs): register_cli_argument(self._commmand, argument_name, options_list=options_list, **kwargs)
# workaround an api defect, that 'name' is '<webapp>/<hostname>' return [r.name.split('/', 1)[1] for r in result] # pylint: disable=line-too-long # PARAMETER REGISTRATION name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') sku_arg_type = CliArgumentType(help='The pricing tiers, e.g., F1(Free), D1(Shared), B1(Basic Small), B2(Basic Medium), B3(Basic Large), S1(Standard Small), P1(Premium Small), etc', **enum_choice_list(['F1', 'FREE', 'D1', 'SHARED', 'B1', 'B2', 'B3', 'S1', 'S2', 'S3', 'P1', 'P2', 'P3'])) webapp_name_arg_type = CliArgumentType(configured_default='web', options_list=('--name', '-n'), metavar='NAME', completer=get_resource_name_completion_list('Microsoft.Web/sites'), id_part='name', help="name of the web. You can configure the default using 'az configure --defaults web=<name>'") # use this hidden arg to give a command the right instance, that functionapp commands # work on function app and webapp ones work on web app register_cli_argument('webapp', 'app_instance', ignore_type) register_cli_argument('functionapp', 'app_instance', ignore_type) # function app doesn't have slot support register_cli_argument('functionapp', 'slot', ignore_type) register_cli_argument('appservice', 'resource_group_name', arg_type=resource_group_name_type) register_cli_argument('appservice', 'location', arg_type=location_type) register_cli_argument('appservice list-locations', 'linux_workers_enabled', action='store_true', help='get regions which support hosting webapps on Linux workers') register_cli_argument('appservice list-locations', 'sku', arg_type=sku_arg_type) register_cli_argument('appservice plan', 'name', arg_type=name_arg_type, help='The name of the app service plan', completer=get_resource_name_completion_list('Microsoft.Web/serverFarms'), id_part='name') register_cli_argument('appservice plan create', 'name', options_list=('--name', '-n'), help="Name of the new app service plan", completer=None) register_cli_argument('appservice plan create', 'sku', arg_type=sku_arg_type) register_cli_argument('appservice plan create', 'is_linux', action='store_true', required=False, help='host webapp on Linux worker') register_cli_argument('appservice plan update', 'sku', arg_type=sku_arg_type) register_cli_argument('appservice plan update', 'allow_pending_state', ignore_type)
def reg_arg(self, *args, **kwargs): return register_cli_argument(self._scope, *args, **kwargs)
# -------------------------------------------------------------------------------------------- # 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.core.commands import register_cli_argument from azure.cli.core.cloud import get_clouds from azure.cli.core.context import get_contexts # pylint: disable=line-too-long def get_cloud_name_completion_list(prefix, action, parsed_args, **kwargs):#pylint: disable=unused-argument return [c.name for c in get_clouds()] def get_context_completion_list(prefix, action, parsed_args, **kwargs):#pylint: disable=unused-argument return [c['name'] for c in get_contexts()] register_cli_argument('context', 'context_name', options_list=('--name', '-n'), help='Name of context', completer=get_context_completion_list) register_cli_argument('context', 'cloud_name', options_list=('--cloud',), help='Name of the registered cloud', completer=get_cloud_name_completion_list) register_cli_argument('context modify', 'context_name', help='Name of the context to modify. If not specified, we use the current context') register_cli_argument('context modify', 'default_subscription', help='Name or id of the default subscription to be used with this context') register_cli_argument('context show', 'context_name', help='Name of the context to modify. If not specified, we use the current context') register_cli_argument('context create', 'use_later', action='store_true', help='After creating the context, do not set it to be active immediately.') register_cli_argument('context create', 'context_name', completer=None)
# -------------------------------------------------------------------------------------------- # 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.core.commands import register_cli_argument # pylint: disable=line-too-long register_cli_argument('component', 'component_name', options_list=('--name', '-n'), help='Name of component') register_cli_argument('component', 'link', 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', help='Include packages from a private server.', action='store_true') register_cli_argument('component', 'pre', help='Include pre-release versions', action='store_true') register_cli_argument('component', 'show_logs', help='Show logs from packaging installing/updating', action='store_true') register_cli_argument('component', 'additional_components', options_list=('--add',), nargs='+', help='The names of additional components to install (space separated)')
# -------------------------------------------------------------------------------------------- # 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.cli.core.commands import CliArgumentType from azure.cli.core.commands import register_cli_argument from azure.cli.core.commands.parameters import enum_choice_list from .custom import get_role_definition_name_completion_list 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', 'available_to_other_tenants', action='store_true', help='the application can be used from any Azure AD tenants') register_cli_argument('ad app', 'key_value', help='the value for the key credentials associated with the application') # TODO: Update these with **enum_choice_list(...) when SDK supports proper enums register_cli_argument('ad app', 'key_type', default='AsymmetricX509Cert', help='the type of the key credentials associated with the application', **enum_choice_list(['AsymmetricX509Cert', 'Password', 'Symmetric'])) register_cli_argument('ad app', 'key_usage', default='Verify', help='the usage of the key credentials associated with the application.', **enum_choice_list(['Sign', 'Verify'])) name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME')
location = get_one_of_subscription_locations() result = get_vm_sizes(location) return [r.name for r in result] # REUSABLE ARGUMENT DEFINITIONS 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') vmss_name_type = CliArgumentType(name_arg_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'), help='Scale set name.', id_part='name') # ARGUMENT REGISTRATION register_cli_argument('vm', 'vm_name', existing_vm_name) register_cli_argument('vm', 'size', completer=get_vm_size_completion_list) register_cli_argument('vm', 'tags', tags_type) register_cli_argument('vm', 'name', arg_type=name_arg_type) for item in ['show', 'list']: register_cli_argument('vm {}'.format(item), 'show_details', action='store_true', options_list=('--show-details', '-d'), help='show public ip address, FQDN, and power states. command will run slow') register_cli_argument('vm disk', 'vm_name', arg_type=existing_vm_name, options_list=('--vm-name',)) register_cli_argument('vm disk', 'disk_name', options_list=('--name', '-n'), help='The data disk name. If missing, will retrieve from vhd uri') register_cli_argument('vm disk', 'disk_size', help='Size of disk (GiB)', default=1023, type=int) register_cli_argument('vm disk', 'lun', type=int, help='0-based logical unit number (LUN). Max value depends on the Virutal Machine size.') register_cli_argument('vm disk', 'vhd', type=VirtualHardDisk, help='virtual hard disk\'s uri. For example:https://mystorage.blob.core.windows.net/vhds/d1.vhd') register_cli_argument('vm disk', 'caching', help='Host caching policy', default=CachingTypes.none.value, **enum_choice_list(CachingTypes)) for item in ['attach-existing', 'attach-new', 'detach']:
help=argparse.SUPPRESS, required=False, validator=generate_deployment_name ) quotes = '""' if platform.system() == 'Windows' else "''" quote_text = 'Use {} to clear existing tags.'.format(quotes) tags_type = CliArgumentType( validator=validate_tags, help="space separated tags in 'key[=value]' format. {}".format(quote_text), nargs='*' ) tag_type = CliArgumentType( type=validate_tag, help="a single tag in 'key[=value]' format. {}".format(quote_text), nargs='?', const='' ) no_wait_type = CliArgumentType( options_list=('--no-wait', ), help='do not wait for the long running operation to finish', action='store_true' ) 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.cli.core.commands import CliArgumentType from azure.cli.core.commands import register_cli_argument from azure.cli.core.commands.parameters import enum_choice_list from .custom import get_role_definition_name_completion_list 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',
class ScheduleEntryList(list): def __init__(self, value): super(ScheduleEntryList, self).__init__() if value[0] in ("'", '"') and value[-1] == value[0]: # Remove leading and trailing quotes for dos/cmd.exe users value = value[1:-1] dictval = shell_safe_json_parse(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, help='Name of the redis cache.', 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', **enum_choice_list(RebootType)) register_cli_argument('redis', 'key_type', **enum_choice_list(RedisKeyType)) register_cli_argument('redis', 'shard_id', type=int) register_cli_argument('redis', 'sku', **enum_choice_list(SkuName)) register_cli_argument('redis', 'vm_size', help='Size of redis cache to deploy. ' 'Example : values for C family (C0, C1, C2, C3, C4, C5, C6). ' 'For P family (P1, P2, P3, P4)') register_cli_argument('redis', 'enable_non_ssl_port', action='store_true') register_cli_argument('redis', 'shard_count', type=int) register_cli_argument('redis', 'subnet_id') register_cli_argument('redis import-method', 'files', nargs='+')
# pylint: disable=line-too-long def get_cloud_name_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument return [c.name for c in get_clouds()] def get_custom_cloud_name_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument return [c.name for c in get_custom_clouds()] register_cli_argument('cloud', 'cloud_name', options_list=('--name', '-n'), help='Name of the registered cloud', completer=get_cloud_name_completion_list) register_cli_argument( 'cloud show', 'cloud_name', help= 'Name of the registered cloud. If not specified, we use the current active cloud.' ) register_cli_argument( 'cloud update', 'cloud_name', help= 'Name of the registered cloud. If not specified, we use the current active cloud.' )
from azure.cli.core.commands.parameters import \ location_type, enum_choice_list, get_resource_name_completion_list, CliArgumentType from azure.cli.core.commands import register_cli_argument from azure.mgmt.iothub.models.iot_hub_client_enums import IotHubSku from ._factory import iot_hub_service_factory from .custom import iot_device_list, KeyType def get_device_id_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument client = iot_hub_service_factory(kwargs) return [d.device_id for d in iot_device_list(client, parsed_args.hub_name, top=100)] if parsed_args.hub_name else [] hub_name_type = CliArgumentType(completer=get_resource_name_completion_list('Microsoft.Devices/IotHubs'), help='IoT Hub name.') register_cli_argument('iot hub', 'hub_name', hub_name_type, options_list=('--name', '-n')) for subgroup in ['consumer-group', 'policy', 'job']: register_cli_argument('iot hub {}'.format(subgroup), 'hub_name', options_list=('--hub-name',)) register_cli_argument('iot device', 'hub_name', hub_name_type) register_cli_argument('iot', 'device_id', options_list=('--device-id', '-d'), help='Device Id.', completer=get_device_id_completion_list) # Arguments for 'iot hub consumer-group' group register_cli_argument('iot hub consumer-group', 'consumer_group_name', options_list=('--name', '-n'), help='Event hub consumer group name.') register_cli_argument('iot hub consumer-group', 'event_hub_name', help='Target event hub name.') # Arguments for 'iot hub policy' group register_cli_argument('iot hub policy', 'policy_name', options_list=('--name', '-n'), help='Share access policy name.')