blob: cd28f155742e089a70c90acfdb45eecb8d3a7733 [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
34 ./configure
35 make install
36 cd $TOP_DIR
37fi
38
39# Helper to create networks
40function create_network() {
41 if ! xe network-list | grep bridge | grep -q $1; then
42 echo "Creating bridge $1"
43 xe network-create name-label=$1
44 fi
45}
46
47# Create host, vm, mgmt, pub networks
48create_network xapi0
49create_network $VM_BR
50create_network $MGT_BR
51create_network $PUB_BR
52
53# Get the uuid for our physical (public) interface
54PIF=`xe pif-list --minimal device=eth0`
55
56# Create networks/bridges for vm and management
57VM_NET=`xe network-list --minimal bridge=$VM_BR`
58MGT_NET=`xe network-list --minimal bridge=$MGT_BR`
59
60# Helper to create vlans
61function create_vlan() {
62 pif=$1
63 vlan=$2
64 net=$3
65 if ! xe vlan-list | grep tag | grep -q $vlan; then
66 xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
67 fi
68}
69
70# Create vlans for vm and management
71create_vlan $PIF $VM_VLAN $VM_NET
72create_vlan $PIF $MGT_VLAN $MGT_NET
73
Anthony Young11889042012-01-12 17:11:56 -080074# dom0 ip
75HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
76
Anthony Youngb62b4ca2011-10-26 22:29:08 -070077# Setup host-only nat rules
78HOST_NET=169.254.0.0/16
79if ! iptables -L -v -t nat | grep -q $HOST_NET; then
80 iptables -t nat -A POSTROUTING -s $HOST_NET -j SNAT --to-source $HOST_IP
81 iptables -I FORWARD 1 -s $HOST_NET -j ACCEPT
82 /etc/init.d/iptables save
83fi
84
85# Set up ip forwarding
86if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
87 # FIXME: This doesn't work on reboot!
88 echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network
89fi
90
91# Also, enable ip forwarding in rc.local, since the above trick isn't working
92if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then
93 echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
94fi
95
96# Enable ip forwarding at runtime as well
97echo 1 > /proc/sys/net/ipv4/ip_forward
98
Anthony Young11889042012-01-12 17:11:56 -080099# Set local storage il8n
100SR_UUID=`xe sr-list --minimal name-label="Local storage"`
101xe sr-param-set uuid=$SR_UUID other-config:i18n-key=local-storage
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700102
103# Clean nova if desired
104if [ "$CLEAN" = "1" ]; then
105 rm -rf $TOP_DIR/nova
106fi
107
108# Checkout nova
109if [ ! -d $TOP_DIR/nova ]; then
Anthony Young419770f2012-01-11 17:35:40 -0800110 git clone $NOVA_REPO
111 cd $TOP_DIR/nova
112 git checkout $NOVA_BRANCH
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700113fi
114
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700115# Install plugins
116cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/
117chmod a+x /etc/xapi.d/plugins/*
118yum --enablerepo=base install -y parted
119mkdir -p /boot/guest
120
Anthony Young346e4912011-11-05 00:22:47 -0500121# Shutdown previous runs
122DO_SHUTDOWN=${DO_SHUTDOWN:-1}
123if [ "$DO_SHUTDOWN" = "1" ]; then
Anthony Young40b57372011-11-05 00:30:07 -0500124 # Shutdown all domU's that created previously
Anthony Young346e4912011-11-05 00:22:47 -0500125 xe vm-list --minimal name-label="$LABEL" | xargs ./scripts/uninstall-os-vpx.sh
126
127 # Destroy any instances that were launched
128 for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
129 echo "Shutting down nova instance $uuid"
130 xe vm-unpause uuid=$uuid || true
131 xe vm-shutdown uuid=$uuid
132 xe vm-destroy uuid=$uuid
133 done
Anthony Youngfa4ecc62011-11-11 10:23:22 -0800134
135 # Destroy orphaned vdis
136 for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do
137 xe vdi-destroy uuid=$uuid
138 done
Anthony Young346e4912011-11-05 00:22:47 -0500139fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700140
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700141# Start guest
142$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR
Anthony Young3eb8f592011-10-26 23:11:52 -0700143
Anthony Young1de18c62011-11-01 14:19:18 -0500144# If we have copied our ssh credentials, use ssh to monitor while the installation runs
145WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
146if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
147 # Done creating the container, let's tail the log
148 echo
149 echo "============================================================="
150 echo " -- YAY! --"
151 echo "============================================================="
152 echo
153 echo "We're done launching the vm, about to start tailing the"
154 echo "stack.sh log. It will take a second or two to start."
155 echo
156 echo "Just CTRL-C at any time to stop tailing."
157
158 set +o xtrace
159
160 while ! ssh -q stack@$PUB_IP "[ -e run.sh.log ]"; do
161 sleep 1
162 done
163
164 ssh stack@$PUB_IP 'tail -f run.sh.log' &
165
166 TAIL_PID=$!
167
168 function kill_tail() {
169 kill $TAIL_PID
170 exit 1
171 }
172
173 # Let Ctrl-c kill tail and exit
174 trap kill_tail SIGINT
175
176 echo "Waiting stack.sh to finish..."
Anthony Youngf0dca552011-11-01 14:23:14 -0700177 while ! ssh -q stack@$PUB_IP "grep -q 'stack.sh completed in' run.sh.log"; do
Anthony Young1de18c62011-11-01 14:19:18 -0500178 sleep 1
179 done
180
181 kill $TAIL_PID
182
Anthony Youngf0dca552011-11-01 14:23:14 -0700183 if ssh -q stack@$PUB_IP "grep -q 'stack.sh failed' run.sh.log"; then
Anthony Young1de18c62011-11-01 14:19:18 -0500184 exit 1
185 fi
186 echo ""
187 echo "Finished - Zip-a-dee Doo-dah!"
188 echo "You can then visit the OpenStack Dashboard"
189 echo "at http://$PUB_IP, and contact other services at the usual ports."
190else
191 echo "################################################################################"
192 echo ""
193 echo "All Finished!"
194 echo "Now, you can monitor the progress of the stack.sh installation by "
195 echo "tailing /opt/stack/run.sh.log from within your domU."
196 echo ""
197 echo "ssh into your domU now: 'ssh stack@$PUB_IP' using your password"
198 echo "and then do: 'tail -f /opt/stack/run.sh.log'"
199 echo ""
200 echo "When the script completes, you can then visit the OpenStack Dashboard"
201 echo "at http://$PUB_IP, and contact other services at the usual ports."
202
203fi