blob: f4ca71a90687289dd6aee22629dd0fcad5b10971 [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 Youngaf6ed6b2011-11-02 07:50:27 -050015# This directory
Mate Lakata8bf0f22013-03-07 18:37:31 +000016THIS_DIR=$(cd $(dirname "$0") && pwd)
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050017
John Garbuttdaadf742012-04-27 18:28:28 +010018# Include onexit commands
Mate Lakata8bf0f22013-03-07 18:37:31 +000019. $THIS_DIR/scripts/on_exit.sh
John Garbuttdaadf742012-04-27 18:28:28 +010020
Mate Lakat57e3da92013-03-22 16:34:05 +000021# xapi functions
22. $THIS_DIR/functions
23
John Garbuttdaadf742012-04-27 18:28:28 +010024#
25# Get Settings
26#
Huan Xiecc6af3f2015-12-23 02:17:01 +000027TOP_DIR=$(cd $THIS_DIR/../../ && pwd)
28source $TOP_DIR/inc/meta-config
29rm -f $TOP_DIR/.localrc.auto
30extract_localrc_section $TOP_DIR/local.conf $TOP_DIR/localrc $TOP_DIR/.localrc.auto
John Garbuttdaadf742012-04-27 18:28:28 +010031
Anthony Youngb3e2f332012-03-16 17:01:49 -070032# Source params - override xenrc params in your localrc to suit your taste
Mate Lakat0b3804b2013-05-07 16:58:17 +010033source $THIS_DIR/xenrc
Anthony Youngaf6ed6b2011-11-02 07:50:27 -050034
Renuka Apte0af143b2012-04-02 15:46:53 -070035xe_min()
36{
Sean Dague0b865a52013-10-22 11:37:35 -040037 local cmd="$1"
38 shift
39 xe "$cmd" --minimal "$@"
Renuka Apte0af143b2012-04-02 15:46:53 -070040}
Anthony Youngb62b4ca2011-10-26 22:29:08 -070041
John Garbuttdaadf742012-04-27 18:28:28 +010042#
43# Prepare Dom0
44# including installing XenAPI plugins
45#
46
Mate Lakata8bf0f22013-03-07 18:37:31 +000047cd $THIS_DIR
John Garbuttdaadf742012-04-27 18:28:28 +010048
Mate Lakatd8511032013-07-03 10:44:44 +010049# Die if multiple hosts listed
50if have_multiple_hosts; then
51 cat >&2 << EOF
52ERROR: multiple hosts found. This might mean that the XenServer is a member
53of a pool - Exiting.
54EOF
55 exit 1
56fi
57
John Garbuttdaadf742012-04-27 18:28:28 +010058#
59# Configure Networking
60#
Bob Ball78ef1f32013-09-29 11:36:28 +010061
62MGT_NETWORK=`xe pif-list management=true params=network-uuid minimal=true`
63MGT_BRIDGE_OR_NET_NAME=`xe network-list uuid=$MGT_NETWORK params=bridge minimal=true`
64
Mate Lakat9e326772013-05-08 16:42:22 +010065setup_network "$VM_BRIDGE_OR_NET_NAME"
66setup_network "$MGT_BRIDGE_OR_NET_NAME"
67setup_network "$PUB_BRIDGE_OR_NET_NAME"
Anthony Youngb62b4ca2011-10-26 22:29:08 -070068
Mate Lakat9e326772013-05-08 16:42:22 +010069if parameter_is_specified "FLAT_NETWORK_BRIDGE"; then
Mate Lakat2b8814d2013-09-25 17:07:06 +010070 if [ "$(bridge_for "$VM_BRIDGE_OR_NET_NAME")" != "$(bridge_for "$FLAT_NETWORK_BRIDGE")" ]; then
71 cat >&2 << EOF
72ERROR: FLAT_NETWORK_BRIDGE is specified in localrc file, and either no network
73found on XenServer by searching for networks by that value as name-label or
74bridge name or the network found does not match the network specified by
75VM_BRIDGE_OR_NET_NAME. Please check your localrc file.
Mate Lakat9e326772013-05-08 16:42:22 +010076EOF
Mate Lakat2b8814d2013-09-25 17:07:06 +010077 exit 1
78 fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -070079fi
80
Mate Lakat9e326772013-05-08 16:42:22 +010081if ! xenapi_is_listening_on "$MGT_BRIDGE_OR_NET_NAME"; then
82 cat >&2 << EOF
83ERROR: XenAPI does not have an assigned IP address on the management network.
84please review your XenServer network configuration / localrc file.
85EOF
86 exit 1
87fi
88
89HOST_IP=$(xenapi_ip_on "$MGT_BRIDGE_OR_NET_NAME")
John Garbuttdaadf742012-04-27 18:28:28 +010090
91# Set up ip forwarding, but skip on xcp-xapi
John Garbuttd8f1a872012-06-26 11:16:38 +010092if [ -a /etc/sysconfig/network ]; then
John Garbuttdaadf742012-04-27 18:28:28 +010093 if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
Sean Dague0b865a52013-10-22 11:37:35 -040094 # FIXME: This doesn't work on reboot!
95 echo "FORWARD_IPV4=YES" >> /etc/sysconfig/network
John Garbuttdaadf742012-04-27 18:28:28 +010096 fi
97fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -070098# Also, enable ip forwarding in rc.local, since the above trick isn't working
99if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then
100 echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
101fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700102# Enable ip forwarding at runtime as well
103echo 1 > /proc/sys/net/ipv4/ip_forward
104
John Garbuttdaadf742012-04-27 18:28:28 +0100105
106#
Anthony Young346e4912011-11-05 00:22:47 -0500107# Shutdown previous runs
John Garbuttdaadf742012-04-27 18:28:28 +0100108#
109
Anthony Young346e4912011-11-05 00:22:47 -0500110DO_SHUTDOWN=${DO_SHUTDOWN:-1}
John Garbuttdaadf742012-04-27 18:28:28 +0100111CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false}
Anthony Young346e4912011-11-05 00:22:47 -0500112if [ "$DO_SHUTDOWN" = "1" ]; then
Anthony Young40b57372011-11-05 00:30:07 -0500113 # Shutdown all domU's that created previously
John Garbuttdaadf742012-04-27 18:28:28 +0100114 clean_templates_arg=""
115 if $CLEAN_TEMPLATES; then
116 clean_templates_arg="--remove-templates"
117 fi
118 ./scripts/uninstall-os-vpx.sh $clean_templates_arg
Anthony Young346e4912011-11-05 00:22:47 -0500119
120 # Destroy any instances that were launched
121 for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
122 echo "Shutting down nova instance $uuid"
Mate Lakat0d97cbe2013-07-29 09:41:50 +0100123 xe vm-uninstall uuid=$uuid force=true
Anthony Young346e4912011-11-05 00:22:47 -0500124 done
Anthony Youngfa4ecc62011-11-11 10:23:22 -0800125
126 # Destroy orphaned vdis
127 for uuid in `xe vdi-list | grep -1 Glance | grep uuid | sed "s/.*\: //g"`; do
128 xe vdi-destroy uuid=$uuid
129 done
Anthony Young346e4912011-11-05 00:22:47 -0500130fi
Anthony Youngb62b4ca2011-10-26 22:29:08 -0700131
Renuka Apte0af143b2012-04-02 15:46:53 -0700132
John Garbuttdaadf742012-04-27 18:28:28 +0100133#
134# Create Ubuntu VM template
135# and/or create VM from template
136#
Renuka Apte0af143b2012-04-02 15:46:53 -0700137
John Garbuttdaadf742012-04-27 18:28:28 +0100138GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"}
Mate Lakatc02b2f82013-07-30 19:43:10 +0100139TNAME="jeos_template_for_devstack"
140SNAME_TEMPLATE="jeos_snapshot_for_devstack"
John Garbuttdaadf742012-04-27 18:28:28 +0100141SNAME_FIRST_BOOT="before_first_boot"
142
Ian Wienandaee18c72014-02-21 15:35:08 +1100143function wait_for_VM_to_halt {
Bob Ball63c6c2b2013-01-24 13:13:51 +0000144 set +x
Bob Balle356d8c2015-02-17 15:05:34 +0000145 echo "Waiting for the VM to halt. Progress in-VM can be checked with XenCenter or xl console:"
Bob Ball63c6c2b2013-01-24 13:13:51 +0000146 mgmt_ip=$(echo $XENAPI_CONNECTION_URL | tr -d -c '1234567890.')
Mate Lakatd15c8a02014-02-04 12:38:14 +0000147 domid=$(get_domid "$GUEST_NAME")
Bob Balle356d8c2015-02-17 15:05:34 +0000148 echo "ssh root@$mgmt_ip \"xl console $domid\""
Chmouel Boudjnah86a8e972014-02-04 15:20:15 +0100149 while true; do
Renuka Apte0af143b2012-04-02 15:46:53 -0700150 state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted)
Sean Dague16dd8b32014-02-03 09:10:54 +0900151 if [ -n "$state" ]; then
Renuka Apte0af143b2012-04-02 15:46:53 -0700152 break
153 else
Bob Ball63c6c2b2013-01-24 13:13:51 +0000154 echo -n "."
John Garbuttdaadf742012-04-27 18:28:28 +0100155 sleep 20
Renuka Apte0af143b2012-04-02 15:46:53 -0700156 fi
157 done
Bob Ball63c6c2b2013-01-24 13:13:51 +0000158 set -x
John Garbuttdaadf742012-04-27 18:28:28 +0100159}
Renuka Apte0af143b2012-04-02 15:46:53 -0700160
John Garbuttdaadf742012-04-27 18:28:28 +0100161templateuuid=$(xe template-list name-label="$TNAME")
162if [ -z "$templateuuid" ]; then
163 #
164 # Install Ubuntu over network
165 #
Bob Ball78ef1f32013-09-29 11:36:28 +0100166 UBUNTU_INST_BRIDGE_OR_NET_NAME=${UBUNTU_INST_BRIDGE_OR_NET_NAME:-"$MGT_BRIDGE_OR_NET_NAME"}
John Garbuttdaadf742012-04-27 18:28:28 +0100167
John Garbuttdaadf742012-04-27 18:28:28 +0100168 # always update the preseed file, incase we have a newer one
169 PRESEED_URL=${PRESEED_URL:-""}
170 if [ -z "$PRESEED_URL" ]; then
171 PRESEED_URL="${HOST_IP}/devstackubuntupreseed.cfg"
Bob Ball5b9adb62015-02-10 08:09:08 +0000172
John Garbuttdaadf742012-04-27 18:28:28 +0100173 HTTP_SERVER_LOCATION="/opt/xensource/www"
174 if [ ! -e $HTTP_SERVER_LOCATION ]; then
175 HTTP_SERVER_LOCATION="/var/www/html"
176 mkdir -p $HTTP_SERVER_LOCATION
177 fi
Bob Ball5b9adb62015-02-10 08:09:08 +0000178
179 # Copy the tools DEB to the XS web server
180 XS_TOOLS_URL="https://github.com/downloads/citrix-openstack/warehouse/xe-guest-utilities_5.6.100-651_amd64.deb"
181 ISO_DIR="/opt/xensource/packages/iso"
Bob Ball5b9adb62015-02-10 08:09:08 +0000182 if [ -e "$ISO_DIR" ]; then
Huan Xief179eb72016-06-02 01:24:22 -0700183 TOOLS_ISO=$(ls -1 $ISO_DIR/*-tools-*.iso | head -1)
Bob Ball5b9adb62015-02-10 08:09:08 +0000184 TMP_DIR=/tmp/temp.$RANDOM
185 mkdir -p $TMP_DIR
186 mount -o loop $TOOLS_ISO $TMP_DIR
jianghua wang78f6c1d2015-09-18 11:17:46 +0100187 # the target deb package maybe *amd64.deb or *all.deb,
188 # so use *amd64.deb by default. If it doesn't exist,
189 # then use *all.deb.
190 DEB_FILE=$(ls $TMP_DIR/Linux/*amd64.deb || ls $TMP_DIR/Linux/*all.deb)
Bob Ball5b9adb62015-02-10 08:09:08 +0000191 cp $DEB_FILE $HTTP_SERVER_LOCATION
192 umount $TMP_DIR
193 rmdir $TMP_DIR
194 XS_TOOLS_URL=${HOST_IP}/$(basename $DEB_FILE)
195 fi
196
Mate Lakata8bf0f22013-03-07 18:37:31 +0000197 cp -f $THIS_DIR/devstackubuntupreseed.cfg $HTTP_SERVER_LOCATION
Bob Ball5b9adb62015-02-10 08:09:08 +0000198 cp -f $THIS_DIR/devstackubuntu_latecommand.sh $HTTP_SERVER_LOCATION/latecommand.sh
Mate Lakatd3740f72013-05-09 15:02:21 +0100199
200 sed \
201 -e "s,\(d-i mirror/http/hostname string\).*,\1 $UBUNTU_INST_HTTP_HOSTNAME,g" \
202 -e "s,\(d-i mirror/http/directory string\).*,\1 $UBUNTU_INST_HTTP_DIRECTORY,g" \
203 -e "s,\(d-i mirror/http/proxy string\).*,\1 $UBUNTU_INST_HTTP_PROXY,g" \
Bob Ball105eaee2014-07-14 15:21:07 +0100204 -e "s,\(d-i passwd/root-password password\).*,\1 $GUEST_PASSWORD,g" \
205 -e "s,\(d-i passwd/root-password-again password\).*,\1 $GUEST_PASSWORD,g" \
Bob Ball5b9adb62015-02-10 08:09:08 +0000206 -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 +0100207 -i "${HTTP_SERVER_LOCATION}/devstackubuntupreseed.cfg"
Bob Ball5b9adb62015-02-10 08:09:08 +0000208
209 sed \
210 -e "s,@XS_TOOLS_URL@,$XS_TOOLS_URL,g" \
211 -i "${HTTP_SERVER_LOCATION}/latecommand.sh"
John Garbuttdaadf742012-04-27 18:28:28 +0100212 fi
213
John Garbuttd8f1a872012-06-26 11:16:38 +0100214 # Update the template
Mate Lakata8bf0f22013-03-07 18:37:31 +0000215 $THIS_DIR/scripts/install_ubuntu_template.sh $PRESEED_URL
John Garbuttdaadf742012-04-27 18:28:28 +0100216
Mate Lakat2f524bd2013-06-19 12:32:23 +0100217 # create a new VM from the given template with eth0 attached to the given
218 # network
Mate Lakat9e326772013-05-08 16:42:22 +0100219 $THIS_DIR/scripts/install-os-vpx.sh \
220 -t "$UBUNTU_INST_TEMPLATE_NAME" \
Mate Lakat2f524bd2013-06-19 12:32:23 +0100221 -n "$UBUNTU_INST_BRIDGE_OR_NET_NAME" \
Mate Lakat16ed0682013-08-30 13:28:31 +0100222 -l "$GUEST_NAME"
223
Bob Ball1340ee72015-03-06 21:11:55 +0000224 set_vm_memory "$GUEST_NAME" "1024"
Mate Lakat16ed0682013-08-30 13:28:31 +0100225
226 xe vm-start vm="$GUEST_NAME"
John Garbuttdaadf742012-04-27 18:28:28 +0100227
228 # wait for install to finish
229 wait_for_VM_to_halt
230
231 # set VM to restart after a reboot
Renuka Apte0af143b2012-04-02 15:46:53 -0700232 vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME")
233 xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid"
234
235 # Make template from VM
Mate Lakatc02b2f82013-07-30 19:43:10 +0100236 snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_TEMPLATE")
John Garbuttdaadf742012-04-27 18:28:28 +0100237 xe snapshot-clone uuid=$snuuid new-name-label="$TNAME"
238else
239 #
240 # Template already installed, create VM from template
241 #
242 vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME")
Renuka Apte0af143b2012-04-02 15:46:53 -0700243fi
244
Mate Lakat2a324dd2014-10-15 17:40:41 +0200245if [ -n "${EXIT_AFTER_JEOS_INSTALLATION:-}" ]; then
zhangyanxianc6f857f2016-07-25 08:44:28 +0000246 echo "User requested to quit after JEOS installation"
Mate Lakat2a324dd2014-10-15 17:40:41 +0200247 exit 0
248fi
249
Mate Lakatc02b2f82013-07-30 19:43:10 +0100250#
251# Prepare VM for DevStack
252#
Bob Ball0df75a72015-02-12 11:59:46 +0000253xe vm-param-set other-config:os-vpx=true uuid="$vm_uuid"
Mate Lakatc02b2f82013-07-30 19:43:10 +0100254
255# Install XenServer tools, and other such things
256$THIS_DIR/prepare_guest_template.sh "$GUEST_NAME"
257
Mate Lakat16ed0682013-08-30 13:28:31 +0100258# Set virtual machine parameters
259set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB"
260
Mate Lakat9f878cb2013-10-04 09:56:24 +0100261# Max out VCPU count for better performance
262max_vcpus "$GUEST_NAME"
263
Mate Lakat8787e0f2013-10-28 18:15:57 +0000264# Wipe out all network cards
265destroy_all_vifs_of "$GUEST_NAME"
266
267# Add only one interface to prepare the guest template
268add_interface "$GUEST_NAME" "$MGT_BRIDGE_OR_NET_NAME" "0"
269
Mate Lakatc02b2f82013-07-30 19:43:10 +0100270# start the VM to run the prepare steps
271xe vm-start vm="$GUEST_NAME"
272
273# Wait for prep script to finish and shutdown system
274wait_for_VM_to_halt
275
Mate Lakat5a56cd62013-06-17 13:54:43 +0100276## Setup network cards
277# Wipe out all
278destroy_all_vifs_of "$GUEST_NAME"
279# Tenant network
280add_interface "$GUEST_NAME" "$VM_BRIDGE_OR_NET_NAME" "$VM_DEV_NR"
281# Management network
282add_interface "$GUEST_NAME" "$MGT_BRIDGE_OR_NET_NAME" "$MGT_DEV_NR"
283# Public network
284add_interface "$GUEST_NAME" "$PUB_BRIDGE_OR_NET_NAME" "$PUB_DEV_NR"
John Garbuttdaadf742012-04-27 18:28:28 +0100285
286#
287# Inject DevStack inside VM disk
288#
Mate Lakata8bf0f22013-03-07 18:37:31 +0000289$THIS_DIR/build_xva.sh "$GUEST_NAME"
Renuka Apte0af143b2012-04-02 15:46:53 -0700290
Mate Lakat2b8814d2013-09-25 17:07:06 +0100291FLAT_NETWORK_BRIDGE="${FLAT_NETWORK_BRIDGE:-$(bridge_for "$VM_BRIDGE_OR_NET_NAME")}"
Mate Lakat8ff33ce2013-05-30 13:26:58 +0100292append_kernel_cmdline "$GUEST_NAME" "flat_network_bridge=${FLAT_NETWORK_BRIDGE}"
293
Mate Lakat68ac03c2013-06-06 16:22:34 +0100294# Add a separate xvdb, if it was requested
295if [[ "0" != "$XEN_XVDB_SIZE_GB" ]]; then
296 vm=$(xe vm-list name-label="$GUEST_NAME" --minimal)
297
298 # Add a new disk
299 localsr=$(get_local_sr)
300 extra_vdi=$(xe vdi-create \
301 name-label=xvdb-added-by-devstack \
302 virtual-size="${XEN_XVDB_SIZE_GB}GiB" \
303 sr-uuid=$localsr type=user)
304 xe vbd-create vm-uuid=$vm vdi-uuid=$extra_vdi device=1
305fi
306
John Garbuttdaadf742012-04-27 18:28:28 +0100307# create a snapshot before the first boot
308# to allow a quick re-run with the same settings
309xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_FIRST_BOOT"
310
John Garbuttdaadf742012-04-27 18:28:28 +0100311#
312# Run DevStack VM
313#
Renuka Apte0af143b2012-04-02 15:46:53 -0700314xe vm-start vm="$GUEST_NAME"
Anthony Young3eb8f592011-10-26 23:11:52 -0700315
Ian Wienandaee18c72014-02-21 15:35:08 +1100316function ssh_no_check {
John Garbuttdaadf742012-04-27 18:28:28 +0100317 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"
318}
319
Mate Lakat86446762013-05-12 18:34:29 +0100320# Get hold of the Management IP of OpenStack VM
321OS_VM_MANAGEMENT_ADDRESS=$MGT_IP
322if [ $OS_VM_MANAGEMENT_ADDRESS == "dhcp" ]; then
Mate Lakat5a56cd62013-06-17 13:54:43 +0100323 OS_VM_MANAGEMENT_ADDRESS=$(find_ip_by_name $GUEST_NAME $MGT_DEV_NR)
Mate Lakat86446762013-05-12 18:34:29 +0100324fi
325
326# Get hold of the Service IP of OpenStack VM
Mate Lakat5a56cd62013-06-17 13:54:43 +0100327if [ $HOST_IP_IFACE == "eth${MGT_DEV_NR}" ]; then
Mate Lakat86446762013-05-12 18:34:29 +0100328 OS_VM_SERVICES_ADDRESS=$MGT_IP
John Garbuttdaadf742012-04-27 18:28:28 +0100329 if [ $MGT_IP == "dhcp" ]; then
Mate Lakat5a56cd62013-06-17 13:54:43 +0100330 OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME $MGT_DEV_NR)
John Garbuttdaadf742012-04-27 18:28:28 +0100331 fi
332else
Mate Lakat86446762013-05-12 18:34:29 +0100333 OS_VM_SERVICES_ADDRESS=$PUB_IP
John Garbuttdaadf742012-04-27 18:28:28 +0100334 if [ $PUB_IP == "dhcp" ]; then
Mate Lakat5a56cd62013-06-17 13:54:43 +0100335 OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME $PUB_DEV_NR)
John Garbuttdaadf742012-04-27 18:28:28 +0100336 fi
Renuka Aptec56885a2012-02-29 16:09:26 -0800337fi
338
Mate Lakatd15c8a02014-02-04 12:38:14 +0000339# Create an ssh-keypair, and set it up for dom0 user
340rm -f /root/dom0key /root/dom0key.pub
341ssh-keygen -f /root/dom0key -P "" -C "dom0"
342DOMID=$(get_domid "$GUEST_NAME")
343
344xenstore-write /local/domain/$DOMID/authorized_keys/$DOMZERO_USER "$(cat /root/dom0key.pub)"
345xenstore-chmod -u /local/domain/$DOMID/authorized_keys/$DOMZERO_USER r$DOMID
346
Ian Wienandaee18c72014-02-21 15:35:08 +1100347function run_on_appliance {
Mate Lakatd15c8a02014-02-04 12:38:14 +0000348 ssh \
349 -i /root/dom0key \
350 -o UserKnownHostsFile=/dev/null \
351 -o StrictHostKeyChecking=no \
352 -o BatchMode=yes \
353 "$DOMZERO_USER@$OS_VM_MANAGEMENT_ADDRESS" "$@"
354}
355
356# Wait until we can log in to the appliance
357while ! run_on_appliance true; do
358 sleep 1
359done
360
361# Remove authenticated_keys updater cronjob
362echo "" | run_on_appliance crontab -
363
364# Generate a passwordless ssh key for domzero user
365echo "ssh-keygen -f /home/$DOMZERO_USER/.ssh/id_rsa -C $DOMZERO_USER@appliance -N \"\" -q" | run_on_appliance
366
367# Authenticate that user to dom0
368run_on_appliance cat /home/$DOMZERO_USER/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
369
Anthony Young1de18c62011-11-01 14:19:18 -0500370# If we have copied our ssh credentials, use ssh to monitor while the installation runs
371WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
John Garbuttdaadf742012-04-27 18:28:28 +0100372COPYENV=${COPYENV:-1}
Anthony Young1de18c62011-11-01 14:19:18 -0500373if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
Bob Ball7fcc1572013-02-20 15:56:25 +0000374 set +x
Anthony Young1de18c62011-11-01 14:19:18 -0500375
Bob Ball0686dae2015-01-15 12:48:26 +0000376 echo "VM Launched - Waiting for run.sh"
377 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 +0100378 sleep 10
Anthony Young1de18c62011-11-01 14:19:18 -0500379 done
Bob Balld6b43a02014-07-14 15:18:33 +0100380 echo -n "devstack service is running, waiting for stack.sh to start logging..."
381
Bob Ball0686dae2015-01-15 12:48:26 +0000382 pid=`ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "cat /opt/stack/run_sh.pid"`
Bob Ball1e3a5d22015-01-16 13:06:58 +0000383 if [ -n "$SCREEN_LOGDIR" ]; then
384 while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e ${SCREEN_LOGDIR}/stack.log"; do
385 sleep 10
386 done
Bob Balldc7ebbb2014-06-24 13:59:49 +0100387
Bob Ball1e3a5d22015-01-16 13:06:58 +0000388 ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "tail --pid $pid -n +1 -f ${SCREEN_LOGDIR}/stack.log"
389 else
390 echo -n "SCREEN_LOGDIR not set; just waiting for process $pid to finish"
391 ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "wait $pid"
392 fi
393
394 set -x
Mate Lakat93f3b862013-09-24 17:35:00 +0100395 # Fail if devstack did not succeed
Bob Ball0686dae2015-01-15 12:48:26 +0000396 ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'test -e /opt/stack/runsh.succeeded'
Mate Lakat9efcf602012-12-19 10:23:06 +0000397
Bob Ball63c6c2b2013-01-24 13:13:51 +0000398 set +x
John Garbuttdaadf742012-04-27 18:28:28 +0100399 echo "################################################################################"
Anthony Young1de18c62011-11-01 14:19:18 -0500400 echo ""
John Garbuttdaadf742012-04-27 18:28:28 +0100401 echo "All Finished!"
402 echo "You can visit the OpenStack Dashboard"
Mate Lakat86446762013-05-12 18:34:29 +0100403 echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports."
Anthony Young1de18c62011-11-01 14:19:18 -0500404else
Bob Ball63c6c2b2013-01-24 13:13:51 +0000405 set +x
Anthony Young1de18c62011-11-01 14:19:18 -0500406 echo "################################################################################"
407 echo ""
408 echo "All Finished!"
409 echo "Now, you can monitor the progress of the stack.sh installation by "
Mate Lakat93f3b862013-09-24 17:35:00 +0100410 echo "looking at the console of your domU / checking the log files."
Anthony Young1de18c62011-11-01 14:19:18 -0500411 echo ""
Mate Lakat86446762013-05-12 18:34:29 +0100412 echo "ssh into your domU now: 'ssh stack@$OS_VM_MANAGEMENT_ADDRESS' using your password"
Jianghua Wang6e49cab2017-02-22 11:42:22 +0800413 echo "and then do: 'sudo systemctl status devstack' to check if devstack is still running."
Bob Ball0686dae2015-01-15 12:48:26 +0000414 echo "Check that /opt/stack/runsh.succeeded exists"
Anthony Young1de18c62011-11-01 14:19:18 -0500415 echo ""
Mate Lakat93f3b862013-09-24 17:35:00 +0100416 echo "When devstack completes, you can visit the OpenStack Dashboard"
Mate Lakat86446762013-05-12 18:34:29 +0100417 echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports."
Anthony Young1de18c62011-11-01 14:19:18 -0500418fi