-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Compute] az vm create: Support creating VM from shared gallery image
#19037
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
Changes from all commits
956df1b
7fc9efe
a8a3e63
00e1ef9
9e7461a
0fbaa00
ad8adfe
c16afa7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,10 @@ def _parse_image_argument(cmd, namespace): | |
| if is_valid_resource_id(namespace.image): | ||
| return 'image_id' | ||
|
|
||
| from ._vm_utils import is_shared_gallery_image_id | ||
| if is_shared_gallery_image_id(namespace.image): | ||
| return 'shared_gallery_image_id' | ||
|
|
||
| # 2 - attempt to match an URN pattern | ||
| urn_match = re.match('([^:]*):([^:]*):([^:]*):([^:]*)', namespace.image) | ||
| if urn_match: | ||
|
|
@@ -324,7 +328,7 @@ def _get_image_plan_info_if_exists(cmd, namespace): | |
| "will be skipped", namespace.image, ex.message) | ||
|
|
||
|
|
||
| # pylint: disable=inconsistent-return-statements | ||
| # pylint: disable=inconsistent-return-statements, too-many-return-statements | ||
| def _get_storage_profile_description(profile): | ||
| if profile == StorageProfile.SACustomImage: | ||
| return 'create unmanaged OS disk created from generalized VHD' | ||
|
|
@@ -338,6 +342,8 @@ def _get_storage_profile_description(profile): | |
| return 'create managed OS disk from Azure Marketplace image' | ||
| if profile == StorageProfile.ManagedSpecializedOSDisk: | ||
| return 'attach existing managed OS disk' | ||
| if profile == StorageProfile.SharedGalleryImage: | ||
| return 'create OS disk from shared gallery image' | ||
|
|
||
|
|
||
| def _validate_location(cmd, namespace, zone_info, size_info): | ||
|
|
@@ -379,6 +385,8 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False): | |
| elif image_type == 'image_id': | ||
| # STORAGE PROFILE #5 | ||
| namespace.storage_profile = StorageProfile.ManagedCustomImage | ||
| elif image_type == 'shared_gallery_image_id': | ||
| namespace.storage_profile = StorageProfile.SharedGalleryImage | ||
| elif image_type == 'urn': | ||
| if namespace.use_unmanaged_disk: | ||
| # STORAGE PROFILE #1 | ||
|
|
@@ -411,6 +419,11 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False): | |
| if for_scale_set: | ||
| forbidden.append('os_disk_name') | ||
|
|
||
| elif namespace.storage_profile == StorageProfile.SharedGalleryImage: | ||
| required = ['image'] | ||
| forbidden = ['os_type', 'attach_os_disk', 'storage_account', | ||
| 'storage_container_name', 'use_unmanaged_disk'] | ||
|
|
||
| elif namespace.storage_profile == StorageProfile.ManagedSpecializedOSDisk: | ||
| required = ['os_type', 'attach_os_disk'] | ||
| forbidden = ['os_disk_name', 'os_caching', 'storage_account', 'ephemeral_os_disk', | ||
|
|
@@ -505,7 +518,7 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False): | |
| namespace.attach_data_disks = [_get_resource_id(cmd.cli_ctx, d, namespace.resource_group_name, 'disks', | ||
| 'Microsoft.Compute') for d in namespace.attach_data_disks] | ||
|
|
||
| if not namespace.os_type: | ||
| if not namespace.os_type and namespace.storage_profile != StorageProfile.SharedGalleryImage: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is shared gallery image excluded in this logic?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because the shared gallery image does not require |
||
| namespace.os_type = 'windows' if 'windows' in namespace.os_offer.lower() else 'linux' | ||
|
|
||
| from ._vm_utils import normalize_disk_info | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -361,6 +361,17 @@ def _update(info, lun, value): | |
| _update(info_dict, lun, value) | ||
|
|
||
|
|
||
| def is_shared_gallery_image_id(image_reference): | ||
| if not image_reference: | ||
| return False | ||
|
|
||
| shared_gallery_id_pattern = re.compile(r'^/SharedGalleries/[^/]*/Images/[^/]*/Versions/.*$', re.IGNORECASE) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure this regex covers all scenario for shared gallery image id?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I confirmed this regex expression with @kangsun-ctrl |
||
| if shared_gallery_id_pattern.match(image_reference): | ||
| return True | ||
|
|
||
| return False | ||
|
|
||
|
|
||
| class ArmTemplateBuilder20190401(ArmTemplateBuilder): | ||
|
|
||
| def __init__(self): | ||
|
|
||
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.
Is
os_disk_namealso forbidden by shared gallery image?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.
No, it supports setting the
os_disk_namefor shared gallery image