Neutron doesn't have a command to show the available IP addresses for one subnet

Bug #1526587 reported by carl
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
neutron
Won't Fix
Wishlist
Prateek khushalani
python-neutronclient
Won't Fix
Undecided
Unassigned
python-openstackclient
In Progress
Undecided
Prateek khushalani

Bug Description

Neutron doesn't have a command to show the allocated ip addresses for one subnet.

We can get the allocated ip list with command:
[root@cts-orch ~]# neutron port-list | grep `neutron subnet-show 110-OAM2 | awk '/ id / {print $4}'` | cut -d"|" -f5 | cut -d":" -f3 | sort
 "135.111.122.97"}
 "135.111.122.98"}

But we don't have a command to show the available ips for one subnet. I write a shell script to show the available ports as below, but it will be helpful if we can provide such a neutron command.

[root@cts-orch ~]# ./show_available_ip.sh 110-OAM2
135.111.122.99
135.111.122.100
135.111.122.101
135.111.122.102
135.111.122.103
135.111.122.104
135.111.122.105
135.111.122.106
135.111.122.107
135.111.122.108
135.111.122.109
135.111.122.110
135.111.122.111
135.111.122.112
135.111.122.113
135.111.122.114
135.111.122.115
135.111.122.116
135.111.122.117
135.111.122.118
135.111.122.119
135.111.122.120
135.111.122.121
135.111.122.122
135.111.122.123
135.111.122.124
Total Count: 26

Changed in neutron:
importance: Undecided → Wishlist
Revision history for this message
Carl Baldwin (carl-baldwin) wrote :

I adjusted the description based on my understanding. Please double check it to make sure that I got it right. Also, readers might be interested in your show_available_ip.sh script. Could you stick it in a pastebin?

description: updated
Revision history for this message
carl (gsl0610) wrote :

Hi Carl,

This is just for my internal usage, not error exceptions, and it only support IPv4, but I think it should be similar for IPv6.

show_available_ip.sh script is as below,

[root@o ~]# cat show_available_ip.sh
#!/bin/bash

SUBNET_NAME=$1
start_point=$(neutron subnet-show $SUBNET_NAME | grep allocation_pools | cut -d"|" -f3 | cut -d":" -f2| cut -d"\"" -f2| cut -d"." -f4)
ip_prefix=$(neutron subnet-show $SUBNET_NAME | grep allocation_pools | cut -d"|" -f3 | cut -d":" -f2| cut -d"\"" -f2| cut -d"." -f1-3)
end_point=$(neutron subnet-show $SUBNET_NAME | grep allocation_pools | cut -d"|" -f3 | cut -d":" -f3| cut -d"\"" -f2| cut -d"." -f4)
ip_list=$(neutron port-list | grep `neutron subnet-show $SUBNET_NAME | awk '/ id / {print $4}'` | cut -d"|" -f5 | cut -d":" -f3 | cut -d"\"" -f2| sort)

total_count=0
for((index=$start_point; index<$end_point;index++))
do
        ip=$ip_prefix"."$index
        result=$(echo $ip_list | grep $ip)

        if [[ -z $result ]]; then
                echo $ip
                let total_count++
        fi
done
echo "Total Count: "$total_count

Revision history for this message
Eugene Nikanorov (enikanorov) wrote :

For ipv6 i guess it may take... some time to finish :)

Revision history for this message
carl (gsl0610) wrote :

It should be easy, I will attach the ipv6 later : )

Veena (mveenasl)
Changed in neutron:
assignee: nobody → Veena (mveenasl)
Revision history for this message
Akihiro Motoki (amotoki) wrote :

You can do this by "neutron port-list --fixed-ips subnet_id=<subnet-UUID>"

This is an example: http://paste.openstack.org/show/482993/

Similarly, you can use neutron "port-list --fixed-ips ip_address=<IP-address>"

