Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Abort if localrc is not set |
| 4 | if [ ! -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 |
| 8 | fi |
| 9 | |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 10 | # This directory |
| 11 | TOP_DIR=$(cd $(dirname "$0") && pwd) |
| 12 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 13 | # Source params - override xenrc params in your localrc to suite your taste |
| 14 | source xenrc |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 15 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 16 | # Echo commands |
| 17 | set -o xtrace |
| 18 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 19 | # Check for xva file |
| 20 | if [ ! -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 |
| 24 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 25 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 26 | # Make sure we have git |
| 27 | if ! 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 Apte | 7bf87af | 2012-02-02 18:25:35 -0800 | [diff] [blame] | 34 | ./configure --with-curl --with-expat |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 35 | make install |
| 36 | cd $TOP_DIR |
| 37 | fi |
| 38 | |
| 39 | # Helper to create networks |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 40 | # Uses echo trickery to return network uuid |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 41 | function create_network() { |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 42 | 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 | |
| 69 | function errorcheck() { |
| 70 | rc=$? |
| 71 | if [ $rc -ne 0 ] |
| 72 | then |
| 73 | exit $rc |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 74 | fi |
| 75 | } |
| 76 | |
| 77 | # Create host, vm, mgmt, pub networks |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 78 | VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr") |
| 79 | errorcheck |
| 80 | MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr") |
| 81 | errorcheck |
| 82 | PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr") |
| 83 | errorcheck |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 84 | |
| 85 | # Helper to create vlans |
| 86 | function create_vlan() { |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 87 | dev=$1 |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 88 | vlan=$2 |
| 89 | net=$3 |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 90 | # 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 Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 108 | fi |
| 109 | } |
| 110 | |
| 111 | # Create vlans for vm and management |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 112 | create_vlan $PUB_DEV $PUB_VLAN $PUB_NET |
| 113 | create_vlan $VM_DEV $VM_VLAN $VM_NET |
| 114 | create_vlan $MGT_DEV $MGT_VLAN $MGT_NET |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 115 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 116 | # dom0 ip |
| 117 | HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`} |
| 118 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 119 | # Set up ip forwarding |
| 120 | if ! 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 |
| 123 | fi |
| 124 | |
| 125 | # Also, enable ip forwarding in rc.local, since the above trick isn't working |
| 126 | if ! 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 |
| 128 | fi |
| 129 | |
| 130 | # Enable ip forwarding at runtime as well |
| 131 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 132 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 133 | # Set local storage il8n |
| 134 | SR_UUID=`xe sr-list --minimal name-label="Local storage"` |
| 135 | xe sr-param-set uuid=$SR_UUID other-config:i18n-key=local-storage |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 136 | |
| 137 | # Clean nova if desired |
| 138 | if [ "$CLEAN" = "1" ]; then |
| 139 | rm -rf $TOP_DIR/nova |
| 140 | fi |
| 141 | |
| 142 | # Checkout nova |
| 143 | if [ ! -d $TOP_DIR/nova ]; then |
Renuka Apte | 7bf87af | 2012-02-02 18:25:35 -0800 | [diff] [blame] | 144 | env GIT_SSL_NO_VERIFY=true git clone $NOVA_REPO |
Anthony Young | 419770f | 2012-01-11 17:35:40 -0800 | [diff] [blame] | 145 | cd $TOP_DIR/nova |
| 146 | git checkout $NOVA_BRANCH |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 147 | fi |
| 148 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 149 | # Install plugins |
| 150 | cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/ |
| 151 | chmod a+x /etc/xapi.d/plugins/* |
| 152 | yum --enablerepo=base install -y parted |
| 153 | mkdir -p /boot/guest |
| 154 | |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 155 | # Shutdown previous runs |
| 156 | DO_SHUTDOWN=${DO_SHUTDOWN:-1} |
| 157 | if [ "$DO_SHUTDOWN" = "1" ]; then |
Anthony Young | 40b5737 | 2011-11-05 00:30:07 -0500 | [diff] [blame] | 158 | # Shutdown all domU's that created previously |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 159 | 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 Young | fa4ecc6 | 2011-11-11 10:23:22 -0800 | [diff] [blame] | 168 | |
| 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 Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 173 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 174 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 175 | # Start guest |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 176 | if [ -z $VM_BR ]; then |
| 177 | VM_BR=$(xe network-list --minimal uuid=$VM_NET params=bridge) |
| 178 | fi |
| 179 | if [ -z $MGT_BR ]; then |
| 180 | MGT_BR=$(xe network-list --minimal uuid=$MGT_NET params=bridge) |
| 181 | fi |
| 182 | if [ -z $PUB_BR ]; then |
| 183 | PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge) |
| 184 | fi |
Renuka Apte | 3993816 | 2012-03-01 15:43:36 -0800 | [diff] [blame^] | 185 | $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 Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 186 | |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 187 | # If we have copied our ssh credentials, use ssh to monitor while the installation runs |
| 188 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
| 189 | if [ "$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 Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 220 | while ! ssh -q stack@$PUB_IP "grep -q 'stack.sh completed in' run.sh.log"; do |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 221 | sleep 1 |
| 222 | done |
| 223 | |
| 224 | kill $TAIL_PID |
| 225 | |
Anthony Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 226 | if ssh -q stack@$PUB_IP "grep -q 'stack.sh failed' run.sh.log"; then |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 227 | 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." |
| 233 | else |
| 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 | |
| 246 | fi |