{Network} az network: Migrate commands calling Compute module to aaz-based implementation#32949
{Network} az network: Migrate commands calling Compute module to aaz-based implementation#32949william051200 wants to merge 1 commit intoAzure:devfrom
Conversation
❌AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
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). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
Migrates az network watcher helpers that previously queried VM/VMSS location via azure.mgmt.compute to instead use AAZ-based VM/VMSS show implementations from the vm command module, aligning Network Watcher commands with the ongoing AAZ migration.
Changes:
- Replace
mgmt.computeVM lookup withVMShow(AAZ) via newnetwork.custom.get_vm. - Replace
mgmt.computeVMSS lookup withVMSSShow(AAZ) via newnetwork.custom.get_vmss. - Update Network Watcher pre-operations to derive
locationfrom AAZ show results.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/network/operations/watcher.py |
Switch VM/VMSS location resolution from Compute SDK client to new AAZ-based helpers. |
src/azure-cli/azure/cli/command_modules/network/custom.py |
Add get_vm / get_vmss helpers that invoke VMShow / VMSSShow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| vm_name = parse_resource_id(args.vm.to_serialized_data())["name"] | ||
| vm = compute_client.get(args.resource_group_name, vm_name) | ||
| vm = get_vm(cmd.cli_ctx, args.resource_group_name, vm_name) | ||
| args.location = vm.location |
There was a problem hiding this comment.
get_vm returns the deserialized output from VMShow (a dict), but this code still accesses vm.location like an SDK model. This will raise AttributeError at runtime (e.g., for az network watcher test-ip-flow, show-next-hop, etc.). Use the returned mapping to set the location (e.g., vm["location"] / vm.get("location")) before calling get_network_watcher_from_location.
| args.location = vm.location | |
| location = vm.get("location") if isinstance(vm, dict) else getattr(vm, "location", None) | |
| if not location: | |
| raise ValidationError("Unable to determine location for the specified virtual machine.") | |
| args.location = location |
| vmss_name = parse_resource_id(args.target.to_serialized_data())["name"] | ||
| vmss = compute_client.get(args.resource_group_name, vmss_name) | ||
| vmss = get_vmss(cmd.cli_ctx, args.resource_group_name, vmss_name) | ||
| args.location = vmss.location |
There was a problem hiding this comment.
get_vmss returns the deserialized output from VMSSShow (a dict), but this code still accesses vmss.location like an SDK model. This will raise AttributeError when --target-type AzureVMSS flows call this helper. Read the location from the dict output (e.g., vmss["location"] / vmss.get("location")).
| args.location = vmss.location | |
| args.location = vmss["location"] |
Related command
az network watcher test-connectivityaz network watcher test-ip-flowaz network watcher show-next-hopaz network watcher show-security-group-viewaz network watcher packet-capture createDescription
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.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.