This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
delete-network
executable file
·109 lines (80 loc) · 2.4 KB
/
delete-network
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
102
103
104
105
106
107
108
#!/bin/bash
# VARs
TENANT_NAME=""
ROUTER_ID=""
ROUTER_NAME="ext-to-int"
PORT_ID=""
NET_ID=""
NETWORK_NAME=""
NETWORK_NAME_CHECK=""
NETWORK_NAME_GUESS=""
NETWORK_NUMBERS=""
SUBNET_ID=""
SUBNET_NAME=""
#SUBNET_NAME_CHECK=""
# GET tenant name
if [ "$1" != "" ]
then
TENANT_NAME="$1"
else
# ask tenant name
echo "enter tenant name"
read -r TENANT_NAME
fi
# CONVERT tenant to lowercase
TENANT_NAME_LOWERCASE=${TENANT_NAME,,}
# CHECK network name
# get network name
NETWORK_NAME_CHECK=$(neutron net-list | grep -i "${TENANT_NAME_LOWERCASE}" | awk '{print $4}')
# guess network name
NETWORK_NAME_GUESS="${TENANT_NAME_LOWERCASE}-net"
# save network name
if [ "${NETWORK_NAME_CHECK}" == "${NETWORK_NAME_GUESS}" ]; then
NETWORK_NAME="${NETWORK_NAME_CHECK}"
echo "checking network name"
echo "${NETWORK_NAME}"
else
NETWORK_NAME="${NETWORK_NAME_GUESS}"
fi
# CHECK subnet name
echo "check subnet name"
SUBNET_NAME="${TENANT_NAME_LOWERCASE}-pool"
echo "${SUBNET_NAME}"
# GET router id
ROUTER_ID=$(neutron router-list | grep ext-to-int | awk '{print $2}')
echo "router_id = ${ROUTER_ID}"
# GET NETWORK_NUMBERS
NETWORK_NUMBERS=$(neutron net-list | grep -i "${TENANT_NAME_LOWERCASE}" | awk '{print $7}')
# GET port id
PORT_ID=$(neutron router-port-list "${ROUTER_ID}" | grep "${NETWORK_NUMBERS}" | awk '{print $2}')
echo "port_id = $PORT_ID"
# GET net id
NET_ID=$(neutron net-list | grep "${NETWORK_NAME}" | awk '{print $2}')
echo "${NET_ID}"
# GET subnet id
SUBNET_ID=$(neutron subnet-list | grep "${SUBNET_NAME}" | awk '{print $2}')
# CONFIRM delete
echo "TENANT: $TENANT_NAME"
echo "Network: $NETWORK_NAME $NETWORK_NUMBERS $NET_ID"
echo "Subnet: $SUBNET_NAME $SUBNET_ID"
echo "Router: $ROUTER_NAME $ROUTER_ID"
echo "delete net, subnet and router interface $NETWORK_NAME (yes/no)"
read -r ANSWER
# DELETE it
if [ "$ANSWER" == "yes" ]; then
# DELETE interface
echo "neutron router-interface-delete $ROUTER_ID $SUBNET_ID"
neutron router-interface-delete "${ROUTER_ID}" "${SUBNET_ID}"
# DELETE PORTS
SUBNET_PORTS=$(neutron port-list | grep "${SUBNET_ID}" | awk '{print $2}')
for i in ${SUBNET_PORTS}
do
neutron port-delete "$i"
done
# DELETE subnet
echo "neutron subnet-delete ${SUBNET_ID}"
neutron subnet-delete "${SUBNET_ID}"
# DELETE net
echo "neutron net-delete ${NET_ID}"
neutron net-delete "${NET_ID}"
fi