blob: f46525074b461f8009391f922787d63e3a95d787 [file] [log] [blame]
Gary Wucc10f1c2018-01-03 11:19:28 -08001#!/bin/bash -x
2
eHanan58ccb9d2018-08-07 14:09:26 +01003full_deletion=false
4
5usage() { echo "Usage: $0 [-n <string>] [-r]" 1>&2; exit 1; }
6
7while 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
eHanan97b7a9c2018-09-05 14:09:19 +010017
eHanan58ccb9d2018-08-07 14:09:26 +010018 if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then
19 full_deletion=true
eHanan97b7a9c2018-09-05 14:09:19 +010020 else
eHanan58ccb9d2018-08-07 14:09:26 +010021 echo "Ending program"
22 exit 1
23 fi
eHanan97b7a9c2018-09-05 14:09:19 +010024 else
eHanan58ccb9d2018-08-07 14:09:26 +010025 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
40done
41shift $((OPTIND-1))
42
Gary Wucc10f1c2018-01-03 11:19:28 -080043if [ -z "$WORKSPACE" ]; then
44 export WORKSPACE=`git rev-parse --show-toplevel`
45fi
46
47source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh
48
eHanan97b7a9c2018-09-05 14:09:19 +010049if [ "$full_deletion" = true ];then
eHanan58ccb9d2018-08-07 14:09:26 +010050 echo "Commencing delete, press CRTL-C to stop"
51 sleep 10
Gary Wucc10f1c2018-01-03 11:19:28 -080052
eHanan58ccb9d2018-08-07 14:09:26 +010053 # delete all instances
Gary Wu133c6642018-10-02 10:51:09 -070054 SERVERS=$(openstack server list -c ID -f value --project $OS_PROJECT_ID)
55 if [ $? -ne 0 ]; then
56 # only admin roles support --project parameter, so retry without it if the above returns an error
57 SERVERS=$(openstack server list -c ID -f value)
58 fi
59 if [ ! -z "$SERVERS" ]; then
60 openstack server delete $SERVERS
61 sleep 1
62 fi
Gary Wucc10f1c2018-01-03 11:19:28 -080063
eHanan58ccb9d2018-08-07 14:09:26 +010064 # miscellaneous cleanup
Gary Wu133c6642018-10-02 10:51:09 -070065 FLOATING_IPS=$(openstack floating ip list -c ID -f value --project $OS_PROJECT_ID)
66 if [ ! -z "$FLOATING_IPS" ]; then
67 openstack floating ip delete $FLOATING_IPS
68 sleep 1
69 fi
Gary Wucc10f1c2018-01-03 11:19:28 -080070
Gary Wu17cd9062018-09-13 13:02:07 -070071 ROUTERS=$(openstack router list -c ID -f value --project $OS_PROJECT_ID)
eHanan58ccb9d2018-08-07 14:09:26 +010072 echo $ROUTERS
73 for ROUTER in $ROUTERS; do
74 echo $ROUTER;
75 PORTS=$(openstack router show $ROUTER -c "interfaces_info" -f "value" | jq -r '.[].port_id')
76 for PORT in $PORTS; do
77 openstack router remove port $ROUTER $PORT
Gary Wucc10f1c2018-01-03 11:19:28 -080078 done
eHanan58ccb9d2018-08-07 14:09:26 +010079 openstack router delete $ROUTER
Gary Wucc10f1c2018-01-03 11:19:28 -080080 done
eHanan58ccb9d2018-08-07 14:09:26 +010081 sleep 1
82
Gary Wu133c6642018-10-02 10:51:09 -070083 PORTS=$(openstack port list -f value -c ID --project $OS_PROJECT_ID)
84 if [ ! -z "$PORTS" ]; then
85 openstack port delete $PORTS
86 sleep 1
87 fi
88 VOLUMES=$(openstack volume list -f value -c ID --project $OS_PROJECT_ID)
89 if [ ! -z "$VOLUMES" ]; then
90 openstack volume delete $VOLUMES
91 sleep 1
92 fi
93
eHanan58ccb9d2018-08-07 14:09:26 +010094
95 # Delete all existing stacks
96 STACKS=$(openstack stack list -c "Stack Name" -f value)
97
98 if [ ! -z "${STACKS}" ]; then
99 openstack stack delete -y $STACKS
100 for STACK in ${STACKS}; do
101 until [ "DELETE_IN_PROGRESS" != "$(openstack stack show -c stack_status -f value $STACK)" ]; do
102 sleep 2
103 done
104 done
105 else
106 echo "No existing stacks to delete."
107 fi
108
eHanan97b7a9c2018-09-05 14:09:19 +0100109else
110 #Restrained teardown
eHanan58ccb9d2018-08-07 14:09:26 +0100111 echo "Restrained teardown"
eHanan97b7a9c2018-09-05 14:09:19 +0100112
eHanan58ccb9d2018-08-07 14:09:26 +0100113 STACK=$install_name
114
Konrad Bańkaa3990d02019-07-30 09:02:42 +0200115 STATUS=$(openstack stack check $STACK 2>&1)
eHanan97b7a9c2018-09-05 14:09:19 +0100116
117 if [ "Stack not found: $install_name" != "$STATUS" ]; then
eHanan58ccb9d2018-08-07 14:09:26 +0100118 openstack stack delete $STACK
eHanan97b7a9c2018-09-05 14:09:19 +0100119
eHanan58ccb9d2018-08-07 14:09:26 +0100120 until [ "DELETE_IN_PROGRESS" != "$(openstack stack show -c stack_status -f value $STACK)" ]; do
121 sleep 2
122 done
123 else
124 echo "No existing stack with the name $install_name."
125 fi
eHanan97b7a9c2018-09-05 14:09:19 +0100126fi