| 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 |  | 
| Mate Lakat | 1ca490c | 2013-09-19 10:03:36 +0100 | [diff] [blame] | 13 | export LC_ALL=C | 
|  | 14 |  | 
| Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 15 | # This directory | 
| Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 16 | THIS_DIR=$(cd $(dirname "$0") && pwd) | 
| Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 17 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 18 | # Include onexit commands | 
| Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 19 | . $THIS_DIR/scripts/on_exit.sh | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 20 |  | 
| Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 21 | # xapi functions | 
|  | 22 | . $THIS_DIR/functions | 
|  | 23 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 24 | # | 
|  | 25 | # Get Settings | 
|  | 26 | # | 
| Huan Xie | cc6af3f | 2015-12-23 02:17:01 +0000 | [diff] [blame] | 27 | TOP_DIR=$(cd $THIS_DIR/../../ && pwd) | 
|  | 28 | source $TOP_DIR/inc/meta-config | 
|  | 29 | rm -f $TOP_DIR/.localrc.auto | 
|  | 30 | extract_localrc_section $TOP_DIR/local.conf $TOP_DIR/localrc $TOP_DIR/.localrc.auto | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 31 |  | 
| Anthony Young | b3e2f33 | 2012-03-16 17:01:49 -0700 | [diff] [blame] | 32 | # Source params - override xenrc params in your localrc to suit your taste | 
| Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 33 | source $THIS_DIR/xenrc | 
| Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 34 |  | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 35 | xe_min() | 
|  | 36 | { | 
| Sean Dague | 0b865a5 | 2013-10-22 11:37:35 -0400 | [diff] [blame] | 37 | local cmd="$1" | 
|  | 38 | shift | 
|  | 39 | xe "$cmd" --minimal "$@" | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 40 | } | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 41 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 42 | # | 
|  | 43 | # Prepare Dom0 | 
|  | 44 | # including installing XenAPI plugins | 
|  | 45 | # | 
|  | 46 |  | 
| Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 47 | cd $THIS_DIR | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 48 |  | 
| Mate Lakat | d851103 | 2013-07-03 10:44:44 +0100 | [diff] [blame] | 49 | # Die if multiple hosts listed | 
|  | 50 | if have_multiple_hosts; then | 
|  | 51 | cat >&2 << EOF | 
|  | 52 | ERROR: multiple hosts found. This might mean that the XenServer is a member | 
|  | 53 | of a pool - Exiting. | 
|  | 54 | EOF | 
|  | 55 | exit 1 | 
|  | 56 | fi | 
|  | 57 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 58 | # | 
|  | 59 | # Configure Networking | 
|  | 60 | # | 
| Bob Ball | 78ef1f3 | 2013-09-29 11:36:28 +0100 | [diff] [blame] | 61 |  | 
|  | 62 | MGT_NETWORK=`xe pif-list management=true params=network-uuid minimal=true` | 
|  | 63 | MGT_BRIDGE_OR_NET_NAME=`xe network-list uuid=$MGT_NETWORK params=bridge minimal=true` | 
|  | 64 |  | 
| Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 65 | setup_network "$VM_BRIDGE_OR_NET_NAME" | 
|  | 66 | setup_network "$MGT_BRIDGE_OR_NET_NAME" | 
|  | 67 | setup_network "$PUB_BRIDGE_OR_NET_NAME" | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 68 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 69 | # With neutron, one more network is required, which is internal to the | 
| Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 70 | # hypervisor, and used by the VMs | 
| Mate Lakat | 6df6489 | 2014-10-17 13:09:49 +0200 | [diff] [blame] | 71 | setup_network "$XEN_INT_BRIDGE_OR_NET_NAME" | 
| Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 72 |  | 
| Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 73 | if parameter_is_specified "FLAT_NETWORK_BRIDGE"; then | 
| Mate Lakat | 2b8814d | 2013-09-25 17:07:06 +0100 | [diff] [blame] | 74 | if [ "$(bridge_for "$VM_BRIDGE_OR_NET_NAME")" != "$(bridge_for "$FLAT_NETWORK_BRIDGE")" ]; then | 
|  | 75 | cat >&2 << EOF | 
|  | 76 | ERROR: FLAT_NETWORK_BRIDGE is specified in localrc file, and either no network | 
|  | 77 | found on XenServer by searching for networks by that value as name-label or | 
|  | 78 | bridge name or the network found does not match the network specified by | 
|  | 79 | VM_BRIDGE_OR_NET_NAME. Please check your localrc file. | 
| Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 80 | EOF | 
| Mate Lakat | 2b8814d | 2013-09-25 17:07:06 +0100 | [diff] [blame] | 81 | exit 1 | 
|  | 82 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 83 | fi | 
|  | 84 |  | 
| Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 85 | if ! xenapi_is_listening_on "$MGT_BRIDGE_OR_NET_NAME"; then | 
|  | 86 | cat >&2 << EOF | 
|  | 87 | ERROR: XenAPI does not have an assigned IP address on the management network. | 
|  | 88 | please review your XenServer network configuration / localrc file. | 
|  | 89 | EOF | 
|  | 90 | exit 1 | 
|  | 91 | fi | 
|  | 92 |  | 
|  | 93 | HOST_IP=$(xenapi_ip_on "$MGT_BRIDGE_OR_NET_NAME") | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 94 |  | 
|  | 95 | # Set up ip forwarding, but skip on xcp-xapi | 
| John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 96 | if [ -a /etc/sysconfig/network ]; then | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 97 | if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then | 
| Sean Dague | 0b865a5 | 2013-10-22 11:37:35 -0400 | [diff] [blame] | 98 | # FIXME: This doesn't work on reboot! | 
|  | 99 | echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 100 | fi | 
|  | 101 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 102 | # Also, enable ip forwarding in rc.local, since the above trick isn't working | 
|  | 103 | if ! grep -q  "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then | 
|  | 104 | echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local | 
|  | 105 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 106 | # Enable ip forwarding at runtime as well | 
|  | 107 | echo 1 > /proc/sys/net/ipv4/ip_forward | 
|  | 108 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 109 |  | 
|  | 110 | # | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 111 | # Shutdown previous runs | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 112 | # | 
|  | 113 |  | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 114 | DO_SHUTDOWN=${DO_SHUTDOWN:-1} | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 115 | CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false} | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 116 | if [ "$DO_SHUTDOWN" = "1" ]; then | 
| Anthony Young | 40b5737 | 2011-11-05 00:30:07 -0500 | [diff] [blame] | 117 | # Shutdown all domU's that created previously | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 118 | clean_templates_arg="" | 
|  | 119 | if $CLEAN_TEMPLATES; then | 
|  | 120 | clean_templates_arg="--remove-templates" | 
|  | 121 | fi | 
|  | 122 | ./scripts/uninstall-os-vpx.sh $clean_templates_arg | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 123 |  | 
|  | 124 | # Destroy any instances that were launched | 
|  | 125 | for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do | 
|  | 126 | echo "Shutting down nova instance $uuid" | 
| Mate Lakat | 0d97cbe | 2013-07-29 09:41:50 +0100 | [diff] [blame] | 127 | xe vm-uninstall uuid=$uuid force=true | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 128 | done | 
| Anthony Young | fa4ecc6 | 2011-11-11 10:23:22 -0800 | [diff] [blame] | 129 |  | 
|  | 130 | # Destroy orphaned vdis | 
|  | 131 | for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do | 
|  | 132 | xe vdi-destroy uuid=$uuid | 
|  | 133 | done | 
| Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 134 | fi | 
| Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 135 |  | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 136 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 137 | # | 
|  | 138 | # Create Ubuntu VM template | 
|  | 139 | # and/or create VM from template | 
|  | 140 | # | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 141 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 142 | GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"} | 
| Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 143 | TNAME="jeos_template_for_devstack" | 
|  | 144 | SNAME_TEMPLATE="jeos_snapshot_for_devstack" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 145 | SNAME_FIRST_BOOT="before_first_boot" | 
|  | 146 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 147 | function wait_for_VM_to_halt { | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 148 | set +x | 
| Bob Ball | e356d8c | 2015-02-17 15:05:34 +0000 | [diff] [blame] | 149 | echo "Waiting for the VM to halt.  Progress in-VM can be checked with XenCenter or xl console:" | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 150 | mgmt_ip=$(echo $XENAPI_CONNECTION_URL | tr -d -c '1234567890.') | 
| Mate Lakat | d15c8a0 | 2014-02-04 12:38:14 +0000 | [diff] [blame] | 151 | domid=$(get_domid "$GUEST_NAME") | 
| Bob Ball | e356d8c | 2015-02-17 15:05:34 +0000 | [diff] [blame] | 152 | echo "ssh root@$mgmt_ip \"xl console $domid\"" | 
| Chmouel Boudjnah | 86a8e97 | 2014-02-04 15:20:15 +0100 | [diff] [blame] | 153 | while true; do | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 154 | state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted) | 
| Sean Dague | 16dd8b3 | 2014-02-03 09:10:54 +0900 | [diff] [blame] | 155 | if [ -n "$state" ]; then | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 156 | break | 
|  | 157 | else | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 158 | echo -n "." | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 159 | sleep 20 | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 160 | fi | 
|  | 161 | done | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 162 | set -x | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 163 | } | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 164 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 165 | templateuuid=$(xe template-list name-label="$TNAME") | 
|  | 166 | if [ -z "$templateuuid" ]; then | 
|  | 167 | # | 
|  | 168 | # Install Ubuntu over network | 
|  | 169 | # | 
| Bob Ball | 78ef1f3 | 2013-09-29 11:36:28 +0100 | [diff] [blame] | 170 | UBUNTU_INST_BRIDGE_OR_NET_NAME=${UBUNTU_INST_BRIDGE_OR_NET_NAME:-"$MGT_BRIDGE_OR_NET_NAME"} | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 171 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 172 | # always update the preseed file, incase we have a newer one | 
|  | 173 | PRESEED_URL=${PRESEED_URL:-""} | 
|  | 174 | if [ -z "$PRESEED_URL" ]; then | 
|  | 175 | PRESEED_URL="${HOST_IP}/devstackubuntupreseed.cfg" | 
| Bob Ball | 5b9adb6 | 2015-02-10 08:09:08 +0000 | [diff] [blame] | 176 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 177 | HTTP_SERVER_LOCATION="/opt/xensource/www" | 
|  | 178 | if [ ! -e $HTTP_SERVER_LOCATION ]; then | 
|  | 179 | HTTP_SERVER_LOCATION="/var/www/html" | 
|  | 180 | mkdir -p $HTTP_SERVER_LOCATION | 
|  | 181 | fi | 
| Bob Ball | 5b9adb6 | 2015-02-10 08:09:08 +0000 | [diff] [blame] | 182 |  | 
|  | 183 | # Copy the tools DEB to the XS web server | 
|  | 184 | XS_TOOLS_URL="https://github.com/downloads/citrix-openstack/warehouse/xe-guest-utilities_5.6.100-651_amd64.deb" | 
|  | 185 | ISO_DIR="/opt/xensource/packages/iso" | 
|  | 186 | XS_TOOLS_FILE_NAME="xs-tools.deb" | 
|  | 187 | XS_TOOLS_PATH="/root/$XS_TOOLS_FILE_NAME" | 
|  | 188 | if [ -e "$ISO_DIR" ]; then | 
|  | 189 | TOOLS_ISO=$(ls -1 $ISO_DIR/xs-tools-*.iso | head -1) | 
|  | 190 | TMP_DIR=/tmp/temp.$RANDOM | 
|  | 191 | mkdir -p $TMP_DIR | 
|  | 192 | mount -o loop $TOOLS_ISO $TMP_DIR | 
| jianghua wang | 78f6c1d | 2015-09-18 11:17:46 +0100 | [diff] [blame] | 193 | # the target deb package maybe *amd64.deb or *all.deb, | 
|  | 194 | # so use *amd64.deb by default. If it doesn't exist, | 
|  | 195 | # then use *all.deb. | 
|  | 196 | DEB_FILE=$(ls $TMP_DIR/Linux/*amd64.deb || ls $TMP_DIR/Linux/*all.deb) | 
| Bob Ball | 5b9adb6 | 2015-02-10 08:09:08 +0000 | [diff] [blame] | 197 | cp $DEB_FILE $HTTP_SERVER_LOCATION | 
|  | 198 | umount $TMP_DIR | 
|  | 199 | rmdir $TMP_DIR | 
|  | 200 | XS_TOOLS_URL=${HOST_IP}/$(basename $DEB_FILE) | 
|  | 201 | fi | 
|  | 202 |  | 
| Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 203 | cp -f $THIS_DIR/devstackubuntupreseed.cfg $HTTP_SERVER_LOCATION | 
| Bob Ball | 5b9adb6 | 2015-02-10 08:09:08 +0000 | [diff] [blame] | 204 | cp -f $THIS_DIR/devstackubuntu_latecommand.sh $HTTP_SERVER_LOCATION/latecommand.sh | 
| Mate Lakat | d3740f7 | 2013-05-09 15:02:21 +0100 | [diff] [blame] | 205 |  | 
|  | 206 | sed \ | 
|  | 207 | -e "s,\(d-i mirror/http/hostname string\).*,\1 $UBUNTU_INST_HTTP_HOSTNAME,g" \ | 
|  | 208 | -e "s,\(d-i mirror/http/directory string\).*,\1 $UBUNTU_INST_HTTP_DIRECTORY,g" \ | 
|  | 209 | -e "s,\(d-i mirror/http/proxy string\).*,\1 $UBUNTU_INST_HTTP_PROXY,g" \ | 
| Bob Ball | 105eaee | 2014-07-14 15:21:07 +0100 | [diff] [blame] | 210 | -e "s,\(d-i passwd/root-password password\).*,\1 $GUEST_PASSWORD,g" \ | 
|  | 211 | -e "s,\(d-i passwd/root-password-again password\).*,\1 $GUEST_PASSWORD,g" \ | 
| Bob Ball | 5b9adb6 | 2015-02-10 08:09:08 +0000 | [diff] [blame] | 212 | -e "s,\(d-i preseed/late_command string\).*,\1 in-target mkdir -p /tmp; in-target wget --no-proxy ${HOST_IP}/latecommand.sh -O /root/latecommand.sh; in-target bash /root/latecommand.sh,g" \ | 
| Mate Lakat | d3740f7 | 2013-05-09 15:02:21 +0100 | [diff] [blame] | 213 | -i "${HTTP_SERVER_LOCATION}/devstackubuntupreseed.cfg" | 
| Bob Ball | 5b9adb6 | 2015-02-10 08:09:08 +0000 | [diff] [blame] | 214 |  | 
|  | 215 | sed \ | 
|  | 216 | -e "s,@XS_TOOLS_URL@,$XS_TOOLS_URL,g" \ | 
|  | 217 | -i "${HTTP_SERVER_LOCATION}/latecommand.sh" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 218 | fi | 
|  | 219 |  | 
| John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 220 | # Update the template | 
| Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 221 | $THIS_DIR/scripts/install_ubuntu_template.sh $PRESEED_URL | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 222 |  | 
| Mate Lakat | 2f524bd | 2013-06-19 12:32:23 +0100 | [diff] [blame] | 223 | # create a new VM from the given template with eth0 attached to the given | 
|  | 224 | # network | 
| Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 225 | $THIS_DIR/scripts/install-os-vpx.sh \ | 
|  | 226 | -t "$UBUNTU_INST_TEMPLATE_NAME" \ | 
| Mate Lakat | 2f524bd | 2013-06-19 12:32:23 +0100 | [diff] [blame] | 227 | -n "$UBUNTU_INST_BRIDGE_OR_NET_NAME" \ | 
| Mate Lakat | 16ed068 | 2013-08-30 13:28:31 +0100 | [diff] [blame] | 228 | -l "$GUEST_NAME" | 
|  | 229 |  | 
| Bob Ball | 1340ee7 | 2015-03-06 21:11:55 +0000 | [diff] [blame] | 230 | set_vm_memory "$GUEST_NAME" "1024" | 
| Mate Lakat | 16ed068 | 2013-08-30 13:28:31 +0100 | [diff] [blame] | 231 |  | 
|  | 232 | xe vm-start vm="$GUEST_NAME" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 233 |  | 
|  | 234 | # wait for install to finish | 
|  | 235 | wait_for_VM_to_halt | 
|  | 236 |  | 
|  | 237 | # set VM to restart after a reboot | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 238 | vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME") | 
|  | 239 | xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid" | 
|  | 240 |  | 
|  | 241 | # Make template from VM | 
| Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 242 | snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_TEMPLATE") | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 243 | xe snapshot-clone uuid=$snuuid new-name-label="$TNAME" | 
|  | 244 | else | 
|  | 245 | # | 
|  | 246 | # Template already installed, create VM from template | 
|  | 247 | # | 
|  | 248 | vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME") | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 249 | fi | 
|  | 250 |  | 
| Mate Lakat | 2a324dd | 2014-10-15 17:40:41 +0200 | [diff] [blame] | 251 | if [ -n "${EXIT_AFTER_JEOS_INSTALLATION:-}" ]; then | 
|  | 252 | echo "User requested to quit after JEOS instalation" | 
|  | 253 | exit 0 | 
|  | 254 | fi | 
|  | 255 |  | 
| Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 256 | # | 
|  | 257 | # Prepare VM for DevStack | 
|  | 258 | # | 
| Bob Ball | 0df75a7 | 2015-02-12 11:59:46 +0000 | [diff] [blame] | 259 | xe vm-param-set other-config:os-vpx=true uuid="$vm_uuid" | 
| Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 260 |  | 
|  | 261 | # Install XenServer tools, and other such things | 
|  | 262 | $THIS_DIR/prepare_guest_template.sh "$GUEST_NAME" | 
|  | 263 |  | 
| Mate Lakat | 16ed068 | 2013-08-30 13:28:31 +0100 | [diff] [blame] | 264 | # Set virtual machine parameters | 
|  | 265 | set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB" | 
|  | 266 |  | 
| Mate Lakat | 9f878cb | 2013-10-04 09:56:24 +0100 | [diff] [blame] | 267 | # Max out VCPU count for better performance | 
|  | 268 | max_vcpus "$GUEST_NAME" | 
|  | 269 |  | 
| Mate Lakat | 8787e0f | 2013-10-28 18:15:57 +0000 | [diff] [blame] | 270 | # Wipe out all network cards | 
|  | 271 | destroy_all_vifs_of "$GUEST_NAME" | 
|  | 272 |  | 
|  | 273 | # Add only one interface to prepare the guest template | 
|  | 274 | add_interface "$GUEST_NAME" "$MGT_BRIDGE_OR_NET_NAME" "0" | 
|  | 275 |  | 
| Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 276 | # start the VM to run the prepare steps | 
|  | 277 | xe vm-start vm="$GUEST_NAME" | 
|  | 278 |  | 
|  | 279 | # Wait for prep script to finish and shutdown system | 
|  | 280 | wait_for_VM_to_halt | 
|  | 281 |  | 
| Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 282 | ## Setup network cards | 
|  | 283 | # Wipe out all | 
|  | 284 | destroy_all_vifs_of "$GUEST_NAME" | 
|  | 285 | # Tenant network | 
|  | 286 | add_interface "$GUEST_NAME" "$VM_BRIDGE_OR_NET_NAME" "$VM_DEV_NR" | 
|  | 287 | # Management network | 
|  | 288 | add_interface "$GUEST_NAME" "$MGT_BRIDGE_OR_NET_NAME" "$MGT_DEV_NR" | 
|  | 289 | # Public network | 
|  | 290 | add_interface "$GUEST_NAME" "$PUB_BRIDGE_OR_NET_NAME" "$PUB_DEV_NR" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 291 |  | 
|  | 292 | # | 
|  | 293 | # Inject DevStack inside VM disk | 
|  | 294 | # | 
| Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 295 | $THIS_DIR/build_xva.sh "$GUEST_NAME" | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 296 |  | 
| Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 297 | # Attach a network interface for the integration network (so that the bridge | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 298 | # is created by XenServer). This is required for Neutron. Also pass that as a | 
| Mate Lakat | 8ff33ce | 2013-05-30 13:26:58 +0100 | [diff] [blame] | 299 | # kernel parameter for DomU | 
| Mate Lakat | 6df6489 | 2014-10-17 13:09:49 +0200 | [diff] [blame] | 300 | attach_network "$XEN_INT_BRIDGE_OR_NET_NAME" | 
| Mate Lakat | 8ff33ce | 2013-05-30 13:26:58 +0100 | [diff] [blame] | 301 |  | 
| Mate Lakat | 6df6489 | 2014-10-17 13:09:49 +0200 | [diff] [blame] | 302 | XEN_INTEGRATION_BRIDGE=$(bridge_for "$XEN_INT_BRIDGE_OR_NET_NAME") | 
|  | 303 | append_kernel_cmdline \ | 
|  | 304 | "$GUEST_NAME" \ | 
|  | 305 | "xen_integration_bridge=${XEN_INTEGRATION_BRIDGE}" | 
| Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 306 |  | 
| Mate Lakat | 2b8814d | 2013-09-25 17:07:06 +0100 | [diff] [blame] | 307 | FLAT_NETWORK_BRIDGE="${FLAT_NETWORK_BRIDGE:-$(bridge_for "$VM_BRIDGE_OR_NET_NAME")}" | 
| Mate Lakat | 8ff33ce | 2013-05-30 13:26:58 +0100 | [diff] [blame] | 308 | append_kernel_cmdline "$GUEST_NAME" "flat_network_bridge=${FLAT_NETWORK_BRIDGE}" | 
|  | 309 |  | 
| Mate Lakat | 68ac03c | 2013-06-06 16:22:34 +0100 | [diff] [blame] | 310 | # Add a separate xvdb, if it was requested | 
|  | 311 | if [[ "0" != "$XEN_XVDB_SIZE_GB" ]]; then | 
|  | 312 | vm=$(xe vm-list name-label="$GUEST_NAME" --minimal) | 
|  | 313 |  | 
|  | 314 | # Add a new disk | 
|  | 315 | localsr=$(get_local_sr) | 
|  | 316 | extra_vdi=$(xe vdi-create \ | 
|  | 317 | name-label=xvdb-added-by-devstack \ | 
|  | 318 | virtual-size="${XEN_XVDB_SIZE_GB}GiB" \ | 
|  | 319 | sr-uuid=$localsr type=user) | 
|  | 320 | xe vbd-create vm-uuid=$vm vdi-uuid=$extra_vdi device=1 | 
|  | 321 | fi | 
|  | 322 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 323 | # create a snapshot before the first boot | 
|  | 324 | # to allow a quick re-run with the same settings | 
|  | 325 | xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_FIRST_BOOT" | 
|  | 326 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 327 | # | 
|  | 328 | # Run DevStack VM | 
|  | 329 | # | 
| Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 330 | xe vm-start vm="$GUEST_NAME" | 
| Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 331 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 332 | function ssh_no_check { | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 333 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@" | 
|  | 334 | } | 
|  | 335 |  | 
| Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 336 | # Get hold of the Management IP of OpenStack VM | 
|  | 337 | OS_VM_MANAGEMENT_ADDRESS=$MGT_IP | 
|  | 338 | if [ $OS_VM_MANAGEMENT_ADDRESS == "dhcp" ]; then | 
| Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 339 | OS_VM_MANAGEMENT_ADDRESS=$(find_ip_by_name $GUEST_NAME $MGT_DEV_NR) | 
| Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 340 | fi | 
|  | 341 |  | 
|  | 342 | # Get hold of the Service IP of OpenStack VM | 
| Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 343 | if [ $HOST_IP_IFACE == "eth${MGT_DEV_NR}" ]; then | 
| Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 344 | OS_VM_SERVICES_ADDRESS=$MGT_IP | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 345 | if [ $MGT_IP == "dhcp" ]; then | 
| Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 346 | OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME $MGT_DEV_NR) | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 347 | fi | 
|  | 348 | else | 
| Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 349 | OS_VM_SERVICES_ADDRESS=$PUB_IP | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 350 | if [ $PUB_IP == "dhcp" ]; then | 
| Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 351 | OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME $PUB_DEV_NR) | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 352 | fi | 
| Renuka Apte | c56885a | 2012-02-29 16:09:26 -0800 | [diff] [blame] | 353 | fi | 
|  | 354 |  | 
| Mate Lakat | d15c8a0 | 2014-02-04 12:38:14 +0000 | [diff] [blame] | 355 | # Create an ssh-keypair, and set it up for dom0 user | 
|  | 356 | rm -f /root/dom0key /root/dom0key.pub | 
|  | 357 | ssh-keygen -f /root/dom0key -P "" -C "dom0" | 
|  | 358 | DOMID=$(get_domid "$GUEST_NAME") | 
|  | 359 |  | 
|  | 360 | xenstore-write /local/domain/$DOMID/authorized_keys/$DOMZERO_USER "$(cat /root/dom0key.pub)" | 
|  | 361 | xenstore-chmod -u /local/domain/$DOMID/authorized_keys/$DOMZERO_USER r$DOMID | 
|  | 362 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 363 | function run_on_appliance { | 
| Mate Lakat | d15c8a0 | 2014-02-04 12:38:14 +0000 | [diff] [blame] | 364 | ssh \ | 
|  | 365 | -i /root/dom0key \ | 
|  | 366 | -o UserKnownHostsFile=/dev/null \ | 
|  | 367 | -o StrictHostKeyChecking=no \ | 
|  | 368 | -o BatchMode=yes \ | 
|  | 369 | "$DOMZERO_USER@$OS_VM_MANAGEMENT_ADDRESS" "$@" | 
|  | 370 | } | 
|  | 371 |  | 
|  | 372 | # Wait until we can log in to the appliance | 
|  | 373 | while ! run_on_appliance true; do | 
|  | 374 | sleep 1 | 
|  | 375 | done | 
|  | 376 |  | 
|  | 377 | # Remove authenticated_keys updater cronjob | 
|  | 378 | echo "" | run_on_appliance crontab - | 
|  | 379 |  | 
|  | 380 | # Generate a passwordless ssh key for domzero user | 
|  | 381 | echo "ssh-keygen -f /home/$DOMZERO_USER/.ssh/id_rsa -C $DOMZERO_USER@appliance -N \"\" -q" | run_on_appliance | 
|  | 382 |  | 
|  | 383 | # Authenticate that user to dom0 | 
|  | 384 | run_on_appliance cat /home/$DOMZERO_USER/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys | 
|  | 385 |  | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 386 | # If we have copied our ssh credentials, use ssh to monitor while the installation runs | 
|  | 387 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 388 | COPYENV=${COPYENV:-1} | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 389 | 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] | 390 | set +x | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 391 |  | 
| Bob Ball | 0686dae | 2015-01-15 12:48:26 +0000 | [diff] [blame] | 392 | echo "VM Launched - Waiting for run.sh" | 
|  | 393 | while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e /opt/stack/run_sh.pid"; do | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 394 | sleep 10 | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 395 | done | 
| Bob Ball | d6b43a0 | 2014-07-14 15:18:33 +0100 | [diff] [blame] | 396 | echo -n "devstack service is running, waiting for stack.sh to start logging..." | 
|  | 397 |  | 
| Bob Ball | 0686dae | 2015-01-15 12:48:26 +0000 | [diff] [blame] | 398 | pid=`ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "cat /opt/stack/run_sh.pid"` | 
| Bob Ball | 1e3a5d2 | 2015-01-16 13:06:58 +0000 | [diff] [blame] | 399 | if [ -n "$SCREEN_LOGDIR" ]; then | 
|  | 400 | while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e ${SCREEN_LOGDIR}/stack.log"; do | 
|  | 401 | sleep 10 | 
|  | 402 | done | 
| Bob Ball | dc7ebbb | 2014-06-24 13:59:49 +0100 | [diff] [blame] | 403 |  | 
| Bob Ball | 1e3a5d2 | 2015-01-16 13:06:58 +0000 | [diff] [blame] | 404 | ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "tail --pid $pid -n +1 -f ${SCREEN_LOGDIR}/stack.log" | 
|  | 405 | else | 
|  | 406 | echo -n "SCREEN_LOGDIR not set; just waiting for process $pid to finish" | 
|  | 407 | ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "wait $pid" | 
|  | 408 | fi | 
|  | 409 |  | 
|  | 410 | set -x | 
| Mate Lakat | 93f3b86 | 2013-09-24 17:35:00 +0100 | [diff] [blame] | 411 | # Fail if devstack did not succeed | 
| Bob Ball | 0686dae | 2015-01-15 12:48:26 +0000 | [diff] [blame] | 412 | ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'test -e /opt/stack/runsh.succeeded' | 
| Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 413 |  | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 414 | set +x | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 415 | echo "################################################################################" | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 416 | echo "" | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 417 | echo "All Finished!" | 
|  | 418 | echo "You can visit the OpenStack Dashboard" | 
| Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 419 | 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] | 420 | else | 
| Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 421 | set +x | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 422 | echo "################################################################################" | 
|  | 423 | echo "" | 
|  | 424 | echo "All Finished!" | 
|  | 425 | echo "Now, you can monitor the progress of the stack.sh installation by " | 
| Mate Lakat | 93f3b86 | 2013-09-24 17:35:00 +0100 | [diff] [blame] | 426 | echo "looking at the console of your domU / checking the log files." | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 427 | echo "" | 
| Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 428 | echo "ssh into your domU now: 'ssh stack@$OS_VM_MANAGEMENT_ADDRESS' using your password" | 
| Mate Lakat | 93f3b86 | 2013-09-24 17:35:00 +0100 | [diff] [blame] | 429 | echo "and then do: 'sudo service devstack status' to check if devstack is still running." | 
| Bob Ball | 0686dae | 2015-01-15 12:48:26 +0000 | [diff] [blame] | 430 | echo "Check that /opt/stack/runsh.succeeded exists" | 
| Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 431 | echo "" | 
| Mate Lakat | 93f3b86 | 2013-09-24 17:35:00 +0100 | [diff] [blame] | 432 | echo "When devstack completes, you can visit the OpenStack Dashboard" | 
| Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 433 | 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] | 434 | fi |