blob: a0fd316a8d8942a4320f73ab82ac8c85520d5169 [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 Young11889042012-01-12 17:11:56 -080013# Source params - override xenrc params in your localrc to suite your taste
14source xenrc
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050015
Anthony Youngb62b4ca2011-10-26 22:29:08 -070016# Echo commands
17set -o xtrace
18
Anthony Young11889042012-01-12 17:11:56 -080019# Check for xva file
20if [ ! -e $XVA ]; then
21 echo "Missing xva file. Please run build_xva.sh (ideally on a non dom0 host since the build can require lots of space)."
22 echo "Place the resulting xva file in $XVA"
23 exit 1
24fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -070025
Anthony Youngb62b4ca2011-10-26 22:29:08 -070026# Make sure we have git
27if ! which git; then
28 GITDIR=/tmp/git-1.7.7
29 cd /tmp
30 rm -rf $GITDIR*
31 wget http://git-core.googlecode.com/files/git-1.7.7.tar.gz
32 tar xfv git-1.7.7.tar.gz
33 cd $GITDIR
Renuka Apte7bf87af2012-02-02 18:25:35 -080034 ./configure --with-curl --with-expat
Anthony Youngb62b4ca2011-10-26 22:29:08 -070035 make install
36 cd $TOP_DIR
37fi
38
39# Helper to create networks
rootb1153412012-01-19 13:28:21 -080040# Uses echo trickery to return network uuid
Anthony Youngb62b4ca2011-10-26 22:29:08 -070041function create_network() {
rootb1153412012-01-19 13:28:21 -080042 br=$1
43 dev=$2
44 vlan=$3
45 netname=$4
46 if [ -z $br ]
47 then
48 pif=$(xe pif-list --minimal device=$dev VLAN=$vlan)
49 if [ -z $pif ]
50 then
51 net=$(xe network-create name-label=$netname)
52 else
53 net=$(xe network-list --minimal PIF-uuids=$pif)
54 fi
55 echo $net
56 return 0
57 fi
58 if [ ! $(xe network-list --minimal params=bridge | grep -w --only-matching $br) ]
59 then
60 echo "Specified bridge $br does not exist"
61 echo "If you wish to use defaults, please keep the bridge name empty"
62 exit 1
63 else
64 net=$(xe network-list --minimal bridge=$br)
65 echo $net
66 fi
67}
68
69function errorcheck() {
70 rc=$?
71 if [ $rc -ne 0 ]
72 then
73 exit $rc
Anthony Youngb62b4ca2011-10-26 22:29:08 -070074 fi
75}
76
77# Create host, vm, mgmt, pub networks
rootb1153412012-01-19 13:28:21 -080078VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr")
79errorcheck
80MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr")
81errorcheck
82PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr")
83errorcheck
Anthony Youngb62b4ca2011-10-26 22:29:08 -070084
85# Helper to create vlans
86function create_vlan() {
rootb1153412012-01-19 13:28:21 -080087 dev=$1
Anthony Youngb62b4ca2011-10-26 22:29:08 -070088 vlan=$2
89 net=$3
rootb1153412012-01-19 13:28:21 -080090 # VLAN -1 refers to no VLAN (physical network)
91 if [ $vlan -eq -1 ]
92 then
93 return
94 fi
95 if [ -z $(xe vlan-list --minimal tag=$vlan) ]
96 then
97 pif=$(xe pif-list --minimal network-uuid=$net)
98 # We created a brand new network this time
99 if [ -z $pif ]
100 then
101 pif=$(xe pif-list --minimal device=$dev VLAN=-1)
102 xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
103 else
104 echo "VLAN does not exist but PIF attached to this network"
105 echo "How did we reach here?"
106 exit 1
107 fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700108 fi
109}
110
111# Create vlans for vm and management
rootb1153412012-01-19 13:28:21 -0800112create_vlan $PUB_DEV $PUB_VLAN $PUB_NET
113create_vlan $VM_DEV $VM_VLAN $VM_NET
114create_vlan $MGT_DEV $MGT_VLAN $MGT_NET
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700115
Anthony Young11889042012-01-12 17:11:56 -0800116# dom0 ip
117HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
118
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700119# Set up ip forwarding
120if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
121 # FIXME: This doesn't work on reboot!
122 echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network
123fi
124
125# Also, enable ip forwarding in rc.local, since the above trick isn't working
126if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then
127 echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
128fi
129
130# Enable ip forwarding at runtime as well
131echo 1 > /proc/sys/net/ipv4/ip_forward
132
Anthony Young11889042012-01-12 17:11:56 -0800133# Set local storage il8n
134SR_UUID=`xe sr-list --minimal name-label="Local storage"`
135xe sr-param-set uuid=$SR_UUID other-config:i18n-key=local-storage
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700136
137# Clean nova if desired
138if [ "$CLEAN" = "1" ]; then
139 rm -rf $TOP_DIR/nova
140fi
141
142# Checkout nova
143if [ ! -d $TOP_DIR/nova ]; then
Renuka Apte7bf87af2012-02-02 18:25:35 -0800144 env GIT_SSL_NO_VERIFY=true git clone $NOVA_REPO
Anthony Young419770f2012-01-11 17:35:40 -0800145 cd $TOP_DIR/nova
146 git checkout $NOVA_BRANCH
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700147fi
148
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700149# Install plugins
150cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/
151chmod a+x /etc/xapi.d/plugins/*
152yum --enablerepo=base install -y parted
153mkdir -p /boot/guest
154
Anthony Young346e4912011-11-05 00:22:47 -0500155# Shutdown previous runs
156DO_SHUTDOWN=${DO_SHUTDOWN:-1}
157if [ "$DO_SHUTDOWN" = "1" ]; then
Anthony Young40b57372011-11-05 00:30:07 -0500158 # Shutdown all domU's that created previously
Anthony Young346e4912011-11-05 00:22:47 -0500159 xe vm-list --minimal name-label="$LABEL" | xargs ./scripts/uninstall-os-vpx.sh
160
161 # Destroy any instances that were launched
162 for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
163 echo "Shutting down nova instance $uuid"
164 xe vm-unpause uuid=$uuid || true
165 xe vm-shutdown uuid=$uuid
166 xe vm-destroy uuid=$uuid
167 done
Anthony Youngfa4ecc62011-11-11 10:23:22 -0800168
169 # Destroy orphaned vdis
170 for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do
171 xe vdi-destroy uuid=$uuid
172 done
Anthony Young346e4912011-11-05 00:22:47 -0500173fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700174
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700175# Start guest
rootb1153412012-01-19 13:28:21 -0800176if [ -z $VM_BR ]; then
177 VM_BR=$(xe network-list --minimal uuid=$VM_NET params=bridge)
178fi
179if [ -z $MGT_BR ]; then
180 MGT_BR=$(xe network-list --minimal uuid=$MGT_NET params=bridge)
181fi
182if [ -z $PUB_BR ]; then
183 PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge)
184fi
Renuka Apte39938162012-03-01 15:43:36 -0800185$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 -0700186
Anthony Young1de18c62011-11-01 14:19:18 -0500187# If we have copied our ssh credentials, use ssh to monitor while the installation runs
188WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
189if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
190 # Done creating the container, let's tail the log
191 echo
192 echo "============================================================="
193 echo " -- YAY! --"
194 echo "============================================================="
195 echo
196 echo "We're done launching the vm, about to start tailing the"
197 echo "stack.sh log. It will take a second or two to start."
198 echo
199 echo "Just CTRL-C at any time to stop tailing."
200
201 set +o xtrace
202
203 while ! ssh -q stack@$PUB_IP "[ -e run.sh.log ]"; do
204 sleep 1
205 done
206
207 ssh stack@$PUB_IP 'tail -f run.sh.log' &
208
209 TAIL_PID=$!
210
211 function kill_tail() {
212 kill $TAIL_PID
213 exit 1
214 }
215
216 # Let Ctrl-c kill tail and exit
217 trap kill_tail SIGINT
218
219 echo "Waiting stack.sh to finish..."
Anthony Youngf0dca552011-11-01 14:23:14 -0700220 while ! ssh -q stack@$PUB_IP "grep -q 'stack.sh completed in' run.sh.log"; do
Anthony Young1de18c62011-11-01 14:19:18 -0500221 sleep 1
222 done
223
224 kill $TAIL_PID
225
Anthony Youngf0dca552011-11-01 14:23:14 -0700226 if ssh -q stack@$PUB_IP "grep -q 'stack.sh failed' run.sh.log"; then
Anthony Young1de18c62011-11-01 14:19:18 -0500227 exit 1
228 fi
229 echo ""
230 echo "Finished - Zip-a-dee Doo-dah!"
231 echo "You can then visit the OpenStack Dashboard"
232 echo "at http://$PUB_IP, and contact other services at the usual ports."
233else
234 echo "################################################################################"
235 echo ""
236 echo "All Finished!"
237 echo "Now, you can monitor the progress of the stack.sh installation by "
238 echo "tailing /opt/stack/run.sh.log from within your domU."
239 echo ""
240 echo "ssh into your domU now: 'ssh stack@$PUB_IP' using your password"
241 echo "and then do: 'tail -f /opt/stack/run.sh.log'"
242 echo ""
243 echo "When the script completes, you can then visit the OpenStack Dashboard"
244 echo "at http://$PUB_IP, and contact other services at the usual ports."
245
246fi