Skip to content

Commit

Permalink
[Image Copy] Fix snapshot create issue (Azure#1172)
Browse files Browse the repository at this point in the history
* [Image Copy]Fix issue 11625

* Add test case
  • Loading branch information
qwordy authored and ManuInNZ committed Apr 11, 2020
1 parent 134ef16 commit 81c0b75
Show file tree
Hide file tree
Showing 4 changed files with 1,725 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/image-copy/azext_imagecopy/create_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from knack.util import CLIError
from knack.log import get_logger

from msrestazure.tools import resource_id
from azure.cli.core.commands.client_factory import get_subscription_id

from azext_imagecopy.cli_utils import run_cli_command, prepare_cli_command

logger = get_logger(__name__)
Expand All @@ -18,7 +21,7 @@

# pylint: disable=too-many-statements
# pylint: disable=too-many-locals
def create_target_image(location, transient_resource_group_name, source_type, source_object_name,
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):
Expand Down Expand Up @@ -113,11 +116,21 @@ def create_target_image(location, transient_resource_group_name, source_type, so
else:
snapshot_resource_group_name = transient_resource_group_name

storage_account_name = target_blob_path.split('.')[0].split('/')[-1]
if target_subscription:
subscription_id = target_subscription
else:
subscription_id = get_subscription_id(cmd.cli_ctx)
source_storage_account_id = resource_id(
subscription=subscription_id, resource_group=transient_resource_group_name,
namespace='Microsoft.Storage', type='storageAccounts', name=storage_account_name)

cli_cmd = prepare_cli_command(['snapshot', 'create',
'--resource-group', snapshot_resource_group_name,
'--name', target_snapshot_name,
'--location', location,
'--source', target_blob_path],
'--source', target_blob_path,
'--source-storage-account-id', source_storage_account_id],
subscription=target_subscription)

json_output = run_cli_command(cli_cmd, return_as_json=True)
Expand Down
4 changes: 2 additions & 2 deletions src/image-copy/azext_imagecopy/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# pylint: disable=too-many-statements
# pylint: disable=too-many-locals
# pylint: disable=too-many-branches
def imagecopy(source_resource_group_name, source_object_name, target_location,
def imagecopy(cmd, source_resource_group_name, source_object_name, target_location,
target_resource_group_name, temporary_resource_group_name='image-copy-rg',
source_type='image', cleanup='false', parallel_degree=-1, tags=None, target_name=None,
target_subscription=None, export_as_snapshot='false', timeout=3600):
Expand Down Expand Up @@ -130,7 +130,7 @@ def imagecopy(source_resource_group_name, source_object_name, target_location,
logger.debug("Starting sync process for all locations")
for location in target_location:
location = location.strip()
create_target_image(location, transient_resource_group_name, source_type,
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)
Expand Down
Loading

0 comments on commit 81c0b75

Please sign in to comment.