Skip to content

Update compute SDK imports to use non-versioned models path#32282

Closed
Copilot wants to merge 2 commits into
devfrom
copilot/update-sdk-to-single-api-version-again
Closed

Update compute SDK imports to use non-versioned models path#32282
Copilot wants to merge 2 commits into
devfrom
copilot/update-sdk-to-single-api-version-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 20, 2025

Problem

The Azure Compute SDK (azure-mgmt-compute) is transitioning from a multi-version structure with versioned import paths (e.g., azure.mgmt.compute.v2024_11_01.models) to a single-version structure with direct model imports from azure.mgmt.compute.models. This change is part of the SDK's evolution to simplify package structure and reduce complexity.

Solution

This PR updates the _get_compute_model() helper method in the VM test module to use the non-versioned import path instead of dynamically constructing versioned paths.

Changed

File: src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_actions.py

The _get_compute_model() method previously:

  1. Retrieved the API version from the profile system
  2. Constructed a versioned import path (e.g., azure.mgmt.compute.v2024_11_01.models)
  3. Dynamically imported models from that versioned path

Now it:

  1. Imports models directly from azure.mgmt.compute.models
  2. Eliminates dependency on API version formatting

Before:

def _get_compute_model(model_type, api_version=None):
    from azure.cli.core.profiles._shared import AZURE_API_PROFILES, ResourceType
    from importlib import import_module

    if api_version is None:
        api_version = AZURE_API_PROFILES['latest'][ResourceType.MGMT_COMPUTE].default_api_version
    api_version = "v" + api_version.replace("-", "_")
    result = getattr(import_module('azure.mgmt.compute.{}.models'.format(api_version)), model_type)
    return result

After:

def _get_compute_model(model_type, api_version=None):
    # With azure-mgmt-compute 34.1.0+, models are imported directly from azure.mgmt.compute.models
    # instead of versioned paths like azure.mgmt.compute.v2024_11_01.models
    from importlib import import_module
    
    result = getattr(import_module('azure.mgmt.compute.models'), model_type)
    return result

Impact

  • Forward Compatible: Works with future SDK versions (35.0.0+) that will only have the single models module
  • Backward Compatible: Works with current SDK version (34.1.0) which still has both structures
  • No Breaking Changes: This is a test-only change that doesn't affect runtime behavior

Verification

✅ Verified the import works correctly with azure-mgmt-compute 34.1.0
✅ Python syntax validation passed
✅ Confirmed no other versioned imports exist in the codebase
✅ Other modules already use non-versioned imports correctly

Related

This change addresses the issue described in the problem statement about adapting to the compute SDK's single API version structure after the SDK upgrade.

Original prompt

compute sdk之前是多个api版本同时存在,现在sdk升级后变为单个api版本,只有最新的api, 该如何修改代码来使用新的sdk 需要修改的地方有哪些


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Breaking Change Starting...

Thanks for your contribution!

Co-authored-by: Jing-song <37168047+Jing-song@users.noreply.github.com>
Copilot AI changed the title [WIP] Update code to use new SDK with single API version Update compute SDK imports to use non-versioned models path Oct 20, 2025
Copilot AI requested a review from Jing-song October 20, 2025 04:35
@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Oct 20, 2025

compute

@Jing-song Jing-song closed this Oct 20, 2025
@Jing-song Jing-song deleted the copilot/update-sdk-to-single-api-version-again branch October 20, 2025 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants