Skip to content

[Compute] az vm disk attach: Add new parameters --source-snapshots-or-disks --source-disk-restore-point to support implicit disk creation from snapshot and disk restore points#31830

Merged
zhoxing-ms merged 2 commits intoAzure:devfrom
Jing-song:jins-imdisk
Jul 22, 2025

Conversation

@Jing-song
Copy link
Contributor

Related command

az vm disk attach

Description

Implicit Disk Creation from Snapshot and Disk Restore Points for already created VMs
close #31676

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 July 17, 2025 03:11
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jul 17, 2025

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

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

azure-client-tools-bot-prd bot commented Jul 17, 2025

⚠️AzureCLI-BreakingChangeTest
⚠️vm
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd vm disk attach cmd vm disk attach added parameter source_disk_restore_point
⚠️ 1006 - ParaAdd vm disk attach cmd vm disk attach added parameter source_snapshots_or_disks

@microsoft-github-policy-service microsoft-github-policy-service bot added the Auto-Assign Auto assign by bot label Jul 17, 2025
@Jing-song Jing-song changed the title [Compute] az vm disk attach: Add new parameters --source-snapshots-or-disks --source-disk-restore-point to support Iimplicit disk creation from snapshot and disk restore points for already created VMs [Compute] az vm disk attach: Add new parameters --source-snapshots-or-disks --source-disk-restore-point to support implicit disk creation from snapshot and disk restore points for already created VMs Jul 17, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Compute az vm/vmss/image/disk/snapshot label Jul 17, 2025
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

Add new parameters to az vm disk attach for implicit data disk creation from snapshots and restore points.

  • Extended the attach_managed_data_disk function to support --source-snapshots-or-disks and --source-disk-restore-point
  • Updated CLI parameter definitions and validators for the new options
  • Introduced an integration test covering attach behavior for copied disks, snapshots, and restore points

Reviewed Changes

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

File Description
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py Added test_vm_disk_attach_from_copy_and_restore verifying disk attach from snapshots, copies, and RPs
src/azure-cli/azure/cli/command_modules/vm/custom.py Extended attach_managed_data_disk signature and logic to handle source_snapshots_or_disks and RPs
src/azure-cli/azure/cli/command_modules/vm/_validators.py Updated process_vm_disk_attach_namespace to include new source parameters in required-argument checks
src/azure-cli/azure/cli/command_modules/vm/_params.py Defined new arguments --source-snapshots-or-disks and --source-disk-restore-point with help messages

for disk_item in source_snapshots_or_disks:
disk = {
'create_option': 'Copy',
'caching': caching,
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

The 'caching' field is always included even when its value is None, which may lead to API errors. Consider only including this key when a valid value is provided or applying a default.

Suggested change
'caching': caching,
**({'caching': caching} if caching is not None else {}),

Copilot uses AI. Check for mistakes.
def process_vm_disk_attach_namespace(cmd, namespace):
if not namespace.disks and not namespace.disk and not namespace.disk_ids:
raise RequiredArgumentMissingError("Please use at least one of --name, --disks and --disk-ids")
if not namespace.disks and not namespace.disk and not namespace.disk_ids and \
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

Use parentheses to wrap this multi-line if condition instead of a backslash continuation for better readability and to comply with the guideline on breaking long expressions.

Copilot uses AI. Check for mistakes.
disk_lun = _get_disk_lun(vm.storage_profile.data_disks)
if source_snapshots_or_disks is not None:
for disk_item in source_snapshots_or_disks:
disk = {
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

The variable name 'disk' here shadows the function parameter of the same name, which can be confusing. Consider renaming it (e.g., data_disk) to improve clarity.

Copilot uses AI. Check for mistakes.
@yonzhan
Copy link
Collaborator

yonzhan commented Jul 17, 2025

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

@github-actions
Copy link

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>

@Jing-song Jing-song changed the title [Compute] az vm disk attach: Add new parameters --source-snapshots-or-disks --source-disk-restore-point to support implicit disk creation from snapshot and disk restore points for already created VMs [Compute] az vm disk attach: Add new parameters --source-snapshots-or-disks --source-disk-restore-point to support implicit disk creation from snapshot and disk restore points for already created VMs Jul 17, 2025
@zhoxing-ms zhoxing-ms merged commit 6b1c304 into Azure:dev Jul 22, 2025
48 checks passed
@zhoxing-ms zhoxing-ms changed the title [Compute] az vm disk attach: Add new parameters --source-snapshots-or-disks --source-disk-restore-point to support implicit disk creation from snapshot and disk restore points for already created VMs [Compute] az vm disk attach: Add new parameters --source-snapshots-or-disks --source-disk-restore-point to support implicit disk creation from snapshot and disk restore points Jul 22, 2025
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.

[CLI] Implicit Disk Creation from Snapshot and Disk Restore Points for already created VMs (not new VMs) - Single VMs, VMs in an AvSet, VMs in VMSS

5 participants