forked from docc-lab/openstack-build-ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-basic-networks.sh
executable file
·214 lines (177 loc) · 6.65 KB
/
setup-basic-networks.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/sh
##
## Initialize some basic useful stuff.
##
set -x
DIRNAME=`dirname $0`
# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Grab our libs
. "$DIRNAME/setup-lib.sh"
if [ "$HOSTNAME" != "$CONTROLLER" ]; then
exit 0;
fi
logtstart "basic-networks"
if [ -f $SETTINGS ]; then
. $SETTINGS
fi
. $OURDIR/admin-openrc.sh
#
# Before we do any network stuff, wait for Neutron to be up. Neutron
# takes awhile to start up, and if that was one of the last things we
# did in setup-controller.sh, it might not be up. It has to be up for
# any of this stuff to work, so wait forever. The only reason it would
# fail to come up at this point would be a config error.
#
while [ true ]; do
echo "Checking for neutron-server to be up..."
neutron net-list
if [ $? -eq 0 ]; then
break
fi
sleep 1
done
#
# Before we setup networks, create a Designate zone.
#
if [ $OSVERSION -ge $OSNEWTON ]; then
mydomain=`hostname | sed -n -e 's/[^\.]*\.\(.*\)$/\1/p'`
openstack zone create --email root@localhost "${mydomain}."
fi
#
# Setup tunnel-based networks
#
if [ ${DATATUNNELS} -gt 0 ]; then
i=0
while [ $i -lt ${DATATUNNELS} ]; do
LAN="tun${i}"
#. $OURDIR/info.$LAN
. $OURDIR/ipinfo.$LAN
echo "*** Creating GRE data network $LAN and subnet $CIDR ..."
neutron net-create ${LAN}-net --shared --provider:network_type gre
neutron subnet-create ${LAN}-net --name ${LAN}-subnet "$CIDR"
neutron router-create ${LAN}-router
neutron router-interface-add ${LAN}-router ${LAN}-subnet
neutron router-gateway-set ${LAN}-router ext-net
# Create a share network for this network; and maybe a Designate DNS domain.
if [ $OSVERSION -ge $OSMITAKA ]; then
NETID=`neutron net-show ${LAN}-net | awk '/ id / { print $4 }'`
SUBNETID=`neutron subnet-show ${LAN}-subnet | awk '/ id / { print $4 }'`
manila share-network-create --name share-${LAN}-net \
--neutron-net-id $NETID --neutron-subnet-id $SUBNETID
if [ $OSVERSION -ge $OSNEWTON ]; then
neutron net-update $NETID --dns-domain ${mydomain}.
fi
fi
i=`expr $i + 1`
done
fi
for lan in ${DATAFLATLANS} ; do
. $OURDIR/info.${lan}
name="$lan"
echo "*** Creating Flat data network ${lan} and subnet ..."
nmdataip=`cat $OURDIR/data-hosts.${lan} | grep ${NETWORKMANAGER} | sed -n -e 's/^\([0-9]*.[0-9]*.[0-9]*.[0-9]*\).*$/\1/p'`
allocation_pool=`cat $OURDIR/data-allocation-pool.${lan}`
cidr=`cat $OURDIR/data-cidr.${lan}`
# Make sure to set the right gateway IP (to our router)
routeripaddr=`cat $OURDIR/router-ipaddr.$lan`
neutron net-create ${name}-net --shared --provider:physical_network ${lan} --provider:network_type flat
neutron subnet-create ${name}-net --name ${name}-subnet --allocation-pool ${allocation_pool} --gateway $routeripaddr $cidr
subnetid=`neutron subnet-show ${name}-subnet | awk '/ id / {print $4}'`
neutron router-create ${name}-router
neutron router-interface-add ${name}-router ${name}-subnet
#if [ $PUBLICCOUNT -ge 3 ] ; then
neutron router-gateway-set ${name}-router ext-net
#fi
# Fix up the dhcp agent port IP addr. We can't set this in the
# creation command, so do a port update!
ports=`neutron port-list | grep $subnetid | awk '{print $2}'`
for port in $ports ; do
owner=`neutron port-show $port | awk '/ device_owner / {print $4}'`
#if [ "x$owner" = "xnetwork:router_interface" -a -f $OURDIR/router-ipaddr.$lan ]; then
# newipaddr=`cat $OURDIR/router-ipaddr.$lan`
# neutron port-update $port --fixed-ip subnet_id=$subnetid,ip_address=$newipaddr
#fi
if [ "x$owner" = "xnetwork:dhcp" -a -f $OURDIR/dhcp-agent-ipaddr.$lan ]; then
newipaddr=`cat $OURDIR/dhcp-agent-ipaddr.$lan`
neutron port-update $port --fixed-ip subnet_id=$subnetid,ip_address=$newipaddr
fi
done
# Create a share network for this network; and maybe a Designate DNS domain.
if [ $OSVERSION -ge $OSMITAKA ]; then
NETID=`neutron net-show ${lan}-net | awk '/ id / { print $4 }'`
SUBNETID=`neutron subnet-show ${lan}-subnet | awk '/ id / { print $4 }'`
manila share-network-create --name share-${lan}-net \
--neutron-net-id $NETID --neutron-subnet-id $SUBNETID
if [ $OSVERSION -ge $OSNEWTON ]; then
neutron net-update $NETID --dns-domain ${mydomain}.
fi
fi
done
for lan in ${DATAVLANS} ; do
. $OURDIR/info.${lan}
. $OURDIR/ipinfo.${lan}
echo "*** Creating VLAN data network $lan and subnet $CIDR ..."
neutron net-create ${lan}-net --shared --provider:physical_network ${DATAVLANDEV} --provider:network_type vlan
# NB: for now don't specify an allocation_pool:
# --allocation-pool ${ALLOCATION_POOL}
neutron subnet-create ${lan}-net --name ${lan}-subnet "$CIDR"
neutron router-create ${lan}-router
neutron router-interface-add ${lan}-router ${lan}-subnet
#if [ $PUBLICCOUNT -ge 3 ] ; then
neutron router-gateway-set ${lan}-router ext-net
#fi
# Create a share network for this network; and maybe a Designate DNS domain.
if [ $OSVERSION -ge $OSMITAKA ]; then
NETID=`neutron net-show ${lan}-net | awk '/ id / { print $4 }'`
SUBNETID=`neutron subnet-show ${lan}-subnet | awk '/ id / { print $4 }'`
manila share-network-create --name share-${lan}-net \
--neutron-net-id $NETID --neutron-subnet-id $SUBNETID
if [ $OSVERSION -ge $OSNEWTON ]; then
neutron net-update $NETID --dns-domain ${mydomain}.
fi
fi
done
#
# Setup VXLAN-based networks
#
if [ ${DATAVXLANS} -gt 0 ]; then
i=0
while [ $i -lt ${DATAVXLANS} ]; do
LAN="vxlan${i}"
#. $OURDIR/info.$LAN
. $OURDIR/ipinfo.$LAN
echo "*** Creating VXLAN data network $LAN and subnet $CIDR ..."
neutron net-create ${LAN}-net --shared --provider:network_type vxlan
neutron subnet-create ${LAN}-net --name ${LAN}-subnet "$CIDR"
neutron router-create ${LAN}-router
neutron router-interface-add ${LAN}-router ${LAN}-subnet
neutron router-gateway-set ${LAN}-router ext-net
# Create a share network for this network; and maybe a Designate DNS domain.
if [ $OSVERSION -ge $OSMITAKA ]; then
NETID=`neutron net-show ${LAN}-net | awk '/ id / { print $4 }'`
SUBNETID=`neutron subnet-show ${LAN}-subnet | awk '/ id / { print $4 }'`
manila share-network-create --name share-${LAN}-net \
--neutron-net-id $NETID --neutron-subnet-id $SUBNETID
if [ $OSVERSION -ge $OSNEWTON ]; then
neutron net-update $NETID --dns-domain ${mydomain}.
fi
fi
i=`expr $i + 1`
done
fi
#
# Finally, now that we've created all our routers (and their gateways to
# the ext-net), create floating IPs until we get an error.
#
#while [ true ]; do
# neutron floatingip-create ext-net
# if [ ! $? -eq 0 ]; then
# break
# fi
#done
logtend "basic-networks"
exit 0