[Network]: az network vnet list-available-cidrs/list-used-cidrs better CIDR insights#33311
Conversation
❌AzureCLI-FullTest
|
❌AzureCLI-BreakingChangeTest
Please submit your Breaking Change Pre-announcement ASAP if you haven't already. Please note:
|
|
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>
|
|
Thank you for your contribution @AlvinRamoutar! We will review the pull request and get back to you soon. |
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR adds two preview az network vnet commands to report available and used CIDR blocks within a VNet, along with table-format output, help text, parameters, and scenario tests. It extends the network command module with customer-facing capacity-inspection tooling for VNet address spaces.
Changes:
- Add
network vnet list-available-cidrsandnetwork vnet list-used-cidrscustom commands. - Implement CIDR parsing/aggregation logic plus table transformers for human-readable output.
- Add scenario tests and command help/parameter wiring for the new commands.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/network/custom.py |
Implements the new CIDR discovery logic and shared prefix/subnet helpers. |
src/azure-cli/azure/cli/command_modules/network/commands.py |
Registers the two new preview VNet commands and their table transformers. |
src/azure-cli/azure/cli/command_modules/network/_params.py |
Adds --address-prefixes filtering arguments for both commands. |
src/azure-cli/azure/cli/command_modules/network/_help.py |
Documents the new commands and example invocations. |
src/azure-cli/azure/cli/command_modules/network/_format.py |
Adds table-output flatteners for available/used CIDR results. |
src/azure-cli/azure/cli/command_modules/network/tests/latest/test_network_commands.py |
Adds scenario coverage for the new commands against IPv4 VNet address spaces. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def list_available_cidrs(cmd, resource_group_name, virtual_network_name, address_prefixes=None): | ||
| vnet, subnets = _fetch_vnet_and_subnets(cmd, resource_group_name, virtual_network_name) | ||
| merged = _merge_subnet_ranges(subnets) |
There was a problem hiding this comment.
okay good point, will revisit my approach + extend support for IPv6
| def list_used_cidrs(cmd, resource_group_name, virtual_network_name, address_prefixes=None): | ||
| vnet, subnets = _fetch_vnet_and_subnets(cmd, resource_group_name, virtual_network_name) | ||
|
|
||
| vnet_prefixes = vnet["addressSpace"]["addressPrefixes"] | ||
| if address_prefixes: | ||
| _validate_address_prefixes(address_prefixes, vnet_prefixes, virtual_network_name) | ||
| vnet_prefixes = [p for p in vnet_prefixes if p in address_prefixes] |
| @ResourceGroupPreparer(name_prefix='cli_vnet_available_cidrs') | ||
| def test_network_vnet_list_available_cidrs(self, resource_group): | ||
| self.kwargs.update({ | ||
| 'vnet': 'vnet1', | ||
| 'rg': resource_group, | ||
| 'prefixes': '10.198.0.0/16 10.197.0.0/16', |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Related command
Description
As a network admin, I want to interrogate VNETs and their address prefixes for available/used CIDRs to understand VNET capacity (in terms of subnet spacing) before doing things like making new subnets.
other thoughts/notes:
list_used_cidrsbut decided to implement it anyways as an inverse oflist_available_cidrssince subnet list is not useful enough to a network admin from an addressing perspective and adding an inverse flag onlist_available_cidrsdidn't sit right with me semanticallyTesting Guide
Available CIDRs, output JSON
OUTPUT
[ { "addressPrefixes": "10.197.0.0/16", "availableCIDRs": [ { "cidrAddress": "10.197.1.0/24", "endingAddress": "10.197.1.255", "startingAddress": "10.197.1.0", "usableIPs": 251 }, { "cidrAddress": "10.197.2.0/23", "endingAddress": "10.197.3.255", "startingAddress": "10.197.2.0", "usableIPs": 507 }, { "cidrAddress": "10.197.4.0/22", "endingAddress": "10.197.7.255", "startingAddress": "10.197.4.0", "usableIPs": 1019 }, { "cidrAddress": "10.197.8.0/23", "endingAddress": "10.197.9.255", "startingAddress": "10.197.8.0", "usableIPs": 507 }, { "cidrAddress": "10.197.12.0/22", "endingAddress": "10.197.15.255", "startingAddress": "10.197.12.0", "usableIPs": 1019 }, { "cidrAddress": "10.197.16.0/20", "endingAddress": "10.197.31.255", "startingAddress": "10.197.16.0", "usableIPs": 4091 }, { "cidrAddress": "10.197.32.0/19", "endingAddress": "10.197.63.255", "startingAddress": "10.197.32.0", "usableIPs": 8187 }, { "cidrAddress": "10.197.64.0/18", "endingAddress": "10.197.127.255", "startingAddress": "10.197.64.0", "usableIPs": 16379 }, { "cidrAddress": "10.197.128.0/17", "endingAddress": "10.197.255.255", "startingAddress": "10.197.128.0", "usableIPs": 32763 } ] }, { "addressPrefixes": "10.196.0.0/16", "availableCIDRs": [ { "cidrAddress": "10.196.1.0/24", "endingAddress": "10.196.1.255", "startingAddress": "10.196.1.0", "usableIPs": 251 }, { "cidrAddress": "10.196.2.0/23", "endingAddress": "10.196.3.255", "startingAddress": "10.196.2.0", "usableIPs": 507 }, { "cidrAddress": "10.196.4.0/22", "endingAddress": "10.196.7.255", "startingAddress": "10.196.4.0", "usableIPs": 1019 }, { "cidrAddress": "10.196.8.0/21", "endingAddress": "10.196.15.255", "startingAddress": "10.196.8.0", "usableIPs": 2043 }, { "cidrAddress": "10.196.16.0/20", "endingAddress": "10.196.31.255", "startingAddress": "10.196.16.0", "usableIPs": 4091 }, { "cidrAddress": "10.196.32.0/19", "endingAddress": "10.196.63.255", "startingAddress": "10.196.32.0", "usableIPs": 8187 }, { "cidrAddress": "10.196.64.0/18", "endingAddress": "10.196.127.255", "startingAddress": "10.196.64.0", "usableIPs": 16379 }, { "cidrAddress": "10.196.128.0/17", "endingAddress": "10.196.255.255", "startingAddress": "10.196.128.0", "usableIPs": 32763 } ] } ]Available CIDRs, output table using custom formatter
OUTPUT
AddressPrefix CIDRAddress StartingAddress EndingAddress UsableIPs --------------- --------------- ----------------- --------------- ----------- 10.197.0.0/16 10.197.1.0/24 10.197.1.0 10.197.1.255 251 10.197.0.0/16 10.197.2.0/23 10.197.2.0 10.197.3.255 507 10.197.0.0/16 10.197.4.0/22 10.197.4.0 10.197.7.255 1019 10.197.0.0/16 10.197.8.0/23 10.197.8.0 10.197.9.255 507 10.197.0.0/16 10.197.12.0/22 10.197.12.0 10.197.15.255 1019 10.197.0.0/16 10.197.16.0/20 10.197.16.0 10.197.31.255 4091 10.197.0.0/16 10.197.32.0/19 10.197.32.0 10.197.63.255 8187 10.197.0.0/16 10.197.64.0/18 10.197.64.0 10.197.127.255 16379 10.197.0.0/16 10.197.128.0/17 10.197.128.0 10.197.255.255 32763Used CIDRs, output TSV
OUTPUT
10.197.0.0/16 9 10.196.0.0/16 8History Notes
[Network]
az network vnet list-available-cidrslist available CIDRs in VNET[Network]
az network vnet list-used-cidrslist used CIDRs in VNETThis 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.