blob: 31bcc40cbf6a251c520b852c0e44b4e155ebeef9 [file] [log] [blame]
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001#!/bin/bash
2
Renuka Apte0af143b2012-04-02 15:46:53 -07003# Exit on errors
4set -o errexit
5
Anthony Youngb62b4ca2011-10-26 22:29:08 -07006# Abort if localrc is not set
7if [ ! -e ../../localrc ]; then
8 echo "You must have a localrc with ALL necessary passwords defined before proceeding."
9 echo "See the xen README for required passwords."
10 exit 1
11fi
12
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050013# This directory
14TOP_DIR=$(cd $(dirname "$0") && pwd)
15
Anthony Youngb3e2f332012-03-16 17:01:49 -070016# Source lower level functions
17. $TOP_DIR/../../functions
18
19# Source params - override xenrc params in your localrc to suit your taste
Anthony Young11889042012-01-12 17:11:56 -080020source xenrc
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050021
Anthony Youngb62b4ca2011-10-26 22:29:08 -070022# Echo commands
23set -o xtrace
24
Renuka Apte0af143b2012-04-02 15:46:53 -070025xe_min()
26{
27 local cmd="$1"
28 shift
29 xe "$cmd" --minimal "$@"
30}
Anthony Youngb62b4ca2011-10-26 22:29:08 -070031
Renuka Apte0af143b2012-04-02 15:46:53 -070032cd $TOP_DIR
33if [ -f ./master ]
34then
35 rm -rf ./master
36 rm -rf ./nova
Anthony Youngb62b4ca2011-10-26 22:29:08 -070037fi
Renuka Apte0af143b2012-04-02 15:46:53 -070038wget https://github.com/openstack/nova/zipball/master --no-check-certificate
39unzip -o master -d ./nova
40cp -pr ./nova/*/plugins/xenserver/xenapi/etc/xapi.d /etc/
41chmod a+x /etc/xapi.d/plugins/*
42
43mkdir -p /boot/guest
44
45GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"}
46SNAME="ubuntusnapshot"
47TNAME="ubuntuready"
Anthony Youngb62b4ca2011-10-26 22:29:08 -070048
49# Helper to create networks
rootb1153412012-01-19 13:28:21 -080050# Uses echo trickery to return network uuid
Anthony Youngb62b4ca2011-10-26 22:29:08 -070051function create_network() {
rootb1153412012-01-19 13:28:21 -080052 br=$1
53 dev=$2
54 vlan=$3
55 netname=$4
56 if [ -z $br ]
57 then
Renuka Apte0af143b2012-04-02 15:46:53 -070058 pif=$(xe_min pif-list device=$dev VLAN=$vlan)
rootb1153412012-01-19 13:28:21 -080059 if [ -z $pif ]
60 then
61 net=$(xe network-create name-label=$netname)
62 else
Renuka Apte0af143b2012-04-02 15:46:53 -070063 net=$(xe_min network-list PIF-uuids=$pif)
rootb1153412012-01-19 13:28:21 -080064 fi
65 echo $net
66 return 0
67 fi
Renuka Apte0af143b2012-04-02 15:46:53 -070068 if [ ! $(xe_min network-list params=bridge | grep -w --only-matching $br) ]
rootb1153412012-01-19 13:28:21 -080069 then
70 echo "Specified bridge $br does not exist"
71 echo "If you wish to use defaults, please keep the bridge name empty"
72 exit 1
73 else
Renuka Apte0af143b2012-04-02 15:46:53 -070074 net=$(xe_min network-list bridge=$br)
rootb1153412012-01-19 13:28:21 -080075 echo $net
76 fi
77}
78
79function errorcheck() {
80 rc=$?
81 if [ $rc -ne 0 ]
82 then
83 exit $rc
Anthony Youngb62b4ca2011-10-26 22:29:08 -070084 fi
85}
86
87# Create host, vm, mgmt, pub networks
rootb1153412012-01-19 13:28:21 -080088VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr")
89errorcheck
90MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr")
91errorcheck
92PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr")
93errorcheck
Anthony Youngb62b4ca2011-10-26 22:29:08 -070094
95# Helper to create vlans
96function create_vlan() {
rootb1153412012-01-19 13:28:21 -080097 dev=$1
Anthony Youngb62b4ca2011-10-26 22:29:08 -070098 vlan=$2
99 net=$3
rootb1153412012-01-19 13:28:21 -0800100 # VLAN -1 refers to no VLAN (physical network)
101 if [ $vlan -eq -1 ]
102 then
103 return
104 fi
Renuka Apte0af143b2012-04-02 15:46:53 -0700105 if [ -z $(xe_min vlan-list tag=$vlan) ]
rootb1153412012-01-19 13:28:21 -0800106 then
Renuka Apte0af143b2012-04-02 15:46:53 -0700107 pif=$(xe_min pif-list network-uuid=$net)
rootb1153412012-01-19 13:28:21 -0800108 # We created a brand new network this time
109 if [ -z $pif ]
110 then
Renuka Apte0af143b2012-04-02 15:46:53 -0700111 pif=$(xe_min pif-list device=$dev VLAN=-1)
rootb1153412012-01-19 13:28:21 -0800112 xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
113 else
114 echo "VLAN does not exist but PIF attached to this network"
115 echo "How did we reach here?"
116 exit 1
117 fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700118 fi
119}
120
121# Create vlans for vm and management
rootb1153412012-01-19 13:28:21 -0800122create_vlan $PUB_DEV $PUB_VLAN $PUB_NET
123create_vlan $VM_DEV $VM_VLAN $VM_NET
124create_vlan $MGT_DEV $MGT_VLAN $MGT_NET
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700125
Anthony Young11889042012-01-12 17:11:56 -0800126# dom0 ip
127HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
128
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700129# Set up ip forwarding
130if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
131 # FIXME: This doesn't work on reboot!
132 echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network
133fi
134
135# Also, enable ip forwarding in rc.local, since the above trick isn't working
136if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then
137 echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
138fi
139
140# Enable ip forwarding at runtime as well
141echo 1 > /proc/sys/net/ipv4/ip_forward
142
Anthony Young346e4912011-11-05 00:22:47 -0500143# Shutdown previous runs
144DO_SHUTDOWN=${DO_SHUTDOWN:-1}
145if [ "$DO_SHUTDOWN" = "1" ]; then
Anthony Young40b57372011-11-05 00:30:07 -0500146 # Shutdown all domU's that created previously
Renuka Apte0af143b2012-04-02 15:46:53 -0700147 xe_min vm-list name-label="$GUEST_NAME" | xargs ./scripts/uninstall-os-vpx.sh
Anthony Young346e4912011-11-05 00:22:47 -0500148
149 # Destroy any instances that were launched
150 for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
151 echo "Shutting down nova instance $uuid"
152 xe vm-unpause uuid=$uuid || true
153 xe vm-shutdown uuid=$uuid
154 xe vm-destroy uuid=$uuid
155 done
Anthony Youngfa4ecc62011-11-11 10:23:22 -0800156
157 # Destroy orphaned vdis
158 for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do
159 xe vdi-destroy uuid=$uuid
160 done
Anthony Young346e4912011-11-05 00:22:47 -0500161fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700162
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700163# Start guest
rootb1153412012-01-19 13:28:21 -0800164if [ -z $VM_BR ]; then
Renuka Apte0af143b2012-04-02 15:46:53 -0700165 VM_BR=$(xe_min network-list uuid=$VM_NET params=bridge)
rootb1153412012-01-19 13:28:21 -0800166fi
167if [ -z $MGT_BR ]; then
Renuka Apte0af143b2012-04-02 15:46:53 -0700168 MGT_BR=$(xe_min network-list uuid=$MGT_NET params=bridge)
rootb1153412012-01-19 13:28:21 -0800169fi
170if [ -z $PUB_BR ]; then
Renuka Apte0af143b2012-04-02 15:46:53 -0700171 PUB_BR=$(xe_min network-list uuid=$PUB_NET params=bridge)
rootb1153412012-01-19 13:28:21 -0800172fi
Renuka Apte0af143b2012-04-02 15:46:53 -0700173
174templateuuid=$(xe template-list name-label="$TNAME")
175if [ -n "$templateuuid" ]
176then
177 vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME")
178else
179 template=$(xe_min template-list name-label="Ubuntu 11.10 (64-bit)")
180 if [ -z "$template" ]
181 then
182 $TOP_DIR/scripts/xenoneirictemplate.sh
183 fi
184 $TOP_DIR/scripts/install-os-vpx.sh -t "Ubuntu 11.10 (64-bit)" -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -r $OSDOMU_MEM_MB -k "flat_network_bridge=${VM_BR}"
185
186 # Wait for install to finish
187 while true
188 do
189 state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted)
190 if [ -n "$state" ]
191 then
192 break
193 else
194 echo "Waiting for "$GUEST_NAME" to finish installation..."
195 sleep 30
196 fi
197 done
198
199 vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME")
200 xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid"
201
202 # Make template from VM
203 snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME")
204 template_uuid=$(xe snapshot-clone uuid=$snuuid new-name-label="$TNAME")
205fi
206
207$TOP_DIR/build_xva.sh "$GUEST_NAME"
208
209xe vm-start vm="$GUEST_NAME"
Anthony Young3eb8f592011-10-26 23:11:52 -0700210
Renuka Aptec56885a2012-02-29 16:09:26 -0800211if [ $PUB_IP == "dhcp" ]; then
Renuka Apte0af143b2012-04-02 15:46:53 -0700212 PUB_IP=$(xe_min vm-list name-label=$GUEST_NAME params=networks | sed -ne 's,^.*3/ip: \([0-9.]*\).*$,\1,p')
Renuka Aptec56885a2012-02-29 16:09:26 -0800213fi
214
Anthony Young1de18c62011-11-01 14:19:18 -0500215# If we have copied our ssh credentials, use ssh to monitor while the installation runs
216WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
217if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
218 # Done creating the container, let's tail the log
219 echo
220 echo "============================================================="
221 echo " -- YAY! --"
222 echo "============================================================="
223 echo
224 echo "We're done launching the vm, about to start tailing the"
225 echo "stack.sh log. It will take a second or two to start."
226 echo
227 echo "Just CTRL-C at any time to stop tailing."
228
229 set +o xtrace
230
231 while ! ssh -q stack@$PUB_IP "[ -e run.sh.log ]"; do
232 sleep 1
233 done
234
235 ssh stack@$PUB_IP 'tail -f run.sh.log' &
236
237 TAIL_PID=$!
238
239 function kill_tail() {
240 kill $TAIL_PID
241 exit 1
242 }
243
244 # Let Ctrl-c kill tail and exit
245 trap kill_tail SIGINT
246
247 echo "Waiting stack.sh to finish..."
Anthony Youngf0dca552011-11-01 14:23:14 -0700248 while ! ssh -q stack@$PUB_IP "grep -q 'stack.sh completed in' run.sh.log"; do
Anthony Young1de18c62011-11-01 14:19:18 -0500249 sleep 1
250 done
251
252 kill $TAIL_PID
253
Anthony Youngf0dca552011-11-01 14:23:14 -0700254 if ssh -q stack@$PUB_IP "grep -q 'stack.sh failed' run.sh.log"; then
Anthony Young1de18c62011-11-01 14:19:18 -0500255 exit 1
256 fi
257 echo ""
258 echo "Finished - Zip-a-dee Doo-dah!"
259 echo "You can then visit the OpenStack Dashboard"
260 echo "at http://$PUB_IP, and contact other services at the usual ports."
261else
262 echo "################################################################################"
263 echo ""
264 echo "All Finished!"
265 echo "Now, you can monitor the progress of the stack.sh installation by "
266 echo "tailing /opt/stack/run.sh.log from within your domU."
267 echo ""
268 echo "ssh into your domU now: 'ssh stack@$PUB_IP' using your password"
269 echo "and then do: 'tail -f /opt/stack/run.sh.log'"
270 echo ""
271 echo "When the script completes, you can then visit the OpenStack Dashboard"
272 echo "at http://$PUB_IP, and contact other services at the usual ports."
273
274fi