-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Compute] image builder create: add --image-template; image template: rename template to builder #11865
Changes from 25 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 |
---|---|---|
|
@@ -5,10 +5,13 @@ | |
|
||
# TODO refactor out _image_builder commands. | ||
# i.e something like image_builder/_client_factory image_builder/commands.py image_builder/_params.py | ||
|
||
import os | ||
import re | ||
import json | ||
import traceback | ||
from enum import Enum | ||
|
||
import requests | ||
|
||
try: | ||
from urllib.parse import urlparse | ||
|
@@ -152,6 +155,9 @@ def _validate_location(location, location_names, location_display_names): | |
|
||
|
||
def process_image_template_create_namespace(cmd, namespace): # pylint: disable=too-many-locals, too-many-branches, too-many-statements | ||
if namespace.image_template is not None: | ||
return | ||
|
||
from azure.cli.core.commands.parameters import get_subscription_locations | ||
|
||
source = None | ||
|
@@ -370,16 +376,47 @@ def process_img_tmpl_output_add_namespace(cmd, namespace): | |
|
||
# region Custom Commands | ||
|
||
def create_image_template( # pylint: disable=too-many-locals | ||
def create_image_template( # pylint: disable=too-many-locals, too-many-branches, too-many-statements | ||
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, 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: | ||
if os.path.exists(image_template): | ||
# Local file | ||
with open(image_template) as f: | ||
content = f.read() | ||
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. why local file content has no json schema validation? 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. compare to URL logic, seems it should be content = json.loads(f.read()) here ? 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. I should reduce indent. Fixed. |
||
else: | ||
# It should be an URL | ||
msg = '\nusage error: --image-template is not a correct local path or URL' | ||
try: | ||
r = requests.get(image_template) | ||
except Exception: | ||
raise CLIError(traceback.format_exc() + msg) | ||
if r.status_code != 200: | ||
raise CLIError(traceback.format_exc() + msg) | ||
content = r.content | ||
|
||
try: | ||
obj = json.loads(content) | ||
except json.JSONDecodeError: | ||
raise CLIError(traceback.format_exc() + | ||
'\nusage error: Content of --image-template is not a valid JSON string') | ||
content = {} | ||
if 'properties' in obj: | ||
content = obj['properties'] | ||
if 'location' in obj: | ||
content['location'] = obj['location'] | ||
if 'tags' in obj: | ||
content['tags'] = obj['tags'] | ||
return client.virtual_machine_image_templates.create_or_update( | ||
yungezz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parameters=content, resource_group_name=resource_group_name, image_template_name=image_template_name) | ||
|
||
template_source, template_scripts, template_destinations = None, [], [] | ||
|
||
# create image template source settings | ||
|
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.
This only supports absolute path? Can you add an example in help?
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.
It supports both absolute path and relative path.
Added.