Ask Your Question
2

Available FloatingIP's in pool

asked 2013-09-19 10:01:15 -0500

foexle gravatar image

Heyho guys,

i'm looking for a solution to show how many floatingIP's are present in my pools. I'll write a small Nagios check for this because it's very bad if customers trying to assotiate IP's and there are no more available :).

I've looked into the default commands of nova and nova-manage but i can't find any command there give me these informations out of the box.

Do anyone have a solution ? Maybe they are a new Api call in the next Havana release ?!

Thanks and cheers Heiko

edit retag flag offensive close merge delete

Comments

Additional Informations: Neutron, OVS-Plugin, Gre-Tunneling with SecGroup Plugin

foexle gravatar imagefoexle ( 2013-09-19 10:08:28 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-09-19 12:25:05 -0500

darragh-oreilly gravatar image

updated 2014-01-31 07:58:00 -0500

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
edit flag offensive delete link more

Comments

Hi Darragh, of course but i'll get only a list of assoitiate addresses, so i need to build my own request ?! I need first the pools of available IP's so i take a look into the public marked networks after that i've all subnets + submask => thats the maximum number of IP's .... but if i have the range restricted with 'start=' and 'end=' i've an other problem. So it's a little bit more complicated and i think to operate OpenStack as a public Cloud it's would be nice to have this feature as CLI command. But thanks, i'll try to code to get all this informations. Cheers

foexle gravatar imagefoexle ( 2013-09-20 04:31:48 -0500 )edit

Hi, yes there are many complications. If you add fixed_ip_address='' it should return unused floating ips and this number can be subtracted from the first to find used ips. Another problem is that fips are owned by tenants, and they may not release their unused fips and so starve others.

darragh-oreilly gravatar imagedarragh-oreilly ( 2013-09-20 05:17:11 -0500 )edit

A query to find the total number of possible floating ips is a little more difficult, but it is possible. The Python ipaddr library should have something to count the number of addresses from a start address to an end address.

darragh-oreilly gravatar imagedarragh-oreilly ( 2013-09-20 05:30:52 -0500 )edit

sorry, I meant the netaddr module. Like this: import netaddr; range=netaddr.IPRange('10.0.0.20','10.0.0.30'); print range.size

darragh-oreilly gravatar imagedarragh-oreilly ( 2013-09-20 07:58:36 -0500 )edit
0

answered 2014-01-29 08:31:19 -0500

foexle gravatar image

updated 2014-01-31 09:08:34 -0500

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2013-09-19 10:01:15 -0500

Seen: 455 times

Last updated: Jan 31 '14