Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 1 | #!/bin/bash -x |
| 2 | |
| 3 | if [ -z "$WORKSPACE" ]; then |
| 4 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 5 | fi |
| 6 | |
| 7 | source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh |
| 8 | |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 9 | # delete all instances |
| 10 | openstack server delete $(openstack server list -c ID -f value) |
| 11 | sleep 1 |
| 12 | |
| 13 | # miscellaneous cleanup |
| 14 | openstack floating ip delete $(openstack floating ip list -c ID -f value) |
| 15 | sleep 1 |
| 16 | |
| 17 | ROUTERS=$(openstack router list -c ID -f value) |
| 18 | echo $ROUTERS |
| 19 | for ROUTER in $ROUTERS; do |
Gary Wu | 808b13d | 2018-02-13 18:28:37 -0800 | [diff] [blame] | 20 | echo $ROUTER; |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 21 | PORTS=$(openstack router show $ROUTER -c "interfaces_info" -f "value" | jq -r '.[].port_id') |
| 22 | for PORT in $PORTS; do |
Gary Wu | 13709ea | 2018-02-15 11:28:50 -0800 | [diff] [blame] | 23 | openstack router remove port $ROUTER $PORT |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 24 | done |
| 25 | openstack router delete $ROUTER |
| 26 | done |
| 27 | |
| 28 | openstack port delete $(openstack port list -f value -c ID) |
| 29 | openstack volume delete $(openstack volume list -f value -c ID) |
| 30 | |
| 31 | # delete all except "default" security group |
Gary Wu | edcb04b | 2018-02-06 21:39:05 -0800 | [diff] [blame] | 32 | SECURITY_GROUPS=$(openstack security group list -c ID -f value | grep -v default) |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 33 | openstack security group delete $SECURITY_GROUPS |
| 34 | sleep 1 |
| 35 | |
| 36 | |
| 37 | # Delete all existing stacks |
| 38 | STACKS=$(openstack stack list -c "Stack Name" -f value) |
| 39 | |
| 40 | if [ ! -z "${STACKS}" ]; then |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 41 | openstack stack delete -y $STACKS |
| 42 | for STACK in ${STACKS}; do |
| 43 | until [ "DELETE_IN_PROGRESS" != "$(openstack stack show -c stack_status -f value $STACK)" ]; do |
| 44 | sleep 2 |
| 45 | done |
| 46 | done |
| 47 | else |
| 48 | echo "No existing stacks to delete." |
| 49 | fi |