Skip to content

Commit

Permalink
[Compute] Fix #5258: az image copy: Fix expected not NoneType err…
Browse files Browse the repository at this point in the history
…or (#5274)
  • Loading branch information
yanzhudd authored Nov 30, 2022
1 parent bae75f7 commit 8e47d9d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
4 changes: 4 additions & 0 deletions src/image-copy/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 16 additions & 15 deletions src/image-copy/azext_imagecopy/create_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ 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,
'--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']
Expand All @@ -143,13 +143,14 @@ 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,
'--hyper-v-generation', hyper_v_generation]
cli_cmd = prepare_cli_command(cmd_content,
tags=tags,
subscription=target_subscription)

Expand Down
40 changes: 21 additions & 19 deletions src/image-copy/azext_imagecopy/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion src/image-copy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 8e47d9d

Please sign in to comment.