Merge pull request #6 from aaronorosen/master

Add delete_orphan_floatingips script
This commit is contained in:
Mike Dorman 2015-03-24 15:12:18 -06:00
commit 09e7902401
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
"""
This script deletes all the floatingips a user has that are not
associated with a port_id.
"""
import os
import sys
from neutronclient.v2_0 import client
def main():
try:
username = os.environ['OS_USERNAME']
tenant_name = os.environ['OS_TENANT_NAME']
password = os.environ['OS_PASSWORD']
auth_url = os.environ['OS_AUTH_URL']
except KeyError:
print("You need to source your openstack creds file first!")
sys.exit(1)
neutron = client.Client(username=username,
tenant_name=tenant_name,
password=password,
auth_url=auth_url)
floatingips = neutron.list_floatingips()
for floatingip in floatingips['floatingips']:
if not floatingip['port_id']:
print(("Deleting floatingip %s - %s") %
(floatingip['id'], floatingip['floating_ip_address']))
neutron.delete_floatingip(floatingip['id'])
main()