Skip to content

Instantly share code, notes, and snippets.

@tamirko
Last active September 20, 2016 11:08
Show Gist options
  • Save tamirko/7b268ec1c6472abaf5cff365cc46e39c to your computer and use it in GitHub Desktop.
Save tamirko/7b268ec1c6472abaf5cff365cc46e39c to your computer and use it in GitHub Desktop.
Clear DataCentred OpenStack
#!/bin/bash
for routerID in `neutron router-list | grep -viE "cfy|management|mngmnt|--|external_gateway_info|composer|cloudify" | awk -F\| '{ print $2}' | sed 's/ //g'`; do
echo " xxx routerID is $routerID"
export subnetID=`neutron router-port-list $routerID | grep -viE "cfy|management|fixed_ips|--|composer|cloudify" | awk -F\| '{print $5}' | awk -F: '{print $2}' | awk -F, '{print $1}' | sed -e 's/[" ]//g'`
echo " xxx subnetID is $subnetID"
for portIDFloating in `neutron floatingip-list | awk -F\| '{ print $5 }' | sed 's/ //g' | grep "-" | grep -v "port"`; do
echo " xxx portIDFloating is $portIDFloating"
export portInSubnet=`neutron port-list -c id -c fixed_ips | grep $subnetID | grep -c "${portIDInFloating}"`
echo " xxx portInSubnet is $portInSubnet"
if [ "x${portInSubnet}x" != "xx" ]; then
if [ $portInSubnet -gt 0 ]; then
currentFloatingIP=`neutron floatingip-list | grep $portIDFloating | awk -F\| '{ print $2 }' | sed 's/ //g'`
neutron floatingip-disassociate $currentFloatingIP
neutron floatingip-delete $currentFloatingIP
fi
fi
echo "-----"
done
neutron router-gateway-clear $routerID
neutron router-interface-delete $routerID $subnetID
neutron router-delete $routerID
neutron port-list -c id -c fixed_ips | grep $subnetID | awk -F\| '{print $2}' | sed 's/ //g' | xargs -I file neutron port-delete file
neutron subnet-delete $subnetID
done
for netID in `neutron net-list | grep -viE "cfy|management|mngmnt|external|composer|cloudify" | grep "/" | awk -F\| '{ print $2}' | sed 's/ //g'`; do
neutron net-delete $netID
done
for secGrpID in `neutron security-group-list | grep -Ei "brocade|forti" | awk -F"\|" '{ print $2 }' | sed 's/ //g'`; do
neutron security-group-delete $secGrpID
done
for instanceID in `nova list | grep -iE "brocade|fortigate" | awk -F"\|" '{ print $2 }' | sed 's/ //g'`; do
nova delete $instanceID
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment