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 | edcb04b | 2018-02-06 21:39:05 -0800 | [diff] [blame] | 9 | # skip use of multi-vim APIs for now |
Gary Wu | f19734c | 2018-01-19 14:39:34 -0800 | [diff] [blame] | 10 | # delete all Proxy Designate DNS records; do this first since we rely on multi-vim for this |
Gary Wu | edcb04b | 2018-02-06 21:39:05 -0800 | [diff] [blame] | 11 | # $WORKSPACE/test/ete/scripts/dns-zones/delete-dns-zones.sh $OS_PROJECT_NAME |
| 12 | # sleep 1 |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 13 | |
Gary Wu | 13709ea | 2018-02-15 11:28:50 -0800 | [diff] [blame^] | 14 | # delete all Desigate DNS zones belonging to this project |
Gary Wu | 3c18c54 | 2018-01-19 15:10:37 -0800 | [diff] [blame] | 15 | ZONES=$(openstack zone list -c "id" -f value) |
Gary Wu | f19734c | 2018-01-19 14:39:34 -0800 | [diff] [blame] | 16 | for ZONE in ${ZONES}; do |
Gary Wu | 13709ea | 2018-02-15 11:28:50 -0800 | [diff] [blame^] | 17 | ZONE_PROJECT_ID=$(openstack zone show $ZONE -f json | jq -r '.project_id') |
| 18 | if [ "$OS_PROJECT_ID" == "$ZONE_PROJECT_ID" ]; then |
| 19 | openstack zone delete $ZONE |
| 20 | fi |
Gary Wu | f19734c | 2018-01-19 14:39:34 -0800 | [diff] [blame] | 21 | done |
| 22 | |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 23 | # delete all instances |
| 24 | openstack server delete $(openstack server list -c ID -f value) |
| 25 | sleep 1 |
| 26 | |
| 27 | # miscellaneous cleanup |
| 28 | openstack floating ip delete $(openstack floating ip list -c ID -f value) |
| 29 | sleep 1 |
| 30 | |
| 31 | ROUTERS=$(openstack router list -c ID -f value) |
| 32 | echo $ROUTERS |
| 33 | for ROUTER in $ROUTERS; do |
Gary Wu | 808b13d | 2018-02-13 18:28:37 -0800 | [diff] [blame] | 34 | echo $ROUTER; |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 35 | PORTS=$(openstack router show $ROUTER -c "interfaces_info" -f "value" | jq -r '.[].port_id') |
| 36 | for PORT in $PORTS; do |
Gary Wu | 13709ea | 2018-02-15 11:28:50 -0800 | [diff] [blame^] | 37 | openstack router remove port $ROUTER $PORT |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 38 | done |
| 39 | openstack router delete $ROUTER |
| 40 | done |
| 41 | |
| 42 | openstack port delete $(openstack port list -f value -c ID) |
| 43 | openstack volume delete $(openstack volume list -f value -c ID) |
| 44 | |
| 45 | # delete all except "default" security group |
Gary Wu | edcb04b | 2018-02-06 21:39:05 -0800 | [diff] [blame] | 46 | 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] | 47 | openstack security group delete $SECURITY_GROUPS |
| 48 | sleep 1 |
| 49 | |
| 50 | |
| 51 | # Delete all existing stacks |
| 52 | STACKS=$(openstack stack list -c "Stack Name" -f value) |
| 53 | |
| 54 | if [ ! -z "${STACKS}" ]; then |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 55 | openstack stack delete -y $STACKS |
| 56 | for STACK in ${STACKS}; do |
| 57 | until [ "DELETE_IN_PROGRESS" != "$(openstack stack show -c stack_status -f value $STACK)" ]; do |
| 58 | sleep 2 |
| 59 | done |
| 60 | done |
| 61 | else |
| 62 | echo "No existing stacks to delete." |
| 63 | fi |