Skip to content

Instantly share code, notes, and snippets.

@dougbtv
Created November 5, 2016 16:34
Show Gist options
  • Save dougbtv/9c79dde81b1e35208c85bb2924dc1c96 to your computer and use it in GitHub Desktop.
Save dougbtv/9c79dde81b1e35208c85bb2924dc1c96 to your computer and use it in GitHub Desktop.
#!/bin/bash
# -------------------------------------------------------
# - Deletes networks created by ansible-openshift -
# - Author: Doug Smith - twitter @dougbtv -
# -------------------------------------------------------
# What's the cluster name?
CLUSTER_NAME="test_cluster"
# Always source the overcloud
source ~/overcloudrc
# make newlines the only separator
IFS=$'\n'
# See if there's any floating IPs
neutron floatingip-list | grep -P "\d" &> /dev/null
if [ $? -eq 0 ]
then
echo "Clear all floating IPs"
for floating_ip in $(neutron floatingip-list | grep -P "\d" | awk '{print $2}')
do
neutron floatingip-delete $floating_ip
done
else
echo "No floating IPs to delete"
fi
# Get the router ID
neutron router-list | grep $CLUSTER_NAME &> /dev/null
if [ $? -ne 0 ];
then
echo "No router found"
exit 1
fi
router_id=$(neutron router-list | grep $CLUSTER_NAME | awk '{print $2}')
echo "Operating on router: $router_id"
echo "Clearing gateway"
neutron router-gateway-clear $router_id
echo "Clearing ports"
for subnet_port_id in $(neutron router-port-list $router_id | grep -i "subnet_id" | perl -p -i -e 's/^.+subnet_id": "([\da-f\-]+).+$/$1/')
do
# syntax is: `neutron router-interface-delete ROUTER_ID SUBNET_ID` (subnet ID is on the right in the port list)
neutron router-interface-delete $router_id $subnet_port_id
done
echo "Deleting router"
neutron router-delete $router_id
echo "Deleting subnets"
for subnet_id in $(neutron subnet-list | grep $CLUSTER_NAME | awk '{print $2}')
do
neutron port-list | grep $subnet_id &> /dev/null
if [ $? -eq 0 ];
then
echo "Removing ports"
for port_id in $(neutron port-list | grep $subnet_id | awk '{print $2}')
do
neutron port-delete $port_id
done
fi
neutron subnet-delete $subnet_id
done
echo "Deleting networks"
for network_id in $(neutron net-list | grep $CLUSTER_NAME | awk '{print $2}')
do
neutron net-delete $network_id
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment