Skip to content

{Compute} az vm unmanaged-disk: Migrate command group to aaz-based implementation#32754

Open
william051200 wants to merge 3 commits intoAzure:devfrom
william051200:vm-unmanaged-disk-migration
Open

{Compute} az vm unmanaged-disk: Migrate command group to aaz-based implementation#32754
william051200 wants to merge 3 commits intoAzure:devfrom
william051200:vm-unmanaged-disk-migration

Conversation

@william051200
Copy link
Member

Related command

az vm unmanaged-disk attach
az vm unmanaged-disk detach
az vm unmanaged-disk list

Description

Migration from mgmt.compute to aaz-based

Testing Guide

History Notes

[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change
[Component Name 2] az command b: Add some customer-facing feature


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 6, 2026 07:25
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Feb 6, 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

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

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

@yonzhan
Copy link
Collaborator

yonzhan commented Feb 6, 2026

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

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

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
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

This pull request migrates the az vm unmanaged-disk command group from SDK-based (mgmt.compute) to AAZ-based implementation. The migration follows the established pattern used elsewhere in the VM module for AAZ migrations.

Changes:

  • Migrated az vm unmanaged-disk attach, detach, and list commands to use AAZ-based functions
  • Added helper function _get_disk_lun_by_aaz and DiskCreateOptionTypes enum to support the AAZ-based implementation
  • Removed SDK dependency from the command group declaration

Reviewed changes

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

File Description
src/azure-cli/azure/cli/command_modules/vm/custom.py Migrated three unmanaged disk functions to AAZ: detach, attach, and list. Added helper function _get_disk_lun_by_aaz for AAZ-based disk LUN calculation.
src/azure-cli/azure/cli/command_modules/vm/commands.py Removed SDK client factory parameter from vm unmanaged-disk command group since AAZ-based implementations don't require it.
src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py Added DiskCreateOptionTypes enum to replace SDK-based enum in AAZ implementation.

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

if len(vm.storage_profile.data_disks) == len(leftovers):
vm = get_vm_to_update_by_aaz(cmd, resource_group_name, vm_name)
vm = convert_show_result_to_snake_case(vm)
leftovers = [d for d in vm.get('storage_profile', {}).get('data_disks', []) if d.get('name').lower() != disk_name.lower()]
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The expression d.get('name').lower() will raise an AttributeError if the 'name' key is missing from the disk dictionary, as d.get('name') would return None. Change to d.get('name', '').lower() to provide a default empty string when the key is missing.

Suggested change
leftovers = [d for d in vm.get('storage_profile', {}).get('data_disks', []) if d.get('name').lower() != disk_name.lower()]
leftovers = [d for d in vm.get('storage_profile', {}).get('data_disks', []) if d.get('name', '').lower() != disk_name.lower()]

Copilot uses AI. Check for mistakes.
Comment on lines 2456 to 2457
if vm.get('storage_profile', {}).get('data_disks'):
vm['storage_profile']['data_disks'] = leftovers
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The conditional check on line 2456 is unnecessary and differs from the original implementation. Since the error check on line 2453 confirms that data_disks exist and contain the disk to remove, the assignment should happen unconditionally. Change to: vm['storage_profile']['data_disks'] = leftovers without the if condition, matching the original logic where vm.storage_profile.data_disks = leftovers was always executed.

Suggested change
if vm.get('storage_profile', {}).get('data_disks'):
vm['storage_profile']['data_disks'] = leftovers
vm['storage_profile']['data_disks'] = leftovers

Copilot uses AI. Check for mistakes.
@william051200
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Comment on lines +1019 to +1020
self.assertIsNotNone(converted[0].get('managedDisk'))
self.assertIsNone(converted[0].get('vhd'))
Copy link
Contributor

Choose a reason for hiding this comment

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

May I ask why we need to change these verified functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reason as in result return from aaz will not include managedDisk and vhd when there is no value.

Copy link
Contributor

Choose a reason for hiding this comment

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

does the previous logic return converted[0]['managedDisk'] as True and converted[0]['vhd'] as False?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it is actually returning in either "None" or "{}" object, there is no True or False

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.

4 participants