Skip to content
Open
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
48 changes: 47 additions & 1 deletion src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,7 @@ def process_disk_create_namespace(cmd, namespace):
'--source VHD_BLOB_URI [--source-storage-account-id ID]'
try:
namespace.source_blob_uri, namespace.source_disk, namespace.source_snapshot, \
namespace.source_restore_point, _ = _figure_out_storage_source(
namespace.source_restore_point, _ = _figure_out_storage_source_by_aaz(
cmd.cli_ctx, namespace.resource_group_name, namespace.source)
if not namespace.source_blob_uri and namespace.source_storage_account_id:
raise ArgumentUsageError(usage_error)
Expand Down Expand Up @@ -2218,6 +2218,30 @@ def _figure_out_storage_source(cli_ctx, resource_group_name, source):
return (source_blob_uri, source_disk, source_snapshot, source_restore_point, source_info)


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)
Comment on lines +2221 to +2242
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

_figure_out_storage_source_by_aaz largely duplicates _figure_out_storage_source, differing mainly in how it resolves a bare name (AAZ show) and how it reads the resource id (dict.get('id') vs .id). To reduce divergence risk (future fixes landing in only one path), consider factoring the shared parsing logic into a single helper and injecting the "name -> (info,is_snapshot)" resolver and an "extract_id" helper that supports both SDK objects and dict outputs.

Copilot uses AI. Check for mistakes.


def _get_disk_or_snapshot_info(cli_ctx, resource_group_name, source):
compute_client = _compute_client_factory(cli_ctx)
is_snapshot = True
Expand All @@ -2231,6 +2255,28 @@ def _get_disk_or_snapshot_info(cli_ctx, resource_group_name, source):
return info, is_snapshot


def _get_disk_or_snapshot_info_by_aaz(cli_ctx, resource_group_name, source):
from .aaz.latest.snapshot import Show as SnapshotShow
from .aaz.latest.disk import Show as DiskShow
is_snapshot = True

try:
command_args = {
'resource_group': resource_group_name,
'snapshot_name': source
}
info = SnapshotShow(cli_ctx=cli_ctx)(command_args=command_args)
except ResourceNotFoundError:
command_args = {
'resource_group': resource_group_name,
'disk_name': source
}
is_snapshot = False
info = DiskShow(cli_ctx=cli_ctx)(command_args=command_args)

return info, is_snapshot


def process_disk_encryption_namespace(cmd, namespace):
namespace.disk_encryption_keyvault = _get_resource_id(cmd.cli_ctx, namespace.disk_encryption_keyvault,
namespace.resource_group_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ interactions:
User-Agent:
- AZURECLI/2.77.0 azsdk-python-core/1.35.0 Python/3.10.11 (Windows-10-10.0.26100-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_disk_encryption_set_disk_update_000001/providers/Microsoft.Compute/snapshots/disk-000005?api-version=2023-10-02
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_disk_encryption_set_disk_update_000001/providers/Microsoft.Compute/snapshots/disk-000005?api-version=2025-01-02
response:
body:
string: '{"error":{"code":"ResourceNotFound","message":"The Resource ''Microsoft.Compute/snapshots/disk-000005''
Expand Down Expand Up @@ -1490,7 +1490,7 @@ interactions:
User-Agent:
- AZURECLI/2.77.0 azsdk-python-core/1.35.0 Python/3.10.11 (Windows-10-10.0.26100-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_disk_encryption_set_disk_update_000001/providers/Microsoft.Compute/disks/disk-000005?api-version=2023-04-02
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_disk_encryption_set_disk_update_000001/providers/Microsoft.Compute/disks/disk-000005?api-version=2025-01-02
response:
body:
string: "{\r\n \"name\": \"disk-000005\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_disk_encryption_set_disk_update_000001/providers/Microsoft.Compute/disks/disk-000005\",\r\n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5422,7 +5422,7 @@ interactions:
User-Agent:
- AZURECLI/2.76.0 azsdk-python-core/1.35.0 Python/3.10.11 (Windows-10-10.0.26100-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_data_disk_creation_from_copy_and_restore000001/providers/Microsoft.Compute/snapshots/disk_000008?api-version=2023-10-02
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_data_disk_creation_from_copy_and_restore000001/providers/Microsoft.Compute/snapshots/disk_000008?api-version=2025-01-02
response:
body:
string: '{"error":{"code":"ResourceNotFound","message":"The Resource ''Microsoft.Compute/snapshots/disk_000008''
Expand Down Expand Up @@ -5470,7 +5470,7 @@ interactions:
User-Agent:
- AZURECLI/2.76.0 azsdk-python-core/1.35.0 Python/3.10.11 (Windows-10-10.0.26100-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_data_disk_creation_from_copy_and_restore000001/providers/Microsoft.Compute/disks/disk_000008?api-version=2023-04-02
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_data_disk_creation_from_copy_and_restore000001/providers/Microsoft.Compute/disks/disk_000008?api-version=2025-01-02
response:
body:
string: "{\r\n \"name\": \"disk_000008\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_data_disk_creation_from_copy_and_restore000001/providers/Microsoft.Compute/disks/disk_000008\",\r\n
Expand Down