def test_register_command(self): command_table.clear() cli_command(None, 'test command sample-vm-get', '{}#Test_command_registration.sample_vm_get'.format(__name__), None) self.assertEqual(len(command_table), 1, 'We expect exactly one command in the command table') command_table['test command sample-vm-get'].load_arguments() command_metadata = command_table['test command 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, help='The name of the resource group.'), 'vm_name': CliArgumentType(dest='vm_name', required=True, help='The name of the virtual machine.'), 'opt_param': CliArgumentType(required=False, help='Used to verify reflection correctly identifies optional params.'), # pylint: disable=line-too-long 'expand': CliArgumentType(required=False, help='The expand expression to apply on the operation.') } 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['resource_group_name'].options_list, ['--resource-group-name'])
def test_override_argtype_with_argtype(self): existing_options_list = ('--default', '-d') arg = CliArgumentType(options_list=existing_options_list, validator=None, completer='base', help='base', required=True) overriding_argtype = CliArgumentType(options_list=('--overridden', ), validator='overridden', completer=None, overrides=arg, help='overridden', required=CliArgumentType.REMOVE) self.assertEqual(overriding_argtype.settings['validator'], 'overridden') self.assertEqual(overriding_argtype.settings['completer'], None) self.assertEqual(overriding_argtype.settings['options_list'], ('--overridden', )) self.assertEqual(overriding_argtype.settings['help'], 'overridden') self.assertEqual(overriding_argtype.settings['required'], CliArgumentType.REMOVE) cmd_arg = CliCommandArgument(dest='whatever', argtype=overriding_argtype, help=CliArgumentType.REMOVE) self.assertFalse('required' in cmd_arg.options) self.assertFalse('help' in cmd_arg.options)
def test_override_existing_option_string(self): arg = CliArgumentType(options_list=('--funky', '-f')) updated_options_list = ('--something-else', '-s') arg.update(options_list=updated_options_list, validator=lambda: (), completer=lambda: ()) self.assertEqual(arg.settings['options_list'], updated_options_list) self.assertIsNotNone(arg.settings['validator']) self.assertIsNotNone(arg.settings['completer'])
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_command_build_argument_help_text(self): def sample_sdk_method_with_weird_docstring(param_a, param_b, param_c): # pylint: disable=unused-argument """ An operation with nothing good. :param dict param_a: :param param_b: The name of nothing. :param param_c: The name of nothing2. """ command_table.clear() setattr(sys.modules[__name__], sample_sdk_method_with_weird_docstring.__name__, sample_sdk_method_with_weird_docstring) #pylint: disable=line-too-long cli_command(None, 'test command foo', '{}#{}'.format(__name__, sample_sdk_method_with_weird_docstring.__name__), None) #pylint: disable=line-too-long command_table['test command foo'].load_arguments() _update_command_definitions(command_table) command_metadata = command_table['test command foo'] self.assertEqual(len(command_metadata.arguments), 3, 'We expected exactly 3 arguments') some_expected_arguments = { 'param_a': CliArgumentType(dest='param_a', required=True, help=''), 'param_b': CliArgumentType(dest='param_b', required=True, help='The name of nothing.'), 'param_c': CliArgumentType(dest='param_c', required=True, help='The name of nothing2.') } 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) command_table.clear()
def test_register_extra_cli_argument(self): command_table.clear() cli_command( None, 'test command sample-vm-get', '{}#Test_command_registration.sample_vm_get'.format(__name__), None) register_extra_cli_argument('test command sample-vm-get', 'added_param', options_list=('--added-param', ), metavar='ADDED', help='Just added this right now!', required=True) command_table['test command 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 command sample-vm-get'] self.assertEqual(len(command_metadata.arguments), 5, 'We expected exactly 5 arguments') some_expected_arguments = { 'added_param': CliArgumentType(dest='added_param', required=True) } 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) 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()
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 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')
images = load_images_from_aliases_doc() return [i['urnAlias'] for i in images] def get_vm_size_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument try: location = parsed_args.location except AttributeError: 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='+') 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)
params = {'choices': CaseInsenstiveList(choices), 'type': _type} return params class IgnoreAction(argparse.Action): # pylint: disable=too-few-public-methods def __call__(self, parser, namespace, values, option_string=None): raise argparse.ArgumentError( None, 'unrecognized argument: {} {}'.format(option_string, values or '')) # GLOBAL ARGUMENT DEFINTIONS ignore_type = CliArgumentType(help=argparse.SUPPRESS, nargs='?', action=IgnoreAction, required=False) resource_group_name_type = CliArgumentType( options_list=('--resource-group', '-g'), completer=get_resource_group_completion_list, id_part='resource_group', 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, type=location_name_type, help='Location.',
'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 create-for-rbac', 'years', type=int) register_cli_argument('ad sp create-for-rbac', 'scopes', nargs='+') 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. # -------------------------------------------------------------------------------------------- from azure.cli.core.commands import CliArgumentType, register_cli_argument query = CliArgumentType(options_list=('--search-query', '-q'), help='Query text to find.', nargs='+') register_cli_argument('find', 'criteria', query)
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') 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', name_arg_type) register_cli_argument('ad sp create-for-rbac', 'years', type=int) register_cli_argument('ad sp create-for-rbac', 'scopes', nargs='+')
import itertools from enum import Enum from ._util import ParametersContext, patch_arg_make_required from azure.cli.core.commands import CliArgumentType from azure.mgmt.sql.models.database import Database from azure.mgmt.sql.models.elastic_pool import ElasticPool from azure.mgmt.sql.models.server import Server from azure.mgmt.sql.models.sql_management_client_enums import CreateMode ##### # Reusable param type definitions ##### server_param_type = CliArgumentType( options_list=('--server', '-s'), help='Name of the Azure SQL server.') ##### # SizeWithUnitConverter - consider moving to common code (azure.cli.commands.parameters) ##### class SizeWithUnitConverter(object): # pylint: disable=too-few-public-methods def __init__( self, unit='kB', result_type=int, unit_map=None):
register_cli_argument( 'cosmosdb update', 'ip_range_filter', validator=validate_ip_range_filter, help= "firewall support. Specifies the set of IP addresses or IP address ranges in CIDR form to be included as the allowed list of client IPs for a given database account. IP addresses/ranges must be comma separated and must not contain any spaces", nargs='+') register_cli_argument( 'cosmosdb update', 'enable_automatic_failover', help= 'Enables automatic failover of the write region in the rare event that the region is unavailable due to an outage. Automatic failover will result in a new write region for the account and is chosen based on the failover priorities configured for the account.', type=bool) # database id database_id = CliArgumentType(options_list=('--db-name', '-d'), help='Database Name') register_cli_argument('cosmosdb database', 'database_id', database_id) register_cli_argument('cosmosdb collection', 'database_id', database_id) register_cli_argument('cosmosdb collection', 'collection_id', options_list=('--collection-name', '-c'), help='Collection Name') register_cli_argument('cosmosdb collection', 'throughput', options_list=('--throughput'), help='Offer Throughput', type=int) register_cli_argument('cosmosdb collection',
def test_dont_override_existing_option_string(self): existing_options_list = ('--something-else', '-s') arg = CliArgumentType(options_list=existing_options_list) arg.update() self.assertEqual(arg.settings['options_list'], existing_options_list)
elif system == 'Linux' or system == 'Darwin': install_location = '/usr/local/bin/{}'.format(exe_name) else: install_location = None return install_location def _get_feature_in_preview_message(): return "Feature in preview, only in " + ", ".join(regionsInPreview) + ". " regionsInPreview = ["ukwest", "uksouth", "westcentralus", "westus2", "canadaeast", "canadacentral", "westindia", "southindia", "centralindia", "koreasouth", "koreacentral"] regionsInProd = ["australiasoutheast", "northeurope", "brazilsouth", "australiaeast", "japaneast", "northcentralus", "westus", "eastasia", "eastus2", "southcentralus", "southeastasia", "eastus", "westeurope", "centralus", "japanwest"] name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') orchestratorTypes = ["Custom", "DCOS", "Kubernetes", "Swarm", "DockerCE"] aci_connector_os_type = ['Windows', 'Linux', 'Both'] aci_connector_chart_url = 'https://github.com/virtual-kubelet/virtual-kubelet/raw/master/charts/virtual-kubelet-0.1.0.tgz' k8s_version_arg_type = CliArgumentType(options_list=('--kubernetes-version', '-k'), metavar='KUBERNETES_VERSION') storageProfileTypes = ["StorageAccount", "ManagedDisks"] 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>`",
if parsed_args.resource_group_name and ag_name: ag = client.application_gateways.get(parsed_args.resource_group_name, ag_name) url_map = next((x for x in ag.url_path_maps if x.name == parsed_args.url_path_map_name), None) # pylint: disable=no-member return [r.name for r in url_map.path_rules] return completer def get_tm_endpoint_completion_list(): def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument return list_traffic_manager_endpoints(parsed_args.resource_group_name, parsed_args.profile_name) \ if parsed_args.resource_group_name and parsed_args.profile_name \ else [] return completer # BASIC PARAMETER CONFIGURATION name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') nic_type = CliArgumentType(options_list=('--nic-name',), metavar='NIC_NAME', help='The network interface (NIC).', id_part='name', completer=get_resource_name_completion_list('Microsoft.Network/networkInterfaces')) nsg_name_type = CliArgumentType(options_list=('--nsg-name',), metavar='NSG', help='Name of the network security group.') circuit_name_type = CliArgumentType(options_list=('--circuit-name',), metavar='CIRCUIT', help='ExpressRoute circuit name.', id_part='name', completer=get_resource_name_completion_list('Microsoft.Network/expressRouteCircuits')) 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(**enum_choice_list(ApplicationGatewayCookieBasedAffinity)) http_protocol_type = CliArgumentType(**enum_choice_list(ApplicationGatewayProtocol)) 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)
def test_override_remove_validator(self): existing_options_list = ('--something-else', '-s') arg = CliArgumentType(options_list=existing_options_list, validator=lambda *args, **kwargs: ()) arg.update(validator=None) self.assertIsNone(arg.settings['validator'])
from azure.cli.core.commands import \ (register_cli_argument, CliArgumentType, register_extra_cli_argument) from azure.cli.core.commands.parameters import \ (tags_type, location_type, resource_group_name_type, ignore_type, get_resource_name_completion_list, enum_choice_list, file_type) from azure.cli.command_modules.batch._validators import \ (application_enabled, datetime_format, storage_account_id, application_package_reference_format, validate_client_parameters, 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) # 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.')
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_set_completion_list, get_policy_assignment_completion_list, get_resource_types_completion_list, get_providers_completion_list) from ._validators import (process_deployment_create_namespace, validate_lock_parameters, validate_subscription_lock, validate_group_lock, validate_resource_lock) # BASIC PARAMETER CONFIGURATION 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',
} return params class IgnoreAction(argparse.Action): # pylint: disable=too-few-public-methods def __call__(self, parser, namespace, values, option_string=None): raise argparse.ArgumentError(None, 'unrecognized argument: {} {}'.format( option_string, values or '')) # GLOBAL ARGUMENT DEFINITIONS ignore_type = CliArgumentType( help=argparse.SUPPRESS, nargs='?', action=IgnoreAction, required=False) resource_group_name_type = CliArgumentType( options_list=('--resource-group', '-g'), completer=get_resource_group_completion_list, id_part='resource_group', help="Name of resource group. You can configure the default group using `az configure --defaults group=<name>`", configured_default='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,
# pylint: disable=line-too-long from argcomplete.completers import FilesCompleter from azure.mgmt.resource.resources.models import DeploymentMode from azure.cli.core.commands import register_cli_argument, CliArgumentType from azure.cli.core.commands.parameters import ( ignore_type, resource_group_name_type, tag_type, tags_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_name_type = CliArgumentType(options_list=('--name', '-n'), help='The resource name.') 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) for item in ['tag', 'update', 'show', 'delete', 'exists']: register_cli_argument('resource {}'.format(item), 'resource_provider_namespace', ignore_type) register_cli_argument('resource', 'resource_type', help='The resource type in <namespace>/<type> format.', type=validate_resource_type,
} delete_snapshot_types = { 'include': DeleteSnapshot.Include, 'only': DeleteSnapshot.Only } 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.',
# -------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- import os from azure.cli.core.commands import (CliArgumentType, register_cli_argument) from azure.cli.core.commands.parameters import ( resource_group_name_type, location_type) # pylint: disable=line-too-long,invalid-name remote_access_token = CliArgumentType( options_list=('--remote-access-token', '-t'), help='GitHub personal access token.' ) project_path = CliArgumentType( options_list=('--project-path', '-p'), help='Project/Services path to deploy on the Kubernetes cluster or defaults to current directory.', default='.', required=False ) ssh_private_key = CliArgumentType( options_list=('--ssh-private-key', '-k'), help='Path to SSH private key. Please provide the full path.', default=os.path.join( os.path.expanduser("~"), '.ssh', 'id_rsa'), required=False
from azure.mgmt.datalake.analytics.account.models.data_lake_analytics_account_management_client_enums \ import (FirewallState, TierType, FirewallAllowAzureIpsState) 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',
result = get_vm_sizes(location) return [r.name for r in result] # CHOICE LISTS 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] # 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')
from azure.mgmt.resource.resources.models import DeploymentMode from azure.cli.core.commands import register_cli_argument, CliArgumentType 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,
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) # ARGUMENT DEFINITIONS vault_name_type = CliArgumentType( help='Name of the key vault.', options_list=('--vault-name', ), metavar='NAME', completer=get_resource_name_completion_list('Microsoft.KeyVault/vaults'), id_part=None) # PARAMETER REGISTRATIONS register_cli_argument( 'keyvault', 'resource_group_name', resource_group_name_type, id_part=None, required=False, help='Proceed only if Key Vault belongs to the specified resource group.', validator=validate_resource_group_name) register_cli_argument('keyvault', 'vault_name',