Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ def load_arguments(self, _):
completer=get_resource_name_completion_list('Microsoft.Compute/disks'))
c.argument('ids', deprecate_info=c.deprecate(target='--ids', redirect='--disks', hide=True))
c.argument('disk_ids', nargs='+', min_api='2024-03-01', help='The disk IDs of the managed disk (space-delimited).')
c.argument('source_snapshots_or_disks', options_list=['--source-snapshots-or-disks', '--source-resource'], nargs='+', min_api='2024-11-01', help='Create a data disk from a snapshot or another disk. Can use the ID of a disk or snapshot.')
c.argument('source_disk_restore_point', options_list=['--source-disk-restore-point', '--source-disk-rp'], nargs='+', min_api='2024-11-01', help='create a data disk from a disk restore point. Can use the ID of a disk restore point.')

with self.argument_context('vm disk detach') as c:
c.argument('disk_name', arg_type=name_arg_type, help='The data disk name.')
Expand Down
6 changes: 4 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,8 +1886,10 @@ def validate_vmss_update_namespace(cmd, namespace): # pylint: disable=unused-ar

# region disk, snapshot, image validators
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.
not namespace.source_snapshots_or_disks and not namespace.source_disk_restore_point:
raise RequiredArgumentMissingError("Please use at least one of --name, --disks, --disk-ids,"
" --source-snapshots-or-disks and --source-disk-restore-point")

if namespace.disk and namespace.disks:
raise MutuallyExclusiveArgumentError("You can only specify one of --name and --disks")
Expand Down
30 changes: 29 additions & 1 deletion src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,8 @@ def show_default_diagnostics_configuration(is_windows_os=False):

# region VirtualMachines Disks (Managed)
def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=None, disks=None, new=False, sku=None,
size_gb=None, lun=None, caching=None, enable_write_accelerator=False, disk_ids=None):
size_gb=None, lun=None, caching=None, enable_write_accelerator=False, disk_ids=None,
source_snapshots_or_disks=None, source_disk_restore_point=None):
# attach multiple managed disks using disk attach API
vm = get_vm_to_update(cmd, resource_group_name, vm_name)
if not new and not sku and not size_gb and disk_ids is not None:
Expand Down Expand Up @@ -2148,6 +2149,33 @@ def attach_managed_data_disk(cmd, resource_group_name, vm_name, disk=None, ids=N
data_disk.write_accelerator_enabled = enable_write_accelerator

vm.storage_profile.data_disks.append(data_disk)
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.
'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.
'lun': disk_lun,
'writeAcceleratorEnabled': enable_write_accelerator,
"sourceResource": {
"id": disk_item
}
}
disk_lun += 1
vm.storage_profile.data_disks.append(disk)
if source_disk_restore_point is not None:
for disk_item in source_disk_restore_point:
disk = {
'create_option': 'Restore',
'caching': caching,
'lun': disk_lun,
'writeAcceleratorEnabled': enable_write_accelerator,
"sourceResource": {
"id": disk_item
}
}
disk_lun += 1
vm.storage_profile.data_disks.append(disk)

set_vm(cmd, vm)

Expand Down
Loading
Loading