From 70fbf8e9d4b847c473cbbfce876fa3b5f77353ea Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Tue, 24 Mar 2015 13:20:04 -0700 Subject: [PATCH] Add delete_orphan_floatingips script This script is useful to cleanup floatingips that are not mapped to any neutron ports. --- neutron/delete_orphan_floatingips.py | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 neutron/delete_orphan_floatingips.py diff --git a/neutron/delete_orphan_floatingips.py b/neutron/delete_orphan_floatingips.py new file mode 100644 index 0000000..095330c --- /dev/null +++ b/neutron/delete_orphan_floatingips.py @@ -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()