In neutron/api/v2/attributes.py, fixed_ips in subnet resource has "convert_list_to': convert_kvp_list_to_dict", so specified filter parameters are converted into a dict.
Then neutron/db/db_base_plugin_v2.py _get_ports_query() does a special magic.
https://github.com/openstack/neutron/blob/master/neutron/db/db_base_plugin_v2.py#L1311-L1313

Revision history for this message
Akihiro Motoki (amotoki) wrote :

However, it is not easy to know without reading the code.
It looks nice if neutronclient supports appropriate command line options for subnet-list.

Changed in python-neutronclient:
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
Akihiro Motoki (amotoki) wrote :

Sorry, I misunderstood the bug description..... :-(
I thought the bug said there is no way to know allocation IPs per subnet, but it was not....

no longer affects: python-neutronclient
summary: - Neutron doesn't have a command to show the available ports for one
- subnet
+ Neutron doesn't have a command to show the available IP addresses for
+ one subnet
Revision history for this message
Akihiro Motoki (amotoki) wrote :

I think the bug can be split into two problems:

* IP address usage per subnet
* Which IP addresses are available?

These two are similar, but they are different problem.
The first one is related to the usage of an IP allocation pool of a subnet.
If a user has no interest in which IP address is available and just wants to know the usage of IP addresses, the latter one is unnecessary.

Which one do you need?

Revision history for this message
carl (gsl0610) wrote :

Hi Akihiro,

Thanks for your kind reply.
For me, I need : * Which IP addresses are available?
it will be useful for our deployment, and we can select the available IP for the fixed_ips of the OS::Neutron::Port.

Thanks,
Carl

Veena (mveenasl)
Changed in neutron:
assignee: Veena (mveenasl) → nobody
Changed in neutron:
assignee: nobody → Prateek khushalani (prateek-khushalani)
status: New → In Progress
Revision history for this message
Prateek khushalani (prateek-khushalani) wrote :

The way I see it is :-

1. We need to introduce a command ( neutron available-port-show <SUBNET-ID> )

2. This command will take the subnet-uuid and check which ports are in use and display only free ports that are present in the allocated range

I have started working on this flow.

Revision history for this message
Prateek khushalani (prateek-khushalani) wrote :

I did an analysis on the change. The changes will have to be made on neutron-server and neutronclient(CLI). Here are the list of changes that will be done

Neutronclient side-

1. A new command to be added.
2. A new resource to be created
3. The resource will take subnet-id and return available IP's in the allocation range.

Neutron-server side-

1. A new api will be created.
2. The api will accept subnet-id and return list of available IP's in the allocation range.

Changed in python-neutronclient:
assignee: nobody → Prateek khushalani (prateek-khushalani)
status: New → In Progress
Revision history for this message
John Davidge (john-davidge) wrote :

python-neutronclient has been deprecated. Any changes will need to be made in python-openstackclient.

Changed in python-neutronclient:
status: In Progress → Won't Fix
assignee: Prateek khushalani (prateek-khushalani) → nobody
Changed in python-openstackclient:
assignee: nobody → Prateek khushalani (prateek-khushalani)
status: New → In Progress
Revision history for this message
SATYAM KUMAR (satykumar) wrote :

Is the script ready for V6 .Can you please share ?

Revision history for this message
Akihiro Motoki (amotoki) wrote :

The openstackclient team does not use launchpad any more, so I am marking it as Invalid in python-openstackclient.
All bugs related to openstackclient should be filed to https://storyboard.openstack.org/#!/project/openstack/openstackclient.

Looking at the bug comments, there is no progress for long.
Especially, the status both in neutron and python-openstackclient are "In Progress" so it is not clear there is a dependency between them.

I would suggest to file a bug against openstackclient once the direction is clarified.

Revision history for this message
Akihiro Motoki (amotoki) wrote :

I don't have a right to change the status in python-openstakcclinet....

Revision history for this message
Lajos Katona (lajos-katona) wrote :

As I see the history we can close this with won't fix if you think please reopen this bug

Changed in neutron:
status: In Progress → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.