forked from marafa/openstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openstack-outside.sh
executable file
·146 lines (131 loc) · 3.31 KB
/
openstack-outside.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
echo -n " WARN: `basename $0` will modify your network settings. Continue? YES/n: "
read answer
if ! [ "$answer" == "YES" ]
then
exit 1
fi
source /root/keystonerc_admin
interfaces(){
lines=`ifconfig | awk -F "[: ]+" '/inet addr:/ { if ($4 != "127.0.0.1") print $4 }' | cut -d. -f1,2,3| wc -l`
if [ $lines -gt 1 ]
then
echo " WARN: More than 1 physical network interface found"
echo " Pls edit the variable available to `basename $0`"
exit 1
else
vlan=`ifconfig | awk -F "[: ]+" '/inet addr:/ { if ($4 != "127.0.0.1") print $4 }' | cut -d. -f1,2,3`
fi
}
#interfaces #disable this if the script detects more than one interface and enable the below line
vlan=192.168.0
now=`date +%Y%m%d%H%M`
device=eth0
start=$vlan.150
end=$vlan.200
gw=$vlan.1
dns1=4.2.2.2
dns2=
dns3=
hwaddr=`cat /etc/udev/rules.d/70-persistent-net.rules | grep $device | cut -d, -f4 | sed 's/ ATTR{address}=="//g' | sed 's/"//g'`
IP=`ifconfig $device|grep -w inet|awk '{print $2}'|cut -d: -f2`
domain=marafa.vm
PublicNet=PublicNet
PublicSubNet=PublicSubNet
##determine one physical nic or more
##if one nic move ip from nic to br-ex in /etc/sysconfig/network-scripts
device_exist(){
ifconfig $device > /dev/null 2>&1
if ! [ $? -eq 0 ]
then
echo " ERROR: $device not found"
echo " Pls edit the variable available to `basename $0`"
exit 2
fi
if [ -f /etc/sysconfig/network-scripts/ifcfg-br-ex ]
then
echo " WARN: br-ex already configured. Backup & Continue?"
read answer
if ! [ "$answer" == "y" ]
then
exit 4
fi
mv /etc/sysconfig/network-scripts/ifcfg-br-ex /root/ifcfg-br-ex-$now
echo " WARN: /etc/sysconfig/network-scripts/ifcfg-br-ex found. Saving $device to /root/ifcfg-$device.$now"
mv /etc/sysconfig/network-scripts/ifcfg-$device /root/ifcfg-$device.$now
fi
}
device_primary(){
cat >> /etc/sysconfig/network-scripts/ifcfg-$device << EOF
DEVICE=$device
HWADDR=$hwaddr
ONBOOT=yes
#TYPE=OVSPort
#DEVICETYPE=ovs
#OVS_BRIDGE=br-ex
EOF
}
device_bridge(){
cat >> /etc/sysconfig/network-scripts/ifcfg-br-ex << EOF
DEVICE=br-ex
IPADDR=$IP
PREFIX=24
GATEWAY=$gw
DNS1=$dns1
DNS2=$dns2
DNS3=$dns3
SEARCH=$domain
ONBOOT=yes
#DEVICETYPE=ovs
#TYPE=OVSBridge
#BOOTPROTO=static
#NETMASK=255.255.255.0
EOF
}
ovs(){ #open vswitch
ovs-vsctl add-port br-ex $device; service network restart
}
public_net(){
echo check if the public network exists
neutron net-show public > /dev/null 2>&1
if ! [ $? -eq 0 ]
then
echo create the public net
neutron net-create --tenant-id admin $PublicNet --router:external=True
fi
}
public_subnet(){
echo check if the public subnet exists
neutron subnet-show public_subnet > /dev/null 2>&1
if ! [ $? -eq 0 ]
then
echo create the public subnet
#neutron subnet-create --name $PublicSubNet $PublicNet $vlan.0/24
neutron subnet-create --tenant-id admin --allocation-pool start=$start,end=$end --gateway=$gw --disable-dhcp --name $PublicSubNet $PublicNet $vlan.0/24
fi
}
public_router(){
echo check if the router1 exists
neutron router-show router1 > /dev/null 2>&1 #assuming our router isnt there
if ! [ $? -eq 0 ]
then
echo create the public router
neutron router-create PublicRouter
neutron router-gateway-set PublicRouter $PublicNet
fi
}
public_floatingip(){
neutron floatingip-create $PublicNet
}
public_network(){
public_net
public_subnet
public_router
public_floatingip
}
###MAIN
check
device_primary
device_bridge
ovs
public_network