You can use something like this to count the number of floating ips:
#!/usr/bin/python
import os
from quantumclient.quantum import client
def load_creds():
d = {}
d['username'] = os.environ['OS_USERNAME']
d['password'] = os.environ['OS_PASSWORD']
d['auth_url'] = os.environ['OS_AUTH_URL']
d['tenant_name'] = os.environ['OS_TENANT_NAME']
return d
qc = client.Client('2.0', **load_creds())
print len(qc.list_floatingips(fields=['id'])['floatingips'])
And you can filter by floating ip attributes if needed. e.g. qc.list_floatingips(fields=['id'], fixed_ip_address='')
Update: to show how the allocations can be totted up.
import os
import netaddr
from neutronclient.neutron import client
creds = {'username': os.environ['OS_USERNAME'],
'password': os.environ['OS_PASSWORD'],
'auth_url': os.environ['OS_AUTH_URL'],
'tenant_name': os.environ['OS_TENANT_NAME']}
nc = client.Client('2.0', **creds)
all_nets = nc.list_networks()['networks']
ext_nets = [net for net in all_nets if net['router:external']]
total = 0
for net in ext_nets:
net_total = 0
# TODO request only the id and allocation_pools fields
subnets = nc.list_subnets(network_id=net['id'])['subnets']
for subnet in subnets:
subnet_total = 0
for alloc_pool in subnet['allocation_pools']:
range = netaddr.IPRange(alloc_pool['start'], alloc_pool['end'])
subnet_total += range.size
net_total += subnet_total
print 'net:', net['id'], 'subnet:', subnet['id'], 'count:', subnet_total
total += net_total
print 'net:', net['id'], 'count:', net_total
print 'total:', total
Additional Informations: Neutron, OVS-Plugin, Gre-Tunneling with SecGroup Plugin