Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Network] az network vnet subnet list-available-ips: Get list of available IPs for subnet #23109

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5925,6 +5925,15 @@
crafted: true
"""

helps['network vnet subnet list-available-ips'] = """
type: command
short-summary: List some available ips in the subnet.
examples:
- name: List some available ips in the subnet.
text: |
az network vnet subnet list-available-ips --resource-group MyResourceGroup --vnet-name MyVNet -n MySubnet
"""

helps['network vnet subnet show'] = """
type: command
short-summary: Show details of a subnet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ def _make_singular(value):
g.generic_update_command('update', setter_name='begin_create_or_update', setter_arg_name='subnet_parameters',
custom_func_name='update_subnet')
g.custom_command('list-available-delegations', 'list_avail_subnet_delegations', min_api='2018-08-01', validator=process_list_delegations_namespace)
g.custom_command('list-available-ips', 'subnet_list_available_ips', min_api='2016-09-01', is_preview=True)
# endregion

# region VirtualNetworkGateways
Expand Down
12 changes: 12 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7261,6 +7261,18 @@ def list_available_ips(cmd, resource_group_name, virtual_network_name):
ip_address=start_ip)
return available_ips.available_ip_addresses


def subnet_list_available_ips(cmd, resource_group_name, virtual_network_name, subnet_name):
client = network_client_factory(cmd.cli_ctx)
subnet = client.subnets.get(resource_group_name=resource_group_name,
virtual_network_name=virtual_network_name,
subnet_name=subnet_name)
if subnet.address_prefix is not None:
start_ip = subnet.address_prefix.split('/')[0]
available_ips = client.virtual_networks.check_ip_address_availability(resource_group_name=resource_group_name,
virtual_network_name=virtual_network_name,
ip_address=start_ip)
return available_ips.available_ip_addresses
# endregion


Expand Down
Loading