Improvements to DevStack's XenServer scripts

I have ensured:
- template gets re-used on second run
- template includes XenServer tools, and custom user accounts
- take snapshot before first boot, for easy re-run
- make host_ip_iface work with either eth2 or eth3
- make ssh into domU checks looser
- above is all ground work for improved jenkins tests
- added some more comments to make it scripts clearer

Change-Id: I5c45370bf8a1393d669480e196b13f592d29154f
diff --git a/tools/xen/prepare_guest.sh b/tools/xen/prepare_guest.sh
index 74efaff..89a0169 100755
--- a/tools/xen/prepare_guest.sh
+++ b/tools/xen/prepare_guest.sh
@@ -1,6 +1,18 @@
 #!/bin/bash
 
+# This script is run on an Ubuntu VM.
+# This script is inserted into the VM by prepare_guest_template.sh
+# and is run when that VM boots.
+# It customizes a fresh Ubuntu install, so it is ready
+# to run stack.sh
+#
+# This includes installing the XenServer tools,
+# creating the user called "stack",
+# and shuts down the VM to signal the script has completed
+
 set -x
+# Echo commands
+set -o xtrace
 
 # Configurable nuggets
 GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
@@ -13,7 +25,7 @@
 chroot $STAGING_DIR apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo
 chroot $STAGING_DIR pip install xenapi
 
-# Install guest utilities
+# Install XenServer guest utilities
 XEGUEST=xe-guest-utilities_5.6.100-651_amd64.deb
 wget http://images.ansolabs.com/xen/$XEGUEST -O $XEGUEST
 cp $XEGUEST $STAGING_DIR/root
@@ -68,3 +80,12 @@
     rm -f stage.tgz
     tar cfz stage.tgz stage
 fi
+
+# remove self from local.rc
+# so this script is not run again
+rm -rf /etc/rc.local
+mv /etc/rc.local.preparebackup /etc/rc.local
+cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.backup
+
+# shutdown to notify we are done
+shutdown -h now