Skip to content

Instantly share code, notes, and snippets.

@weshayutin
Last active March 27, 2018 14:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weshayutin/72890b1619efa5cd3b99223ef837f6d6 to your computer and use it in GitHub Desktop.
Save weshayutin/72890b1619efa5cd3b99223ef837f6d6 to your computer and use it in GitHub Desktop.
clean internal tenant
Clear keypairs and stacks https://github.com/openstack/tripleo-quickstart-extras/blob/master/roles/ovb-manage-stack/templates/cleanup-stacks-keypairs.sh.j2
Delete a specific stack https://github.com/openstack/tripleo-quickstart-extras/blob/master/roles/ovb-manage-stack/tasks/ovb-delete-stack.yml
# Clear all the stacks #############################################################
ALL_STACKS=$(openstack stack list | grep "COMPLETE\|CREATE_FAILED" | cut -d '|' -f 3)
echo $ALL_STACKS
for STACK in $ALL_STACKS; do
echo "Deleting Heat stack $STACK"
openstack stack delete --yes $STACK
COUNTER=0
while [[ $(openstack stack list) == *"$STACK"* ]]; do
if [[ $COUNTER -gt 6 ]]; then
echo "$STACK could not be deleted in time or is in FAILED state."
exit 1
else
echo "Polling for stack $STACK to be deleted"
sleep 30
COUNTER=$((COUNTER+1))
fi
done
## * Delete the key pair associated with the stack
## ::
KEYPAIR=$(echo ${STACK/stack/key} | sed 's/oooq-//')
if [[ $(nova keypair-list) == *"$KEYPAIR"* ]]; then
echo "Deleting key pair $KEYPAIR"
nova keypair-delete $KEYPAIR
fi
done
#####################################################
Clear floating ips
neutron router-list | tail -n +4 | head -n -1 | awk '{print $2}' > /tmp/routers exclude 48a7327a-d1d0-4bdc-bce7-4c0e9685f235
for ROUTER in `cat /tmp/routers`;
do
neutron router-gateway-clear $ROUTER
INTERFACE=`openstack port list --router $ROUTER | tail -n +4 | awk '{print $2}'`
openstack router remove port $ROUTER $INTERFACE
echo Deleting ROUTER: $ROUTER
neutron router-delete $ROUTER
done
for PORT in $(neutron port-list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting PORT: $PORT
neutron port-delete $PORT
sleep 1
done
for SUBNET in $(neutron subnet-list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting SUBNET: $SUBNET
neutron subnet-delete $SUBNET
done
for NETWORK in $(openstack network list | tail -n +4 | head -n -1 | awk '{print $2}')
do
echo Deleting NET: $NETWORK
openstack network delete $NETWORK
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment