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 | b3e2f33 | 2012-03-16 17:01:49 -0700 | [diff] [blame] | 13 | # Source lower level functions |
| 14 | . $TOP_DIR/../../functions |
| 15 | |
| 16 | # Source params - override xenrc params in your localrc to suit your taste |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 17 | source xenrc |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 18 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 19 | # Echo commands |
| 20 | set -o xtrace |
| 21 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 22 | # Check for xva file |
| 23 | if [ ! -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 |
| 27 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 28 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 29 | # Make sure we have git |
| 30 | if ! 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 Apte | 7bf87af | 2012-02-02 18:25:35 -0800 | [diff] [blame] | 37 | ./configure --with-curl --with-expat |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 38 | make install |
| 39 | cd $TOP_DIR |
| 40 | fi |
| 41 | |
| 42 | # Helper to create networks |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 43 | # Uses echo trickery to return network uuid |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 44 | function create_network() { |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 45 | 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 | |
| 72 | function errorcheck() { |
| 73 | rc=$? |
| 74 | if [ $rc -ne 0 ] |
| 75 | then |
| 76 | exit $rc |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 77 | fi |
| 78 | } |
| 79 | |
| 80 | # Create host, vm, mgmt, pub networks |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 81 | VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr") |
| 82 | errorcheck |
| 83 | MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr") |
| 84 | errorcheck |
| 85 | PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr") |
| 86 | errorcheck |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 87 | |
| 88 | # Helper to create vlans |
| 89 | function create_vlan() { |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 90 | dev=$1 |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 91 | vlan=$2 |
| 92 | net=$3 |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 93 | # 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 Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 111 | fi |
| 112 | } |
| 113 | |
| 114 | # Create vlans for vm and management |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 115 | create_vlan $PUB_DEV $PUB_VLAN $PUB_NET |
| 116 | create_vlan $VM_DEV $VM_VLAN $VM_NET |
| 117 | create_vlan $MGT_DEV $MGT_VLAN $MGT_NET |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 118 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 119 | # dom0 ip |
| 120 | HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`} |
| 121 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 122 | # Set up ip forwarding |
| 123 | if ! 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 |
| 126 | fi |
| 127 | |
| 128 | # Also, enable ip forwarding in rc.local, since the above trick isn't working |
| 129 | if ! 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 |
| 131 | fi |
| 132 | |
| 133 | # Enable ip forwarding at runtime as well |
| 134 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 135 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 136 | # Set local storage il8n |
| 137 | SR_UUID=`xe sr-list --minimal name-label="Local storage"` |
| 138 | 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] | 139 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 140 | # Checkout nova |
Anthony Young | b3e2f33 | 2012-03-16 17:01:49 -0700 | [diff] [blame] | 141 | git_clone $NOVA_REPO $TOP_DIR/nova $NOVA_BRANCH |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 142 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 143 | # Install plugins |
| 144 | cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/ |
| 145 | chmod a+x /etc/xapi.d/plugins/* |
| 146 | yum --enablerepo=base install -y parted |
| 147 | mkdir -p /boot/guest |
| 148 | |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 149 | # Shutdown previous runs |
| 150 | DO_SHUTDOWN=${DO_SHUTDOWN:-1} |
| 151 | if [ "$DO_SHUTDOWN" = "1" ]; then |
Anthony Young | 40b5737 | 2011-11-05 00:30:07 -0500 | [diff] [blame] | 152 | # Shutdown all domU's that created previously |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 153 | 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 Young | fa4ecc6 | 2011-11-11 10:23:22 -0800 | [diff] [blame] | 162 | |
| 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 Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 167 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 168 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 169 | # Start guest |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 170 | if [ -z $VM_BR ]; then |
| 171 | VM_BR=$(xe network-list --minimal uuid=$VM_NET params=bridge) |
| 172 | fi |
| 173 | if [ -z $MGT_BR ]; then |
| 174 | MGT_BR=$(xe network-list --minimal uuid=$MGT_NET params=bridge) |
| 175 | fi |
| 176 | if [ -z $PUB_BR ]; then |
| 177 | PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge) |
| 178 | fi |
Renuka Apte | 3993816 | 2012-03-01 15:43:36 -0800 | [diff] [blame] | 179 | $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] | 180 | |
Renuka Apte | c56885a | 2012-02-29 16:09:26 -0800 | [diff] [blame] | 181 | if [ $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') |
| 183 | fi |
| 184 | |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 185 | # If we have copied our ssh credentials, use ssh to monitor while the installation runs |
| 186 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
| 187 | if [ "$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 Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 218 | 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] | 219 | sleep 1 |
| 220 | done |
| 221 | |
| 222 | kill $TAIL_PID |
| 223 | |
Anthony Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 224 | 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] | 225 | 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." |
| 231 | else |
| 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 | |
| 244 | fi |