From acfb3d594919cbc386dad7592e59e025a20f6365 Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 6 Mar 2026 16:01:13 +0800 Subject: [PATCH 1/2] Migrate disk command --- .../cli/command_modules/vm/_validators.py | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index cb1aec242f6..216e07099e4 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -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) @@ -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) + + def _get_disk_or_snapshot_info(cli_ctx, resource_group_name, source): compute_client = _compute_client_factory(cli_ctx) is_snapshot = True @@ -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, From e1c181d647f6d6302cf4ec7c46ea4a176d7fa99d Mon Sep 17 00:00:00 2001 From: william051200 Date: Mon, 9 Mar 2026 08:38:08 +0800 Subject: [PATCH 2/2] Update test case recording --- .../recordings/test_disk_encryption_set_disk_update.yaml | 4 ++-- .../test_vm_data_disk_creation_from_copy_and_restore.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_disk_encryption_set_disk_update.yaml b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_disk_encryption_set_disk_update.yaml index 95b314f9179..c7bd207e066 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_disk_encryption_set_disk_update.yaml +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_disk_encryption_set_disk_update.yaml @@ -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'' @@ -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 diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_data_disk_creation_from_copy_and_restore.yaml b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_data_disk_creation_from_copy_and_restore.yaml index cc65621d8a5..5ffb5f2469e 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_data_disk_creation_from_copy_and_restore.yaml +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_data_disk_creation_from_copy_and_restore.yaml @@ -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'' @@ -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