Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,24 @@ 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 and namespace.storage_profile != StorageProfile.SharedGalleryImage:
namespace.os_type = 'windows' if 'windows' in namespace.os_offer.lower() else 'linux'
if not namespace.os_type:
if namespace.storage_profile == StorageProfile.SharedGalleryImage:

if namespace.location is None:
from azure.cli.core.azclierror import RequiredArgumentMissingError
raise RequiredArgumentMissingError(
'Please input the location of the shared gallery image through the parameter --location.')

from ._vm_utils import parse_shared_gallery_image_id
image_info = parse_shared_gallery_image_id(namespace.image)

from ._client_factory import cf_shared_gallery_image
shared_gallery_image_info = cf_shared_gallery_image(cmd.cli_ctx).get(
location=namespace.location, gallery_unique_name=image_info[0], gallery_image_name=image_info[1])
namespace.os_type = shared_gallery_image_info.os_type

else:
namespace.os_type = 'windows' if 'windows' in namespace.os_offer.lower() else 'linux'

from ._vm_utils import normalize_disk_info
# attach_data_disks are not exposed yet for VMSS, so use 'getattr' to avoid crash
Expand Down
17 changes: 17 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,23 @@ def is_shared_gallery_image_id(image_reference):
return False


def parse_shared_gallery_image_id(image_reference):
from azure.cli.core.azclierror import InvalidArgumentValueError

if not image_reference:
raise InvalidArgumentValueError(
'Please pass in the shared gallery image id through the parameter --image')

image_info = re.search(r'^/SharedGalleries/([^/]*)/Images/([^/]*)/Versions/.*$', image_reference, re.IGNORECASE)
if not image_info or len(image_info.groups()) < 2:
raise InvalidArgumentValueError(
'The shared gallery image id is invalid. The valid format should be '
'"/SharedGalleries/{gallery_unique_name}/Images/{gallery_image_name}/Versions/{image_version}"')

# Return the gallery unique name and gallery image name parsed from shared gallery image id
return image_info.group(1), image_info.group(2)


class ArmTemplateBuilder20190401(ArmTemplateBuilder):

def __init__(self):
Expand Down
Loading