Introducing a new way to review your PRs.

Read the announcement

azure / azure-cli

Azure Command-Line Interface

View on GitHub

13 documents · Updated Nov 16, 2026

docs / compute-vm-commands

Compute and VM command modules

Overview

This doc covers the compute-oriented Azure CLI command modules under src/azure-cli/azure/cli/command_modules/vm/**, src/azure-cli/azure/cli/command_modules/compute_recommender/**, src/azure-cli/azure/cli/command_modules/computefleet/**, and src/azure-cli/azure/cli/command_modules/sqlvm/**. Routing note: these paths own the built-in command loaders for classic Compute (az vm, az vmss, az disk, az sig, az image, az ppg, az capacity reservation, az restore-point), Compute Fleet (az compute-fleet), Compute Recommender (az compute-recommender), and SQL VM (az sql vm).

The main Compute loader is src/…/__init__.py. ComputeCommandsLoader sets ResourceType.MGMT_COMPUTE, loads generated AAZ command tables from src/azure-cli/azure/cli/command_modules/vm/aaz/**, then overlays hand-authored registrations from src/…/commands.py; it also optionally loads generated/manual legacy tables from generated and manual packages. src/…/commands.py is the routing map: most user-visible verbs dispatch to src/…/custom.py, while selected newer commands are implemented as AAZ wrapper classes in src/azure-cli/azure/cli/command_modules/vm/operations/** or directly by generated AAZ classes. Examples include disk update and disk grant-access from operations/disk.py, VM show/update/capture flattening fixes from operations/vm.py, VMSS update/list/show behavior from operations/vmss.py, and Shared Image Gallery, PPG, capacity reservation, restore point, and extension-image wrappers from sibling operations/*.py files.

Compute creation is template-first. az vm create is registered in vm/commands.py with validator process_vm_create_namespace from src/…/_validators.py, then calls create_vm in src/…/custom.py. The validator chooses defaults such as Standard_D2s_v5, validates location, image/storage/network/auth/MSI/security/capacity-reservation choices, and mutates argparse state before creation. create_vm resolves resource IDs, constructs network/storage dependencies, reads custom_data and user_data from files when paths exist, merges secrets, and builds an ARM deployment using resource builders from src/…/_template_builder.py. az vmss create follows the same pattern through process_vmss_create_namespace and create_vmss; the VMSS path enforces Flexible-mode restrictions, Standard Load Balancer defaults, NAT rule/pool choices, zonal placement, and template resources for load balancers, app gateways, NSGs, storage pools, and scale set profiles.

State for the VM module is split between ARM deployments, direct AAZ/SDK calls, and data-plane clients. src/…/_client_factory.py creates Compute management clients, Marketplace Ordering agreement operations for az vm image terms, Log Analytics management clients, and an azure.monitor.query.LogsQueryClient for az vm monitor log show. src/…/_actions.py handles VM image alias and server enumeration, reading cloud endpoint vm_image_alias_doc when available and falling back to the local alias JSON. src/…/disk_encryption.py manages Azure Disk Encryption through VM/VMSS extension configuration, Key Vault data-plane key lookups, and optional encryption identity updates. src/…/_vm_utils.py centralizes API-version selection, resource existence checks through ARM resources, SKU availability helpers, disk normalization, Key Vault client creation, and dynamic imports of profile-specific AAZ commands.

Arguments for the Compute module are concentrated in src/…/_params.py. It defines the large enum surface for VM/VMSS/disk/gallery/image-builder features, reusable argument types, completers, configured defaults for vm and vmss, and validators that normalize names to IDs. New command registrations in vm/commands.py almost always need matching argument contexts in _params.py and matching validation in _validators.py. Image Builder is a sub-area inside this module: command routing lives in vm/commands.py, argument validation and object assembly live in src/…/_image_builder.py, and service calls go through azure.mgmt.imagebuilder.ImageBuilderClient.

src/azure-cli/azure/cli/command_modules/compute_recommender/** is an AAZ-only module. Its loader in compute_recommender/__init__.py loads generated AAZ registrations; compute_recommender/commands.py, _params.py, and custom.py are placeholders. compute_recommender/…/__cmd_group.py registers az compute-recommender, and the two command files post to /subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/placementScores/spot/generate: compute_recommender/…/_spot_placement_score.py uses stable API 2025-06-05, while _spot_placement_recommender.py is preview and uses 2024-06-01-preview. Tests in compute_recommender/…/test_compute_recommender.py pass JSON strings for --desired-locations and --desired-sizes and assert placementScores is returned.

src/azure-cli/azure/cli/command_modules/computefleet/** is also AAZ-first. computefleet/__init__.py loads the generated AAZ package, while computefleet/commands.py, _params.py, and custom.py are empty overlays. computefleet/…/__cmd_group.py registers az compute-fleet; compute_fleet/__init__.py imports create, delete, list, list-vms, list-vmss, show, update, and wait command classes. These commands call the Microsoft.AzureFleet resource provider at /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureFleet/fleets/{fleetName} using API 2026-08-01. compute_fleet/_create.py and _update.py expose deeply nested AAZ object arguments for --compute-profile, --regular-priority-profile, --spot-priority-profile, --vm-sizes-profile, additional locations, VM attributes, and Fleet mode. Identity subcommands under computefleet/aaz/latest/compute_fleet/identity/** read the fleet, select its identity subresource, patch system/user-assigned identities, and send create-or-update LROs. computefleet/…/test_computefleet.py builds realistic fleet JSON with network public IP prerequisites and exercises both long option names and aliases such as --spp, --cp, and --vmsizeprof.

src/azure-cli/azure/cli/command_modules/sqlvm/** is a separate SDK-backed command module for Microsoft.SqlVirtualMachine. Its loader in sqlvm/__init__.py uses ResourceType.MGMT_SQLVM and suppresses the old sqlvm-preview extension. src/…/commands.py binds az sql vm, az sql vm group, and az sql vm group ag-listener to SDK operation groups returned by src/…/_util.py. Custom functions in src/…/custom.py assemble SDK model objects for SQL virtual machines, WSFC groups, availability group listeners, auto-patching, auto-backup, Key Vault credentials, connectivity, workload type, least-privilege mode, Azure AD auth, and assessment settings. src/…/_params.py defines the SQL VM argument surface and validators from src/…/_validators.py convert related resource names to ARM IDs and enforce combinations such as --sql-mgmt-type NoAgent requiring image offer/SKU and least-privilege requiring Full management mode.

SQL VM assessment is the most cross-module part of the SQL VM module. sqlvm/custom.py calls set_assessment_properties during sqlvm_update; that function uses raw ARM requests, Log Analytics workspace metadata, custom table migration/creation, and DCR/DCE discovery or deployment. Constants for the custom log/table and file pattern live in src/…/_assessment_data_source.py; ARM resource fragments for data collection endpoints/rules and AMA extension installation live in src/…/_template_builder.py; helpers in src/…/_util.py reuse VM module Log Analytics clients and VM extension commands from src/…/custom.py. SQL VM tests in sqlvm/…/test_sqlvm_commands.py create real VMs via az vm create, validate assessment scheduling, and check management/backup/patching/group/listener flows.

Coupling

  • If a command is added or renamed in src/…/commands.py, also update src/…/_params.py and src/…/_validators.py when the command needs custom option names, defaults, enum validation, ID normalization, or namespace mutation; the custom handlers in src/…/custom.py assume those normalized namespace fields already exist.
  • If az vm create or az vmss create template shape changes in src/…/custom.py, verify the builders in src/…/_template_builder.py and validators in src/…/_validators.py; template deployment validation and later generic update paths depend on the same storage/network/security profile structure.
  • If generated AAZ classes under src/azure-cli/azure/cli/command_modules/vm/aaz/** change their output schema for nested resources or VMSS extension profiles, re-check wrapper classes in src/…/vm.py and src/…/vmss.py; they delete or remap conflicting type fields before client-flattened output is returned.
  • If VM/VMSS identity payload semantics change, update both the classic VM wrappers in src/…/vm.py and VMSS wrappers in src/…/vmss.py; their remove flows explicitly serialize removed user-assigned identities as None and set identity type to None.
  • If the Compute image alias document contract changes, update src/…/_actions.py and the embedded aliases in src/…/_alias.py; load_images_from_aliases_doc expects outputs.aliases.value with publisher/offer/sku/version/architecture entries and silently falls back to the local copy.
  • If SQL VM assessment log names, table names, or file paths change, update all three locations together: constants in src/…/_assessment_data_source.py, DCR template shape in src/…/_template_builder.py, and validation/comparison logic in src/…/_util.py and src/…/custom.py.
  • If VM extension helpers in src/…/custom.py change return shape, verify SQL VM assessment helpers in src/…/_util.py; get_workspace_id_from_log_analytics_extension expects extension objects with publisher, type_properties_type, and settings attributes.
  • If Azure AD authentication validation changes in src/…/_validators.py, verify src/…/custom.py and src/…/vm.py; the validator fetches the underlying Azure VM using VM module VMShow and checks system/user-assigned managed identity fields before sqlvm_enable_azure_ad_auth writes AADAuthenticationSettings.
  • If Compute Fleet API versions or resource provider paths change, regenerate or update every AAZ command under src/azure-cli/azure/cli/command_modules/computefleet/aaz/latest/compute_fleet/**; create/update/show/list/delete/wait and identity subcommands all hard-code 2026-08-01 and Microsoft.AzureFleet/fleets URLs.
  • If Compute Recommender promotes or deprecates an endpoint, keep src/…/_spot_placement_score.py, _spot_placement_recommender.py, and compute_recommender/…/test_compute_recommender.py aligned; the two commands currently hit the same path with different API versions and slightly different requiredness for --desired-count.

Risks

  • src/…/custom.py, src/…/_validators.py, and src/…/_params.py are very large, stateful files. A new create/update option can appear to work at argument parsing time but fail later if namespace normalization, template construction, and output transformation are not all updated.
  • src/…/_vm_utils.py pins the network API for ARM-template-based VM and VMSS creation to 2022-01-01 on the latest cloud profile to avoid mass test re-recording. Changing that API selection can alter emitted deployment templates and invalidate many VM/VMSS scenario recordings under src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/**.
  • src/…/vm.py and src/…/vmss.py contain explicit workarounds for AAZ/client-flattening type field conflicts. If generated schemas are regenerated without preserving equivalent fixes, az vm show/update/create and az vmss show/list/update can emit incorrect nested extension/resource data.
  • SQL VM assessment setup in src/…/custom.py depends on raw ARM URLs, Log Analytics table migration, DCR/DCE naming conventions, and Windows AMA file paths. If any service API version or file pattern changes, az sql vm update --enable-assessment can fail after partially creating monitoring resources.
  • src/…/_validators.py validates SQL VM Azure AD authentication by querying the underlying Azure VM and Microsoft Graph permissions before the SQL VM RP call. In non-public clouds or tenants with restricted Graph permission visibility, az sql vm enable-azure-ad-auth can fail client-side unless users pass the skip-validation path.
  • src/…/_create.py and _update.py expose huge nested object arguments as inline CLI JSON. Small casing or requiredness changes in the generated AAZ schema can break tests and user scripts because aliases such as --cp, --spp, and --vmsizeprof map directly into deeply nested request bodies.