-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Compute] image builder create: add --image-template; image template: rename template to builder #11865
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
[Compute] image builder create: add --image-template; image template: rename template to builder #11865
Changes from 13 commits
c8de859
428a4f2
6735e4f
95c68a3
448b7b3
782c901
67d1b0c
e52f447
01efbdb
07c00c0
a4aa547
57198e5
815a91d
8f8a648
29aba58
50c79dc
35fd323
ef13ba5
3bd036e
ba7181c
0ed0d23
785855a
c88fda4
7f9aaf6
8c1b812
b7ce361
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 |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
| # i.e something like image_builder/_client_factory image_builder/commands.py image_builder/_params.py | ||
|
|
||
| import re | ||
| import json | ||
| from json import JSONDecodeError | ||
| from enum import Enum | ||
|
|
||
|
|
||
|
|
@@ -374,12 +376,16 @@ def create_image_template( # pylint: disable=too-many-locals | |
| cmd, client, resource_group_name, image_template_name, location=None, | ||
| source_dict=None, scripts_list=None, destinations_lists=None, build_timeout=None, tags=None, | ||
| source=None, scripts=None, checksum=None, managed_image_destinations=None, # pylint: disable=unused-argument | ||
| shared_image_destinations=None, no_wait=False): # pylint: disable=unused-argument, too-many-locals | ||
| shared_image_destinations=None, no_wait=False, customize=None, distribute=None, image_template=None): # pylint: disable=unused-argument, too-many-locals | ||
| from azure.mgmt.imagebuilder.models import (ImageTemplate, ImageTemplateSharedImageVersionSource, | ||
| ImageTemplatePlatformImageSource, ImageTemplateIsoSource, ImageTemplateManagedImageSource, # pylint: disable=line-too-long | ||
| ImageTemplateShellCustomizer, ImageTemplatePowerShellCustomizer, | ||
| ImageTemplateManagedImageDistributor, ImageTemplateSharedImageDistributor) # pylint: disable=line-too-long | ||
|
|
||
| if image_template is not None: | ||
|
|
||
| return | ||
|
|
||
| template_source, template_scripts, template_destinations = None, [], [] | ||
|
|
||
| # create image template source settings | ||
|
|
@@ -394,29 +400,46 @@ def create_image_template( # pylint: disable=too-many-locals | |
|
|
||
| # create image template customizer settings | ||
| # Script structure can be found in _parse_script's function definition | ||
| for script in scripts_list: | ||
| script.pop("is_url") | ||
| script["script_uri"] = script.pop("script") | ||
|
|
||
| if script["type"] == ScriptType.SHELL: | ||
| template_scripts.append(ImageTemplateShellCustomizer(**script)) | ||
| elif script["type"] == ScriptType.POWERSHELL: | ||
| template_scripts.append(ImageTemplatePowerShellCustomizer(**script)) | ||
| else: # Should never happen | ||
| logger.debug("Script %s has type %s", script["script"], script["type"]) | ||
| raise CLIError("Script {} has an invalid type.".format(script["script"])) | ||
| if customize is not None: | ||
| if scripts_list: | ||
| raise CLIError('usage error: Do not use --scripts and --customize together') | ||
| try: | ||
| template_scripts = json.loads(customize) | ||
yungezz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| except JSONDecodeError: | ||
| raise CLIError('usage error: JSON decode error in --customize') | ||
|
||
| else: | ||
| for script in scripts_list: | ||
| script.pop("is_url") | ||
| script["script_uri"] = script.pop("script") | ||
|
|
||
| if script["type"] == ScriptType.SHELL: | ||
| template_scripts.append(ImageTemplateShellCustomizer(**script)) | ||
| elif script["type"] == ScriptType.POWERSHELL: | ||
| template_scripts.append(ImageTemplatePowerShellCustomizer(**script)) | ||
| else: # Should never happen | ||
| logger.debug("Script %s has type %s", script["script"], script["type"]) | ||
| raise CLIError("Script {} has an invalid type.".format(script["script"])) | ||
|
|
||
| # create image template distribution / destination settings | ||
| for dest_type, rid, loc_info in destinations_lists: | ||
| parsed = parse_resource_id(rid) | ||
| if dest_type == _DestType.MANAGED_IMAGE: | ||
| template_destinations.append(ImageTemplateManagedImageDistributor( | ||
| image_id=rid, location=loc_info, run_output_name=parsed['name'])) | ||
| elif dest_type == _DestType.SHARED_IMAGE_GALLERY: | ||
| template_destinations.append(ImageTemplateSharedImageDistributor( | ||
| gallery_image_id=rid, replication_regions=loc_info, run_output_name=parsed['child_name_1'])) | ||
| else: | ||
| logger.info("No applicable destination found for destination %s", str(tuple([dest_type, rid, loc_info]))) | ||
| if distribute is not None: | ||
| if destinations_lists: | ||
| raise CLIError('usage error: Do not use (--managed-image-destinations | --shared-image-destinations) and --distribute together') | ||
| try: | ||
| template_destinations = json.loads(distribute) | ||
yungezz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| except JSONDecodeError: | ||
| raise CLIError('usage error: JSON decode error in --distribute') | ||
|
||
|
|
||
| else: | ||
| for dest_type, rid, loc_info in destinations_lists: | ||
| parsed = parse_resource_id(rid) | ||
|
||
| if dest_type == _DestType.MANAGED_IMAGE: | ||
| template_destinations.append(ImageTemplateManagedImageDistributor( | ||
| image_id=rid, location=loc_info, run_output_name=parsed['name'])) | ||
| elif dest_type == _DestType.SHARED_IMAGE_GALLERY: | ||
| template_destinations.append(ImageTemplateSharedImageDistributor( | ||
| gallery_image_id=rid, replication_regions=loc_info, run_output_name=parsed['child_name_1'])) | ||
| else: | ||
| logger.info("No applicable destination found for destination %s", str(tuple([dest_type, rid, loc_info]))) | ||
|
|
||
| image_template = ImageTemplate(source=template_source, customize=template_scripts, distribute=template_destinations, | ||
| location=location, build_timeout_in_minutes=build_timeout, tags=(tags or {})) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.