Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 1 | #!/bin/bash -x |
| 2 | |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 3 | full_deletion=false |
| 4 | |
| 5 | usage() { echo "Usage: $0 [-n <string>] [-r]" 1>&2; exit 1; } |
| 6 | |
| 7 | while getopts ":rqn:" o; do |
| 8 | case "${o}" in |
| 9 | |
| 10 | r) |
| 11 | echo "The following command will delete all information relating to onap within your enviroment" |
| 12 | read -p "Are you certain this is what you want? (type y to confirm):" answer |
| 13 | |
| 14 | if [ $answer = "y" ] || [ $answer = "Y" ] || [ $answer = "yes" ] || [ $answer = "Yes"]; then |
| 15 | echo "This may delete the work of other colleages within the same enviroment" |
| 16 | read -p "Are you certain this is what you want? (type y to confirm):" answer2 |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 17 | |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 18 | if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then |
| 19 | full_deletion=true |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 20 | else |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 21 | echo "Ending program" |
| 22 | exit 1 |
| 23 | fi |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 24 | else |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 25 | echo "Ending program" |
| 26 | exit 1 |
| 27 | fi |
| 28 | ;; |
| 29 | q) |
| 30 | full_deletion=true |
| 31 | ;; |
| 32 | n) |
| 33 | install_name=${OPTARG} |
| 34 | ;; |
| 35 | |
| 36 | *) |
| 37 | usage |
| 38 | ;; |
| 39 | esac |
| 40 | done |
| 41 | shift $((OPTIND-1)) |
| 42 | |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 43 | if [ -z "$WORKSPACE" ]; then |
| 44 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 45 | fi |
| 46 | |
| 47 | source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh |
| 48 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 49 | if [ "$full_deletion" = true ];then |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 50 | echo "Commencing delete, press CRTL-C to stop" |
| 51 | sleep 10 |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 52 | |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 53 | # delete all instances |
Gary Wu | 17cd906 | 2018-09-13 13:02:07 -0700 | [diff] [blame] | 54 | openstack server delete $(openstack server list -c ID -f value --project $OS_PROJECT_ID) |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 55 | sleep 1 |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 56 | |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 57 | # miscellaneous cleanup |
Gary Wu | 17cd906 | 2018-09-13 13:02:07 -0700 | [diff] [blame] | 58 | openstack floating ip delete $(openstack floating ip list -c ID -f value --project $OS_PROJECT_ID) |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 59 | sleep 1 |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 60 | |
Gary Wu | 17cd906 | 2018-09-13 13:02:07 -0700 | [diff] [blame] | 61 | ROUTERS=$(openstack router list -c ID -f value --project $OS_PROJECT_ID) |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 62 | echo $ROUTERS |
| 63 | for ROUTER in $ROUTERS; do |
| 64 | echo $ROUTER; |
| 65 | PORTS=$(openstack router show $ROUTER -c "interfaces_info" -f "value" | jq -r '.[].port_id') |
| 66 | for PORT in $PORTS; do |
| 67 | openstack router remove port $ROUTER $PORT |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 68 | done |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 69 | openstack router delete $ROUTER |
Gary Wu | cc10f1c | 2018-01-03 11:19:28 -0800 | [diff] [blame] | 70 | done |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 71 | |
Gary Wu | 17cd906 | 2018-09-13 13:02:07 -0700 | [diff] [blame] | 72 | openstack port delete $(openstack port list -f value -c ID --project $OS_PROJECT_ID) |
| 73 | openstack volume delete $(openstack volume list -f value -c ID --project $OS_PROJECT_ID) |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 74 | |
| 75 | # delete all except "default" security group |
Gary Wu | 17cd906 | 2018-09-13 13:02:07 -0700 | [diff] [blame] | 76 | SECURITY_GROUPS=$(openstack security group list -c ID -f value --project $OS_PROJECT_ID | grep -v default) |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 77 | openstack security group delete $SECURITY_GROUPS |
| 78 | sleep 1 |
| 79 | |
| 80 | |
| 81 | # Delete all existing stacks |
| 82 | STACKS=$(openstack stack list -c "Stack Name" -f value) |
| 83 | |
| 84 | if [ ! -z "${STACKS}" ]; then |
| 85 | openstack stack delete -y $STACKS |
| 86 | for STACK in ${STACKS}; do |
| 87 | until [ "DELETE_IN_PROGRESS" != "$(openstack stack show -c stack_status -f value $STACK)" ]; do |
| 88 | sleep 2 |
| 89 | done |
| 90 | done |
| 91 | else |
| 92 | echo "No existing stacks to delete." |
| 93 | fi |
| 94 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 95 | else |
| 96 | #Restrained teardown |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 97 | echo "Restrained teardown" |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 98 | |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 99 | STACK=$install_name |
| 100 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 101 | STATUS=$(openstack stack check $STACK) |
| 102 | |
| 103 | if [ "Stack not found: $install_name" != "$STATUS" ]; then |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 104 | openstack stack delete $STACK |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 105 | |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 106 | until [ "DELETE_IN_PROGRESS" != "$(openstack stack show -c stack_status -f value $STACK)" ]; do |
| 107 | sleep 2 |
| 108 | done |
| 109 | else |
| 110 | echo "No existing stack with the name $install_name." |
| 111 | fi |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 112 | fi |