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