blob: 5fa7aa8529c109508a731a5b1f53001191ba8a5e [file] [log] [blame]
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001#!/bin/bash
2
3# Abort if localrc is not set
4if [ ! -e ../../localrc ]; then
5 echo "You must have a localrc with ALL necessary passwords defined before proceeding."
6 echo "See the xen README for required passwords."
7 exit 1
8fi
9
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050010# This directory
11TOP_DIR=$(cd $(dirname "$0") && pwd)
12
Anthony Youngb3e2f332012-03-16 17:01:49 -070013# Source lower level functions
14. $TOP_DIR/../../functions
15
16# Source params - override xenrc params in your localrc to suit your taste
Anthony Young11889042012-01-12 17:11:56 -080017source xenrc
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050018
Anthony Youngb62b4ca2011-10-26 22:29:08 -070019# Echo commands
20set -o xtrace
21
Anthony Young11889042012-01-12 17:11:56 -080022# Check for xva file
23if [ ! -e $XVA ]; then
24 echo "Missing xva file. Please run build_xva.sh (ideally on a non dom0 host since the build can require lots of space)."
25 echo "Place the resulting xva file in $XVA"
26 exit 1
27fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -070028
Anthony Youngb62b4ca2011-10-26 22:29:08 -070029# Make sure we have git
30if ! which git; then
31 GITDIR=/tmp/git-1.7.7
32 cd /tmp
33 rm -rf $GITDIR*
34 wget http://git-core.googlecode.com/files/git-1.7.7.tar.gz
35 tar xfv git-1.7.7.tar.gz
36 cd $GITDIR
Renuka Apte7bf87af2012-02-02 18:25:35 -080037 ./configure --with-curl --with-expat
Anthony Youngb62b4ca2011-10-26 22:29:08 -070038 make install
39 cd $TOP_DIR
40fi
41
42# Helper to create networks
rootb1153412012-01-19 13:28:21 -080043# Uses echo trickery to return network uuid
Anthony Youngb62b4ca2011-10-26 22:29:08 -070044function create_network() {
rootb1153412012-01-19 13:28:21 -080045 br=$1
46 dev=$2
47 vlan=$3
48 netname=$4
49 if [ -z $br ]
50 then
51 pif=$(xe pif-list --minimal device=$dev VLAN=$vlan)
52 if [ -z $pif ]
53 then
54 net=$(xe network-create name-label=$netname)
55 else
56 net=$(xe network-list --minimal PIF-uuids=$pif)
57 fi
58 echo $net
59 return 0
60 fi
61 if [ ! $(xe network-list --minimal params=bridge | grep -w --only-matching $br) ]
62 then
63 echo "Specified bridge $br does not exist"
64 echo "If you wish to use defaults, please keep the bridge name empty"
65 exit 1
66 else
67 net=$(xe network-list --minimal bridge=$br)
68 echo $net
69 fi
70}
71
72function errorcheck() {
73 rc=$?
74 if [ $rc -ne 0 ]
75 then
76 exit $rc
Anthony Youngb62b4ca2011-10-26 22:29:08 -070077 fi
78}
79
80# Create host, vm, mgmt, pub networks
rootb1153412012-01-19 13:28:21 -080081VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr")
82errorcheck
83MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr")
84errorcheck
85PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr")
86errorcheck
Anthony Youngb62b4ca2011-10-26 22:29:08 -070087
88# Helper to create vlans
89function create_vlan() {
rootb1153412012-01-19 13:28:21 -080090 dev=$1
Anthony Youngb62b4ca2011-10-26 22:29:08 -070091 vlan=$2
92 net=$3
rootb1153412012-01-19 13:28:21 -080093 # VLAN -1 refers to no VLAN (physical network)
94 if [ $vlan -eq -1 ]
95 then
96 return
97 fi
98 if [ -z $(xe vlan-list --minimal tag=$vlan) ]
99 then
100 pif=$(xe pif-list --minimal network-uuid=$net)
101 # We created a brand new network this time
102 if [ -z $pif ]
103 then
104 pif=$(xe pif-list --minimal device=$dev VLAN=-1)
105 xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
106 else
107 echo "VLAN does not exist but PIF attached to this network"
108 echo "How did we reach here?"
109 exit 1
110 fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700111 fi
112}
113
114# Create vlans for vm and management
rootb1153412012-01-19 13:28:21 -0800115create_vlan $PUB_DEV $PUB_VLAN $PUB_NET
116create_vlan $VM_DEV $VM_VLAN $VM_NET
117create_vlan $MGT_DEV $MGT_VLAN $MGT_NET
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700118
Anthony Young11889042012-01-12 17:11:56 -0800119# dom0 ip
120HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
121
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700122# Set up ip forwarding
123if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
124 # FIXME: This doesn't work on reboot!
125 echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network
126fi
127
128# Also, enable ip forwarding in rc.local, since the above trick isn't working
129if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then
130 echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
131fi
132
133# Enable ip forwarding at runtime as well
134echo 1 > /proc/sys/net/ipv4/ip_forward
135
Anthony Young11889042012-01-12 17:11:56 -0800136# Set local storage il8n
137SR_UUID=`xe sr-list --minimal name-label="Local storage"`
138xe sr-param-set uuid=$SR_UUID other-config:i18n-key=local-storage
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700139
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700140# Checkout nova
Anthony Youngb3e2f332012-03-16 17:01:49 -0700141git_clone $NOVA_REPO $TOP_DIR/nova $NOVA_BRANCH
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700142
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700143# Install plugins
144cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/
145chmod a+x /etc/xapi.d/plugins/*
146yum --enablerepo=base install -y parted
147mkdir -p /boot/guest
148
Anthony Young346e4912011-11-05 00:22:47 -0500149# Shutdown previous runs
150DO_SHUTDOWN=${DO_SHUTDOWN:-1}
151if [ "$DO_SHUTDOWN" = "1" ]; then
Anthony Young40b57372011-11-05 00:30:07 -0500152 # Shutdown all domU's that created previously
Anthony Young346e4912011-11-05 00:22:47 -0500153 xe vm-list --minimal name-label="$LABEL" | xargs ./scripts/uninstall-os-vpx.sh
154
155 # Destroy any instances that were launched
156 for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
157 echo "Shutting down nova instance $uuid"
158 xe vm-unpause uuid=$uuid || true
159 xe vm-shutdown uuid=$uuid
160 xe vm-destroy uuid=$uuid
161 done
Anthony Youngfa4ecc62011-11-11 10:23:22 -0800162
163 # Destroy orphaned vdis
164 for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do
165 xe vdi-destroy uuid=$uuid
166 done
Anthony Young346e4912011-11-05 00:22:47 -0500167fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700168
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700169# Start guest
rootb1153412012-01-19 13:28:21 -0800170if [ -z $VM_BR ]; then
171 VM_BR=$(xe network-list --minimal uuid=$VM_NET params=bridge)
172fi
173if [ -z $MGT_BR ]; then
174 MGT_BR=$(xe network-list --minimal uuid=$MGT_NET params=bridge)
175fi
176if [ -z $PUB_BR ]; then
177 PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge)
178fi
Renuka Apte39938162012-03-01 15:43:36 -0800179$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -w -k "flat_network_bridge=${VM_BR}"
Anthony Young3eb8f592011-10-26 23:11:52 -0700180
Renuka Aptec56885a2012-02-29 16:09:26 -0800181if [ $PUB_IP == "dhcp" ]; then
182 PUB_IP=$(xe vm-list --minimal name-label=$GUEST_NAME params=networks | sed -ne 's,^.*3/ip: \([0-9.]*\).*$,\1,p')
183fi
184
Anthony Young1de18c62011-11-01 14:19:18 -0500185# If we have copied our ssh credentials, use ssh to monitor while the installation runs
186WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
187if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
188 # Done creating the container, let's tail the log
189 echo
190 echo "============================================================="
191 echo " -- YAY! --"
192 echo "============================================================="
193 echo
194 echo "We're done launching the vm, about to start tailing the"
195 echo "stack.sh log. It will take a second or two to start."
196 echo
197 echo "Just CTRL-C at any time to stop tailing."
198
199 set +o xtrace
200
201 while ! ssh -q stack@$PUB_IP "[ -e run.sh.log ]"; do
202 sleep 1
203 done
204
205 ssh stack@$PUB_IP 'tail -f run.sh.log' &
206
207 TAIL_PID=$!
208
209 function kill_tail() {
210 kill $TAIL_PID
211 exit 1
212 }
213
214 # Let Ctrl-c kill tail and exit
215 trap kill_tail SIGINT
216
217 echo "Waiting stack.sh to finish..."
Anthony Youngf0dca552011-11-01 14:23:14 -0700218 while ! ssh -q stack@$PUB_IP "grep -q 'stack.sh completed in' run.sh.log"; do
Anthony Young1de18c62011-11-01 14:19:18 -0500219 sleep 1
220 done
221
222 kill $TAIL_PID
223
Anthony Youngf0dca552011-11-01 14:23:14 -0700224 if ssh -q stack@$PUB_IP "grep -q 'stack.sh failed' run.sh.log"; then
Anthony Young1de18c62011-11-01 14:19:18 -0500225 exit 1
226 fi
227 echo ""
228 echo "Finished - Zip-a-dee Doo-dah!"
229 echo "You can then visit the OpenStack Dashboard"
230 echo "at http://$PUB_IP, and contact other services at the usual ports."
231else
232 echo "################################################################################"
233 echo ""
234 echo "All Finished!"
235 echo "Now, you can monitor the progress of the stack.sh installation by "
236 echo "tailing /opt/stack/run.sh.log from within your domU."
237 echo ""
238 echo "ssh into your domU now: 'ssh stack@$PUB_IP' using your password"
239 echo "and then do: 'tail -f /opt/stack/run.sh.log'"
240 echo ""
241 echo "When the script completes, you can then visit the OpenStack Dashboard"
242 echo "at http://$PUB_IP, and contact other services at the usual ports."
243
244fi