| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 3 | # This script is a level script | 
|  | 4 | # It must be run on a XenServer or XCP machine | 
|  | 5 | # | 
|  | 6 | # It creates a DomU VM that runs OpenStack services | 
|  | 7 | # | 
|  | 8 | # For more details see: README.md | 
|  | 9 |  | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 10 | # Exit on errors | 
|  | 11 | set -o errexit | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 12 | # Echo commands | 
|  | 13 | set -o xtrace | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 14 |  | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 15 | # Abort if localrc is not set | 
|  | 16 | if [ ! -e ../../localrc ]; then | 
|  | 17 | echo "You must have a localrc with ALL necessary passwords defined before proceeding." | 
|  | 18 | echo "See the xen README for required passwords." | 
|  | 19 | exit 1 | 
|  | 20 | fi | 
|  | 21 |  | 
| Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 22 | # This directory | 
|  | 23 | TOP_DIR=$(cd $(dirname "$0") && pwd) | 
|  | 24 |  | 
| Anthony Young | b3e2f33 | 2012-03-16 17:01:49 -0700 | [diff] [blame] | 25 | # Source lower level functions | 
|  | 26 | . $TOP_DIR/../../functions | 
|  | 27 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 28 | # Include onexit commands | 
|  | 29 | . $TOP_DIR/scripts/on_exit.sh | 
|  | 30 |  | 
|  | 31 |  | 
|  | 32 | # | 
|  | 33 | # Get Settings | 
|  | 34 | # | 
|  | 35 |  | 
| Anthony Young | b3e2f33 | 2012-03-16 17:01:49 -0700 | [diff] [blame] | 36 | # Source params - override xenrc params in your localrc to suit your taste | 
| Anthony Young | 1188904 | 2012-01-12 17:11:56 -0800 | [diff] [blame] | 37 | source xenrc | 
| Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 38 |  | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 39 | xe_min() | 
|  | 40 | { | 
|  | 41 | local cmd="$1" | 
|  | 42 | shift | 
|  | 43 | xe "$cmd" --minimal "$@" | 
|  | 44 | } | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 45 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 46 |  | 
|  | 47 | # | 
|  | 48 | # Prepare Dom0 | 
|  | 49 | # including installing XenAPI plugins | 
|  | 50 | # | 
|  | 51 |  | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 52 | cd $TOP_DIR | 
|  | 53 | if [ -f ./master ] | 
|  | 54 | then | 
|  | 55 | rm -rf ./master | 
|  | 56 | rm -rf ./nova | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 57 | fi | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 58 |  | 
|  | 59 | # get nova | 
| Maru Newby | 3a87edd | 2012-10-25 23:01:06 +0000 | [diff] [blame] | 60 | NOVA_ZIPBALL_URL=${NOVA_ZIPBALL_URL:-$(echo $NOVA_REPO | sed "s:\.git$::;s:$:/zipball/$NOVA_BRANCH:g")} | 
|  | 61 | wget $NOVA_ZIPBALL_URL -O nova-zipball --no-check-certificate | 
| John Garbutt | 7fc6dcd | 2012-07-03 12:25:21 +0100 | [diff] [blame] | 62 | unzip -o nova-zipball  -d ./nova | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 63 |  | 
|  | 64 | # install xapi plugins | 
|  | 65 | XAPI_PLUGIN_DIR=/etc/xapi.d/plugins/ | 
|  | 66 | if [ ! -d $XAPI_PLUGIN_DIR ]; then | 
|  | 67 | # the following is needed when using xcp-xapi | 
|  | 68 | XAPI_PLUGIN_DIR=/usr/lib/xcp/plugins/ | 
|  | 69 | fi | 
|  | 70 | cp -pr ./nova/*/plugins/xenserver/xenapi/etc/xapi.d/plugins/* $XAPI_PLUGIN_DIR | 
| Maru Newby | 2298ca4 | 2012-10-25 23:46:42 +0000 | [diff] [blame] | 71 |  | 
|  | 72 | # Install the netwrap xapi plugin to support agent control of dom0 networking | 
|  | 73 | if [[ "$ENABLED_SERVICES" =~ "q-agt" && "$Q_PLUGIN" = "openvswitch" ]]; then | 
|  | 74 | if [ -f ./quantum ]; then | 
|  | 75 | rm -rf ./quantum | 
|  | 76 | fi | 
|  | 77 | # get quantum | 
|  | 78 | QUANTUM_ZIPBALL_URL=${QUANTUM_ZIPBALL_URL:-$(echo $QUANTUM_REPO | sed "s:\.git$::;s:$:/zipball/$QUANTUM_BRANCH:g")} | 
|  | 79 | wget $QUANTUM_ZIPBALL_URL -O quantum-zipball --no-check-certificate | 
|  | 80 | unzip -o quantum-zipball  -d ./quantum | 
|  | 81 | cp -pr ./quantum/*/quantum/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/* $XAPI_PLUGIN_DIR | 
|  | 82 | fi | 
|  | 83 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 84 | chmod a+x ${XAPI_PLUGIN_DIR}* | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 85 |  | 
|  | 86 | mkdir -p /boot/guest | 
|  | 87 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 88 |  | 
|  | 89 | # | 
|  | 90 | # Configure Networking | 
|  | 91 | # | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | # Helper to create networks | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 94 | # Uses echo trickery to return network uuid | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 95 | function create_network() { | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 96 | br=$1 | 
|  | 97 | dev=$2 | 
|  | 98 | vlan=$3 | 
|  | 99 | netname=$4 | 
|  | 100 | if [ -z $br ] | 
|  | 101 | then | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 102 | pif=$(xe_min pif-list device=$dev VLAN=$vlan) | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 103 | if [ -z $pif ] | 
|  | 104 | then | 
|  | 105 | net=$(xe network-create name-label=$netname) | 
|  | 106 | else | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 107 | net=$(xe_min network-list  PIF-uuids=$pif) | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 108 | fi | 
|  | 109 | echo $net | 
|  | 110 | return 0 | 
|  | 111 | fi | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 112 | if [ ! $(xe_min network-list  params=bridge | grep -w --only-matching $br) ] | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 113 | then | 
|  | 114 | echo "Specified bridge $br does not exist" | 
|  | 115 | echo "If you wish to use defaults, please keep the bridge name empty" | 
|  | 116 | exit 1 | 
|  | 117 | else | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 118 | net=$(xe_min network-list  bridge=$br) | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 119 | echo $net | 
|  | 120 | fi | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | function errorcheck() { | 
|  | 124 | rc=$? | 
|  | 125 | if [ $rc -ne 0 ] | 
|  | 126 | then | 
|  | 127 | exit $rc | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 128 | fi | 
|  | 129 | } | 
|  | 130 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 131 | # Create host, vm, mgmt, pub networks on XenServer | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 132 | VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr") | 
|  | 133 | errorcheck | 
|  | 134 | MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr") | 
|  | 135 | errorcheck | 
|  | 136 | PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr") | 
|  | 137 | errorcheck | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 138 |  | 
|  | 139 | # Helper to create vlans | 
|  | 140 | function create_vlan() { | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 141 | dev=$1 | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 142 | vlan=$2 | 
|  | 143 | net=$3 | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 144 | # VLAN -1 refers to no VLAN (physical network) | 
|  | 145 | if [ $vlan -eq -1 ] | 
|  | 146 | then | 
|  | 147 | return | 
|  | 148 | fi | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 149 | if [ -z $(xe_min vlan-list  tag=$vlan) ] | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 150 | then | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 151 | pif=$(xe_min pif-list  network-uuid=$net) | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 152 | # We created a brand new network this time | 
|  | 153 | if [ -z $pif ] | 
|  | 154 | then | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 155 | pif=$(xe_min pif-list  device=$dev VLAN=-1) | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 156 | xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net | 
|  | 157 | else | 
|  | 158 | echo "VLAN does not exist but PIF attached to this network" | 
|  | 159 | echo "How did we reach here?" | 
|  | 160 | exit 1 | 
|  | 161 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 162 | fi | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | # Create vlans for vm and management | 
| root | b115341 | 2012-01-19 13:28:21 -0800 | [diff] [blame] | 166 | create_vlan $PUB_DEV $PUB_VLAN $PUB_NET | 
|  | 167 | create_vlan $VM_DEV $VM_VLAN $VM_NET | 
|  | 168 | create_vlan $MGT_DEV $MGT_VLAN $MGT_NET | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 169 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 170 | # Get final bridge names | 
|  | 171 | if [ -z $VM_BR ]; then | 
|  | 172 | VM_BR=$(xe_min network-list  uuid=$VM_NET params=bridge) | 
|  | 173 | fi | 
|  | 174 | if [ -z $MGT_BR ]; then | 
|  | 175 | MGT_BR=$(xe_min network-list  uuid=$MGT_NET params=bridge) | 
|  | 176 | fi | 
|  | 177 | if [ -z $PUB_BR ]; then | 
|  | 178 | PUB_BR=$(xe_min network-list  uuid=$PUB_NET params=bridge) | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 179 | fi | 
|  | 180 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 181 | # dom0 ip, XenAPI is assumed to be listening | 
|  | 182 | HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`} | 
|  | 183 |  | 
|  | 184 | # Set up ip forwarding, but skip on xcp-xapi | 
| John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 185 | if [ -a /etc/sysconfig/network ]; then | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 186 | if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then | 
|  | 187 | # FIXME: This doesn't work on reboot! | 
|  | 188 | echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network | 
|  | 189 | fi | 
|  | 190 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 191 | # Also, enable ip forwarding in rc.local, since the above trick isn't working | 
|  | 192 | if ! grep -q  "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then | 
|  | 193 | echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local | 
|  | 194 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 195 | # Enable ip forwarding at runtime as well | 
|  | 196 | echo 1 > /proc/sys/net/ipv4/ip_forward | 
|  | 197 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 198 |  | 
|  | 199 | # | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 200 | # Shutdown previous runs | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 201 | # | 
|  | 202 |  | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 203 | DO_SHUTDOWN=${DO_SHUTDOWN:-1} | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 204 | CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false} | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 205 | if [ "$DO_SHUTDOWN" = "1" ]; then | 
| Anthony Young | 40b5737 | 2011-11-05 00:30:07 -0500 | [diff] [blame] | 206 | # Shutdown all domU's that created previously | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 207 | clean_templates_arg="" | 
|  | 208 | if $CLEAN_TEMPLATES; then | 
|  | 209 | clean_templates_arg="--remove-templates" | 
|  | 210 | fi | 
|  | 211 | ./scripts/uninstall-os-vpx.sh $clean_templates_arg | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 212 |  | 
|  | 213 | # Destroy any instances that were launched | 
|  | 214 | for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do | 
|  | 215 | echo "Shutting down nova instance $uuid" | 
|  | 216 | xe vm-unpause uuid=$uuid || true | 
| Armando Migliaccio | 7a5f7f2 | 2012-04-20 22:58:00 +0100 | [diff] [blame] | 217 | xe vm-shutdown uuid=$uuid || true | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 218 | xe vm-destroy uuid=$uuid | 
|  | 219 | done | 
| Anthony Young | fa4ecc6 | 2011-11-11 10:23:22 -0800 | [diff] [blame] | 220 |  | 
|  | 221 | # Destroy orphaned vdis | 
|  | 222 | for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do | 
|  | 223 | xe vdi-destroy uuid=$uuid | 
|  | 224 | done | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 225 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 226 |  | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 227 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 228 | # | 
|  | 229 | # Create Ubuntu VM template | 
|  | 230 | # and/or create VM from template | 
|  | 231 | # | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 232 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 233 | GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"} | 
| John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 234 | TNAME="devstack_template" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 235 | SNAME_PREPARED="template_prepared" | 
|  | 236 | SNAME_FIRST_BOOT="before_first_boot" | 
|  | 237 |  | 
|  | 238 | function wait_for_VM_to_halt() { | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 239 | set +x | 
|  | 240 | echo "Waiting for the VM to halt.  Progress in-VM can be checked with vncviewer:" | 
|  | 241 | mgmt_ip=$(echo $XENAPI_CONNECTION_URL | tr -d -c '1234567890.') | 
|  | 242 | domid=$(xe vm-list name-label="$GUEST_NAME" params=dom-id minimal=true) | 
|  | 243 | port=$(xenstore-read /local/domain/$domid/console/vnc-port) | 
|  | 244 | echo "vncviewer -via $mgmt_ip localhost:${port:2}" | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 245 | while true | 
|  | 246 | do | 
|  | 247 | state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted) | 
|  | 248 | if [ -n "$state" ] | 
|  | 249 | then | 
|  | 250 | break | 
|  | 251 | else | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 252 | echo -n "." | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 253 | sleep 20 | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 254 | fi | 
|  | 255 | done | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 256 | set -x | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 257 | } | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 258 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 259 | templateuuid=$(xe template-list name-label="$TNAME") | 
|  | 260 | if [ -z "$templateuuid" ]; then | 
|  | 261 | # | 
|  | 262 | # Install Ubuntu over network | 
|  | 263 | # | 
|  | 264 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 265 | # always update the preseed file, incase we have a newer one | 
|  | 266 | PRESEED_URL=${PRESEED_URL:-""} | 
|  | 267 | if [ -z "$PRESEED_URL" ]; then | 
|  | 268 | PRESEED_URL="${HOST_IP}/devstackubuntupreseed.cfg" | 
|  | 269 | HTTP_SERVER_LOCATION="/opt/xensource/www" | 
|  | 270 | if [ ! -e $HTTP_SERVER_LOCATION ]; then | 
|  | 271 | HTTP_SERVER_LOCATION="/var/www/html" | 
|  | 272 | mkdir -p $HTTP_SERVER_LOCATION | 
|  | 273 | fi | 
|  | 274 | cp -f $TOP_DIR/devstackubuntupreseed.cfg $HTTP_SERVER_LOCATION | 
|  | 275 | MIRROR=${MIRROR:-""} | 
|  | 276 | if [ -n "$MIRROR" ]; then | 
|  | 277 | sed -e "s,d-i mirror/http/hostname string .*,d-i mirror/http/hostname string $MIRROR," \ | 
|  | 278 | -i "${HTTP_SERVER_LOCATION}/devstackubuntupreseed.cfg" | 
|  | 279 | fi | 
|  | 280 | fi | 
|  | 281 |  | 
| John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 282 | # Update the template | 
|  | 283 | $TOP_DIR/scripts/install_ubuntu_template.sh $PRESEED_URL | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 284 |  | 
|  | 285 | # create a new VM with the given template | 
|  | 286 | # creating the correct VIFs and metadata | 
| John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 287 | $TOP_DIR/scripts/install-os-vpx.sh -t "$UBUNTU_INST_TEMPLATE_NAME" -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -r $OSDOMU_MEM_MB -k "flat_network_bridge=${VM_BR}" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 288 |  | 
|  | 289 | # wait for install to finish | 
|  | 290 | wait_for_VM_to_halt | 
|  | 291 |  | 
|  | 292 | # set VM to restart after a reboot | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 293 | vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME") | 
|  | 294 | xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid" | 
|  | 295 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 296 | # | 
|  | 297 | # Prepare VM for DevStack | 
|  | 298 | # | 
|  | 299 |  | 
|  | 300 | # Install XenServer tools, and other such things | 
|  | 301 | $TOP_DIR/prepare_guest_template.sh "$GUEST_NAME" | 
|  | 302 |  | 
|  | 303 | # start the VM to run the prepare steps | 
|  | 304 | xe vm-start vm="$GUEST_NAME" | 
|  | 305 |  | 
|  | 306 | # Wait for prep script to finish and shutdown system | 
|  | 307 | wait_for_VM_to_halt | 
|  | 308 |  | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 309 | # Make template from VM | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 310 | snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_PREPARED") | 
|  | 311 | xe snapshot-clone uuid=$snuuid new-name-label="$TNAME" | 
|  | 312 | else | 
|  | 313 | # | 
|  | 314 | # Template already installed, create VM from template | 
|  | 315 | # | 
|  | 316 | vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME") | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 317 | fi | 
|  | 318 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 319 |  | 
|  | 320 | # | 
|  | 321 | # Inject DevStack inside VM disk | 
|  | 322 | # | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 323 | $TOP_DIR/build_xva.sh "$GUEST_NAME" | 
|  | 324 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 325 | # create a snapshot before the first boot | 
|  | 326 | # to allow a quick re-run with the same settings | 
|  | 327 | xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_FIRST_BOOT" | 
|  | 328 |  | 
|  | 329 |  | 
|  | 330 | # | 
|  | 331 | # Run DevStack VM | 
|  | 332 | # | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 333 | xe vm-start vm="$GUEST_NAME" | 
| Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 334 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 335 |  | 
|  | 336 | # | 
|  | 337 | # Find IP and optionally wait for stack.sh to complete | 
|  | 338 | # | 
|  | 339 |  | 
|  | 340 | function find_ip_by_name() { | 
|  | 341 | local guest_name="$1" | 
|  | 342 | local interface="$2" | 
|  | 343 | local period=10 | 
|  | 344 | max_tries=10 | 
|  | 345 | i=0 | 
|  | 346 | while true | 
|  | 347 | do | 
|  | 348 | if [ $i -ge $max_tries ]; then | 
|  | 349 | echo "Timed out waiting for devstack ip address" | 
|  | 350 | exit 11 | 
|  | 351 | fi | 
|  | 352 |  | 
|  | 353 | devstackip=$(xe vm-list --minimal \ | 
|  | 354 | name-label=$guest_name \ | 
|  | 355 | params=networks | sed -ne "s,^.*${interface}/ip: \([0-9.]*\).*\$,\1,p") | 
|  | 356 | if [ -z "$devstackip" ] | 
|  | 357 | then | 
|  | 358 | sleep $period | 
|  | 359 | ((i++)) | 
|  | 360 | else | 
|  | 361 | echo $devstackip | 
|  | 362 | break | 
|  | 363 | fi | 
|  | 364 | done | 
|  | 365 | } | 
|  | 366 |  | 
|  | 367 | function ssh_no_check() { | 
|  | 368 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@" | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | # Note the XenServer needs to be on the chosen | 
|  | 372 | # network, so XenServer can access Glance API | 
|  | 373 | if [ $HOST_IP_IFACE == "eth2" ]; then | 
|  | 374 | DOMU_IP=$MGT_IP | 
|  | 375 | if [ $MGT_IP == "dhcp" ]; then | 
|  | 376 | DOMU_IP=$(find_ip_by_name $GUEST_NAME 2) | 
|  | 377 | fi | 
|  | 378 | else | 
|  | 379 | DOMU_IP=$PUB_IP | 
|  | 380 | if [ $PUB_IP == "dhcp" ]; then | 
|  | 381 | DOMU_IP=$(find_ip_by_name $GUEST_NAME 3) | 
|  | 382 | fi | 
| Renuka Apte | c56885a | 2012-02-29 16:09:26 -0800 | [diff] [blame] | 383 | fi | 
|  | 384 |  | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 385 | # If we have copied our ssh credentials, use ssh to monitor while the installation runs | 
|  | 386 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 387 | COPYENV=${COPYENV:-1} | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 388 | if [ "$WAIT_TILL_LAUNCH" = "1" ]  && [ -e ~/.ssh/id_rsa.pub  ] && [ "$COPYENV" = "1" ]; then | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 389 | echo "We're done launching the vm, about to start tailing the" | 
|  | 390 | echo "stack.sh log. It will take a second or two to start." | 
|  | 391 | echo | 
|  | 392 | echo "Just CTRL-C at any time to stop tailing." | 
|  | 393 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 394 | # wait for log to appear | 
|  | 395 | while ! ssh_no_check -q stack@$DOMU_IP "[ -e run.sh.log ]"; do | 
|  | 396 | sleep 10 | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 397 | done | 
|  | 398 |  | 
| Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 399 | set +x | 
|  | 400 | echo -n "Waiting for startup script to finish" | 
|  | 401 | while [ `ssh_no_check -q stack@$DOMU_IP pgrep -c run.sh` -ge 1 ] | 
|  | 402 | do | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 403 | sleep 10 | 
| Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 404 | echo -n "." | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 405 | done | 
| Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 406 | echo "done!" | 
|  | 407 | set -x | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 408 |  | 
| Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 409 | # output the run.sh.log | 
|  | 410 | ssh_no_check -q stack@$DOMU_IP 'cat run.sh.log' | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 411 |  | 
| Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 412 | # Fail if the expected text is not found | 
|  | 413 | ssh_no_check -q stack@$DOMU_IP 'cat run.sh.log' | grep -q 'stack.sh completed in' | 
|  | 414 |  | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 415 | set +x | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 416 | echo "################################################################################" | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 417 | echo "" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 418 | echo "All Finished!" | 
|  | 419 | echo "You can visit the OpenStack Dashboard" | 
|  | 420 | echo "at http://$DOMU_IP, and contact other services at the usual ports." | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 421 | else | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 422 | set +x | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 423 | echo "################################################################################" | 
|  | 424 | echo "" | 
|  | 425 | echo "All Finished!" | 
|  | 426 | echo "Now, you can monitor the progress of the stack.sh installation by " | 
|  | 427 | echo "tailing /opt/stack/run.sh.log from within your domU." | 
|  | 428 | echo "" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 429 | echo "ssh into your domU now: 'ssh stack@$DOMU_IP' using your password" | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 430 | echo "and then do: 'tail -f /opt/stack/run.sh.log'" | 
|  | 431 | echo "" | 
|  | 432 | echo "When the script completes, you can then visit the OpenStack Dashboard" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 433 | echo "at http://$DOMU_IP, and contact other services at the usual ports." | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 434 | fi |