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