-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Compute} az image create: Migrate command to aaz-based implementation
#32884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
89eb9c9
2df9f37
5c94035
467b41a
c888cb0
fa22547
adab031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2161,27 +2161,33 @@ def process_image_create_namespace(cmd, namespace): | |
| 'virtualMachines', 'Microsoft.Compute') | ||
| res = parse_resource_id(res_id) | ||
| if res['type'] == 'virtualMachines': | ||
| compute_client = _compute_client_factory(cmd.cli_ctx, subscription_id=res['subscription']) | ||
| vm_info = compute_client.virtual_machines.get(res['resource_group'], res['name']) | ||
| from .operations.vm import VMShow | ||
| command_args = { | ||
| 'subscription': res['subscription'], | ||
| 'resource_group': res['resource_group'], | ||
| 'vm_name': res['name'] | ||
| } | ||
| vm_info = VMShow(cli_ctx=cmd.cli_ctx)(command_args=command_args) | ||
| source_from_vm = True | ||
| except ResourceNotFoundError: | ||
| pass | ||
|
|
||
| if source_from_vm: | ||
| # pylint: disable=no-member | ||
| namespace.os_type = vm_info.storage_profile.os_disk.os_type | ||
| namespace.os_type = vm_info.get('storageProfile', {}).get('osDisk', {}).get('osType') | ||
| namespace.source_virtual_machine = res_id | ||
| if namespace.data_disk_sources: | ||
| raise CLIError("'--data-disk-sources' is not allowed when capturing " | ||
| "images from virtual machines") | ||
| else: | ||
| namespace.os_blob_uri, namespace.os_disk, namespace.os_snapshot, _, _ = _figure_out_storage_source(cmd.cli_ctx, namespace.resource_group_name, namespace.source) # pylint: disable=line-too-long | ||
| namespace.os_blob_uri, namespace.os_disk, namespace.os_snapshot, _, _ = \ | ||
| _figure_out_storage_source_by_aaz(cmd.cli_ctx, namespace.resource_group_name, namespace.source) | ||
| namespace.data_blob_uris = [] | ||
| namespace.data_disks = [] | ||
| namespace.data_snapshots = [] | ||
| if namespace.data_disk_sources: | ||
| for data_disk_source in namespace.data_disk_sources: | ||
| source_blob_uri, source_disk, source_snapshot, _, _ = _figure_out_storage_source( | ||
| source_blob_uri, source_disk, source_snapshot, _, _ = _figure_out_storage_source_by_aaz( | ||
| cmd.cli_ctx, namespace.resource_group_name, data_disk_source) | ||
| if source_blob_uri: | ||
| namespace.data_blob_uris.append(source_blob_uri) | ||
|
|
@@ -2218,6 +2224,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
+2227
to
+2248
|
||
|
|
||
|
|
||
| def _get_disk_or_snapshot_info(cli_ctx, resource_group_name, source): | ||
| compute_client = _compute_client_factory(cli_ctx) | ||
| is_snapshot = True | ||
|
|
@@ -2231,6 +2261,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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -811,6 +811,12 @@ class VMGuestPatchClassificationLinux(Enum): | |||||
| SECURITY = 'Security' | ||||||
|
|
||||||
|
|
||||||
| class CachingTypes(Enum): | ||||||
|
||||||
| class CachingTypes(Enum): | |
| class DiskCachingTypes(Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well done!