Skip to content

{Compute} az vmss: Migrate commands to aaz-based implementation#32788

Merged
yanzhudd merged 8 commits intoAzure:devfrom
william051200:vmss-list-instance-migration
Mar 4, 2026
Merged

{Compute} az vmss: Migrate commands to aaz-based implementation#32788
yanzhudd merged 8 commits intoAzure:devfrom
william051200:vmss-list-instance-migration

Conversation

@william051200
Copy link
Copy Markdown
Member

Related command

az vmss list-instance-connection-info
az vmss list-instance-public-ips
az vmss list-instances

Description

Migration from mgmt.compute to aaz-based

Testing Guide

History Notes


This checklist is used to make sure that common guidelines for a pull request are followed.

Copilot AI review requested due to automatic review settings February 13, 2026 00:17
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Feb 13, 2026

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Feb 13, 2026

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Feb 13, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates selected az vmss commands from azure.mgmt.compute SDK usage to AAZ-based implementations, aligning VMSS command behavior with the ongoing AAZ migration in the vm command module.

Changes:

  • Switch VMSS retrieval in list-instance-connection-info and list-instance-public-ips to use AAZ Show output (dict-based access).
  • Move vmss list-instance-* command registrations to the non-SDK vmss command group.
  • Update flex-VMSS detection helper to use dict-style access (orchestrationMode).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/azure-cli/azure/cli/command_modules/vm/custom.py Updates VMSS connection info + public IP listing flows to use AAZ VMSS Show and dict traversal.
src/azure-cli/azure/cli/command_modules/vm/commands.py Rehomes vmss list-instance-* custom command registrations to a separate vmss group block.
src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py Changes flex VMSS detection helper to assume dict-shaped VMSS objects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

for ip in primary_nic_config.ip_configurations:
if ip.load_balancer_inbound_nat_pools:
res_id = ip.load_balancer_inbound_nat_pools[0].id
for ip in primary_nic_config.get('ipConfigurations'):
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primary_nic_config.get('ipConfigurations') can return None when the key is missing, which will raise a TypeError when iterating. Use a default empty list (or guard) so the command returns the intended ResourceNotFoundError/CLIError instead of crashing when ip configurations are absent.

Suggested change
for ip in primary_nic_config.get('ipConfigurations'):
for ip in primary_nic_config.get('ipConfigurations') or []:

Copilot uses AI. Check for mistakes.
Comment on lines 4338 to 4340
from azure.mgmt.core.tools import parse_resource_id
from .aaz.latest.vmss import Show as VmssShow

Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code imports and calls the generated aaz.latest.vmss.Show directly. Elsewhere in this module the wrapper operations.vmss.VMSSShow is used to normalize the output and resolve known flatten conflicts (e.g., the type field). Please switch to VMSSShow here as well to keep behavior consistent and avoid potential output-shape regressions.

Copilot uses AI. Check for mistakes.
Comment on lines +4344 to +4348
command_args = {
'resource_group': resource_group_name,
'vm_scale_set_name': vm_scale_set_name
}
vmss = VmssShow(cli_ctx=cmd.cli_ctx)(command_args=command_args)
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function now calls aaz.latest.vmss.Show (2025-04-01) instead of the mgmt-plane SDK get used previously. This changes the request api-version in scenario tests/recordings (many current recordings show api-version=2024-11-01 for the VMSS GET), so playback will likely fail until the relevant recordings are re-generated.

Copilot uses AI. Check for mistakes.
Comment on lines 4430 to 4431
from .aaz.latest.vmss import Show as VmssShow
ListInstancePublicIps = import_aaz_by_profile(cmd.cli_ctx.cloud.profile, "vmss").ListInstancePublicIps
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: prefer using the operations.vmss.VMSSShow wrapper rather than calling aaz.latest.vmss.Show directly, to avoid known flatten conflicts and keep VMSS show output consistent across commands.

Copilot uses AI. Check for mistakes.
def raise_unsupported_error_for_flex_vmss(vmss, error_message):
if hasattr(vmss, 'orchestration_mode') and vmss.orchestration_mode \
and vmss.orchestration_mode.lower() == 'flexible':
if vmss.get('orchestrationMode', '').lower() == 'flexible':
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise_unsupported_error_for_flex_vmss now assumes vmss is a dict and will throw AttributeError if a caller passes an SDK model (or None). The previous implementation supported SDK objects via attribute access. Consider keeping it compatible with both representations (dict and SDK object) so it remains a safe helper across the module.

Suggested change
if vmss.get('orchestrationMode', '').lower() == 'flexible':
# Support both dict-based representations and SDK model objects (or None)
if not vmss:
return
orchestration_mode = None
# Dict-like representation
if isinstance(vmss, dict):
orchestration_mode = vmss.get('orchestrationMode')
else:
# SDK model or other object representation
orchestration_mode = getattr(vmss, 'orchestration_mode', None)
if orchestration_mode is None:
orchestration_mode = getattr(vmss, 'orchestrationMode', None)
if isinstance(orchestration_mode, str) and orchestration_mode.lower() == 'flexible':

Copilot uses AI. Check for mistakes.
primary_nic_config = next((n for n in nic_configs if n.primary), None)
nic_configs = \
vmss.get('virtualMachineProfile', {}).get('networkProfile', {}).get('networkInterfaceConfigurations', [])
primary_nic_config = next((n for n in nic_configs if n.get('primary')), None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking if it is more appropriate to use {} as the default value, as primary_nic_config will be accessed by key, which is a dictionary behavior

Suggested change
primary_nic_config = next((n for n in nic_configs if n.get('primary')), None)
primary_nic_config = next((n for n in nic_configs if n.get('primary')), {})

@yanzhudd
Copy link
Copy Markdown
Contributor

yanzhudd commented Mar 2, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@william051200
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@yanzhudd yanzhudd merged commit 2a8d47c into Azure:dev Mar 4, 2026
48 checks passed
@william051200 william051200 deleted the vmss-list-instance-migration branch March 4, 2026 02:03
nddq pushed a commit to nddq/azure-cli that referenced this pull request Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants