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 | 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 | |
Bob Ball | 4669122 | 2013-08-12 17:28:50 +0100 | [diff] [blame] | 34 | # Determine what system we are running on. |
| 35 | # Might not be XenServer if we're using xenserver-core |
| 36 | GetDistro |
| 37 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 38 | # |
| 39 | # Get Settings |
| 40 | # |
| 41 | |
Anthony Young | b3e2f33 | 2012-03-16 17:01:49 -0700 | [diff] [blame] | 42 | # Source params - override xenrc params in your localrc to suit your taste |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 43 | source $THIS_DIR/xenrc |
Anthony Young | af6ed6b | 2011-11-02 07:50:27 -0500 | [diff] [blame] | 44 | |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 45 | xe_min() |
| 46 | { |
| 47 | local cmd="$1" |
| 48 | shift |
| 49 | xe "$cmd" --minimal "$@" |
| 50 | } |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 51 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 52 | # |
| 53 | # Prepare Dom0 |
| 54 | # including installing XenAPI plugins |
| 55 | # |
| 56 | |
Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 57 | cd $THIS_DIR |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 58 | |
Mate Lakat | d851103 | 2013-07-03 10:44:44 +0100 | [diff] [blame] | 59 | # Die if multiple hosts listed |
| 60 | if have_multiple_hosts; then |
| 61 | cat >&2 << EOF |
| 62 | ERROR: multiple hosts found. This might mean that the XenServer is a member |
| 63 | of a pool - Exiting. |
| 64 | EOF |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 68 | # Install plugins |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 69 | |
Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 70 | ## Nova plugins |
| 71 | NOVA_ZIPBALL_URL=${NOVA_ZIPBALL_URL:-$(zip_snapshot_location $NOVA_REPO $NOVA_BRANCH)} |
Mate Lakat | abe56ee | 2013-07-24 11:06:27 +0100 | [diff] [blame] | 72 | EXTRACTED_NOVA=$(extract_remote_zipball "$NOVA_ZIPBALL_URL") |
| 73 | install_xapi_plugins_from "$EXTRACTED_NOVA" |
| 74 | |
| 75 | LOGROT_SCRIPT=$(find "$EXTRACTED_NOVA" -name "rotate_xen_guest_logs.sh" -print) |
| 76 | if [ -n "$LOGROT_SCRIPT" ]; then |
| 77 | mkdir -p "/var/log/xen/guest" |
| 78 | cp "$LOGROT_SCRIPT" /root/consolelogrotate |
| 79 | chmod +x /root/consolelogrotate |
| 80 | echo "* * * * * /root/consolelogrotate" | crontab |
| 81 | fi |
| 82 | |
| 83 | rm -rf "$EXTRACTED_NOVA" |
Maru Newby | 2298ca4 | 2012-10-25 23:46:42 +0000 | [diff] [blame] | 84 | |
Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 85 | ## Install the netwrap xapi plugin to support agent control of dom0 networking |
Maru Newby | 2298ca4 | 2012-10-25 23:46:42 +0000 | [diff] [blame] | 86 | if [[ "$ENABLED_SERVICES" =~ "q-agt" && "$Q_PLUGIN" = "openvswitch" ]]; then |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 87 | NEUTRON_ZIPBALL_URL=${NEUTRON_ZIPBALL_URL:-$(zip_snapshot_location $NEUTRON_REPO $NEUTRON_BRANCH)} |
Mate Lakat | abe56ee | 2013-07-24 11:06:27 +0100 | [diff] [blame] | 88 | EXTRACTED_NEUTRON=$(extract_remote_zipball "$NEUTRON_ZIPBALL_URL") |
| 89 | install_xapi_plugins_from "$EXTRACTED_NEUTRON" |
| 90 | rm -rf "$EXTRACTED_NEUTRON" |
Maru Newby | 2298ca4 | 2012-10-25 23:46:42 +0000 | [diff] [blame] | 91 | fi |
| 92 | |
Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 93 | create_directory_for_kernels |
Bob Ball | 39aeda2 | 2013-06-17 12:51:33 +0100 | [diff] [blame] | 94 | create_directory_for_images |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 95 | |
| 96 | # |
| 97 | # Configure Networking |
| 98 | # |
Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 99 | setup_network "$VM_BRIDGE_OR_NET_NAME" |
| 100 | setup_network "$MGT_BRIDGE_OR_NET_NAME" |
| 101 | setup_network "$PUB_BRIDGE_OR_NET_NAME" |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 102 | |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 103 | # With neutron, one more network is required, which is internal to the |
Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 104 | # hypervisor, and used by the VMs |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 105 | if is_service_enabled neutron; then |
Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 106 | setup_network "$XEN_INT_BRIDGE_OR_NET_NAME" |
| 107 | fi |
| 108 | |
Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 109 | if parameter_is_specified "FLAT_NETWORK_BRIDGE"; then |
| 110 | cat >&2 << EOF |
| 111 | ERROR: FLAT_NETWORK_BRIDGE is specified in localrc file |
| 112 | This is considered as an error, as its value will be derived from the |
| 113 | VM_BRIDGE_OR_NET_NAME variable's value. |
| 114 | EOF |
| 115 | exit 1 |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 116 | fi |
| 117 | |
Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 118 | if ! xenapi_is_listening_on "$MGT_BRIDGE_OR_NET_NAME"; then |
| 119 | cat >&2 << EOF |
| 120 | ERROR: XenAPI does not have an assigned IP address on the management network. |
| 121 | please review your XenServer network configuration / localrc file. |
| 122 | EOF |
| 123 | exit 1 |
| 124 | fi |
| 125 | |
| 126 | HOST_IP=$(xenapi_ip_on "$MGT_BRIDGE_OR_NET_NAME") |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 127 | |
| 128 | # Set up ip forwarding, but skip on xcp-xapi |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 129 | if [ -a /etc/sysconfig/network ]; then |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 130 | if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then |
| 131 | # FIXME: This doesn't work on reboot! |
| 132 | echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network |
| 133 | fi |
| 134 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 135 | # Also, enable ip forwarding in rc.local, since the above trick isn't working |
| 136 | if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then |
| 137 | echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local |
| 138 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 139 | # Enable ip forwarding at runtime as well |
| 140 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 141 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 142 | |
| 143 | # |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 144 | # Shutdown previous runs |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 145 | # |
| 146 | |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 147 | DO_SHUTDOWN=${DO_SHUTDOWN:-1} |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 148 | CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false} |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 149 | if [ "$DO_SHUTDOWN" = "1" ]; then |
Anthony Young | 40b5737 | 2011-11-05 00:30:07 -0500 | [diff] [blame] | 150 | # Shutdown all domU's that created previously |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 151 | clean_templates_arg="" |
| 152 | if $CLEAN_TEMPLATES; then |
| 153 | clean_templates_arg="--remove-templates" |
| 154 | fi |
| 155 | ./scripts/uninstall-os-vpx.sh $clean_templates_arg |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 156 | |
| 157 | # Destroy any instances that were launched |
| 158 | for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do |
| 159 | echo "Shutting down nova instance $uuid" |
Mate Lakat | 0d97cbe | 2013-07-29 09:41:50 +0100 | [diff] [blame] | 160 | xe vm-uninstall uuid=$uuid force=true |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 161 | done |
Anthony Young | fa4ecc6 | 2011-11-11 10:23:22 -0800 | [diff] [blame] | 162 | |
| 163 | # Destroy orphaned vdis |
| 164 | for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do |
| 165 | xe vdi-destroy uuid=$uuid |
| 166 | done |
Anthony Young | 346e491 | 2011-11-05 00:22:47 -0500 | [diff] [blame] | 167 | fi |
Anthony Young | b62b4ca | 2011-10-26 22:29:08 -0700 | [diff] [blame] | 168 | |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 169 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 170 | # |
| 171 | # Create Ubuntu VM template |
| 172 | # and/or create VM from template |
| 173 | # |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 174 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 175 | GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"} |
Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 176 | TNAME="jeos_template_for_devstack" |
| 177 | SNAME_TEMPLATE="jeos_snapshot_for_devstack" |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 178 | SNAME_FIRST_BOOT="before_first_boot" |
| 179 | |
| 180 | function wait_for_VM_to_halt() { |
Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 181 | set +x |
| 182 | echo "Waiting for the VM to halt. Progress in-VM can be checked with vncviewer:" |
| 183 | mgmt_ip=$(echo $XENAPI_CONNECTION_URL | tr -d -c '1234567890.') |
| 184 | domid=$(xe vm-list name-label="$GUEST_NAME" params=dom-id minimal=true) |
| 185 | port=$(xenstore-read /local/domain/$domid/console/vnc-port) |
Mate Lakat | 97621a1 | 2013-08-30 13:12:17 +0100 | [diff] [blame] | 186 | echo "vncviewer -via root@$mgmt_ip localhost:${port:2}" |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 187 | while true |
| 188 | do |
| 189 | state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted) |
| 190 | if [ -n "$state" ] |
| 191 | then |
| 192 | break |
| 193 | else |
Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 194 | echo -n "." |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 195 | sleep 20 |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 196 | fi |
| 197 | done |
Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 198 | set -x |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 199 | } |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 200 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 201 | templateuuid=$(xe template-list name-label="$TNAME") |
| 202 | if [ -z "$templateuuid" ]; then |
| 203 | # |
| 204 | # Install Ubuntu over network |
| 205 | # |
| 206 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 207 | # always update the preseed file, incase we have a newer one |
| 208 | PRESEED_URL=${PRESEED_URL:-""} |
| 209 | if [ -z "$PRESEED_URL" ]; then |
| 210 | PRESEED_URL="${HOST_IP}/devstackubuntupreseed.cfg" |
| 211 | HTTP_SERVER_LOCATION="/opt/xensource/www" |
| 212 | if [ ! -e $HTTP_SERVER_LOCATION ]; then |
| 213 | HTTP_SERVER_LOCATION="/var/www/html" |
| 214 | mkdir -p $HTTP_SERVER_LOCATION |
| 215 | fi |
Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 216 | cp -f $THIS_DIR/devstackubuntupreseed.cfg $HTTP_SERVER_LOCATION |
Mate Lakat | d3740f7 | 2013-05-09 15:02:21 +0100 | [diff] [blame] | 217 | |
| 218 | sed \ |
| 219 | -e "s,\(d-i mirror/http/hostname string\).*,\1 $UBUNTU_INST_HTTP_HOSTNAME,g" \ |
| 220 | -e "s,\(d-i mirror/http/directory string\).*,\1 $UBUNTU_INST_HTTP_DIRECTORY,g" \ |
| 221 | -e "s,\(d-i mirror/http/proxy string\).*,\1 $UBUNTU_INST_HTTP_PROXY,g" \ |
| 222 | -i "${HTTP_SERVER_LOCATION}/devstackubuntupreseed.cfg" |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 223 | fi |
| 224 | |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 225 | # Update the template |
Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 226 | $THIS_DIR/scripts/install_ubuntu_template.sh $PRESEED_URL |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 227 | |
Mate Lakat | 2f524bd | 2013-06-19 12:32:23 +0100 | [diff] [blame] | 228 | # create a new VM from the given template with eth0 attached to the given |
| 229 | # network |
Mate Lakat | 9e32677 | 2013-05-08 16:42:22 +0100 | [diff] [blame] | 230 | $THIS_DIR/scripts/install-os-vpx.sh \ |
| 231 | -t "$UBUNTU_INST_TEMPLATE_NAME" \ |
Mate Lakat | 2f524bd | 2013-06-19 12:32:23 +0100 | [diff] [blame] | 232 | -n "$UBUNTU_INST_BRIDGE_OR_NET_NAME" \ |
Mate Lakat | 16ed068 | 2013-08-30 13:28:31 +0100 | [diff] [blame] | 233 | -l "$GUEST_NAME" |
| 234 | |
| 235 | set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB" |
| 236 | |
| 237 | xe vm-start vm="$GUEST_NAME" |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 238 | |
| 239 | # wait for install to finish |
| 240 | wait_for_VM_to_halt |
| 241 | |
| 242 | # set VM to restart after a reboot |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 243 | vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME") |
| 244 | xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid" |
| 245 | |
| 246 | # Make template from VM |
Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 247 | snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_TEMPLATE") |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 248 | xe snapshot-clone uuid=$snuuid new-name-label="$TNAME" |
| 249 | else |
| 250 | # |
| 251 | # Template already installed, create VM from template |
| 252 | # |
| 253 | vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME") |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 254 | fi |
| 255 | |
Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 256 | # |
| 257 | # Prepare VM for DevStack |
| 258 | # |
| 259 | |
| 260 | # Install XenServer tools, and other such things |
| 261 | $THIS_DIR/prepare_guest_template.sh "$GUEST_NAME" |
| 262 | |
Mate Lakat | 16ed068 | 2013-08-30 13:28:31 +0100 | [diff] [blame] | 263 | # Set virtual machine parameters |
| 264 | set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB" |
| 265 | |
Mate Lakat | c02b2f8 | 2013-07-30 19:43:10 +0100 | [diff] [blame] | 266 | # start the VM to run the prepare steps |
| 267 | xe vm-start vm="$GUEST_NAME" |
| 268 | |
| 269 | # Wait for prep script to finish and shutdown system |
| 270 | wait_for_VM_to_halt |
| 271 | |
Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 272 | ## Setup network cards |
| 273 | # Wipe out all |
| 274 | destroy_all_vifs_of "$GUEST_NAME" |
| 275 | # Tenant network |
| 276 | add_interface "$GUEST_NAME" "$VM_BRIDGE_OR_NET_NAME" "$VM_DEV_NR" |
| 277 | # Management network |
| 278 | add_interface "$GUEST_NAME" "$MGT_BRIDGE_OR_NET_NAME" "$MGT_DEV_NR" |
| 279 | # Public network |
| 280 | add_interface "$GUEST_NAME" "$PUB_BRIDGE_OR_NET_NAME" "$PUB_DEV_NR" |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 281 | |
| 282 | # |
| 283 | # Inject DevStack inside VM disk |
| 284 | # |
Mate Lakat | a8bf0f2 | 2013-03-07 18:37:31 +0000 | [diff] [blame] | 285 | $THIS_DIR/build_xva.sh "$GUEST_NAME" |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 286 | |
Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 287 | # Attach a network interface for the integration network (so that the bridge |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 288 | # 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] | 289 | # kernel parameter for DomU |
Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 290 | if is_service_enabled neutron; then |
Mate Lakat | d851103 | 2013-07-03 10:44:44 +0100 | [diff] [blame] | 291 | attach_network "$XEN_INT_BRIDGE_OR_NET_NAME" |
Mate Lakat | 8ff33ce | 2013-05-30 13:26:58 +0100 | [diff] [blame] | 292 | |
| 293 | XEN_INTEGRATION_BRIDGE=$(bridge_for "$XEN_INT_BRIDGE_OR_NET_NAME") |
| 294 | append_kernel_cmdline \ |
| 295 | "$GUEST_NAME" \ |
| 296 | "xen_integration_bridge=${XEN_INTEGRATION_BRIDGE}" |
Mate Lakat | f652e0f | 2013-05-21 18:12:48 +0100 | [diff] [blame] | 297 | fi |
| 298 | |
Mate Lakat | 8ff33ce | 2013-05-30 13:26:58 +0100 | [diff] [blame] | 299 | FLAT_NETWORK_BRIDGE=$(bridge_for "$VM_BRIDGE_OR_NET_NAME") |
| 300 | append_kernel_cmdline "$GUEST_NAME" "flat_network_bridge=${FLAT_NETWORK_BRIDGE}" |
| 301 | |
Mate Lakat | 68ac03c | 2013-06-06 16:22:34 +0100 | [diff] [blame] | 302 | # Add a separate xvdb, if it was requested |
| 303 | if [[ "0" != "$XEN_XVDB_SIZE_GB" ]]; then |
| 304 | vm=$(xe vm-list name-label="$GUEST_NAME" --minimal) |
| 305 | |
| 306 | # Add a new disk |
| 307 | localsr=$(get_local_sr) |
| 308 | extra_vdi=$(xe vdi-create \ |
| 309 | name-label=xvdb-added-by-devstack \ |
| 310 | virtual-size="${XEN_XVDB_SIZE_GB}GiB" \ |
| 311 | sr-uuid=$localsr type=user) |
| 312 | xe vbd-create vm-uuid=$vm vdi-uuid=$extra_vdi device=1 |
| 313 | fi |
| 314 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 315 | # create a snapshot before the first boot |
| 316 | # to allow a quick re-run with the same settings |
| 317 | xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_FIRST_BOOT" |
| 318 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 319 | # |
| 320 | # Run DevStack VM |
| 321 | # |
Renuka Apte | 0af143b | 2012-04-02 15:46:53 -0700 | [diff] [blame] | 322 | xe vm-start vm="$GUEST_NAME" |
Anthony Young | 3eb8f59 | 2011-10-26 23:11:52 -0700 | [diff] [blame] | 323 | |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 324 | function ssh_no_check() { |
| 325 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@" |
| 326 | } |
| 327 | |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 328 | # Get hold of the Management IP of OpenStack VM |
| 329 | OS_VM_MANAGEMENT_ADDRESS=$MGT_IP |
| 330 | if [ $OS_VM_MANAGEMENT_ADDRESS == "dhcp" ]; then |
Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 331 | 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] | 332 | fi |
| 333 | |
| 334 | # Get hold of the Service IP of OpenStack VM |
Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 335 | if [ $HOST_IP_IFACE == "eth${MGT_DEV_NR}" ]; then |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 336 | OS_VM_SERVICES_ADDRESS=$MGT_IP |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 337 | if [ $MGT_IP == "dhcp" ]; then |
Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 338 | 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] | 339 | fi |
| 340 | else |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 341 | OS_VM_SERVICES_ADDRESS=$PUB_IP |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 342 | if [ $PUB_IP == "dhcp" ]; then |
Mate Lakat | 5a56cd6 | 2013-06-17 13:54:43 +0100 | [diff] [blame] | 343 | 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] | 344 | fi |
Renuka Apte | c56885a | 2012-02-29 16:09:26 -0800 | [diff] [blame] | 345 | fi |
| 346 | |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 347 | # If we have copied our ssh credentials, use ssh to monitor while the installation runs |
| 348 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 349 | COPYENV=${COPYENV:-1} |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 350 | 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] | 351 | set +x |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 352 | |
Bob Ball | 7fcc157 | 2013-02-20 15:56:25 +0000 | [diff] [blame] | 353 | echo "VM Launched - Waiting for startup script" |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 354 | # wait for log to appear |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 355 | 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] | 356 | sleep 10 |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 357 | done |
Bob Ball | 7fcc157 | 2013-02-20 15:56:25 +0000 | [diff] [blame] | 358 | echo -n "Running" |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 359 | 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] | 360 | do |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 361 | sleep 10 |
Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 362 | echo -n "." |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 363 | done |
Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 364 | echo "done!" |
| 365 | set -x |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 366 | |
Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 367 | # output the run.sh.log |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 368 | 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] | 369 | |
Mate Lakat | 9efcf60 | 2012-12-19 10:23:06 +0000 | [diff] [blame] | 370 | # Fail if the expected text is not found |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 371 | 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] | 372 | |
Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 373 | set +x |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 374 | echo "################################################################################" |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 375 | echo "" |
John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 376 | echo "All Finished!" |
| 377 | echo "You can visit the OpenStack Dashboard" |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 378 | 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] | 379 | else |
Bob Ball | 63c6c2b | 2013-01-24 13:13:51 +0000 | [diff] [blame] | 380 | set +x |
Anthony Young | 1de18c6 | 2011-11-01 14:19:18 -0500 | [diff] [blame] | 381 | echo "################################################################################" |
| 382 | echo "" |
| 383 | echo "All Finished!" |
| 384 | echo "Now, you can monitor the progress of the stack.sh installation by " |
| 385 | echo "tailing /opt/stack/run.sh.log from within your domU." |
| 386 | echo "" |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 387 | 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] | 388 | echo "and then do: 'tail -f /opt/stack/run.sh.log'" |
| 389 | echo "" |
| 390 | echo "When the script completes, you can then visit the OpenStack Dashboard" |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame] | 391 | 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] | 392 | fi |