-
Notifications
You must be signed in to change notification settings - Fork 5
/
delete_cpod.sh
executable file
·101 lines (77 loc) · 2.01 KB
/
delete_cpod.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
. ./env
[ "$1" == "" ] && echo "usage: $0 <name_of_cpod> <owner's email alias (ex: bdereims)>" && exit 1
if [ "${2}" == "" ]; then
OWNER="admin"
else
OWNER="${2}"
fi
DNSMASQ=/etc/dnsmasq.conf
HOSTS=/etc/hosts
mutex() {
while ! mkdir lock 2>&1 > /dev/null
do
echo "Waiting (PID $$)..."
sleep 2
done
}
network_delete() {
${NETWORK_DIR}/delete_logicalswitch.sh ${1} ${2}
}
vapp_delete() {
${COMPUTE_DIR}/delete_vapp.sh ${1}
}
modify_dnsmasq() {
echo "Modifying '${DNSMASQ}' and '${HOSTS}'."
sed -i "/${1}\./d" ${DNSMASQ}
sed -i "/\t${1}\t/d" ${HOSTS}
systemctl stop dnsmasq
systemctl start dnsmasq
}
bgp_delete_peer() {
./network/delete_bgp_neighbour.sh edge-6 ${1}
}
bgp_delete_peer_vtysh() {
./network/delete_bgp_peer_vtysh.sh ${1} ${2}
}
release_mutex() {
rmdir lock
}
exit_gate() {
exit $1
}
test_owner() {
LINE=$( sed -n "/${CPOD_NAME_LOWER}\t/p" /etc/hosts | cut -f3 | sed "s/#//" | head -1 )
if [ "${LINE}" != "" ] && [ "${LINE}" != "${OWNER}" ]; then
echo "Error: Not Ok for deletion"
./extra/post_slack.sh ":wow: *${OWNER}* you're not allowed to delete *${NAME_HIGH}*"
exit 1
fi
}
main() {
CPOD_NAME="cpod-$1"
CPOD_NAME_HIGH=$( echo ${CPOD_NAME} | tr '[:lower:]' '[:upper:]' )
CPOD_NAME_LOWER=$( echo ${CPOD_NAME} | tr '[:upper:]' '[:lower:]' )
NAME_HIGH=$( echo $1 | tr '[:lower:]' '[:upper:]' )
test_owner ${2}
./extra/post_slack.sh "Deleting cPod *${NAME_HIGH}*"
echo "=== Deleting cPod called '${NAME_HIGH}'."
IP=$( cat ${HOSTS} | grep ${CPOD_NAME_LOWER} | cut -f1 )
TMP=$( echo ${IP} | cut -d"." -f4 )
ASN=$( expr ${ASN} + ${TMP} )
mutex
#bgp_delete_peer ${IP}
bgp_delete_peer_vtysh ${IP} ${ASN}
modify_dnsmasq ${CPOD_NAME_LOWER}
release_mutex
vapp_delete ${NAME_HIGH}
#sleep 15
sleep 5
network_delete ${NSX_TRANSPORTZONE} ${CPOD_NAME_LOWER}
./cpod_lease.sh delete ${1} ${OWNER}
echo "=== Deletion is finished."
./extra/post_slack.sh ":thumbsup: cPod *${NAME_HIGH}* has been deleted"
exit_gate 0
}
main $1