{Compute} az vm create: Fix API version when fetching virtual network resource#31945
{Compute} az vm create: Fix API version when fetching virtual network resource#31945
az vm create: Fix API version when fetching virtual network resource#31945Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an API version compatibility issue in the az vm create command where the resource SDK was upgraded to use API version 2025-01-01 for virtual network operations, but the server doesn't support this version yet. The fix adds a fallback mechanism to use the CLI's supported API version when the default fails.
Key changes:
- Added fallback logic to retry virtual network subnet existence checks with CLI-specific API version
- Imports the network command module to get the supported API version for virtual networks
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets', vnet, 'virtualNetworks') | ||
|
|
||
| if not subnet_exists: | ||
| from azure.cli.command_modules.network.aaz.latest.network.vnet import Show as VNetShow |
There was a problem hiding this comment.
The import statement is placed inside a conditional block that only executes when subnet doesn't exist. Consider moving this import to the top of the file to avoid repeated import overhead if this code path is executed multiple times.
| from azure.cli.command_modules.network.aaz.latest.network.vnet import Show as VNetShow |
|
|
||
| if not subnet_exists: | ||
| from azure.cli.command_modules.network.aaz.latest.network.vnet import Show as VNetShow | ||
| cli_api_version = VNetShow._aaz_info["version"] |
There was a problem hiding this comment.
Accessing private attributes (indicated by underscore prefix) like _aaz_info creates a tight coupling and may break if the internal structure changes. Consider using a public API or method to retrieve the version information.
| cli_api_version = VNetShow._aaz_info["version"] | |
| # Use public API to get version if available | |
| if hasattr(VNetShow, "get_version") and callable(getattr(VNetShow, "get_version")): | |
| cli_api_version = VNetShow.get_version() | |
| elif hasattr(VNetShow, "version"): | |
| cli_api_version = VNetShow.version | |
| else: | |
| # Fallback to private attribute with warning | |
| logger.warning("Accessing private attribute _aaz_info['version']. Consider updating to use a public API if available.") | |
| cli_api_version = VNetShow._aaz_info["version"] |
Related command
az vm createDescription
Inspired by #31868
IcM: 656299018
In
az vm createcommand, we rely on the resource SDK package to determine which API version is used when fetching a virtual network resource from the backend. However, the resource package was upgraded in #31449. And the new API version being used is 2025-01-01 which is not yet supported by server side.The error message is:
Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis 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.