Comment 2 for bug 1526587

Revision history for this message
carl (gsl0610) wrote : Re: Neutron doesn't have a command to show the available ports for one subnet

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