diff --git a/azure-cli.pyproj b/azure-cli.pyproj index 131d0a662ba..3326445dda5 100644 --- a/azure-cli.pyproj +++ b/azure-cli.pyproj @@ -30,6 +30,7 @@ + Code diff --git a/src/azure/cli/application.py b/src/azure/cli/application.py index d2b710984d2..25372da6f00 100644 --- a/src/azure/cli/application.py +++ b/src/azure/cli/application.py @@ -36,6 +36,7 @@ class Application(object): COMMAND_PARSER_CREATED = 'CommandParser.Created' COMMAND_PARSER_LOADED = 'CommandParser.Loaded' COMMAND_PARSER_PARSED = 'CommandParser.Parsed' + COMMAND_TABLE_LOADED = 'CommandTable.Loaded' def __init__(self, configuration): self._event_handlers = defaultdict(lambda: []) @@ -45,6 +46,7 @@ def __init__(self, configuration): self.register(self.GLOBAL_PARSER_CREATED, Application._register_builtin_arguments) self.register(self.COMMAND_PARSER_LOADED, Application._enable_autocomplete) self.register(self.COMMAND_PARSER_PARSED, self._handle_builtin_arguments) + self.register(self.COMMAND_PARSER_PARSED, self._resolve_computed_values) # Let other extensions make their presence known azure.cli.extensions.register_extensions(self) @@ -57,6 +59,7 @@ def __init__(self, configuration): def execute(self, argv): command_table = self.configuration.get_command_table() + self.raise_event(self.COMMAND_TABLE_LOADED, command_table) self.parser.load_command_table(command_table) self.raise_event(self.COMMAND_PARSER_LOADED, self.parser) @@ -148,3 +151,9 @@ def _register_builtin_arguments(parser): def _handle_builtin_arguments(self, args): self.configuration.output_format = args._output_format #pylint: disable=protected-access del args._output_format + + @staticmethod + def _resolve_computed_values(args): + for value in args.__dict__.values(): + if callable(value) and getattr(value, 'computed', False): + value(args) diff --git a/src/azure/cli/commands/__init__.py b/src/azure/cli/commands/__init__.py index 4ea84bb5d76..c80aa6891cb 100644 --- a/src/azure/cli/commands/__init__.py +++ b/src/azure/cli/commands/__init__.py @@ -15,11 +15,10 @@ COMMON_PARAMETERS = { 'resource_group_name': { - 'name': '--resource-group -g', - 'dest': RESOURCE_GROUP_ARG_NAME, + 'name': 'resource_group_name', 'metavar': 'RESOURCEGROUP', 'help': 'The name of the resource group.', - 'required': True + '_semantic_type': 'resource_group_name', }, 'location': { 'name': '--location -l', @@ -116,6 +115,20 @@ def wrapper(func): return func return wrapper +def computed_value(func): + '''For options that have values that are computed based on the + value of other arguments, we extend the "normal" argparse options + to allow for a computed default value. + + Example: + { name='--hello -h', 'default': computed_value(lambda args: return args.foo + args.bar) } + ''' + def wrapped(args): + return func(args) + + setattr(wrapped, 'computed', True) + return wrapped + def _get_command_table(module_name): module = import_module('azure.cli.command_modules.' + module_name) return module.command_table diff --git a/src/azure/cli/extensions/__init__.py b/src/azure/cli/extensions/__init__.py index 84dffe9399f..611ba8901f7 100644 --- a/src/azure/cli/extensions/__init__.py +++ b/src/azure/cli/extensions/__init__.py @@ -1,6 +1,8 @@ from .query import register as register_query from .transform import register as register_transform +from .id import register as register_id def register_extensions(application): register_query(application) register_transform(application) + register_id(application) diff --git a/src/azure/cli/extensions/id.py b/src/azure/cli/extensions/id.py new file mode 100644 index 00000000000..4b61a1c3538 --- /dev/null +++ b/src/azure/cli/extensions/id.py @@ -0,0 +1,52 @@ +import argparse +from azure.cli.commands import computed_value + +def register(application): + def split_id(source, target): + def split(namespace): + try: + idstr = getattr(namespace, source) + parts = idstr.split('/') + setattr(namespace, target, parts[8]) + setattr(namespace, source, parts[4]) + except Exception: + raise RuntimeError( + 'Invalid RESOURCEID "{0}". You have to specify a RESOURCEGROUP and NAME or a valid RESOURCEID' # pylint: disable=line-too-long + .format(idstr)) + return split + + def annotate_id(command_table): + for command in command_table.values(): + arguments = command['arguments'] + rg_name = {arg['_semantic_type']: arg + for arg in arguments + if arg.get('_semantic_type', None) in ('resource_group_name', + 'resource_name')} + try: + rg = rg_name['resource_group_name'] + name = rg_name['resource_name'] + arguments.remove(rg) + arguments.remove(name) + name_dest = name.get('dest') or \ + name.get('name').split()[0].replace('--', '', 1).replace('-', '_') + arguments.extend(( + { + 'name': rg.get('dest', 'resource_group_name'), + 'metavar': '(RESOURCEID | %s %s)' % (rg.get('metavar', 'RESOURCEGROUP'), + name.get('metavar', 'NAME')), + 'help': 'Resource ID or resource group name followed by resource name', + }, + { + 'name': name_dest, + 'help': argparse.SUPPRESS, + 'default': computed_value( + split_id( + rg.get('dest', 'resource_group_name'), + name.get('dest'))), + 'nargs': '?' + })) + except KeyError: + pass + + application.register(application.COMMAND_TABLE_LOADED, annotate_id) + diff --git a/src/azure/cli/parser.py b/src/azure/cli/parser.py index 095107e2efd..2199b56bf03 100644 --- a/src/azure/cli/parser.py +++ b/src/azure/cli/parser.py @@ -38,8 +38,9 @@ def load_command_table(self, command_table): parents=self.parents, conflict_handler='resolve', help_file=metadata.get('help_file')) for arg in metadata['arguments']: - names = arg.get('name').split() - command_parser.add_argument(*names, **{k:v for k, v in arg.items() if k != 'name'}) + names = (arg.get('name') or '').split() + command_parser.add_argument(*names, **{k:v for k, v in arg.items() + if k != 'name' and not k.startswith('_')}) command_parser.set_defaults(func=handler) def _get_subparser(self, path): @@ -67,6 +68,12 @@ def _get_subparser(self, path): self.subparsers[tuple(path[0:length])] = parent_subparser return parent_subparser + def add_argument(self, *args, **kwargs): + if args and not args[0].startswith('-'): + kwargs.pop('dest', None) + kwargs.pop('required', None) + return super(AzCliCommandParser, self).add_argument(*args, **kwargs) + def format_help(self): is_group = not self._defaults.get('func') _help.show_help(self.prog.split()[1:], diff --git a/src/azure/cli/tests/test_autocommand.py b/src/azure/cli/tests/test_autocommand.py index 8c69dee12f8..9ab5ed43fb6 100644 --- a/src/azure/cli/tests/test_autocommand.py +++ b/src/azure/cli/tests/test_autocommand.py @@ -54,12 +54,13 @@ def test_autocommand_basic(self): self.assertEqual(command_metadata['name'], 'test autocommand sample-vm-get', 'Unexpected command name...') self.assertEqual(len(command_metadata['arguments']), 4, 'We expected exactly 4 arguments') some_expected_arguments = [ - {'name': '--resource-group -g', 'dest': 'resource_group_name', 'required': True, 'help':'The name of the resource group.'}, + {'name': 'resource_group_name', 'help':'The name of the resource group.'}, {'name': '--vm-name', 'dest': 'vm_name', 'required': True, 'help': 'The name of the virtual machine.'}, {'name': '--opt-param', 'required': False, 'help': 'Used to verify auto-command correctly identifies optional params.'}, {'name': '--expand', 'required': False, 'help': 'The expand expression to apply on the operation.'}, ] + print(command_metadata['arguments']) for probe in some_expected_arguments: existing = [arg for arg in command_metadata['arguments'] if arg['name'] == probe['name']][0] self.assertDictContainsSubset(probe, existing) @@ -89,7 +90,7 @@ def test_autocommand_with_parameter_alias(self): self.assertEqual(command_metadata['name'], 'test autocommand sample-vm-get', 'Unexpected command name...') self.assertEqual(len(command_metadata['arguments']), 4, 'We expected exactly 4 arguments') some_expected_arguments = [ - {'name': '--resource-group -g', 'dest': 'resource_group_name', 'required': True}, + {'name': 'resource_group_name' }, {'name': '--wonky-name -n', 'dest': 'vm_name', 'required': False}, ] @@ -122,7 +123,7 @@ def test_autocommand_with_extra_parameters(self): self.assertEqual(command_metadata['name'], 'test autocommand sample-vm-get', 'Unexpected command name...') self.assertEqual(len(command_metadata['arguments']), 5, 'We expected exactly 5 arguments') some_expected_arguments = [ - {'name': '--resource-group -g', 'dest': 'resource_group_name', 'required': True}, + {'name': 'resource_group_name' }, {'name': '--vm-name', 'dest': 'vm_name', 'required': True}, {'name': '--added-param', 'required': True}, ] diff --git a/src/command_modules/azure-cli-network/azure/cli/command_modules/network/__init__.py b/src/command_modules/azure-cli-network/azure/cli/command_modules/network/__init__.py index c15bffaa1b2..4e78b4b4f38 100644 --- a/src/command_modules/azure-cli-network/azure/cli/command_modules/network/__init__.py +++ b/src/command_modules/azure-cli-network/azure/cli/command_modules/network/__init__.py @@ -53,7 +53,7 @@ def _network_client_factory(_): ], command_table, { - 'application_gateway_name': {'name': '--name -n'} + 'application_gateway_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # ExpressRouteCircuitAuthorizationsOperations @@ -67,7 +67,7 @@ def _network_client_factory(_): ], command_table, { - 'authorization_name': {'name': '--name -n'} + 'authorization_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) @@ -82,7 +82,7 @@ def _network_client_factory(_): ], command_table, { - 'peering_name': {'name': '--name -n'} + 'peering_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # ExpressRouteCircuitsOperations @@ -100,7 +100,7 @@ def _network_client_factory(_): ], command_table, { - 'circuit_name': {'name': '--name -n'} + 'circuit_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # ExpressRouteServiceProvidersOperations @@ -124,7 +124,7 @@ def _network_client_factory(_): ], command_table, { - 'load_balancer_name': {'name': '--name -n'} + 'load_balancer_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # LocalNetworkGatewaysOperations @@ -138,7 +138,7 @@ def _network_client_factory(_): ], command_table, { - 'local_network_gateway_name': {'name': '--name -n'} + 'local_network_gateway_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) @@ -154,7 +154,7 @@ def _network_client_factory(_): ], command_table, { - 'network_interface_name': {'name': '--name -n'} + 'network_interface_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # NetworkInterfacesOperations: scaleset @@ -169,7 +169,7 @@ def _network_client_factory(_): command_table, { 'virtual_machine_scale_set_name': {'name': '--vm-scale-set'}, - 'network_interface_name': {'name': '--name -n'}, + 'network_interface_name': {'name': '--name -n', '_semantic_type': 'resource_name', }, 'virtualmachine_index': {'name': '--vm-index'} }) @@ -185,7 +185,7 @@ def _network_client_factory(_): ], command_table, { - 'network_security_group_name': {'name': '--name -n'} + 'network_security_group_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # PublicIPAddressesOperations @@ -200,7 +200,7 @@ def _network_client_factory(_): ], command_table, { - 'public_ip_address_name': {'name': '--name -n'} + 'public_ip_address_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # RouteTablesOperations @@ -215,7 +215,7 @@ def _network_client_factory(_): ], command_table, { - 'route_table_name': {'name': '--name -n'} + 'route_table_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) @@ -230,7 +230,7 @@ def _network_client_factory(_): ], command_table, { - 'route_name': {'name': '--name -n'} + 'route_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # SecurityRulesOperations @@ -244,8 +244,8 @@ def _network_client_factory(_): ], command_table, { - 'security_rule_name': {'name': '--name'}, - 'network_security_group_name': {'name': '--nsg-name'} + 'security_rule_name': {'name': '--name', '_semantic_type': 'resource_name', }, + 'network_security_group_name': {'name': '--nsg-name', '_semantic_type': 'resource_name', } }) # SubnetsOperations @@ -259,8 +259,8 @@ def _network_client_factory(_): ], command_table, { - 'subnet_name': {'name': '--name -n'}, - 'virtual_network_name': {'name': _VNET_PARAM_NAME} + 'subnet_name': {'name': '--name -n', '_semantic_type': 'resource_name', }, + 'virtual_network_name': {'name': _VNET_PARAM_NAME, '_semantic_type': 'resource_name', } }) # UsagesOperations @@ -283,7 +283,7 @@ def _network_client_factory(_): ], command_table, { - 'virtual_network_gateway_connection_name': {'name': '--name -n'} + 'virtual_network_gateway_connection_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # VirtualNetworkGatewayConnectionsOperations: shared-key @@ -297,8 +297,8 @@ def _network_client_factory(_): ], command_table, { - 'virtual_network_gateway_connection_name': {'name': '--connection-name'}, - 'connection_shared_key_name': {'name': '--name -n'} + 'virtual_network_gateway_connection_name': {'name': '--connection-name', '_semantic_type': 'resource_name', }, + 'connection_shared_key_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) @@ -314,7 +314,7 @@ def _network_client_factory(_): ], command_table, { - 'virtual_network_gateway_name': {'name': '--name -n'} + 'virtual_network_gateway_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # VirtualNetworksOperations @@ -329,7 +329,7 @@ def _network_client_factory(_): ], command_table, { - 'virtual_network_name': {'name': '--name -n'} + 'virtual_network_name': {'name': '--name -n', '_semantic_type': 'resource_name', } }) # BUG: we are waiting on autorest to support this rename (https://github.com/Azure/autorest/issues/941) @@ -369,8 +369,8 @@ def _network_client_factory(_): @command_table.command('network subnet create') @command_table.description(L('Create or update a virtual network (VNet) subnet')) @command_table.option(**COMMON_PARAMETERS['resource_group_name']) -@command_table.option('--name -n', help=L('the subnet name'), required=True) -@command_table.option(_VNET_PARAM_NAME, help=L('the name of the vnet'), required=True) +@command_table.option('--subnet-name -s', help=L('the subnet name'), required=True) +@command_table.option(_VNET_PARAM_NAME, help=L('the name of the vnet'), required=True, _semantic_type='resource_name') @command_table.option('--address-prefix -a', help=L('the the address prefix in CIDR format'), required=True) def create_update_subnet(args): from azure.mgmt.network.models import Subnet diff --git a/src/command_modules/azure-cli-network/azure/cli/command_modules/network/tests/command_specs.py b/src/command_modules/azure-cli-network/azure/cli/command_modules/network/tests/command_specs.py index c289ad651c0..690c88ddc25 100644 --- a/src/command_modules/azure-cli-network/azure/cli/command_modules/network/tests/command_specs.py +++ b/src/command_modules/azure-cli-network/azure/cli/command_modules/network/tests/command_specs.py @@ -9,7 +9,7 @@ }, { 'test_name': 'network_nic_list', - 'command': 'network nic list -g travistestresourcegroup' + 'command': 'network nic list travistestresourcegroup' } ] diff --git a/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/__init__.py b/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/__init__.py index 739673a2d50..40852a6f043 100644 --- a/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/__init__.py +++ b/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/__init__.py @@ -33,7 +33,8 @@ def list_groups(args): @command_table.description( L('Show details of a specific resource in a resource group or subscription')) @command_table.option(**COMMON_PARAMETERS['resource_group_name']) -@command_table.option('--name -n', help=L('the resource name'), required=True) +@command_table.option('--name -n', help=L('the resource name'), required=True, + _semantic_type='resource_name') @command_table.option('--resource-type -r', help=L('the resource type in format: /'), required=True) diff --git a/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/command_specs.py b/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/command_specs.py index 3f93dad5e21..7ed2d66aa06 100644 --- a/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/command_specs.py +++ b/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/command_specs.py @@ -9,7 +9,7 @@ }, { 'test_name': 'resource_show_under_group', - 'command': 'resource show -n xplatvmExt1314 --resource-group XPLATTESTGEXTENSION9085 --resource-type Microsoft.Compute/virtualMachines --output json' + 'command': 'resource show XPLATTESTGEXTENSION9085 xplatvmExt1314 --resource-type Microsoft.Compute/virtualMachines --output json' } ] diff --git a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py index 481ed77c43f..7aacac29701 100644 --- a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py +++ b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py @@ -42,14 +42,16 @@ def get_sas_token(string): # specified, it is only required unless the connection string has been specified 'required': False, 'type': get_account_name, - 'default': 'query' + 'default': 'query', + '_semantic_type': 'resource_name', }, 'account_name_required': { # this is used only to obtain the connection string. Thus, the env variable default # does not apply and this is a required parameter 'name': '--account-name -n', 'help': L('the storage account name'), - 'required': True + 'required': True, + '_semantic_type': 'resource_name', }, 'blob_name': { 'name': '--blob-name -b', @@ -125,7 +127,7 @@ def get_sas_token(string): 'help': L('metadata in "a=b;c=d" format') }, 'optional_resource_group_name': - extend_parameter(GLOBAL_COMMON_PARAMETERS['resource_group_name'], required=False), + extend_parameter(GLOBAL_COMMON_PARAMETERS['resource_group_name'], nargs='?'), 'permission': { 'name': '--permission', 'help': L('permissions granted: (r)ead (w)rite (d)elete (l)ist. Can be combined.'), diff --git a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/tests/command_specs.py b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/tests/command_specs.py index 79b40f4cce3..70b6c259a1f 100644 --- a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/tests/command_specs.py +++ b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/tests/command_specs.py @@ -22,7 +22,7 @@ } def _get_connection_string(runner): - out = runner.run('storage account connection-string -g {} -n {}' + out = runner.run('storage account connection-string {} {}' .format(RESOURCE_GROUP_NAME, STORAGE_ACCOUNT_NAME)) connection_string = out.replace('Connection String : ', '') runner.set_env('AZURE_STORAGE_CONNECTION_STRING', connection_string) @@ -36,22 +36,22 @@ def test_body(self): s.test('storage account check-name --name teststorageomega', {'nameAvailable': True}) s.test('storage account check-name --name {}'.format(account), {'nameAvailable': False, 'reason': 'AlreadyExists'}) - s.rec('storage account list -g {}'.format(rg)) - s.test('storage account show --resource-group {} --account-name {}'.format(rg, account), + s.rec('storage account list {}'.format(rg)) + s.test('storage account show {} {}'.format(rg, account), {'name': account, 'accountType': 'Standard_LRS', 'location': 'westus', 'resourceGroup': rg}) s.rec('storage account usage') - s.rec('storage account connection-string -g {} --account-name {} --use-http'.format(rg, account)) - s.rec('storage account keys list -g {} --account-name {}'.format(rg, account)) - s.rec('storage account keys renew -g {} --account-name {}'.format(rg, account)) - s.rec('storage account keys renew -g {} --account-name {} --key key2'.format(rg, account)) - s.test('storage account set -g {} -n {} --tags foo=bar;cat'.format(rg, account), + s.rec('storage account connection-string {} {} --use-http'.format(rg, account)) + s.rec('storage account keys list {} {}'.format(rg, account)) + s.rec('storage account keys renew {} {}'.format(rg, account)) + s.rec('storage account keys renew {} {} --key key2'.format(rg, account)) + s.test('storage account set {} {} --tags foo=bar;cat'.format(rg, account), {'tags': {'cat':'', 'foo':'bar'}}) # TODO: This should work like other tag commands--no value to clear - s.test('storage account set -g {} -n {} --tags none='.format(rg, account), + s.test('storage account set {} {} --tags none='.format(rg, account), {'tags': {'none': ''}}) - s.test('storage account set -g {} -n {} --type Standard_GRS'.format(rg, account), + s.test('storage account set {} {} --type Standard_GRS'.format(rg, account), {'accountType': 'Standard_GRS'}) - s.run('storage account set -g {} -n {} --type Standard_LRS'.format(rg, account)) + s.run('storage account set {} {} --type Standard_LRS'.format(rg, account)) def __init__(self): super(StorageAccountScenarioTest, self).__init__(None, self.test_body, None) @@ -313,7 +313,7 @@ def __init__(self): #}, { 'test_name': 'storage_account_delete', - 'command': 'storage account delete -g travistestresourcegroup --account-name teststorageaccount04' + 'command': 'storage account delete travistestresourcegroup teststorageaccount04' }, # STORAGE CONTAINER TESTS { diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py index 4c040826850..ec28ef9ee87 100644 --- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py +++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py @@ -28,7 +28,7 @@ 'required': True }, 'optional_resource_group_name': - extend_parameter(GLOBAL_COMMON_PARAMETERS['resource_group_name'], required=False), + extend_parameter(GLOBAL_COMMON_PARAMETERS['resource_group_name'], nargs='?'), 'vhd': { 'name': '--vhd', 'required': True, diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/custom.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/custom.py index dbcb0b27916..00651e72282 100644 --- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/custom.py +++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/custom.py @@ -55,9 +55,10 @@ def invoke(args): # we add these parameters to all commands command_table[invoke]['arguments'].append(PARAMETER_ALIASES['resource_group_name']) command_table[invoke]['arguments'].append({ - 'name': '--vm-name -n', + 'name': '--name -n', 'dest': 'vm_name', 'help': 'Name of Virtual Machine to update', + '_semantic_type': 'resource_name', 'required': True }) return invoke @@ -240,10 +241,10 @@ def list_vm_images(self, def list_ip_addresses(self, - optional_resource_group_name=None, + resource_group_name=None, vm_name=None): ''' Get IP addresses from one or more Virtual Machines - :param str optional_resource_group_name:Name of resource group. + :param str resource_group_name:Name of resource group. :param str vm_name:Name of virtual machine. ''' from azure.mgmt.network import NetworkManagementClient, NetworkManagementClientConfiguration @@ -267,7 +268,7 @@ def list_ip_addresses(self, # If provided, make sure that resource group name and vm name match the NIC we are # looking at before adding it to the result... - if (optional_resource_group_name in (None, nic_resource_group) + if (resource_group_name == nic_resource_group and vm_name in (None, nic_vm_name)): network_info = { @@ -294,5 +295,3 @@ def list_ip_addresses(self, }) return result - - diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/generated.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/generated.py index 8c20051a080..689efadb418 100644 --- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/generated.py +++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/generated.py @@ -46,7 +46,7 @@ def _patch_aliases(alias_items): ], command_table, _patch_aliases({ - 'availability_set_name': {'name': '--name -n'} + 'availability_set_name': {'name': '--name -n', '_semantic_type': 'resource_name', } })) build_operation("vm machine-extension-image", @@ -68,7 +68,7 @@ def _patch_aliases(alias_items): ], command_table, _patch_aliases({ - 'vm_extension_name': {'name': '--name -n'} + 'vm_extension_name': {'name': '--name -n', '_semantic_type': 'resource_name', } })) build_operation("vm image", @@ -113,7 +113,7 @@ def _patch_aliases(alias_items): ], command_table, _patch_aliases({ - 'vm_name': {'name': '--name -n'} + 'vm_name': {'name': '--name -n', '_semantic_type': 'resource_name'} })) build_operation("vm scaleset", @@ -135,7 +135,7 @@ def _patch_aliases(alias_items): ], command_table, _patch_aliases({ - 'vm_scale_set_name': {'name': '--name -n'} + 'vm_scale_set_name': {'name': '--name -n', '_semantic_type': 'resource_name', } })) build_operation("vm scaleset-vm", @@ -153,7 +153,7 @@ def _patch_aliases(alias_items): ], command_table, _patch_aliases({ - 'vm_scale_set_name': {'name': '--name -n'} + 'vm_scale_set_name': {'name': '--name -n', '_semantic_type': 'resource_name', } })) build_operation("vm", diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/command_specs.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/command_specs.py index 37a052a3186..2c612cafe00 100644 --- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/command_specs.py +++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/command_specs.py @@ -32,7 +32,7 @@ def __init__(self): }, { 'test_name': 'vm_list_from_group', - 'command': 'vm list --resource-group XPLATTESTGEXTENSION9085', + 'command': 'vm list XPLATTESTGEXTENSION9085', }, { 'test_name': 'vm_images_list_by_aliases', @@ -43,5 +43,3 @@ def __init__(self): 'command': VMImageListThruServiceScenarioTest() } ] - -