Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 3 | # Exit on errors |
| 4 | set -o errexit |
| 5 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 6 | # Abort if localrc is not set |
| 7 | if [ ! -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 |
| 11 | fi |
| 12 | |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 13 | # This directory |
| 14 | TOP_DIR=$(cd $(dirname "$0") && pwd) |
| 15 | |
Anthony Young | b3e2f33 | 2012-03-16 17:01:49 -0700 | [diff] [blame] | 16 | # Source lower level functions |
| 17 | . $TOP_DIR/../../functions |
| 18 | |
| 19 | # Source params - override xenrc params in your localrc to suit your taste |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 20 | source xenrc |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 21 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 22 | # Echo commands |
| 23 | set -o xtrace |
| 24 | |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 25 | xe_min() |
| 26 | { |
| 27 | local cmd="$1" |
| 28 | shift |
| 29 | xe "$cmd" --minimal "$@" |
| 30 | } |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 31 | |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 32 | cd $TOP_DIR |
| 33 | if [ -f ./master ] |
| 34 | then |
| 35 | rm -rf ./master |
| 36 | rm -rf ./nova |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 37 | fi |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 38 | wget https://github.com/openstack/nova/zipball/master --no-check-certificate |
| 39 | unzip -o master -d ./nova |
| 40 | cp -pr ./nova/*/plugins/xenserver/xenapi/etc/xapi.d /etc/ |
| 41 | chmod a+x /etc/xapi.d/plugins/* |
| 42 | |
| 43 | mkdir -p /boot/guest |
| 44 | |
| 45 | GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"} |
| 46 | SNAME="ubuntusnapshot" |
| 47 | TNAME="ubuntuready" |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 48 | |
| 49 | # Helper to create networks |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 50 | # Uses echo trickery to return network uuid |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 51 | function create_network() { |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 52 | br=$1 |
| 53 | dev=$2 |
| 54 | vlan=$3 |
| 55 | netname=$4 |
| 56 | if [ -z $br ] |
| 57 | then |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 58 | pif=$(xe_min pif-list device=$dev VLAN=$vlan) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 59 | if [ -z $pif ] |
| 60 | then |
| 61 | net=$(xe network-create name-label=$netname) |
| 62 | else |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 63 | net=$(xe_min network-list PIF-uuids=$pif) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 64 | fi |
| 65 | echo $net |
| 66 | return 0 |
| 67 | fi |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 68 | if [ ! $(xe_min network-list params=bridge | grep -w --only-matching $br) ] |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 69 | 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 Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 74 | net=$(xe_min network-list bridge=$br) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 75 | echo $net |
| 76 | fi |
| 77 | } |
| 78 | |
| 79 | function errorcheck() { |
| 80 | rc=$? |
| 81 | if [ $rc -ne 0 ] |
| 82 | then |
| 83 | exit $rc |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 84 | fi |
| 85 | } |
| 86 | |
| 87 | # Create host, vm, mgmt, pub networks |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 88 | VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr") |
| 89 | errorcheck |
| 90 | MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr") |
| 91 | errorcheck |
| 92 | PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr") |
| 93 | errorcheck |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 94 | |
| 95 | # Helper to create vlans |
| 96 | function create_vlan() { |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 97 | dev=$1 |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 98 | vlan=$2 |
| 99 | net=$3 |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 100 | # VLAN -1 refers to no VLAN (physical network) |
| 101 | if [ $vlan -eq -1 ] |
| 102 | then |
| 103 | return |
| 104 | fi |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 105 | if [ -z $(xe_min vlan-list tag=$vlan) ] |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 106 | then |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 107 | pif=$(xe_min pif-list network-uuid=$net) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 108 | # We created a brand new network this time |
| 109 | if [ -z $pif ] |
| 110 | then |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 111 | pif=$(xe_min pif-list device=$dev VLAN=-1) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 112 | 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 Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 118 | fi |
| 119 | } |
| 120 | |
| 121 | # Create vlans for vm and management |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 122 | create_vlan $PUB_DEV $PUB_VLAN $PUB_NET |
| 123 | create_vlan $VM_DEV $VM_VLAN $VM_NET |
| 124 | create_vlan $MGT_DEV $MGT_VLAN $MGT_NET |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 125 | |
Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 126 | # dom0 ip |
| 127 | HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`} |
| 128 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 129 | # Set up ip forwarding |
| 130 | if ! 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 |
| 133 | fi |
| 134 | |
| 135 | # Also, enable ip forwarding in rc.local, since the above trick isn't working |
| 136 | if ! 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 |
| 138 | fi |
| 139 | |
| 140 | # Enable ip forwarding at runtime as well |
| 141 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 142 | |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 143 | # Shutdown previous runs |
| 144 | DO_SHUTDOWN=${DO_SHUTDOWN:-1} |
| 145 | if [ "$DO_SHUTDOWN" = "1" ]; then |
Anthony Young | 40b5737 | 2011-11-05 00:30:07 -0500 | [diff] [blame] | 146 | # Shutdown all domU's that created previously |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 147 | xe_min vm-list name-label="$GUEST_NAME" | xargs ./scripts/uninstall-os-vpx.sh |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 148 | |
| 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 Young | fa4ecc6 | 2011-11-11 10:23:22 -0800 | [diff] [blame] | 156 | |
| 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 Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 161 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 162 | |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 163 | # Start guest |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 164 | if [ -z $VM_BR ]; then |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 165 | VM_BR=$(xe_min network-list uuid=$VM_NET params=bridge) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 166 | fi |
| 167 | if [ -z $MGT_BR ]; then |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 168 | MGT_BR=$(xe_min network-list uuid=$MGT_NET params=bridge) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 169 | fi |
| 170 | if [ -z $PUB_BR ]; then |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 171 | PUB_BR=$(xe_min network-list uuid=$PUB_NET params=bridge) |
root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 172 | fi |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 173 | |
| 174 | templateuuid=$(xe template-list name-label="$TNAME") |
| 175 | if [ -n "$templateuuid" ] |
| 176 | then |
| 177 | vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME") |
| 178 | else |
| 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") |
| 205 | fi |
| 206 | |
| 207 | $TOP_DIR/build_xva.sh "$GUEST_NAME" |
| 208 | |
| 209 | xe vm-start vm="$GUEST_NAME" |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 210 | |
Renuka Apte | c56885a | 2012-02-29 16:09:26 -0800 | [diff] [blame] | 211 | if [ $PUB_IP == "dhcp" ]; then |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame^] | 212 | PUB_IP=$(xe_min vm-list name-label=$GUEST_NAME params=networks | sed -ne 's,^.*3/ip: \([0-9.]*\).*$,\1,p') |
Renuka Apte | c56885a | 2012-02-29 16:09:26 -0800 | [diff] [blame] | 213 | fi |
| 214 | |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 215 | # If we have copied our ssh credentials, use ssh to monitor while the installation runs |
| 216 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
| 217 | if [ "$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 Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 248 | 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] | 249 | sleep 1 |
| 250 | done |
| 251 | |
| 252 | kill $TAIL_PID |
| 253 | |
Anthony Young | f0dca55 | 2011-11-01 14:23:14 -0700 | [diff] [blame] | 254 | 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] | 255 | 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." |
| 261 | else |
| 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 | |
| 274 | fi |