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 / network-dns-commands

Network and DNS command modules

Overview

This area owns Azure CLI networking command wiring under src/azure-cli/azure/cli/command_modules/network/**, private DNS command wiring under src/azure-cli/azure/cli/command_modules/privatedns/**, and the generic private endpoint connection guidance in doc/private_endpoint_connection_command_guideline.md. Routing starts in each module loader: network/__init__.py imports network._help, loads generated AAZ command tables from network/aaz/**, then overlays hand-authored registrations from network/commands.py; privatedns/__init__.py does the same for privatedns/aaz/** and privatedns/commands.py, with ResourceType.MGMT_NETWORK_PRIVATEDNS as the module default.

network/commands.py is the main command table overlay for az network. It mixes direct AAZ command classes, custom functions from network/custom.py, and subclasses in network/…/*.py. The DNS block registers az network dns commands: network dns list-references comes from network/…/dns.py, zone import/export/create are custom functions in network/custom.py, and each public DNS record type (a, aaaa, caa, cname, ds, mx, naptr, ns, ptr, soa, srv, tlsa, txt) gets explicit show/list/create/update/delete command classes from network/…/dns.py plus add/remove or set-record custom functions. The watcher block registers az network watcher diagnostics, packet capture, flow-log, troubleshooting, and connection-monitor commands through network/…/watcher.py. The traffic manager block registers az network traffic-manager profile and endpoint create/update/list wrappers in network/custom.py, plus generated show-geographic-hierarchy. The private link block registers generic az network private-link-resource and az network private-endpoint-connection commands against network/…/custom.py.

Argument shaping lives in network/_params.py. It normalizes DNS zone names via dns_zone_name_type from network/_validators.py, hides generated record_type arguments for per-type record commands, adds user-facing --record-set-name, --ttl, --if-none-match, --keep-empty-record-set, and record-specific fields, and then defines watcher, traffic-manager, and generic private endpoint connection arguments. The generic private endpoint connection arguments call register_providers() from network/…/custom.py while loading arguments so --type choices are populated from TYPE_CLIENT_MAPPING. network/_help.py supplies the extensive knack.help_files.helps examples and group summaries for these commands.

Public DNS behavior is split between generated AAZ clients and custom mutation helpers. network/…/dns.py subclasses generated record-set commands from network/aaz/latest/network/dns/** to hide the generic record_type parameter, set the record type in pre_operations, format target_resource as an ARM ID on update, and translate network dns list-references --parameters into the generated target_resources payload. network/custom.py handles zone creation with location='global', optional parent-zone delegation, zone import/export, SOA update, and record add/remove helpers. Add helpers build record dictionaries and call _add_save_record; remove helpers build comparable dictionaries and call _remove_record, with record-specific equality checks to prevent duplicate add/remove mismatches. TXT add joins user-provided chunks and re-splits values into 255-character segments before saving.

Zone-file import/export is shared code under network/zone_file/**. network/…/parse_zone_file.py tokenizes and parses $ORIGIN, $TTL, SOA, public DNS record types, SPF-as-TXT, URI, and Azure alias syntax into an ordered object. network/…/make_zone_file.py renders an object back to text and delegates per-record formatting to network/…/record_processors.py. Public DNS import/export in network/custom.py and private DNS import/export in privatedns/custom.py both call this shared parser/renderer, but each maps parsed records into the model shape expected by its own management plane.

The private DNS module is a smaller command surface under the az network private-dns prefix. privatedns/commands.py registers private zone create/list/show/import/export, VNet link create/list/show, record-set create/delete/list/show/update, add-record/remove-record, SOA update, and CNAME set/remove. It uses generated AAZ classes for much of the transport, custom wrappers from privatedns/custom.py for zone import/export and record mutations, table transforms from privatedns/_format.py, and the cf_privatedns_mgmt_zones SDK factory in privatedns/_client_factory.py for legacy zone operations backed by azure.mgmt.privatedns.PrivateDnsManagementClient.private_zones. privatedns/_params.py mirrors the public DNS argument pattern but only exposes private DNS record types supported by the private DNS API (a, aaaa, cname, mx, ptr, srv, txt, plus SOA operations) and validates private zone names/metadata through privatedns/_validators.py.

Network watcher support in network/…/watcher.py primarily adapts generated AAZ watcher commands to CLI-friendly inputs. Helper functions such as get_network_watcher_from_location, get_network_watcher_from_vm, get_network_watcher_from_resource, and get_network_watcher_from_vmss derive the hidden watcher resource group/name from a location or target resource. Diagnostic commands hide generated watcher fields and populate them in pre_operations. Connection-monitor V2 creation flattens many CLI arguments into the generated endpoints, test_configurations, test_groups, and outputs structures, validates that protocol and either location or source resource are present, and can resolve a source resource location through the ARM resource client. Flow-log arguments in network/_params.py preserve the older NSG-based show form while steering users toward the newer --location and --name combination.

Traffic manager commands in network/custom.py are thin adapters over generated network/aaz/latest/network/traffic_manager/** classes. Profile create/update collect DNS config, routing method, monitor config, custom headers, status-code ranges, and optional record type into generated argument names; endpoint create/update do the same for endpoint type, target or target resource, weights, priorities, geo mappings, subnet ranges, and always_serve. list_traffic_manager_endpoints reads the whole profile via the generated profile show command and filters the embedded endpoint list by suffix when an endpoint type is provided.

Generic private endpoint connection support is centered in network/…/custom.py and resource_providers/__init__.py. register_providers() populates TYPE_CLIENT_MAPPING with provider resource types, API versions, whether a provider supports list operations, optional resource-get API versions, and whether connection operations are supported. GeneralPrivateEndpointClient then uses send_raw_request to build raw ARM URLs for /privateLinkResources, /privateEndpointConnections, individual connection GET/PUT/DELETE, or fallback parent-resource GET when a provider cannot list connections directly. Approval and rejection mutate properties.privateLinkServiceConnectionState.status and description, issue a PUT, then poll up to RETRY_MAX times for both provisioning state and status. doc/private_endpoint_connection_command_guideline.md documents the required integration-test flow and points contributors at this generic registration mechanism instead of implementing provider-specific parent-resource command groups.

Tests are organized by scenario under network/tests/latest/** and privatedns/tests/latest/**. Public DNS import/export and record-type behavior live in network/…/test_dns_commands.py, watcher connection monitor behavior in network/…/test_nw_connection_monitor.py, flow logs in network/…/test_nw_flow_log.py, and private endpoint/provider coverage in network/…/test_private_endpoint_commands.py. Private DNS zone, VNet link, record-set, import/export, and validation scenarios live in privatedns/…/test_privatedns_commands.py, with helper data generation in privatedns/…/_test_data_generator.py. Test recordings and sanitizers are local to the module test trees, including network/…/recording_processors.py and credential_replacer.py.

Routing/coverage note: use this doc for changes under src/azure-cli/azure/cli/command_modules/network/**, src/azure-cli/azure/cli/command_modules/privatedns/**, and doc/private_endpoint_connection_command_guideline.md, especially command table additions, DNS/private DNS record behavior, watcher/connection-monitor or traffic-manager adapters, private endpoint connection provider registration, help text, argument validation, and tests in those module trees.

Coupling

  • If a public DNS record type is added or renamed, update all four public DNS layers together: registrations in network/commands.py, arguments in network/_params.py, AAZ subclasses or wrappers in network/…/dns.py, record import/export mapping in network/custom.py, and rendering/parsing support in network/…/parse_zone_file.py and network/…/record_processors.py. Missing one layer can make the command visible without parsable arguments, or make import/export silently skip or mis-shape records.

  • If shared zone-file parsing changes in network/zone_file/**, verify both public DNS (network/custom.py) and private DNS (privatedns/custom.py). Private DNS imports the network module's parser and renderer directly, but its management SDK model only supports a subset of public DNS record types; parser support alone does not mean private DNS can persist that record.

  • If TYPE_CLIENT_MAPPING or _register_one_provider() changes in network/…/custom.py, also check argument choices in network/_params.py and the required scenario coverage described in doc/private_endpoint_connection_command_guideline.md. network/_params.py calls register_providers() at argument-load time, so provider names become user-facing --type enum choices even though operations later do raw ARM calls.

  • If private endpoint connection ID parsing changes in network/_validators.py, verify network/_params.py contexts for network private-link-resource list and network private-endpoint-connection show/approve/reject/delete/list. These commands accept either a resource/connection --id or decomposed --resource-name, --name, --resource-group, and --type, and the generic client only receives parsed provider/resource/connection names.

  • If watcher command arguments around location or target resource change in network/_params.py, verify the corresponding pre_operations in network/…/watcher.py. Many generated watcher fields are hidden and repopulated from --location, VM IDs, resource IDs, or source endpoint IDs; changing only the user-facing argument can leave generated watcher_rg/watcher_name unset.

  • If traffic-manager monitor configuration or endpoint fields change in network/_params.py, also update the create/update adapters in network/custom.py. Those functions manually copy CLI argument names into generated AAZ argument names, so generated model changes do not automatically propagate through the CLI wrapper.

  • If private DNS zone or record-set command registrations change in privatedns/commands.py, verify privatedns/_params.py, privatedns/custom.py, and privatedns/_help.py together. The private DNS module mixes AAZ commands, an SDK client factory, and custom record mutation functions; help and parameter contexts are not generated from the command table.

Risks

  • network/…/__init__.py performs generic private endpoint connection operations with raw ARM URLs and fixed polling (RETRY_MAX = 20, RETRY_INTERVAL = 10). If a provider uses a different connection schema, long-running state name, or API-version behavior than the mapping in network/…/custom.py, approve/reject can PUT an invalid body or time out even though the initial show/list works.

  • network/custom.py contains a comment in public DNS import noting an alias-record mapping bug where an AZURE ALIAS A record may map to ARecords while the generated record-set dictionary lacks a_records. If alias import/export is changed without tests in network/…/test_dns_commands.py, imports may log misleading counts or fail after creating the zone.

  • network/…/watcher.py derives a Network Watcher by matching a location against network watcher list. If no watcher exists in that region, commands such as network watcher test-ip-flow, connection-monitor actions, packet capture, flow-log, or troubleshooting fail before reaching the service operation. Changes that stop passing the expected location from network/_params.py or resource-derived helpers can break all location-based watcher commands.

  • network/custom.py and privatedns/custom.py both write exported zone files directly with open(file_name, 'w') after printing the content. If export file handling changes, preserve the explicit file operation errors tested by network/…/test_dns_commands.py and the private DNS import/export scenarios in privatedns/…/test_privatedns_commands.py; otherwise CLI error classification can regress across platforms.