Skip to content

{Compute} az image create: Migrate command to aaz-based implementation#32884

Open
william051200 wants to merge 5 commits intoAzure:devfrom
william051200:image-migration
Open

{Compute} az image create: Migrate command to aaz-based implementation#32884
william051200 wants to merge 5 commits intoAzure:devfrom
william051200:image-migration

Conversation

@william051200
Copy link
Member

Related command

az image create

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 March 3, 2026 01:50
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Mar 3, 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 Mar 3, 2026

❌AzureCLI-BreakingChangeTest
❌appservice
rule cmd_name rule_message suggest_message
1007 - ParaRemove logicapp create cmd logicapp create removed parameter auto_generated_domain_name_label_scope please add back parameter auto_generated_domain_name_label_scope for cmd logicapp create

Please submit your Breaking Change Pre-announcement ASAP if you haven't already. Please note:

  • Breaking changes can only be merged during the designated breaking change window
  • A pre-announcement must be released at least one month in advance

For more details on how to introduce breaking changes, refer to the documentation: azure-cli/doc/how_to_introduce_breaking_changes.md

@yonzhan
Copy link
Collaborator

yonzhan commented Mar 3, 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 Mar 3, 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

Migrates az image create in the VM command module from a management-plane SDK implementation to an AAZ-based implementation.

Changes:

  • Switches the image command group registration to no longer use the compute image SDK command group binding.
  • Updates process_image_create_namespace to resolve VM/disk/snapshot sources via AAZ show operations.
  • Introduces a local CachingTypes enum and adjusts parameter model loading accordingly.

Reviewed changes

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

File Description
src/azure-cli/azure/cli/command_modules/vm/commands.py Updates image command group registration to support the AAZ migration path.
src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py Adds a local caching enum used by params after model-loading changes.
src/azure-cli/azure/cli/command_modules/vm/_validators.py Replaces mgmt SDK lookups with AAZ show operations for VM/disk/snapshot source resolution.
src/azure-cli/azure/cli/command_modules/vm/_params.py Stops loading CachingTypes from SDK models and imports the new local enum.

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

if source_from_vm:
# pylint: disable=no-member
namespace.os_type = vm_info.storage_profile.os_disk.os_type
namespace.os_type = vm_info.get('storageProfile', {}).get('osDisk', {}).get('osType', '')
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Defaulting namespace.os_type to the empty string can lead to constructing an invalid image create payload (osType is expected to be a valid value like Linux/Windows). Consider either (1) leaving it unset (e.g., None) when it cannot be inferred, or (2) raising a CLIError with a clear message when the VM response does not contain storageProfile.osDisk.osType, so the failure happens early and explains what’s missing.

Suggested change
namespace.os_type = vm_info.get('storageProfile', {}).get('osDisk', {}).get('osType', '')
os_type = vm_info.get('storageProfile', {}).get('osDisk', {}).get('osType')
if not os_type:
raise CLIError("Failed to infer the OS type from the source virtual machine. "
"The field 'storageProfile.osDisk.osType' is missing in the VM resource. "
"Please ensure the VM has a valid OS type before creating an image from it.")
namespace.os_type = os_type

Copilot uses AI. Check for mistakes.
SECURITY = 'Security'


class CachingTypes(Enum):
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Introducing a new CachingTypes enum with the same name as the previously SDK-sourced model type can be confusing (especially in a module where CachingTypes historically referred to an RP model). Consider renaming this local enum to something more specific (e.g., DiskCachingTypes) and updating the import in _params.py accordingly to make it clear this is a CLI-local enum.

Suggested change
class CachingTypes(Enum):
class DiskCachingTypes(Enum):

Copilot uses AI. Check for mistakes.
Comment on lines +2227 to +2248
def _figure_out_storage_source_by_aaz(cli_ctx, resource_group_name, source):
source_blob_uri = None
source_disk = None
source_snapshot = None
source_info = None
source_restore_point = None
if urlparse(source).scheme: # a uri?
source_blob_uri = source
elif '/disks/' in source.lower():
source_disk = source
elif '/snapshots/' in source.lower():
source_snapshot = source
elif '/restorepoints/' in source.lower():
source_restore_point = source
else:
source_info, is_snapshot = _get_disk_or_snapshot_info_by_aaz(cli_ctx, resource_group_name, source)
if is_snapshot:
source_snapshot = source_info.get('id')
else:
source_disk = source_info.get('id')

return (source_blob_uri, source_disk, source_snapshot, source_restore_point, source_info)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

This adds a near-duplicate of _figure_out_storage_source with only the underlying ‘get disk/snapshot info’ mechanism changed. To reduce drift and make future fixes apply to both paths, consider refactoring into a single helper that accepts a resolver function (SDK vs AAZ) or consolidating into one implementation with a strategy switch. That keeps the URI/resource-ID parsing logic in one place.

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

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