-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathos-deploy.sh
executable file
·302 lines (235 loc) · 7.92 KB
/
os-deploy.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#! /bin/bash
# Copyright 2016, Sandvine Incorporated.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Get options, both Linux Bridges and Open vSwitch (default) are supported.
# You can also use --dry-run to NOT run Ansible in the end, just prepare the
# configuration files.
for i in "$@"
do
case $i in
--br-mode=*)
BR_MODE="${i#*=}"
shift
;;
--dry-run)
DRYRUN="yes"
shift
;;
esac
done
# Open vSwitch is the default.
if [ -z $BR_MODE ]
then
BR_MODE=OVS
fi
# Validade the BR_MODE variable.
if ! [[ "$BR_MODE" = "OVS" || "$BR_MODE" = "LBR" ]]
then
echo
echo "Aborting!!!"
echo "You need to correctly specify the Bridge Mode for your OpenStack."
echo
echo "Try:"
echo "./os-deploy.sh --br-mode=OVS # For Open vSwitch."
echo "./os-deploy.sh --br-mode=LBR # For Linux Bridges."
exit 1
fi
# Detect some of the local settings:
WHOAMI=$(whoami)
HOSTNAME=$(hostname)
FQDN=$(hostname -f)
DOMAIN=$(hostname -d)
# If the hostname and hosts file aren't configured according, abort.
if [ -z $HOSTNAME ]; then
echo "Hostname not found... Configure the file /etc/hostname with your hostname. ABORTING!"
exit 1
fi
if [ -z $DOMAIN ]; then
echo "Domain not found... Configure the file /etc/hosts with your \"IP + FQDN + HOSTNAME\". ABORTING!"
exit 1
fi
if [ -z $FQDN ]; then
echo "FQDN not found... Configure your /etc/hosts according. ABORTING!"
exit 1
fi
# Display local configuration
echo
echo "The detected local configuration are:"
echo
echo "You are:" $WHOAMI
echo "Hostname:" $HOSTNAME
echo "FQDN:" $FQDN
echo "Domain:" $DOMAIN
# Configuring dummy interfaces now and on boot
DUMMY="dummy"
if grep -q "$DUMMY" /etc/modules
then
echo
echo "Dummy module already configured..."
else
echo
echo "Configuring dummy module at /etc/modules..."
sudo tee --append /etc/modules > /dev/null <<EOF
dummy numdummies=3
EOF
echo
echo "Loading dummy module..."
sudo modprobe dummy numdummies=3
fi
# Configuring /etc/network/interfaces according to the BR_MODE
if grep -q "$DUMMY" /etc/network/interfaces
then
echo
echo "Dummy interface(s) already configured, not touching /etc/network/interfaces file!"
else
if [ "$BR_MODE" = "LBR" ]
then
echo
echo "Configuring dummy interfaces for Linux Bridges at /etc/network/interfaces..."
sudo tee --append /etc/network/interfaces > /dev/null <<EOF
# Fake External Interface
allow-hotplug dummy0
iface dummy0 inet static
address 172.31.254.129
netmask 25
# VXLAN Data Path
allow-hotplug dummy1
iface dummy1 inet static
mtu 1500
address 10.0.0.1
netmask 24
EOF
echo
echo "Enabling dummy interfaces for Linux Bridges..."
echo
sudo ifup dummy0
sudo ifup dummy1
fi
if [ "$BR_MODE" = "OVS" ]
then
echo
echo "Configuring dummy interfaces for Open vSwitch at /etc/network/interfaces..."
sudo tee --append /etc/network/interfaces > /dev/null <<EOF
# Fake External Interface
allow-hotplug br-ex
iface br-ex inet static
address 172.31.254.129
netmask 25
# VXLAN Data Path
allow-hotplug dummy1
iface dummy1 inet static
mtu 1500
address 10.0.0.1
netmask 24
EOF
echo
echo "Enabling dummy interfaces for Open vSwitch..."
echo
# sudo ifup br-ex
sudo ip link set dev dummy0 up
sudo ifup dummy1
fi
fi
# Configuring Bridge Mode on group_vars/all
echo
echo "Configuring Bridge Mode to "$BR_MODE" on ansible/group_vars/all file..."
# http://docs.openstack.org/networking-guide/scenario_legacy_lb.html
if [ "$BR_MODE" = "LBR" ]
then
sed -i -e 's/br_mode:.*/br_mode: "LBR"/' ansible/group_vars/all
sed -i -e 's/linuxnet_interface_driver:.*/linuxnet_interface_driver: "nova.network.linux_net.LinuxBridgeInterfaceDriver"/' ansible/group_vars/all
sed -i -e 's/neutron_interface_driver:.*/neutron_interface_driver: "neutron.agent.linux.interface.BridgeInterfaceDriver"/' ansible/group_vars/all
sed -i -e 's/mechanism_drivers:.*/mechanism_drivers: "linuxbridge"/' ansible/group_vars/all
sed -i -e 's/firewall_driver:.*/firewall_driver: "neutron.agent.linux.iptables_firewall.IptablesFirewallDriver"/' ansible/group_vars/all
fi
# http://docs.openstack.org/networking-guide/scenario_legacy_ovs.html
if [ "$BR_MODE" = "OVS" ]
then
sed -i -e 's/br_mode:.*/br_mode: "OVS"/' ansible/group_vars/all
sed -i -e 's/linuxnet_interface_driver:.*/linuxnet_interface_driver: "nova.network.linux_net.LinuxOVSInterfaceDriver"/' ansible/group_vars/all
sed -i -e 's/neutron_interface_driver:.*/neutron_interface_driver: "neutron.agent.linux.interface.OVSInterfaceDriver"/' ansible/group_vars/all
sed -i -e 's/mechanism_drivers:.*/mechanism_drivers: "openvswitch"/' ansible/group_vars/all
sed -i -e 's/firewall_driver:.*/firewall_driver: "neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver"/' ansible/group_vars/all
fi
# Configuring FQDN and Domain on group_vars/all
echo
echo "Configuring ansible/group_vars/all file based on current environment..."
sed -i -e 's/controller-1.yourdomain.com/'$FQDN'/g' ansible/group_vars/all
sed -i -e 's/yourdomain.com/'$DOMAIN'/g' ansible/group_vars/all
# Configuring site.yml and some roles
echo
echo "Configuring ansible/site.yml and OpenStack OpenRC files with your current $WHOAMI user..."
sed -i -e 's/administrative/'$WHOAMI'/g' ansible/site.yml
sed -i -e 's/administrative/'$WHOAMI'/g' ansible/roles/keystone/tasks/openrc-files.yml
sed -i -e 's/administrative/'$WHOAMI'/g' ansible/roles/heat/tasks/main.yml
# Configuring the default interface
DEFAULT_GW_INT=$(ip r | grep default | awk '{print $5}')
echo
echo "Your primary network interface is:"
echo "dafault route via:" $DEFAULT_GW_INT
echo
echo "Preparing Ansible templates based on current default gateway interface..."
sed -i -e 's/eth0/'$DEFAULT_GW_INT'/g' ansible/roles/nova_aio/templates/nova.conf
sed -i -e 's/eth0/'$DEFAULT_GW_INT'/g' ansible/roles/cinder/templates/cinder.conf
echo
echo "Running Ansible, deploying OpenStack:"
if [ "$DRYRUN" == "yes" ]
then
echo
echo "WARNING!!!"
echo "Not running Ansible! Just preparing the environment variables..."
else
echo
cd ~/os-ansible-deployment-lite/ansible
ansible-playbook site.yml
fi
# Uploading and/or creating SSH Keypair, only if Nova binary available.
if [ "$DRYRUN" == "yes" ]
then
echo
echo "WARNING!!!"
echo "Not creating / uploading SSH Keypairs on --dry-run..."
else
if [ -f ~/.ssh/id_dsa.pub ] && [ -f /usr/bin/nova ]
then
echo
echo "Creating and uploding your SSH Keypair into OpenStack..."
echo
echo "Safe SSH Key found, uploading it to OpenStack."
source ~/demo-openrc.sh
nova keypair-add --pub-key ~/.ssh/id_dsa.pub default
else
echo
echo "Creating and uploding your SSH Keypair into OpenStack..."
echo
echo "Creating a safe SSH Keypair for you and uploading it to OpenStack."
echo
ssh-keygen -t dsa -N "" -f ~/.ssh/id_dsa
source ~/demo-openrc.sh
nova keypair-add --pub-key ~/.ssh/id_dsa.pub default
fi
fi
# Displaying information about the need for an iptables MASQUERADE rule.
echo
echo "You'll need an iptables MASQUERADE rule to allow your Instances to reach the"
echo "Internet, so, lets add the following line to your /etc/rc.local file:"
echo
echo "iptables -t nat -I POSTROUTING 1 -o $DEFAULT_GW_INT -j MASQUERADE"
sudo sed -i -e '/exit/d' /etc/rc.local
sudo tee --append /etc/rc.local > /dev/null <<EOF
iptables -t nat -I POSTROUTING 1 -o $DEFAULT_GW_INT -j MASQUERADE
EOF
echo
echo "Running /etc/rc.local for you..."
sudo /etc/rc.local