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