[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
Conversation
️✔️AzureCLI-FullTest
|
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| vm disk attach | cmd vm disk attach added parameter source_disk_restore_point |
||
| vm disk attach | cmd vm disk attach added parameter source_snapshots_or_disks |
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 VMsaz 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
There was a problem hiding this comment.
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_diskfunction to support--source-snapshots-or-disksand--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, |
There was a problem hiding this comment.
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.
| 'caching': caching, | |
| **({'caching': caching} if caching is not None else {}), |
| 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 \ |
There was a problem hiding this comment.
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.
| 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 = { |
There was a problem hiding this comment.
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.
|
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>
|
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 VMsaz 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
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 VMsaz 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
Related command
az vm disk attachDescription
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 featureThis 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.