blob: f28ae979406dd62d49442a782987f88ac6233d96 [file] [log] [blame]
Anthony Youngb62b4ca2011-10-26 22:29:08 -07001#!/bin/bash
2
Mate Lakat0b3804b2013-05-07 16:58:17 +01003# This script must be run on a XenServer or XCP machine
John Garbuttdaadf742012-04-27 18:28:28 +01004#
5# It creates a DomU VM that runs OpenStack services
6#
7# For more details see: README.md
8
Renuka Apte0af143b2012-04-02 15:46:53 -07009set -o errexit
Mate Lakat0b3804b2013-05-07 16:58:17 +010010set -o nounset
John Garbuttdaadf742012-04-27 18:28:28 +010011set -o xtrace
Renuka Apte0af143b2012-04-02 15:46:53 -070012
Mate Lakat1ca490c2013-09-19 10:03:36 +010013export LC_ALL=C
14
Anthony Youngb62b4ca2011-10-26 22:29:08 -070015# Abort if localrc is not set
16if [ ! -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
20fi
21
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050022# This directory
Mate Lakata8bf0f22013-03-07 18:37:31 +000023THIS_DIR=$(cd $(dirname "$0") && pwd)
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050024
John Garbuttdaadf742012-04-27 18:28:28 +010025# Include onexit commands
Mate Lakata8bf0f22013-03-07 18:37:31 +000026. $THIS_DIR/scripts/on_exit.sh
John Garbuttdaadf742012-04-27 18:28:28 +010027
Mate Lakat57e3da92013-03-22 16:34:05 +000028# xapi functions
29. $THIS_DIR/functions
30
John Garbuttdaadf742012-04-27 18:28:28 +010031#
32# Get Settings
33#
34
Anthony Youngb3e2f332012-03-16 17:01:49 -070035# Source params - override xenrc params in your localrc to suit your taste
Mate Lakat0b3804b2013-05-07 16:58:17 +010036source $THIS_DIR/xenrc
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050037
Renuka Apte0af143b2012-04-02 15:46:53 -070038xe_min()
39{
Sean Dague0b865a52013-10-22 11:37:35 -040040 local cmd="$1"
41 shift
42 xe "$cmd" --minimal "$@"
Renuka Apte0af143b2012-04-02 15:46:53 -070043}
Anthony Youngb62b4ca2011-10-26 22:29:08 -070044
John Garbuttdaadf742012-04-27 18:28:28 +010045#
46# Prepare Dom0
47# including installing XenAPI plugins
48#
49
Mate Lakata8bf0f22013-03-07 18:37:31 +000050cd $THIS_DIR
John Garbuttdaadf742012-04-27 18:28:28 +010051
Mate Lakatd8511032013-07-03 10:44:44 +010052# Die if multiple hosts listed
53if have_multiple_hosts; then
54 cat >&2 << EOF
55ERROR: multiple hosts found. This might mean that the XenServer is a member
56of a pool - Exiting.
57EOF
58 exit 1
59fi
60
John Garbuttdaadf742012-04-27 18:28:28 +010061#
62# Configure Networking
63#
Bob Ball78ef1f32013-09-29 11:36:28 +010064
65MGT_NETWORK=`xe pif-list management=true params=network-uuid minimal=true`
66MGT_BRIDGE_OR_NET_NAME=`xe network-list uuid=$MGT_NETWORK params=bridge minimal=true`
67
Mate Lakat9e326772013-05-08 16:42:22 +010068setup_network "$VM_BRIDGE_OR_NET_NAME"
69setup_network "$MGT_BRIDGE_OR_NET_NAME"
70setup_network "$PUB_BRIDGE_OR_NET_NAME"
Anthony Youngb62b4ca2011-10-26 22:29:08 -070071
Mark McClainb05c8762013-07-06 23:29:39 -040072# With neutron, one more network is required, which is internal to the
Mate Lakatf652e0f2013-05-21 18:12:48 +010073# hypervisor, and used by the VMs
Mate Lakat6df64892014-10-17 13:09:49 +020074setup_network "$XEN_INT_BRIDGE_OR_NET_NAME"
Mate Lakatf652e0f2013-05-21 18:12:48 +010075
Mate Lakat9e326772013-05-08 16:42:22 +010076if parameter_is_specified "FLAT_NETWORK_BRIDGE"; then
Mate Lakat2b8814d2013-09-25 17:07:06 +010077 if [ "$(bridge_for "$VM_BRIDGE_OR_NET_NAME")" != "$(bridge_for "$FLAT_NETWORK_BRIDGE")" ]; then
78 cat >&2 << EOF
79ERROR: FLAT_NETWORK_BRIDGE is specified in localrc file, and either no network
80found on XenServer by searching for networks by that value as name-label or
81bridge name or the network found does not match the network specified by
82VM_BRIDGE_OR_NET_NAME. Please check your localrc file.
Mate Lakat9e326772013-05-08 16:42:22 +010083EOF
Mate Lakat2b8814d2013-09-25 17:07:06 +010084 exit 1
85 fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -070086fi
87
Mate Lakat9e326772013-05-08 16:42:22 +010088if ! xenapi_is_listening_on "$MGT_BRIDGE_OR_NET_NAME"; then
89 cat >&2 << EOF
90ERROR: XenAPI does not have an assigned IP address on the management network.
91please review your XenServer network configuration / localrc file.
92EOF
93 exit 1
94fi
95
96HOST_IP=$(xenapi_ip_on "$MGT_BRIDGE_OR_NET_NAME")
John Garbuttdaadf742012-04-27 18:28:28 +010097
98# Set up ip forwarding, but skip on xcp-xapi
John Garbuttd8f1a872012-06-26 11:16:38 +010099if [ -a /etc/sysconfig/network ]; then
John Garbuttdaadf742012-04-27 18:28:28 +0100100 if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
Sean Dague0b865a52013-10-22 11:37:35 -0400101 # FIXME: This doesn't work on reboot!
102 echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network
John Garbuttdaadf742012-04-27 18:28:28 +0100103 fi
104fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700105# Also, enable ip forwarding in rc.local, since the above trick isn't working
106if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then
107 echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
108fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700109# Enable ip forwarding at runtime as well
110echo 1 > /proc/sys/net/ipv4/ip_forward
111
John Garbuttdaadf742012-04-27 18:28:28 +0100112
113#
Anthony Young346e4912011-11-05 00:22:47 -0500114# Shutdown previous runs
John Garbuttdaadf742012-04-27 18:28:28 +0100115#
116
Anthony Young346e4912011-11-05 00:22:47 -0500117DO_SHUTDOWN=${DO_SHUTDOWN:-1}
John Garbuttdaadf742012-04-27 18:28:28 +0100118CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false}
Anthony Young346e4912011-11-05 00:22:47 -0500119if [ "$DO_SHUTDOWN" = "1" ]; then
Anthony Young40b57372011-11-05 00:30:07 -0500120 # Shutdown all domU's that created previously
John Garbuttdaadf742012-04-27 18:28:28 +0100121 clean_templates_arg=""
122 if $CLEAN_TEMPLATES; then
123 clean_templates_arg="--remove-templates"
124 fi
125 ./scripts/uninstall-os-vpx.sh $clean_templates_arg
Anthony Young346e4912011-11-05 00:22:47 -0500126
127 # Destroy any instances that were launched
128 for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
129 echo "Shutting down nova instance $uuid"
Mate Lakat0d97cbe2013-07-29 09:41:50 +0100130 xe vm-uninstall uuid=$uuid force=true
Anthony Young346e4912011-11-05 00:22:47 -0500131 done
Anthony Youngfa4ecc62011-11-11 10:23:22 -0800132
133 # Destroy orphaned vdis
134 for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do
135 xe vdi-destroy uuid=$uuid
136 done
Anthony Young346e4912011-11-05 00:22:47 -0500137fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700138
Renuka Apte0af143b2012-04-02 15:46:53 -0700139
John Garbuttdaadf742012-04-27 18:28:28 +0100140#
141# Create Ubuntu VM template
142# and/or create VM from template
143#
Renuka Apte0af143b2012-04-02 15:46:53 -0700144
John Garbuttdaadf742012-04-27 18:28:28 +0100145GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"}
Mate Lakatc02b2f82013-07-30 19:43:10 +0100146TNAME="jeos_template_for_devstack"
147SNAME_TEMPLATE="jeos_snapshot_for_devstack"
John Garbuttdaadf742012-04-27 18:28:28 +0100148SNAME_FIRST_BOOT="before_first_boot"
149
Ian Wienandaee18c72014-02-21 15:35:08 +1100150function wait_for_VM_to_halt {
Bob Ball63c6c2b2013-01-24 13:13:51 +0000151 set +x
152 echo "Waiting for the VM to halt. Progress in-VM can be checked with vncviewer:"
153 mgmt_ip=$(echo $XENAPI_CONNECTION_URL | tr -d -c '1234567890.')
Mate Lakatd15c8a02014-02-04 12:38:14 +0000154 domid=$(get_domid "$GUEST_NAME")
Bob Ball6a95b602014-09-17 12:39:50 +0100155 sleep 20 # Wait for the vnc-port to be written
Bob Ball63c6c2b2013-01-24 13:13:51 +0000156 port=$(xenstore-read /local/domain/$domid/console/vnc-port)
Mate Lakat97621a12013-08-30 13:12:17 +0100157 echo "vncviewer -via root@$mgmt_ip localhost:${port:2}"
Chmouel Boudjnah86a8e972014-02-04 15:20:15 +0100158 while true; do
Renuka Apte0af143b2012-04-02 15:46:53 -0700159 state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted)
Sean Dague16dd8b32014-02-03 09:10:54 +0900160 if [ -n "$state" ]; then
Renuka Apte0af143b2012-04-02 15:46:53 -0700161 break
162 else
Bob Ball63c6c2b2013-01-24 13:13:51 +0000163 echo -n "."
John Garbuttdaadf742012-04-27 18:28:28 +0100164 sleep 20
Renuka Apte0af143b2012-04-02 15:46:53 -0700165 fi
166 done
Bob Ball63c6c2b2013-01-24 13:13:51 +0000167 set -x
John Garbuttdaadf742012-04-27 18:28:28 +0100168}
Renuka Apte0af143b2012-04-02 15:46:53 -0700169
John Garbuttdaadf742012-04-27 18:28:28 +0100170templateuuid=$(xe template-list name-label="$TNAME")
171if [ -z "$templateuuid" ]; then
172 #
173 # Install Ubuntu over network
174 #
Bob Ball78ef1f32013-09-29 11:36:28 +0100175 UBUNTU_INST_BRIDGE_OR_NET_NAME=${UBUNTU_INST_BRIDGE_OR_NET_NAME:-"$MGT_BRIDGE_OR_NET_NAME"}
John Garbuttdaadf742012-04-27 18:28:28 +0100176
John Garbuttdaadf742012-04-27 18:28:28 +0100177 # always update the preseed file, incase we have a newer one
178 PRESEED_URL=${PRESEED_URL:-""}
179 if [ -z "$PRESEED_URL" ]; then
180 PRESEED_URL="${HOST_IP}/devstackubuntupreseed.cfg"
Bob Ball5b9adb62015-02-10 08:09:08 +0000181
John Garbuttdaadf742012-04-27 18:28:28 +0100182 HTTP_SERVER_LOCATION="/opt/xensource/www"
183 if [ ! -e $HTTP_SERVER_LOCATION ]; then
184 HTTP_SERVER_LOCATION="/var/www/html"
185 mkdir -p $HTTP_SERVER_LOCATION
186 fi
Bob Ball5b9adb62015-02-10 08:09:08 +0000187
188 # Copy the tools DEB to the XS web server
189 XS_TOOLS_URL="https://github.com/downloads/citrix-openstack/warehouse/xe-guest-utilities_5.6.100-651_amd64.deb"
190 ISO_DIR="/opt/xensource/packages/iso"
191 XS_TOOLS_FILE_NAME="xs-tools.deb"
192 XS_TOOLS_PATH="/root/$XS_TOOLS_FILE_NAME"
193 if [ -e "$ISO_DIR" ]; then
194 TOOLS_ISO=$(ls -1 $ISO_DIR/xs-tools-*.iso | head -1)
195 TMP_DIR=/tmp/temp.$RANDOM
196 mkdir -p $TMP_DIR
197 mount -o loop $TOOLS_ISO $TMP_DIR
198 DEB_FILE=$(ls $TMP_DIR/Linux/*amd64.deb)
199 cp $DEB_FILE $HTTP_SERVER_LOCATION
200 umount $TMP_DIR
201 rmdir $TMP_DIR
202 XS_TOOLS_URL=${HOST_IP}/$(basename $DEB_FILE)
203 fi
204
Mate Lakata8bf0f22013-03-07 18:37:31 +0000205 cp -f $THIS_DIR/devstackubuntupreseed.cfg $HTTP_SERVER_LOCATION
Bob Ball5b9adb62015-02-10 08:09:08 +0000206 cp -f $THIS_DIR/devstackubuntu_latecommand.sh $HTTP_SERVER_LOCATION/latecommand.sh
Mate Lakatd3740f72013-05-09 15:02:21 +0100207
208 sed \
209 -e "s,\(d-i mirror/http/hostname string\).*,\1 $UBUNTU_INST_HTTP_HOSTNAME,g" \
210 -e "s,\(d-i mirror/http/directory string\).*,\1 $UBUNTU_INST_HTTP_DIRECTORY,g" \
211 -e "s,\(d-i mirror/http/proxy string\).*,\1 $UBUNTU_INST_HTTP_PROXY,g" \
Bob Ball105eaee2014-07-14 15:21:07 +0100212 -e "s,\(d-i passwd/root-password password\).*,\1 $GUEST_PASSWORD,g" \
213 -e "s,\(d-i passwd/root-password-again password\).*,\1 $GUEST_PASSWORD,g" \
Bob Ball5b9adb62015-02-10 08:09:08 +0000214 -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 Lakatd3740f72013-05-09 15:02:21 +0100215 -i "${HTTP_SERVER_LOCATION}/devstackubuntupreseed.cfg"
Bob Ball5b9adb62015-02-10 08:09:08 +0000216
217 sed \
218 -e "s,@XS_TOOLS_URL@,$XS_TOOLS_URL,g" \
219 -i "${HTTP_SERVER_LOCATION}/latecommand.sh"
John Garbuttdaadf742012-04-27 18:28:28 +0100220 fi
221
John Garbuttd8f1a872012-06-26 11:16:38 +0100222 # Update the template
Mate Lakata8bf0f22013-03-07 18:37:31 +0000223 $THIS_DIR/scripts/install_ubuntu_template.sh $PRESEED_URL
John Garbuttdaadf742012-04-27 18:28:28 +0100224
Mate Lakat2f524bd2013-06-19 12:32:23 +0100225 # create a new VM from the given template with eth0 attached to the given
226 # network
Mate Lakat9e326772013-05-08 16:42:22 +0100227 $THIS_DIR/scripts/install-os-vpx.sh \
228 -t "$UBUNTU_INST_TEMPLATE_NAME" \
Mate Lakat2f524bd2013-06-19 12:32:23 +0100229 -n "$UBUNTU_INST_BRIDGE_OR_NET_NAME" \
Mate Lakat16ed0682013-08-30 13:28:31 +0100230 -l "$GUEST_NAME"
231
232 set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB"
233
234 xe vm-start vm="$GUEST_NAME"
John Garbuttdaadf742012-04-27 18:28:28 +0100235
236 # wait for install to finish
237 wait_for_VM_to_halt
238
239 # set VM to restart after a reboot
Renuka Apte0af143b2012-04-02 15:46:53 -0700240 vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME")
241 xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid"
242
243 # Make template from VM
Mate Lakatc02b2f82013-07-30 19:43:10 +0100244 snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_TEMPLATE")
John Garbuttdaadf742012-04-27 18:28:28 +0100245 xe snapshot-clone uuid=$snuuid new-name-label="$TNAME"
246else
247 #
248 # Template already installed, create VM from template
249 #
250 vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME")
Renuka Apte0af143b2012-04-02 15:46:53 -0700251fi
252
Mate Lakat2a324dd2014-10-15 17:40:41 +0200253if [ -n "${EXIT_AFTER_JEOS_INSTALLATION:-}" ]; then
254 echo "User requested to quit after JEOS instalation"
255 exit 0
256fi
257
Mate Lakatc02b2f82013-07-30 19:43:10 +0100258#
259# Prepare VM for DevStack
260#
Bob Ball0df75a72015-02-12 11:59:46 +0000261xe vm-param-set other-config:os-vpx=true uuid="$vm_uuid"
Mate Lakatc02b2f82013-07-30 19:43:10 +0100262
263# Install XenServer tools, and other such things
264$THIS_DIR/prepare_guest_template.sh "$GUEST_NAME"
265
Mate Lakat16ed0682013-08-30 13:28:31 +0100266# Set virtual machine parameters
267set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB"
268
Mate Lakat9f878cb2013-10-04 09:56:24 +0100269# Max out VCPU count for better performance
270max_vcpus "$GUEST_NAME"
271
Mate Lakat8787e0f2013-10-28 18:15:57 +0000272# Wipe out all network cards
273destroy_all_vifs_of "$GUEST_NAME"
274
275# Add only one interface to prepare the guest template
276add_interface "$GUEST_NAME" "$MGT_BRIDGE_OR_NET_NAME" "0"
277
Mate Lakatc02b2f82013-07-30 19:43:10 +0100278# start the VM to run the prepare steps
279xe vm-start vm="$GUEST_NAME"
280
281# Wait for prep script to finish and shutdown system
282wait_for_VM_to_halt
283
Mate Lakat5a56cd62013-06-17 13:54:43 +0100284## Setup network cards
285# Wipe out all
286destroy_all_vifs_of "$GUEST_NAME"
287# Tenant network
288add_interface "$GUEST_NAME" "$VM_BRIDGE_OR_NET_NAME" "$VM_DEV_NR"
289# Management network
290add_interface "$GUEST_NAME" "$MGT_BRIDGE_OR_NET_NAME" "$MGT_DEV_NR"
291# Public network
292add_interface "$GUEST_NAME" "$PUB_BRIDGE_OR_NET_NAME" "$PUB_DEV_NR"
John Garbuttdaadf742012-04-27 18:28:28 +0100293
294#
295# Inject DevStack inside VM disk
296#
Mate Lakata8bf0f22013-03-07 18:37:31 +0000297$THIS_DIR/build_xva.sh "$GUEST_NAME"
Renuka Apte0af143b2012-04-02 15:46:53 -0700298
Mate Lakatf652e0f2013-05-21 18:12:48 +0100299# Attach a network interface for the integration network (so that the bridge
Mark McClainb05c8762013-07-06 23:29:39 -0400300# is created by XenServer). This is required for Neutron. Also pass that as a
Mate Lakat8ff33ce2013-05-30 13:26:58 +0100301# kernel parameter for DomU
Mate Lakat6df64892014-10-17 13:09:49 +0200302attach_network "$XEN_INT_BRIDGE_OR_NET_NAME"
Mate Lakat8ff33ce2013-05-30 13:26:58 +0100303
Mate Lakat6df64892014-10-17 13:09:49 +0200304XEN_INTEGRATION_BRIDGE=$(bridge_for "$XEN_INT_BRIDGE_OR_NET_NAME")
305append_kernel_cmdline \
306 "$GUEST_NAME" \
307 "xen_integration_bridge=${XEN_INTEGRATION_BRIDGE}"
Mate Lakatf652e0f2013-05-21 18:12:48 +0100308
Mate Lakat2b8814d2013-09-25 17:07:06 +0100309FLAT_NETWORK_BRIDGE="${FLAT_NETWORK_BRIDGE:-$(bridge_for "$VM_BRIDGE_OR_NET_NAME")}"
Mate Lakat8ff33ce2013-05-30 13:26:58 +0100310append_kernel_cmdline "$GUEST_NAME" "flat_network_bridge=${FLAT_NETWORK_BRIDGE}"
311
Mate Lakat68ac03c2013-06-06 16:22:34 +0100312# Add a separate xvdb, if it was requested
313if [[ "0" != "$XEN_XVDB_SIZE_GB" ]]; then
314 vm=$(xe vm-list name-label="$GUEST_NAME" --minimal)
315
316 # Add a new disk
317 localsr=$(get_local_sr)
318 extra_vdi=$(xe vdi-create \
319 name-label=xvdb-added-by-devstack \
320 virtual-size="${XEN_XVDB_SIZE_GB}GiB" \
321 sr-uuid=$localsr type=user)
322 xe vbd-create vm-uuid=$vm vdi-uuid=$extra_vdi device=1
323fi
324
John Garbuttdaadf742012-04-27 18:28:28 +0100325# create a snapshot before the first boot
326# to allow a quick re-run with the same settings
327xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_FIRST_BOOT"
328
John Garbuttdaadf742012-04-27 18:28:28 +0100329#
330# Run DevStack VM
331#
Renuka Apte0af143b2012-04-02 15:46:53 -0700332xe vm-start vm="$GUEST_NAME"
Anthony Young3eb8f592011-10-26 23:11:52 -0700333
Ian Wienandaee18c72014-02-21 15:35:08 +1100334function ssh_no_check {
John Garbuttdaadf742012-04-27 18:28:28 +0100335 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"
336}
337
Mate Lakat86446762013-05-12 18:34:29 +0100338# Get hold of the Management IP of OpenStack VM
339OS_VM_MANAGEMENT_ADDRESS=$MGT_IP
340if [ $OS_VM_MANAGEMENT_ADDRESS == "dhcp" ]; then
Mate Lakat5a56cd62013-06-17 13:54:43 +0100341 OS_VM_MANAGEMENT_ADDRESS=$(find_ip_by_name $GUEST_NAME $MGT_DEV_NR)
Mate Lakat86446762013-05-12 18:34:29 +0100342fi
343
344# Get hold of the Service IP of OpenStack VM
Mate Lakat5a56cd62013-06-17 13:54:43 +0100345if [ $HOST_IP_IFACE == "eth${MGT_DEV_NR}" ]; then
Mate Lakat86446762013-05-12 18:34:29 +0100346 OS_VM_SERVICES_ADDRESS=$MGT_IP
John Garbuttdaadf742012-04-27 18:28:28 +0100347 if [ $MGT_IP == "dhcp" ]; then
Mate Lakat5a56cd62013-06-17 13:54:43 +0100348 OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME $MGT_DEV_NR)
John Garbuttdaadf742012-04-27 18:28:28 +0100349 fi
350else
Mate Lakat86446762013-05-12 18:34:29 +0100351 OS_VM_SERVICES_ADDRESS=$PUB_IP
John Garbuttdaadf742012-04-27 18:28:28 +0100352 if [ $PUB_IP == "dhcp" ]; then
Mate Lakat5a56cd62013-06-17 13:54:43 +0100353 OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME $PUB_DEV_NR)
John Garbuttdaadf742012-04-27 18:28:28 +0100354 fi
Renuka Aptec56885a2012-02-29 16:09:26 -0800355fi
356
Mate Lakatd15c8a02014-02-04 12:38:14 +0000357# Create an ssh-keypair, and set it up for dom0 user
358rm -f /root/dom0key /root/dom0key.pub
359ssh-keygen -f /root/dom0key -P "" -C "dom0"
360DOMID=$(get_domid "$GUEST_NAME")
361
362xenstore-write /local/domain/$DOMID/authorized_keys/$DOMZERO_USER "$(cat /root/dom0key.pub)"
363xenstore-chmod -u /local/domain/$DOMID/authorized_keys/$DOMZERO_USER r$DOMID
364
Ian Wienandaee18c72014-02-21 15:35:08 +1100365function run_on_appliance {
Mate Lakatd15c8a02014-02-04 12:38:14 +0000366 ssh \
367 -i /root/dom0key \
368 -o UserKnownHostsFile=/dev/null \
369 -o StrictHostKeyChecking=no \
370 -o BatchMode=yes \
371 "$DOMZERO_USER@$OS_VM_MANAGEMENT_ADDRESS" "$@"
372}
373
374# Wait until we can log in to the appliance
375while ! run_on_appliance true; do
376 sleep 1
377done
378
379# Remove authenticated_keys updater cronjob
380echo "" | run_on_appliance crontab -
381
382# Generate a passwordless ssh key for domzero user
383echo "ssh-keygen -f /home/$DOMZERO_USER/.ssh/id_rsa -C $DOMZERO_USER@appliance -N \"\" -q" | run_on_appliance
384
385# Authenticate that user to dom0
386run_on_appliance cat /home/$DOMZERO_USER/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
387
Anthony Young1de18c62011-11-01 14:19:18 -0500388# If we have copied our ssh credentials, use ssh to monitor while the installation runs
389WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
John Garbuttdaadf742012-04-27 18:28:28 +0100390COPYENV=${COPYENV:-1}
Anthony Young1de18c62011-11-01 14:19:18 -0500391if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
Bob Ball7fcc1572013-02-20 15:56:25 +0000392 set +x
Anthony Young1de18c62011-11-01 14:19:18 -0500393
Bob Ball0686dae2015-01-15 12:48:26 +0000394 echo "VM Launched - Waiting for run.sh"
395 while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e /opt/stack/run_sh.pid"; do
John Garbuttdaadf742012-04-27 18:28:28 +0100396 sleep 10
Anthony Young1de18c62011-11-01 14:19:18 -0500397 done
Bob Balld6b43a02014-07-14 15:18:33 +0100398 echo -n "devstack service is running, waiting for stack.sh to start logging..."
399
Bob Ball0686dae2015-01-15 12:48:26 +0000400 pid=`ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "cat /opt/stack/run_sh.pid"`
Bob Ball1e3a5d22015-01-16 13:06:58 +0000401 if [ -n "$SCREEN_LOGDIR" ]; then
402 while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e ${SCREEN_LOGDIR}/stack.log"; do
403 sleep 10
404 done
Bob Balldc7ebbb2014-06-24 13:59:49 +0100405
Bob Ball1e3a5d22015-01-16 13:06:58 +0000406 ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "tail --pid $pid -n +1 -f ${SCREEN_LOGDIR}/stack.log"
407 else
408 echo -n "SCREEN_LOGDIR not set; just waiting for process $pid to finish"
409 ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "wait $pid"
410 fi
411
412 set -x
Mate Lakat93f3b862013-09-24 17:35:00 +0100413 # Fail if devstack did not succeed
Bob Ball0686dae2015-01-15 12:48:26 +0000414 ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'test -e /opt/stack/runsh.succeeded'
Mate Lakat9efcf602012-12-19 10:23:06 +0000415
Bob Ball63c6c2b2013-01-24 13:13:51 +0000416 set +x
John Garbuttdaadf742012-04-27 18:28:28 +0100417 echo "################################################################################"
Anthony Young1de18c62011-11-01 14:19:18 -0500418 echo ""
John Garbuttdaadf742012-04-27 18:28:28 +0100419 echo "All Finished!"
420 echo "You can visit the OpenStack Dashboard"
Mate Lakat86446762013-05-12 18:34:29 +0100421 echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports."
Anthony Young1de18c62011-11-01 14:19:18 -0500422else
Bob Ball63c6c2b2013-01-24 13:13:51 +0000423 set +x
Anthony Young1de18c62011-11-01 14:19:18 -0500424 echo "################################################################################"
425 echo ""
426 echo "All Finished!"
427 echo "Now, you can monitor the progress of the stack.sh installation by "
Mate Lakat93f3b862013-09-24 17:35:00 +0100428 echo "looking at the console of your domU / checking the log files."
Anthony Young1de18c62011-11-01 14:19:18 -0500429 echo ""
Mate Lakat86446762013-05-12 18:34:29 +0100430 echo "ssh into your domU now: 'ssh stack@$OS_VM_MANAGEMENT_ADDRESS' using your password"
Mate Lakat93f3b862013-09-24 17:35:00 +0100431 echo "and then do: 'sudo service devstack status' to check if devstack is still running."
Bob Ball0686dae2015-01-15 12:48:26 +0000432 echo "Check that /opt/stack/runsh.succeeded exists"
Anthony Young1de18c62011-11-01 14:19:18 -0500433 echo ""
Mate Lakat93f3b862013-09-24 17:35:00 +0100434 echo "When devstack completes, you can visit the OpenStack Dashboard"
Mate Lakat86446762013-05-12 18:34:29 +0100435 echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports."
Anthony Young1de18c62011-11-01 14:19:18 -0500436fi