Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def load_command_table(self, _):
g.custom_command('list', 'list_vm', table_transformer=transform_vm_list)
g.custom_show_command('show', 'show_vm', table_transformer=transform_vm)
g.generic_update_command('update', getter_name='get_vm_to_update_by_aaz', setter_name='update_vm', setter_type=compute_custom, command_type=compute_custom, supports_no_wait=True, validator=process_vm_update_namespace)
g.custom_command('open-port', 'open_vm_port')

with self.command_group('vm', compute_vm_sdk) as g:
g.custom_command('application set', 'set_vm_applications', validator=process_set_applications_namespace, min_api='2021-07-01')
Expand All @@ -295,7 +296,6 @@ def load_command_table(self, _):
g.custom_command('list-ip-addresses', 'list_vm_ip_addresses', table_transformer=transform_ip_addresses)
g.custom_command('list-skus', 'list_skus', table_transformer=transform_sku_for_table_output, min_api='2017-03-30')
g.command('list-usage', 'list', command_type=compute_vm_usage_sdk, transform=transform_vm_usage_list, table_transformer='[].{Name:localName, CurrentValue:currentValue, Limit:limit}')
g.custom_command('open-port', 'open_vm_port')
g.custom_command('resize', 'resize_vm', supports_no_wait=True)
g.custom_command('restart', 'restart_vm', supports_no_wait=True)
g.command('stop', 'begin_power_off', supports_no_wait=True, validator=process_vm_vmss_stop)
Expand Down
10 changes: 5 additions & 5 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,12 +1619,12 @@ def open_vm_port(cmd, resource_group_name, vm_name, port, priority=900, network_
NSGShow, NSGCreate = _nsg.Show, _nsg.Create
NSGRuleCreate = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "network.nsg.rule").Create

vm = get_vm(cmd, resource_group_name, vm_name)
location = vm.location
if not vm.network_profile:
vm = get_vm_by_aaz(cmd, resource_group_name, vm_name)
location = vm.get('location', '')
if not vm.get('networkProfile'):
raise CLIError("Network profile not found for VM '{}'".format(vm_name))

nic_ids = list(vm.network_profile.network_interfaces)
nic_ids = vm.get('networkProfile', {}).get('networkInterfaces', [])
if len(nic_ids) > 1:
raise CLIError('Multiple NICs is not supported for this command. Create rules on the NSG '
'directly.')
Expand All @@ -1634,7 +1634,7 @@ def open_vm_port(cmd, resource_group_name, vm_name, port, priority=900, network_
# get existing NSG or create a new one
created_nsg = False
nic = NicShow(cli_ctx=cmd.cli_ctx)(command_args={
'name': os.path.split(nic_ids[0].id)[1],
'name': os.path.split(nic_ids[0].get('id'))[1],
'resource_group': resource_group_name
})
if not apply_to_subnet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ interactions:
- AZURECLI/2.47.0 azsdk-python-azure-mgmt-compute/29.1.0 Python/3.10.11 (Linux-5.15.0-1036-azure-x86_64-with-glibc2.31)
VSTS_7b238909-6802-4b65-b90d-184bca47f458_build_220_0
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1?api-version=2024-11-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1?api-version=2025-04-01
response:
body:
string: "{\r\n \"name\": \"vm1\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1\",\r\n
Expand Down Expand Up @@ -1424,7 +1424,7 @@ interactions:
- AZURECLI/2.47.0 azsdk-python-azure-mgmt-compute/29.1.0 Python/3.10.11 (Linux-5.15.0-1036-azure-x86_64-with-glibc2.31)
VSTS_7b238909-6802-4b65-b90d-184bca47f458_build_220_0
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1?api-version=2024-11-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1?api-version=2025-04-01
response:
body:
string: "{\r\n \"name\": \"vm1\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1\",\r\n
Expand Down Expand Up @@ -2051,7 +2051,7 @@ interactions:
- AZURECLI/2.47.0 azsdk-python-azure-mgmt-compute/29.1.0 Python/3.10.11 (Linux-5.15.0-1036-azure-x86_64-with-glibc2.31)
VSTS_7b238909-6802-4b65-b90d-184bca47f458_build_220_0
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1?api-version=2024-11-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1?api-version=2025-04-01
response:
body:
string: "{\r\n \"name\": \"vm1\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_open_port000001/providers/Microsoft.Compute/virtualMachines/vm1\",\r\n
Expand Down