Skip to content
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] Increase robustness of vm image list #12134

Merged
merged 2 commits into from
Feb 13, 2020
Merged
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
19 changes: 16 additions & 3 deletions src/azure-cli/azure/cli/command_modules/vm/_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,28 @@ def load_images_thru_services(cli_ctx, publisher, offer, sku, location):
location = get_one_of_subscription_locations(cli_ctx)

def _load_images_from_publisher(publisher):
offers = client.virtual_machine_images.list_offers(location, publisher)
from msrestazure.azure_exceptions import CloudError
try:
offers = client.virtual_machine_images.list_offers(location, publisher)
except CloudError as e:
logger.warning(str(e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, if there is an exception, it will be treated as an error. After updating, it will be treated as a warning, right ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. There are many publishers. This function will be invoked many times. An error will fail the command. But there are other valid publishers. So I catch it.

return
if offer:
offers = [o for o in offers if _matched(offer, o.name)]
for o in offers:
skus = client.virtual_machine_images.list_skus(location, publisher, o.name)
try:
skus = client.virtual_machine_images.list_skus(location, publisher, o.name)
except CloudError as e:
logger.warning(str(e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if meet exception for some offer, the skus of it will be skipped ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

continue
if sku:
skus = [s for s in skus if _matched(sku, s.name)]
for s in skus:
images = client.virtual_machine_images.list(location, publisher, o.name, s.name)
try:
images = client.virtual_machine_images.list(location, publisher, o.name, s.name)
except CloudError as e:
logger.warning(str(e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.message? I'm not familiar with it. What's the difference between e.message and str(e)? @jiasli

Copy link
Contributor

@arrownj arrownj Feb 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I know, str(object) will call the object._str_() at last. and e.message is just a property of e. Whether these two values are the same depends on how to implement the function _str_(). If it return message directly, they will be the same. However, for most cases, _str_ will serialize all the properties of the object. @myronfanqiu

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str(e) can tell more details including which publisher cannot be found. It's ok to use e.message here. The difference depends on specific implementation.
code:
msrestazure\azure_exceptions.py, class CloudError(ClientException):

continue
for i in images:
all_images.append({
'publisher': publisher,
Expand Down