forked from openstack/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_os_domU.sh
More file actions
executable file
·438 lines (371 loc) · 11.6 KB
/
install_os_domU.sh
File metadata and controls
executable file
·438 lines (371 loc) · 11.6 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#!/bin/bash
# This script is a level script
# It must be run on a XenServer or XCP machine
#
# It creates a DomU VM that runs OpenStack services
#
# For more details see: README.md
# Exit on errors
set -o errexit
# Echo commands
set -o xtrace
# Abort if localrc is not set
if [ ! -e ../../localrc ]; then
echo "You must have a localrc with ALL necessary passwords defined before proceeding."
echo "See the xen README for required passwords."
exit 1
fi
# This directory
TOP_DIR=$(cd $(dirname "$0") && pwd)
# Source lower level functions
. $TOP_DIR/../../functions
# Include onexit commands
. $TOP_DIR/scripts/on_exit.sh
#
# Get Settings
#
# Source params - override xenrc params in your localrc to suit your taste
source xenrc
xe_min()
{
local cmd="$1"
shift
xe "$cmd" --minimal "$@"
}
#
# Prepare Dom0
# including installing XenAPI plugins
#
cd $TOP_DIR
if [ -f ./master ]
then
rm -rf ./master
rm -rf ./nova
fi
# get nova
wget https://github.com/openstack/nova/zipball/master --no-check-certificate
unzip -o master -d ./nova
# install xapi plugins
XAPI_PLUGIN_DIR=/etc/xapi.d/plugins/
if [ ! -d $XAPI_PLUGIN_DIR ]; then
# the following is needed when using xcp-xapi
XAPI_PLUGIN_DIR=/usr/lib/xcp/plugins/
fi
cp -pr ./nova/*/plugins/xenserver/xenapi/etc/xapi.d/plugins/* $XAPI_PLUGIN_DIR
chmod a+x ${XAPI_PLUGIN_DIR}*
mkdir -p /boot/guest
#
# Configure Networking
#
# Helper to create networks
# Uses echo trickery to return network uuid
function create_network() {
br=$1
dev=$2
vlan=$3
netname=$4
if [ -z $br ]
then
pif=$(xe_min pif-list device=$dev VLAN=$vlan)
if [ -z $pif ]
then
net=$(xe network-create name-label=$netname)
else
net=$(xe_min network-list PIF-uuids=$pif)
fi
echo $net
return 0
fi
if [ ! $(xe_min network-list params=bridge | grep -w --only-matching $br) ]
then
echo "Specified bridge $br does not exist"
echo "If you wish to use defaults, please keep the bridge name empty"
exit 1
else
net=$(xe_min network-list bridge=$br)
echo $net
fi
}
function errorcheck() {
rc=$?
if [ $rc -ne 0 ]
then
exit $rc
fi
}
# Create host, vm, mgmt, pub networks on XenServer
VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr")
errorcheck
MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr")
errorcheck
PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr")
errorcheck
# Helper to create vlans
function create_vlan() {
dev=$1
vlan=$2
net=$3
# VLAN -1 refers to no VLAN (physical network)
if [ $vlan -eq -1 ]
then
return
fi
if [ -z $(xe_min vlan-list tag=$vlan) ]
then
pif=$(xe_min pif-list network-uuid=$net)
# We created a brand new network this time
if [ -z $pif ]
then
pif=$(xe_min pif-list device=$dev VLAN=-1)
xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
else
echo "VLAN does not exist but PIF attached to this network"
echo "How did we reach here?"
exit 1
fi
fi
}
# Create vlans for vm and management
create_vlan $PUB_DEV $PUB_VLAN $PUB_NET
create_vlan $VM_DEV $VM_VLAN $VM_NET
create_vlan $MGT_DEV $MGT_VLAN $MGT_NET
# Get final bridge names
if [ -z $VM_BR ]; then
VM_BR=$(xe_min network-list uuid=$VM_NET params=bridge)
fi
if [ -z $MGT_BR ]; then
MGT_BR=$(xe_min network-list uuid=$MGT_NET params=bridge)
fi
if [ -z $PUB_BR ]; then
PUB_BR=$(xe_min network-list uuid=$PUB_NET params=bridge)
fi
# dom0 ip, XenAPI is assumed to be listening
HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
# Set up ip forwarding, but skip on xcp-xapi
if [ -a /etc/sysconfig/network]; then
if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
# FIXME: This doesn't work on reboot!
echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network
fi
fi
# Also, enable ip forwarding in rc.local, since the above trick isn't working
if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then
echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
fi
# Enable ip forwarding at runtime as well
echo 1 > /proc/sys/net/ipv4/ip_forward
#
# Shutdown previous runs
#
DO_SHUTDOWN=${DO_SHUTDOWN:-1}
CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false}
if [ "$DO_SHUTDOWN" = "1" ]; then
# Shutdown all domU's that created previously
clean_templates_arg=""
if $CLEAN_TEMPLATES; then
clean_templates_arg="--remove-templates"
fi
./scripts/uninstall-os-vpx.sh $clean_templates_arg
# Destroy any instances that were launched
for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
echo "Shutting down nova instance $uuid"
xe vm-unpause uuid=$uuid || true
xe vm-shutdown uuid=$uuid || true
xe vm-destroy uuid=$uuid
done
# Destroy orphaned vdis
for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do
xe vdi-destroy uuid=$uuid
done
fi
#
# Create Ubuntu VM template
# and/or create VM from template
#
GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"}
TNAME="devstack_template_folsom_11.10"
SNAME_PREPARED="template_prepared"
SNAME_FIRST_BOOT="before_first_boot"
function wait_for_VM_to_halt() {
while true
do
state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted)
if [ -n "$state" ]
then
break
else
echo "Waiting for "$GUEST_NAME" to finish installation..."
sleep 20
fi
done
}
templateuuid=$(xe template-list name-label="$TNAME")
if [ -z "$templateuuid" ]; then
#
# Install Ubuntu over network
#
# try to find ubuntu template
ubuntu_template_name="Ubuntu 11.10 for DevStack (64-bit)"
ubuntu_template=$(xe_min template-list name-label="$ubuntu_template_name")
# remove template, if we are in CLEAN_TEMPLATE mode
if [ -n "$ubuntu_template" ]; then
if $CLEAN_TEMPLATES; then
xe template-param-clear param-name=other-config uuid=$ubuntu_template
xe template-uninstall template-uuid=$ubuntu_template force=true
ubuntu_template=""
fi
fi
# always update the preseed file, incase we have a newer one
PRESEED_URL=${PRESEED_URL:-""}
if [ -z "$PRESEED_URL" ]; then
PRESEED_URL="${HOST_IP}/devstackubuntupreseed.cfg"
HTTP_SERVER_LOCATION="/opt/xensource/www"
if [ ! -e $HTTP_SERVER_LOCATION ]; then
HTTP_SERVER_LOCATION="/var/www/html"
mkdir -p $HTTP_SERVER_LOCATION
fi
cp -f $TOP_DIR/devstackubuntupreseed.cfg $HTTP_SERVER_LOCATION
MIRROR=${MIRROR:-""}
if [ -n "$MIRROR" ]; then
sed -e "s,d-i mirror/http/hostname string .*,d-i mirror/http/hostname string $MIRROR," \
-i "${HTTP_SERVER_LOCATION}/devstackubuntupreseed.cfg"
fi
fi
if [ -z "$ubuntu_template" ]; then
$TOP_DIR/scripts/xenoneirictemplate.sh $PRESEED_URL
fi
# create a new VM with the given template
# creating the correct VIFs and metadata
$TOP_DIR/scripts/install-os-vpx.sh -t "$ubuntu_template_name" -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -r $OSDOMU_MEM_MB -k "flat_network_bridge=${VM_BR}"
# wait for install to finish
wait_for_VM_to_halt
# set VM to restart after a reboot
vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME")
xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid"
#
# Prepare VM for DevStack
#
# Install XenServer tools, and other such things
$TOP_DIR/prepare_guest_template.sh "$GUEST_NAME"
# start the VM to run the prepare steps
xe vm-start vm="$GUEST_NAME"
# Wait for prep script to finish and shutdown system
wait_for_VM_to_halt
# Make template from VM
snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_PREPARED")
xe snapshot-clone uuid=$snuuid new-name-label="$TNAME"
else
#
# Template already installed, create VM from template
#
vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME")
fi
#
# Inject DevStack inside VM disk
#
$TOP_DIR/build_xva.sh "$GUEST_NAME"
# create a snapshot before the first boot
# to allow a quick re-run with the same settings
xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_FIRST_BOOT"
#
# Run DevStack VM
#
xe vm-start vm="$GUEST_NAME"
#
# Find IP and optionally wait for stack.sh to complete
#
function find_ip_by_name() {
local guest_name="$1"
local interface="$2"
local period=10
max_tries=10
i=0
while true
do
if [ $i -ge $max_tries ]; then
echo "Timed out waiting for devstack ip address"
exit 11
fi
devstackip=$(xe vm-list --minimal \
name-label=$guest_name \
params=networks | sed -ne "s,^.*${interface}/ip: \([0-9.]*\).*\$,\1,p")
if [ -z "$devstackip" ]
then
sleep $period
((i++))
else
echo $devstackip
break
fi
done
}
function ssh_no_check() {
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"
}
# Note the XenServer needs to be on the chosen
# network, so XenServer can access Glance API
if [ $HOST_IP_IFACE == "eth2" ]; then
DOMU_IP=$MGT_IP
if [ $MGT_IP == "dhcp" ]; then
DOMU_IP=$(find_ip_by_name $GUEST_NAME 2)
fi
else
DOMU_IP=$PUB_IP
if [ $PUB_IP == "dhcp" ]; then
DOMU_IP=$(find_ip_by_name $GUEST_NAME 3)
fi
fi
# If we have copied our ssh credentials, use ssh to monitor while the installation runs
WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
COPYENV=${COPYENV:-1}
if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
echo "We're done launching the vm, about to start tailing the"
echo "stack.sh log. It will take a second or two to start."
echo
echo "Just CTRL-C at any time to stop tailing."
# wait for log to appear
while ! ssh_no_check -q stack@$DOMU_IP "[ -e run.sh.log ]"; do
sleep 10
done
# output the run.sh.log
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no stack@$DOMU_IP 'tail -f run.sh.log' &
TAIL_PID=$!
function kill_tail() {
kill -9 $TAIL_PID
exit 1
}
# Let Ctrl-c kill tail and exit
trap kill_tail SIGINT
# ensure we kill off the tail if we exit the script early
# for other reasons
add_on_exit "kill -9 $TAIL_PID || true"
# wait silently until stack.sh has finished
set +o xtrace
while ! ssh_no_check -q stack@$DOMU_IP "tail run.sh.log | grep -q 'stack.sh completed in'"; do
sleep 10
done
set -o xtrace
# kill the tail process now stack.sh has finished
kill -9 $TAIL_PID
# check for a failure
if ssh_no_check -q stack@$DOMU_IP "grep -q 'stack.sh failed' run.sh.log"; then
exit 1
fi
echo "################################################################################"
echo ""
echo "All Finished!"
echo "You can visit the OpenStack Dashboard"
echo "at http://$DOMU_IP, and contact other services at the usual ports."
else
echo "################################################################################"
echo ""
echo "All Finished!"
echo "Now, you can monitor the progress of the stack.sh installation by "
echo "tailing /opt/stack/run.sh.log from within your domU."
echo ""
echo "ssh into your domU now: 'ssh stack@$DOMU_IP' using your password"
echo "and then do: 'tail -f /opt/stack/run.sh.log'"
echo ""
echo "When the script completes, you can then visit the OpenStack Dashboard"
echo "at http://$DOMU_IP, and contact other services at the usual ports."
fi