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
/
add-tenant-networks
executable file
·81 lines (60 loc) · 1.93 KB
/
add-tenant-networks
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
#!/bin/bash
# script to create new tenant networks
SPECIAL_OPTIONS=
EXT_TO_INT="ext-to-int"
NET_EXIST="NO"
# tenant network to create
GATEWAY="192.168.111.1"
NETWORK_ID="192.168.111.0/24"
echo 'enter tenant name'
read -r TENANT_NAME
TENANT_NAME_LOWERCASE=${TENANT_NAME,,}
TENANT_ID=`keystone tenant-list | grep $TENANT_NAME | awk '{print $2}'`
if [[ $TENANT_ID == "" ]]; then
echo "ERROR :: tenant $TENANT_ID not found !"
TENANT_ID="== ==### NOT FOUND "
fi
NET="net"
POOL="pool"
# router ext-int id
ROUTER_ID=`neutron router-list | grep $EXT_TO_INT | awk '{print $2}'`
echo ""
echo "gateway: $GATEWAY"
echo "network_id: $NETWORK_ID"
echo "external_network: $EXT_TO_INT"
echo "router_id: $ROUTER_ID"
echo "tenant_name: $TENANT_NAME"
echo "tenant_id: $TENANT_ID"
echo "net_name: $TENANT_NAME_LOWERCASE-$NET"
echo "subnet_name: $TENANT_NAME_LOWERCASE-$POOL"
echo ""
# CHECK network_id
neutron net-list | grep $NETWORK_ID
if [[ $? -eq 0 ]]; then
echo ""
echo "Network id: ${NETWORK_ID} exists, fix NETWORK_ID and GATEWAY"
exit
fi
echo 'do you want to continue? (Yes / No)'
read -r ANSWER
if [[ $ANSWER == "No" || $ANSWER == "" ]]; then
exit 0
fi
# CHECK network
neutron net-list | grep $TENANT_NAME_LOWERCASE-$NET
if [[ $? -eq 0 ]]; then
# ADD subnet
neutron subnet-create --tenant-id $TENANT_ID $TENANT_NAME_LOWERCASE-$NET $NETWORK_ID --gateway $GATEWAY --name $TENANT_NAME_LOWERCASE-$POOL
else
# ADD network
neutron net-create --tenant-id $TENANT_ID $TENANT_NAME_LOWERCASE-$NET $SPECIAL_OPTIONS
# ADD subnet
neutron subnet-create --tenant-id $TENANT_ID $TENANT_NAME_LOWERCASE-$NET $NETWORK_ID --gateway $GATEWAY --name $TENANT_NAME_LOWERCASE-$POOL
fi
# CHECK subnet
neutron subnet-list | grep $TENANT_NAME_LOWERCASE-$POOL
TENANT_NET_SUBNET_ID=`neutron subnet-list | grep $TENANT_NAME_LOWERCASE-$POOL | awk '{print $2}'`
if [[ $? -eq 0 ]]; then
# ADD router interface
neutron router-interface-add $ROUTER_ID $TENANT_NET_SUBNET_ID
fi