Created
March 23, 2015 22:31
-
-
Save aaronorosen/a85235c0a9678d2dff7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment