-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Continue parsing image argument if aliases doc unreachable #10658
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
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 |
|---|---|---|
|
|
@@ -254,14 +254,18 @@ def _parse_image_argument(cmd, namespace): | |
|
|
||
| # 4 - attempt to match an URN alias (most likely) | ||
| from azure.cli.command_modules.vm._actions import load_images_from_aliases_doc | ||
| images = load_images_from_aliases_doc(cmd.cli_ctx) | ||
| matched = next((x for x in images if x['urnAlias'].lower() == namespace.image.lower()), None) | ||
| if matched: | ||
| namespace.os_publisher = matched['publisher'] | ||
| namespace.os_offer = matched['offer'] | ||
| namespace.os_sku = matched['sku'] | ||
| namespace.os_version = matched['version'] | ||
| return 'urn' | ||
| import requests | ||
| try: | ||
| images = load_images_from_aliases_doc(cmd.cli_ctx) | ||
| matched = next((x for x in images if x['urnAlias'].lower() == namespace.image.lower()), None) | ||
| if matched: | ||
| namespace.os_publisher = matched['publisher'] | ||
| namespace.os_offer = matched['offer'] | ||
| namespace.os_sku = matched['sku'] | ||
| namespace.os_version = matched['version'] | ||
| return 'urn' | ||
| except requests.exceptions.ConnectionError: | ||
| pass | ||
|
|
||
| # 5 - check if an existing managed disk image resource | ||
| compute_client = _compute_client_factory(cmd.cli_ctx) | ||
|
|
@@ -271,9 +275,15 @@ def _parse_image_argument(cmd, namespace): | |
| 'images', 'Microsoft.Compute') | ||
| return 'image_id' | ||
| except CloudError: | ||
| err = 'Invalid image "{}". Use a valid image URN, custom image name, custom image id, VHD blob URI, or ' \ | ||
| 'pick an image from {}.\nSee vm create -h for more information on specifying an image.' | ||
| raise CLIError(err.format(namespace.image, [x['urnAlias'] for x in images])) | ||
| if images is not None: | ||
| err = 'Invalid image "{}". Use a valid image URN, custom image name, custom image id, ' \ | ||
| 'VHD blob URI, or pick an image from {}.\nSee vm create -h for more information ' \ | ||
| 'on specifying an image.'.format(namespace.image, [x['urnAlias'] for x in images]) | ||
| else: | ||
| err = 'Failed to connect to remote source of image aliases. Invalid image "{}". Use a ' \ | ||
| 'valid image URN, custom image name, custom image id, or VHD blob URI.\nSee vm ' \ | ||
| 'create -h for more information on specifying an image.'.format(namespace.image) | ||
|
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. If it's not a valid alias nor an existing image name, what will happen?
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. If it's not a valid alias then it goes to |
||
| raise CLIError(err) | ||
|
|
||
|
|
||
| def _get_image_plan_info_if_exists(cmd, namespace): | ||
|
|
||
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.
we can throw the exception here with the error string you put in the 5th step, since that step won't work anyway
CC: @qwordy
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 can be an existing managed disk image resource.
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.
@yugangw-msft no, that's what we are trying to avoid here. Even on failure in
#4,#5should still be attempted.