Skip to content

{vm-repair} Migrate commands calling Compute module to aaz-based implementation and update deprecated package#10106

Draft
william051200 wants to merge 8 commits into
Azure:mainfrom
william051200:vm-repair-migration
Draft

{vm-repair} Migrate commands calling Compute module to aaz-based implementation and update deprecated package#10106
william051200 wants to merge 8 commits into
Azure:mainfrom
william051200:vm-repair-migration

Conversation

@william051200

@william051200 william051200 commented Jul 14, 2026

Copy link
Copy Markdown
Member

Migrate code from Azure SDK to AAZ based commands for compute operations
Replace deprecated pkgutil loader with importlib.import_module

After running some tests for version compatibility, here are the results I got,
az extension add vm-repair 2.2.1 package generated from azdev 0.2.12 & 0.2.13 will show version = null

Those successfully installed (with no null version) also runs properly, with no error.
This confirms the migration has no issue & the issue raised by user is caused by version incompatibility.

Azure CLI 0.87:
1. azdev 0.2.13 - fail (no version)
2. azdev 0.2.12 - fail (no version)
3. azdev 0.2.10 - success
4. azdev 0.2.9 - success
5. azdev 0.2.8 - success

Azure CLI 0.88:
1. azdev 0.2.13 - success
2. azdev 0.2.12 - success
3. azdev 0.2.10 - success
4. azdev 0.2.9 - success
5. azdev 0.2.8 - success

This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install azdev required)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

🤖 PR Validation — ️✔️ All clear

Breaking Changes
️✔️ None

Copilot AI review requested due to automatic review settings July 14, 2026 03:06
@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jul 14, 2026

Copy link
Copy Markdown
️✔️Azure CLI Extensions Breaking Change Test
️✔️Non Breaking Changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the vm-repair extension to use AAZ-based VM retrieval helpers (instead of Compute SDK objects) and adds defensive handling in extension-version checking to avoid crashes when version metadata is missing.

Changes:

  • Bump vm-repair extension version to 2.2.1 and update release notes.
  • Migrate VM object access patterns across custom.py, _validators.py, and repair_utils.py from SDK object attributes to AAZ JSON/dict access.
  • Add handling in check_extension_version to avoid 'str' > 'NoneType' crashes when extension version is null.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/vm-repair/setup.py Version bump to 2.2.1.
src/vm-repair/HISTORY.rst Add 2.2.1 release notes describing the migration and crash fix.
src/vm-repair/azext_vm_repair/repair_utils.py Switch VM parsing to dict access; add null-safe extension version check.
src/vm-repair/azext_vm_repair/custom.py Switch command implementation to AAZ VM retrieval and dict-based VM field access.
src/vm-repair/azext_vm_repair/_validators.py Switch validation logic to AAZ VM retrieval and dict-based access.

Comment on lines +510 to 512
os_image_ref = source_vm.get('storageProfile', {}).get('imageReference', {})
if os_image_ref and os_image_ref.get('version') in urns[0]:
if len(urns) < 2:
Comment on lines +522 to +526
repair_vm = get_vm_by_aaz(cmd, repair_vm_id['resource_group'], repair_vm_id['name'])
data_disks = repair_vm.get('storageProfile', {}).get('dataDisks')

# The params went through validator so no need for existence checks
disk_uri = [disk.vhd.uri for disk in data_disks if disk.name == disk_name][0]
disk_uri = [disk.get('vhd', {}).get('uri') for disk in data_disks if disk.get('name') == disk_name][0]
@yonzhan

yonzhan commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

vm-repair

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@william051200

william051200 commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (2)

src/vm-repair/azext_vm_repair/custom.py:541

  • In the unmanaged-disk restore path, this code assumes parameters have gone through the CLI validator, but restore() is also called internally (e.g., from repair-and-restore flows) without validators. If dataDisks is missing or disk_name isn’t found, the list indexing will raise and get reported as a generic "unexpected error". Add a defensive check and raise a clearer error before indexing.
                repair_vm = get_vm_by_aaz(cmd, repair_vm_id['resource_group'], repair_vm_id['name'])
                data_disks = repair_vm.get('storageProfile', {}).get('dataDisks')

                # The params went through validator so no need for existence checks
                disk_uri = [disk.get('vhd', {}).get('uri') for disk in data_disks if disk.get('name') == disk_name][0]

src/vm-repair/azext_vm_repair/repair_utils.py:576

  • Potential TypeError: os_image_ref.get('version') in urns[0] will raise if the version is None (or otherwise not a string). The previous implementation guarded this with an isinstance(..., str) check; keep that guard when switching to dict access.
    os_image_ref = source_vm.get('storageProfile', {}).get('imageReference', {})
    if os_image_ref and os_image_ref.get('version') in urns[0]:

@@ -30,8 +30,7 @@ def _get_cloud_init_script():
SCRIPTS_DIR_NAME = 'scripts'
CLOUD_INIT = 'linux-build_setup-cloud-init.txt'
# Build absoulte path of driver script
Comment thread src/vm-repair/setup.py
from setuptools import setup, find_packages

VERSION = "2.2.1"
VERSION = "2.2.2"
Comment thread src/vm-repair/HISTORY.rst
Comment on lines +5 to +8
2.2.2
++++++
Migrate code from Azure SDK to AAZ based commands for compute operations
Replace deprecated pkgutil loader with importlib.import_module
Comment thread src/vm-repair/HISTORY.rst

2.2.2
++++++
Migrate code from Azure SDK to AAZ based commands for compute operations
@william051200 william051200 changed the title {vm-repair} Migrate commands calling Compute module to aaz-based implementation and add handling for extension version is null case {vm-repair} Migrate commands calling Compute module to aaz-based implementation and update deprecated package Jul 22, 2026
@william051200
william051200 marked this pull request as draft July 22, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants