{Compute} az vm/vmss create: Fix --os-type auto value assignment and resolve API calling redundancy#33492
Merged
Merged
Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the VM/VMSS create validation flow to determine --os-type from the actual marketplace image metadata (via az vm image show) instead of inferring from namespace.os_offer, and reduces repeated vm image show calls by centralizing the lookup in a cached helper.
Changes:
- Add
_show_vm_image()helper that callsaz vm image showonce and caches the result on the argparse namespace. - Use
osDiskImage.operatingSystemfrom the image response to setnamespace.os_typewhen--os-typeisn’t provided. - Reuse
_show_vm_image()for trusted launch / generation validation to avoid duplicate API calls.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+322
to
+326
| def _show_vm_image(cmd, namespace): | ||
| if getattr(namespace, '_vm_image_info', None): | ||
| return namespace._vm_image_info | ||
|
|
||
| from .aaz.latest.vm.image import Show as VMImageShow |
Comment on lines
+652
to
+659
| if not namespace.os_type: | ||
| namespace.os_type = 'windows' if 'windows' in namespace.os_offer.lower() else 'linux' | ||
| image = _show_vm_image(cmd, namespace) | ||
|
|
||
| os_system = image.get('osDiskImage', {}).get('operatingSystem', '') | ||
| if 'windows' in os_system.lower(): | ||
| namespace.os_type = 'windows' | ||
| else: | ||
| namespace.os_type = 'linux' |
Collaborator
|
Compute |
yanzhudd
reviewed
Jun 4, 2026
yanzhudd
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related command
az vm createaz vmss createDescription
Issue: When
--os-typeis not provided,--os_typeinvm/ vmss createcommand is automatically assigned based on value fromnamespace.os_offer, which is unreliable.Solution: Queries the image via
vm image showAPI/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus/{skus}/versions/{version}and reads the value ofosDiskImage.operatingSystemfield to set--os-type.Issue: There are a redundant of calling of
vm image showAPI, 2 times in total before this change.Solution: I have extracted it into a single
_show_vm_image()helper function and cache collected image value on the namespace, so the same image is being fetch once instead of multiple times.Testing Guide
History Notes
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.