From 01849fdbc373d880b05b0882f51464440874f808 Mon Sep 17 00:00:00 2001 From: Yan Zhu Date: Thu, 25 Aug 2022 17:56:10 +0800 Subject: [PATCH 1/3] fix --- .../azext_imagecopy/create_target.py | 35 ++++++++-------- src/image-copy/azext_imagecopy/custom.py | 40 ++++++++++--------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/image-copy/azext_imagecopy/create_target.py b/src/image-copy/azext_imagecopy/create_target.py index d8f2278f4d8..b91ef1b9129 100644 --- a/src/image-copy/azext_imagecopy/create_target.py +++ b/src/image-copy/azext_imagecopy/create_target.py @@ -21,7 +21,7 @@ def create_target_image(cmd, location, transient_resource_group_name, source_type, source_object_name, source_os_disk_snapshot_name, source_os_disk_snapshot_url, source_os_type, target_resource_group_name, azure_pool_frequency, tags, target_name, target_subscription, - export_as_snapshot, timeout, hyper_v_generation='V1'): + export_as_snapshot, timeout, hyper_v_generation=None): random_string = get_random_string( STORAGE_ACCOUNT_NAME_LENGTH - len(location)) @@ -118,14 +118,15 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ transient_resource_group_name, target_subscription) - cli_cmd = prepare_cli_command(['snapshot', 'create', - '--resource-group', snapshot_resource_group_name, - '--name', target_snapshot_name, - '--location', location, - '--source', target_blob_path, - '--source-storage-account-id', source_storage_account_id, - '--hyper-v-generation', hyper_v_generation], - subscription=target_subscription) + cmd_content = ['snapshot', 'create', + '--resource-group', snapshot_resource_group_name, + '--name', target_snapshot_name, + '--location', location, + '--source', target_blob_path, + '--source-storage-account-id', source_storage_account_id] + if hyper_v_generation: + cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation] + cli_cmd = prepare_cli_command(cmd_content, subscription=target_subscription) json_output = run_cli_command(cli_cmd, return_as_json=True) target_snapshot_id = json_output['id'] @@ -143,13 +144,15 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ else: target_image_name = target_name - cli_cmd = prepare_cli_command(['image', 'create', - '--resource-group', target_resource_group_name, - '--name', target_image_name, - '--location', location, - '--os-type', source_os_type, - '--source', target_snapshot_id, - '--hyper-v-generation', hyper_v_generation], + cmd_content = ['image', 'create', + '--resource-group', target_resource_group_name, + '--name', target_image_name, + '--location', location, + '--os-type', source_os_type, + '--source', target_snapshot_id] + if hyper_v_generation: + cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation] + cli_cmd = prepare_cli_command(cmd_content, tags=tags, subscription=target_subscription) diff --git a/src/image-copy/azext_imagecopy/custom.py b/src/image-copy/azext_imagecopy/custom.py index 92871e23985..088fe21d073 100644 --- a/src/image-copy/azext_imagecopy/custom.py +++ b/src/image-copy/azext_imagecopy/custom.py @@ -90,21 +90,21 @@ def imagecopy(cmd, source_resource_group_name, source_object_name, target_locati source_storage_account_id = get_storage_account_id_from_blob_path(cmd, source_os_disk_id, source_resource_group_name) - cli_cmd = prepare_cli_command(['snapshot', 'create', - '--name', source_os_disk_snapshot_name, - '--location', snapshot_location, - '--resource-group', source_resource_group_name, - '--source', source_os_disk_id, - '--source-storage-account-id', source_storage_account_id, - '--hyper-v-generation', hyper_v_generation]) + cmd_content = ['snapshot', 'create', + '--name', source_os_disk_snapshot_name, + '--location', snapshot_location, + '--resource-group', source_resource_group_name, + '--source', source_os_disk_id, + '--source-storage-account-id', source_storage_account_id] else: - cli_cmd = prepare_cli_command(['snapshot', 'create', - '--name', source_os_disk_snapshot_name, - '--location', snapshot_location, - '--resource-group', source_resource_group_name, - '--source', source_os_disk_id, - '--hyper-v-generation', hyper_v_generation]) - + cmd_content = ['snapshot', 'create', + '--name', source_os_disk_snapshot_name, + '--location', snapshot_location, + '--resource-group', source_resource_group_name, + '--source', source_os_disk_id] + if hyper_v_generation: + cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation] + cli_cmd = prepare_cli_command(cmd_content) run_cli_command(cli_cmd) # Get SAS URL for the snapshotName @@ -169,11 +169,13 @@ def imagecopy(cmd, source_resource_group_name, source_object_name, target_locati tasks = [] for location in target_location: location = location.strip() - tasks.append((location, transient_resource_group_name, source_type, - source_object_name, source_os_disk_snapshot_name, source_os_disk_snapshot_url, - source_os_type, target_resource_group_name, azure_pool_frequency, - tags, target_name, target_subscription, export_as_snapshot, timeout, - hyper_v_generation)) + task_content = (location, transient_resource_group_name, source_type, + source_object_name, source_os_disk_snapshot_name, source_os_disk_snapshot_url, + source_os_type, target_resource_group_name, azure_pool_frequency, + tags, target_name, target_subscription, export_as_snapshot, timeout) + if hyper_v_generation: + task_content = task_content + tuple(hyper_v_generation) + tasks.append(task_content) logger.warning("Starting async process for all locations") From f5a639eec06e238ef8069564784d39ea19de34cc Mon Sep 17 00:00:00 2001 From: Yan Zhu Date: Fri, 26 Aug 2022 18:54:11 +0800 Subject: [PATCH 2/3] default value of hyper_v_generation --- src/image-copy/azext_imagecopy/create_target.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/image-copy/azext_imagecopy/create_target.py b/src/image-copy/azext_imagecopy/create_target.py index b91ef1b9129..32618d9bfa6 100644 --- a/src/image-copy/azext_imagecopy/create_target.py +++ b/src/image-copy/azext_imagecopy/create_target.py @@ -21,7 +21,7 @@ def create_target_image(cmd, location, transient_resource_group_name, source_type, source_object_name, source_os_disk_snapshot_name, source_os_disk_snapshot_url, source_os_type, target_resource_group_name, azure_pool_frequency, tags, target_name, target_subscription, - export_as_snapshot, timeout, hyper_v_generation=None): + export_as_snapshot, timeout, hyper_v_generation='V1'): random_string = get_random_string( STORAGE_ACCOUNT_NAME_LENGTH - len(location)) @@ -123,9 +123,8 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ '--name', target_snapshot_name, '--location', location, '--source', target_blob_path, - '--source-storage-account-id', source_storage_account_id] - if hyper_v_generation: - cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation] + '--source-storage-account-id', source_storage_account_id, + '--hyper-v-generation', hyper_v_generation] cli_cmd = prepare_cli_command(cmd_content, subscription=target_subscription) json_output = run_cli_command(cli_cmd, return_as_json=True) @@ -149,9 +148,8 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ '--name', target_image_name, '--location', location, '--os-type', source_os_type, - '--source', target_snapshot_id] - if hyper_v_generation: - cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation] + '--source', target_snapshot_id, + '--hyper-v-generation', hyper_v_generation] cli_cmd = prepare_cli_command(cmd_content, tags=tags, subscription=target_subscription) From f96b3446f318fff9a17de3821c64e66bf97bb2bd Mon Sep 17 00:00:00 2001 From: Yan Zhu Date: Mon, 29 Aug 2022 15:13:21 +0800 Subject: [PATCH 3/3] default value of create target image is reset to V1, and modify history.rst and setup.py --- src/image-copy/HISTORY.rst | 4 ++++ src/image-copy/azext_imagecopy/create_target.py | 12 +++++------- src/image-copy/setup.py | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/image-copy/HISTORY.rst b/src/image-copy/HISTORY.rst index e8bf471ccef..74ca3cfdbdd 100644 --- a/src/image-copy/HISTORY.rst +++ b/src/image-copy/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +0.2.10 +++++++ +* Fix the issue that the hyper_v_generation used for copying image is None when showing resource. + 0.2.9 ++++++ * Fix the issue that the hyper_v_generation is always V1 when copying the image. diff --git a/src/image-copy/azext_imagecopy/create_target.py b/src/image-copy/azext_imagecopy/create_target.py index b91ef1b9129..32618d9bfa6 100644 --- a/src/image-copy/azext_imagecopy/create_target.py +++ b/src/image-copy/azext_imagecopy/create_target.py @@ -21,7 +21,7 @@ def create_target_image(cmd, location, transient_resource_group_name, source_type, source_object_name, source_os_disk_snapshot_name, source_os_disk_snapshot_url, source_os_type, target_resource_group_name, azure_pool_frequency, tags, target_name, target_subscription, - export_as_snapshot, timeout, hyper_v_generation=None): + export_as_snapshot, timeout, hyper_v_generation='V1'): random_string = get_random_string( STORAGE_ACCOUNT_NAME_LENGTH - len(location)) @@ -123,9 +123,8 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ '--name', target_snapshot_name, '--location', location, '--source', target_blob_path, - '--source-storage-account-id', source_storage_account_id] - if hyper_v_generation: - cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation] + '--source-storage-account-id', source_storage_account_id, + '--hyper-v-generation', hyper_v_generation] cli_cmd = prepare_cli_command(cmd_content, subscription=target_subscription) json_output = run_cli_command(cli_cmd, return_as_json=True) @@ -149,9 +148,8 @@ def create_target_image(cmd, location, transient_resource_group_name, source_typ '--name', target_image_name, '--location', location, '--os-type', source_os_type, - '--source', target_snapshot_id] - if hyper_v_generation: - cmd_content = cmd_content + ['--hyper-v-generation', hyper_v_generation] + '--source', target_snapshot_id, + '--hyper-v-generation', hyper_v_generation] cli_cmd = prepare_cli_command(cmd_content, tags=tags, subscription=target_subscription) diff --git a/src/image-copy/setup.py b/src/image-copy/setup.py index b0e6c1936da..cd53ee43685 100644 --- a/src/image-copy/setup.py +++ b/src/image-copy/setup.py @@ -8,7 +8,7 @@ from codecs import open from setuptools import setup, find_packages -VERSION = "0.2.9" +VERSION = "0.2.10" CLASSIFIERS = [ 'Development Status :: 4 - Beta',