{Compute} az vm monitor log: Migrate command group to aaz-based implementation#32848
{Compute} az vm monitor log: Migrate command group to aaz-based implementation#32848william051200 wants to merge 3 commits intoAzure:devfrom
az vm monitor log: Migrate command group to aaz-based implementation#32848Conversation
️✔️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
Migrates az vm monitor log show’s VM retrieval path from the mgmt.compute SDK object model to the AAZ-based VMShow implementation, adjusting downstream access to the VM’s extension resources accordingly.
Changes:
- Replace
get_vmwithget_vm_by_aazfor VM retrieval inexecute_query_for_vm. - Update extension resource parsing from attribute access (
vm.resources,resource.settings) to dict access (vm.get(...),resource.get(...)).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for resource in extension_resources: | ||
| if resource.name == "MicrosoftMonitoringAgent" or resource.name == "OmsAgentForLinux": | ||
| workspace = resource.settings.get('workspaceId', None) | ||
| if resource.get('name') == "MicrosoftMonitoringAgent" or resource.get('name') == "OmsAgentForLinux": |
There was a problem hiding this comment.
This introduces duplicate literal extension names. Since _WINDOWS_OMS_AGENT_EXT and _LINUX_OMS_AGENT_EXT are already defined in this module, use those constants (and a single membership check) to avoid drift if the extension names ever change.
| if resource.get('name') == "MicrosoftMonitoringAgent" or resource.get('name') == "OmsAgentForLinux": | |
| if resource.get('name') in (_WINDOWS_OMS_AGENT_EXT, _LINUX_OMS_AGENT_EXT): |
| workspace = resource.get('settings').get('workspaceId', None) | ||
| if workspace is None: | ||
| raise CLIError('Cannot find the corresponding log analytics workspace. ' | ||
| 'Please check the status of log analytics workpsace.') |
There was a problem hiding this comment.
Typo in error message: "workpsace" should be "workspace".
| 'Please check the status of log analytics workpsace.') | |
| 'Please check the status of log analytics workspace.') |
| def execute_query_for_vm(cmd, client, resource_group_name, vm_name, analytics_query, timespan=None): | ||
| """Executes a query against the Log Analytics workspace linked with a vm.""" | ||
| vm = get_vm(cmd, resource_group_name, vm_name) | ||
| vm = get_vm_by_aaz(cmd, resource_group_name, vm_name) |
There was a problem hiding this comment.
Switching from get_vm (mgmt SDK) to get_vm_by_aaz changes the underlying REST api-version used for the VM GET request (AAZ vm show targets 2025-04-01). This will likely break VCR playback for existing vm monitor log show test recordings captured with an older api-version, so the recordings should be re-generated/updated.
| vm = get_vm_by_aaz(cmd, resource_group_name, vm_name) | |
| vm = get_vm(cmd, resource_group_name, vm_name) |
Related command
az vm monitor log showDescription
Migration from mgmt.compute to aaz-based
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.