Skip to content

Commit

Permalink
[Network] az network vnet list-available-ips: support list available …
Browse files Browse the repository at this point in the history
…ips in a vnet (#12371)
  • Loading branch information
mmyyrroonn committed Feb 28, 2020
1 parent 1a4a043 commit 77fcc2b
Show file tree
Hide file tree
Showing 5 changed files with 961 additions and 0 deletions.
8 changes: 8 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 @@ -4433,6 +4433,14 @@
text: az network vnet show -g MyResourceGroup -n MyVNet
"""

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

helps['network vnet subnet'] = """
type: group
short-summary: Manage subnets in an Azure Virtual Network.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ def _make_singular(value):
g.custom_command('create', 'create_vnet', transform=transform_vnet_create_output, validator=process_vnet_create_namespace, supports_local_cache=True)
g.generic_update_command('update', custom_func_name='update_vnet', supports_local_cache=True)
g.command('list-endpoint-services', 'list', command_type=network_endpoint_service_sdk)
g.custom_command('list-available-ips', 'list_available_ips', min_api='2016-09-01', is_preview=True)

with self.command_group('network vnet peering', network_vnet_peering_sdk, min_api='2016-09-01') as g:
g.custom_command('create', 'create_vnet_peering')
Expand Down
11 changes: 11 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 @@ -4980,6 +4980,17 @@ def update_vnet_peering(cmd, resource_group_name, virtual_network_name, virtual_
return ncf.virtual_network_peerings.create_or_update(
resource_group_name, virtual_network_name, virtual_network_peering_name, peering)


def list_available_ips(cmd, resource_group_name, virtual_network_name):
client = network_client_factory(cmd.cli_ctx).virtual_networks
vnet = client.get(resource_group_name=resource_group_name,
virtual_network_name=virtual_network_name)
start_ip = vnet.address_space.address_prefixes[0].split('/')[0]
available_ips = client.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

0 comments on commit 77fcc2b

Please sign in to comment.