Merge "Updated CI test script Debo~ Dutta@Cisco, Dave Lapsley@Nicira  * original at https://review.openstack.org/#change,3682  * Allow this exercise to be skipped if quantum is not enabled"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..68c771a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,176 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
diff --git a/files/apts/n-api b/files/apts/n-api
index 0f08daa..ad943ff 100644
--- a/files/apts/n-api
+++ b/files/apts/n-api
@@ -1 +1,2 @@
+gcc  # temporary because this pulls in glance to get the client without running the glance prereqs
 python-dateutil
diff --git a/stack.sh b/stack.sh
index 1d25e4e..8fa3902 100755
--- a/stack.sh
+++ b/stack.sh
@@ -313,7 +313,7 @@
 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
     PUBLIC_INTERFACE_DEFAULT=eth3
     # allow build_domU.sh to specify the flat network bridge via kernel args
-    FLAT_NETWORK_BRIDGE_DEFAULT=$(grep -o 'flat_network_bridge=[^.]*' /proc/cmdline | cut -d= -f 2)
+    FLAT_NETWORK_BRIDGE_DEFAULT=$(grep -o 'flat_network_bridge=[[:alnum:]]*' /proc/cmdline | cut -d= -f 2 | sort -u)
     GUEST_INTERFACE_DEFAULT=eth1
 else
     PUBLIC_INTERFACE_DEFAULT=br100
@@ -959,15 +959,6 @@
     iniset $GLANCE_API_CONF DEFAULT filesystem_store_datadir $GLANCE_IMAGE_DIR/
     iniset $GLANCE_API_CONF paste_deploy flavor keystone
 
-    # Store the images in swift if enabled.
-    if is_service_enabled swift; then
-        iniset $GLANCE_API_CONF DEFAULT default_store swift
-        iniset $GLANCE_API_CONF DEFAULT swift_store_auth_address $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0/
-        iniset $GLANCE_API_CONF DEFAULT swift_store_user $SERVICE_TENANT_NAME:glance
-        iniset $GLANCE_API_CONF DEFAULT swift_store_key $SERVICE_PASSWORD
-        iniset $GLANCE_API_CONF DEFAULT swift_store_create_container_on_put True
-    fi
-
     GLANCE_API_PASTE_INI=$GLANCE_CONF_DIR/glance-api-paste.ini
     cp $GLANCE_DIR/etc/glance-api-paste.ini $GLANCE_API_PASTE_INI
     iniset $GLANCE_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
diff --git a/tools/configure_tempest.sh b/tools/configure_tempest.sh
index 01849ad..6ba301f 100755
--- a/tools/configure_tempest.sh
+++ b/tools/configure_tempest.sh
@@ -37,13 +37,18 @@
 
 # Abort if localrc is not set
 if [ ! -e $TOP_DIR/localrc ]; then
-    echo "You must have a localrc with ALL necessary passwords and configuration defined before proceeding."
-    echo "See stack.sh for required passwords."
+    echo "You must have a localrc with necessary basic configuration defined before proceeding."
     exit 1
 fi
 
-# Source params
-source ./stackrc
+# Abort if openrc is not set
+if [ ! -e $TOP_DIR/openrc ]; then
+    echo "You must have an openrc with ALL necessary passwords and credentials defined before proceeding."
+    exit 1
+fi
+
+# Source params. openrc sources stackrc which sources localrc
+source $TOP_DIR/openrc
 
 # Set defaults not configured by stackrc
 TENANT=${TENANT:-admin}
@@ -132,8 +137,8 @@
 fi
 
 IDENTITY_USE_SSL=${IDENTITY_USE_SSL:-False}
-IDENTITY_PORT=${IDENTITY_PORT:-5000}
-IDENTITY_API_VERSION={$IDENTITY_API_VERSION:-v2.0} # Note: need v for now...
+TEMPEST_IDENTITY_HOST=${IDENTITY_HOST:-127.0.0.1}
+TEMPEST_IDENTITY_API_VERSION="v2.0" # Note: need v for now...
 # TODO(jaypipes): This is dumb and needs to be removed
 # from the Tempest configuration file entirely...
 IDENTITY_PATH=${IDENTITY_PATH:-tokens}
@@ -167,14 +172,16 @@
 # Do any of the following need to be configurable?
 COMPUTE_CATALOG_TYPE=compute
 COMPUTE_CREATE_IMAGE_ENABLED=True
-COMPUTE_RESIZE_AVAILABLE=True
+COMPUTE_RESIZE_AVAILABLE=False  # not supported with QEMU...
 COMPUTE_LOG_LEVEL=ERROR
+BUILD_INTERVAL=10
+BUILD_TIMEOUT=600
 
 sed -e "
     s,%IDENTITY_USE_SSL%,$IDENTITY_USE_SSL,g;
-    s,%IDENTITY_HOST%,$HOST_IP,g;
+    s,%IDENTITY_HOST%,$TEMPEST_IDENTITY_HOST,g;
     s,%IDENTITY_PORT%,$IDENTITY_PORT,g;
-    s,%IDENTITY_API_VERSION%,$IDENTITY_API_VERSION,g;
+    s,%IDENTITY_API_VERSION%,$TEMPEST_IDENTITY_API_VERSION,g;
     s,%IDENTITY_PATH%,$IDENTITY_PATH,g;
     s,%IDENTITY_STRATEGY%,$IDENTITY_STRATEGY,g;
     s,%USERNAME%,$OS_USERNAME,g;
@@ -187,6 +194,8 @@
     s,%COMPUTE_CREATE_IMAGE_ENABLED%,$COMPUTE_CREATE_IMAGE_ENABLED,g;
     s,%COMPUTE_RESIZE_AVAILABLE%,$COMPUTE_RESIZE_AVAILABLE,g;
     s,%COMPUTE_LOG_LEVEL%,$COMPUTE_LOG_LEVEL,g;
+    s,%BUILD_INTERVAL%,$BUILD_INTERVAL,g;
+    s,%BUILD_TIMEOUT%,$BUILD_TIMEOUT,g;
     s,%IMAGE_ID%,$IMAGE_UUID,g;
     s,%IMAGE_ID_ALT%,$IMAGE_UUID_ALT,g;
     s,%FLAVOR_REF%,$FLAVOR_REF,g;
@@ -196,6 +205,10 @@
     s,%ADMIN_TENANT_NAME%,$ADMIN_TENANT_NAME,g;
 " -i $TEMPEST_CONF
 
+echo "Created tempest configuration file:"
+cat $TEMPEST_CONF
+echo "\n\n"
+
 # Create config.ini
 
 CONFIG_INI_TMP=$(mktemp $CONFIG_INI.XXXXXX)
diff --git a/tools/xen/README.md b/tools/xen/README.md
index d487a99..d102b01 100644
--- a/tools/xen/README.md
+++ b/tools/xen/README.md
@@ -1,7 +1,7 @@
 Getting Started With XenServer 5.6 and Devstack
 ===============================================
 The purpose of the code in this directory it to help developers bootstrap
-a XenServer 5.6 + Openstack development environment.  This file gives
+a XenServer 5.6 (or greater) + Openstack development environment.  This file gives
 some pointers on how to get started.
 
 Xenserver is a Type 1 hypervisor, so it needs to be installed on bare metal.
@@ -25,36 +25,25 @@
 * XenServer Gateway: 192.168.1.1
 * XenServer DNS: 192.168.1.1
 
-Note:
-------
-It is advisable (and necessary if you are using Xenserver 6.0, due to space
-limitations), to create the above mentioned OS domU, on a separate dev machine.
-To do this, you will need to run Steps 2 on the dev machine (if required) as
-well as the Xenserver host. Steps 3 and 4 should be run on the dev machine.
-This process requires you to be root on the dev machine.
+Step 2: Download devstack
+--------------------------
+On your XenServer host, run the following commands as root:
 
-Step 2: Prepare DOM0
--------------------
-At this point, your host is missing some critical software that you will
-need to run devstack (like git).  Do this to install required software:
+wget --no-check-certificate https://github.com/openstack-dev/devstack/zipball/master
+unzip -o master -d ./devstack
+cd devstack/*/
 
-    wget --no-check-certificate https://raw.github.com/openstack-dev/devstack/master/tools/xen/prepare_dom0.sh
-    chmod 755 prepare_dom0.sh
-    ./prepare_dom0.sh
-
-This step will also clone devstack in $DEVSTACKSRCROOT/devstack.
-$DEVSTACKSRCROOT=/root by default.
-
-Step 3: Configure your localrc
------------------------------
+Step 3: Configure your localrc inside the devstack directory
+------------------------------------------------------------
 Devstack uses a localrc for user-specific configuration.  Note that
 the XENAPI_PASSWORD must be your dom0 root password.
 Of course, use real passwords if this machine is exposed.
 
-    cat > $DEVSTACKSRCROOT/devstack/localrc <<EOF
+    cat > ./localrc <<EOF
     MYSQL_PASSWORD=my_super_secret
     SERVICE_TOKEN=my_super_secret
     ADMIN_PASSWORD=my_super_secret
+    SERVICE_PASSWORD=$ADMIN_PASSWORD
     RABBIT_PASSWORD=my_super_secret
     # This is the password for your guest (for both stack and root users)
     GUEST_PASSWORD=my_super_secret
@@ -70,32 +59,24 @@
     ACTIVE_TIMEOUT=45
     # Interface on which you would like to access services
     HOST_IP_IFACE=ethX
+    # First time Ubuntu network install params
+    NETINSTALLIP="dhcp"
+    NAMESERVERS=""
+    NETMASK=""
+    GATEWAY=""
     EOF
 
-Step 4: Run ./build_xva.sh
---------------------------
-This script prepares your nova xva image. If you run this on a different machine,
-copy the resulting xva file to tools/xen/xvas/[GUEST_NAME].xva
-(by default tools/xen/xvas/ALLINONE.xva) on the Xenserver host.
+Step 4: Run ./install_os_domU.sh from the tools/xen directory
+-------------------------------------------------------------
+cd tools/xen
+./install_os_domU.sh
 
-cd $DEVSTACKSRCROOT/devstack/tools/xen
-./build_xva.sh
+Once this script finishes executing, log into the VM (openstack domU)
+that it installed and tail the run.sh.log file. You will need to wait
+until it run.sh has finished executing.
 
-You will also need to copy your localrc to the Xenserver host.
 
-Step 5: Run ./build_domU.sh
---------------------------
-This script does a lot of stuff, it is probably best to read it in its entirety.
-But in a nutshell, it performs the following:
-
-* Configures bridges and vlans for public, private, and management nets
-* Creates and installs a OpenStack all-in-one domU in an HA-FlatDHCP configuration
-* A script to create a multi-domU (ie. head node separated from compute) configuration is coming soon!
-
-cd $DEVSTACKSRCROOT/devstack/tools/xen
-./build_domU.sh
-
-Step 6: Do cloudy stuff!
+Step 5: Do cloudy stuff!
 --------------------------
 * Play with horizon
 * Play with the CLI
diff --git a/tools/xen/build_xva.sh b/tools/xen/build_xva.sh
index c235485..2f28b5f 100755
--- a/tools/xen/build_xva.sh
+++ b/tools/xen/build_xva.sh
@@ -1,5 +1,27 @@
 #!/bin/bash
 
+set -e
+
+declare -a on_exit_hooks
+
+on_exit()
+{
+    for i in $(seq $((${#on_exit_hooks[*]} - 1)) -1 0)
+    do
+        eval "${on_exit_hooks[$i]}"
+    done
+}
+
+add_on_exit()
+{
+    local n=${#on_exit_hooks[*]}
+    on_exit_hooks[$n]="$*"
+    if [[ $n -eq 0 ]]
+    then
+        trap on_exit EXIT
+    fi
+}
+
 # Abort if localrc is not set
 if [ ! -e ../../localrc ]; then
     echo "You must have a localrc with ALL necessary passwords defined before proceeding."
@@ -16,27 +38,11 @@
 # Echo commands
 set -o xtrace
 
+GUEST_NAME="$1"
+
 # Directory where we stage the build
-STAGING_DIR=$TOP_DIR/stage
-
-# Option to clean out old stuff
-CLEAN=${CLEAN:-0}
-if [ "$CLEAN" = "1" ]; then
-    rm -rf $STAGING_DIR
-fi
-
-# Download our base image.  This image is made using prepare_guest.sh
-BASE_IMAGE_URL=${BASE_IMAGE_URL:-http://images.ansolabs.com/xen/stage.tgz}
-if [ ! -e $STAGING_DIR ]; then
-    if [ ! -e /tmp/stage.tgz ]; then
-        wget $BASE_IMAGE_URL -O /tmp/stage.tgz
-    fi
-    tar xfz /tmp/stage.tgz
-    cd $TOP_DIR
-fi
-
-# Free up precious disk space
-rm -f /tmp/stage.tgz
+STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*")
+add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1"
 
 # Make sure we have a stage
 if [ ! -d $STAGING_DIR/etc ]; then
@@ -55,63 +61,26 @@
 UBUNTU_VERSION=`cat $STAGING_DIR/etc/lsb-release | grep "DISTRIB_CODENAME=" | sed "s/DISTRIB_CODENAME=//"`
 KERNEL_VERSION=`ls $STAGING_DIR/boot/vmlinuz* | head -1 | sed "s/.*vmlinuz-//"`
 
-# Directory for xvas
-XVA_DIR=$TOP_DIR/xvas
-
-# Create xva dir
-mkdir -p $XVA_DIR
-
-# Path to xva
-XVA=$XVA_DIR/$GUEST_NAME.xva
-
-# Setup fake grub
-rm -rf $STAGING_DIR/boot/grub/
-mkdir -p $STAGING_DIR/boot/grub/
-cp $TEMPLATES_DIR/menu.lst.in $STAGING_DIR/boot/grub/menu.lst
-sed -e "s,@KERNEL_VERSION@,$KERNEL_VERSION,g" -i $STAGING_DIR/boot/grub/menu.lst
-
-# Setup fstab, tty, and other system stuff
-cp $FILES_DIR/fstab $STAGING_DIR/etc/fstab
-cp $FILES_DIR/hvc0.conf $STAGING_DIR/etc/init/
-
-# Put the VPX into UTC.
-rm -f $STAGING_DIR/etc/localtime
-
 # Configure dns (use same dns as dom0)
 cp /etc/resolv.conf $STAGING_DIR/etc/resolv.conf
 
 # Copy over devstack
 rm -f /tmp/devstack.tar
-tar --exclude='stage' --exclude='xen/xvas' --exclude='xen/nova' -cvf /tmp/devstack.tar $TOP_DIR/../../../devstack
-cd $STAGING_DIR/opt/stack/
-tar xf /tmp/devstack.tar
+cd $TOP_DIR/../../
+tar --exclude='stage' --exclude='xen/xvas' --exclude='xen/nova' -cvf /tmp/devstack.tar .
+mkdir -p $STAGING_DIR/opt/stack/devstack
+tar xf /tmp/devstack.tar -C $STAGING_DIR/opt/stack/devstack
 cd $TOP_DIR
 
-# Configure OVA
-VDI_SIZE=$(($VDI_MB*1024*1024))
-PRODUCT_BRAND=${PRODUCT_BRAND:-openstack}
-PRODUCT_VERSION=${PRODUCT_VERSION:-001}
-BUILD_NUMBER=${BUILD_NUMBER:-001}
-LABEL="$PRODUCT_BRAND $PRODUCT_VERSION-$BUILD_NUMBER"
-OVA=$STAGING_DIR/tmp/ova.xml
-cp $TEMPLATES_DIR/ova.xml.in  $OVA
-sed -e "s,@VDI_SIZE@,$VDI_SIZE,g" -i $OVA
-sed -e "s,@PRODUCT_BRAND@,$PRODUCT_BRAND,g" -i $OVA
-sed -e "s,@PRODUCT_VERSION@,$PRODUCT_VERSION,g" -i $OVA
-sed -e "s,@BUILD_NUMBER@,$BUILD_NUMBER,g" -i $OVA
-
 # Run devstack on launch
 cat <<EOF >$STAGING_DIR/etc/rc.local
 # network restart required for getting the right gateway
 /etc/init.d/networking restart
 GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ DO_TGZ=0 bash /opt/stack/devstack/tools/xen/prepare_guest.sh > /opt/stack/prepare_guest.log 2>&1
-su -c "/opt/stack/run.sh > /opt/stack/run.sh.log" stack
+su -c "/opt/stack/run.sh > /opt/stack/run.sh.log 2>&1" stack
 exit 0
 EOF
 
-# Clean old xva. In the future may not do this every time.
-rm -f $XVA
-
 # Configure the hostname
 echo $GUEST_NAME > $STAGING_DIR/etc/hostname
 
@@ -151,10 +120,6 @@
     sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
 fi
 
-if [ -h $STAGING_DIR/sbin/dhclient3 ]; then
-    rm -f $STAGING_DIR/sbin/dhclient3
-fi
-
 # Gracefully cp only if source file/dir exists
 function cp_it {
     if [ -e $1 ] || [ -d $1 ]; then
@@ -181,11 +146,4 @@
 EOF
 chmod 755 $STAGING_DIR/opt/stack/run.sh
 
-# Create xva
-if [ ! -e $XVA ]; then
-    rm -rf /tmp/mkxva*
-    UID=0 $SCRIPT_DIR/mkxva -o $XVA -t xva -x $OVA $STAGING_DIR $VDI_MB /tmp/
-fi
-
-echo "Built $(basename $XVA).  If your dom0 is on a different machine, copy this to [devstackdir]/tools/xen/$(basename $XVA)"
-echo "Also copy your localrc to [devstackdir]"
+echo "Done"
diff --git a/tools/xen/devstackubuntupreseed.cfg b/tools/xen/devstackubuntupreseed.cfg
new file mode 100644
index 0000000..d8caaee
--- /dev/null
+++ b/tools/xen/devstackubuntupreseed.cfg
@@ -0,0 +1,470 @@
+### Contents of the preconfiguration file (for squeeze)
+### Localization
+# Preseeding only locale sets language, country and locale.
+d-i debian-installer/locale string en_US
+
+# The values can also be preseeded individually for greater flexibility.
+#d-i debian-installer/language string en
+#d-i debian-installer/country string NL
+#d-i debian-installer/locale string en_GB.UTF-8
+# Optionally specify additional locales to be generated.
+#d-i localechooser/supported-locales en_US.UTF-8, nl_NL.UTF-8
+
+# Keyboard selection.
+# Disable automatic (interactive) keymap detection.
+d-i console-setup/ask_detect boolean false
+#d-i keyboard-configuration/modelcode string pc105
+d-i keyboard-configuration/layoutcode string us
+# To select a variant of the selected layout (if you leave this out, the
+# basic form of the layout will be used):
+#d-i keyboard-configuration/variantcode string dvorak
+
+### Network configuration
+# Disable network configuration entirely. This is useful for cdrom
+# installations on non-networked devices where the network questions,
+# warning and long timeouts are a nuisance.
+#d-i netcfg/enable boolean false
+
+# netcfg will choose an interface that has link if possible. This makes it
+# skip displaying a list if there is more than one interface.
+d-i netcfg/choose_interface select auto
+
+# To pick a particular interface instead:
+#d-i netcfg/choose_interface select eth1
+
+# If you have a slow dhcp server and the installer times out waiting for
+# it, this might be useful.
+#d-i netcfg/dhcp_timeout string 60
+
+# If you prefer to configure the network manually, uncomment this line and
+# the static network configuration below.
+#d-i netcfg/disable_autoconfig boolean true
+
+# If you want the preconfiguration file to work on systems both with and
+# without a dhcp server, uncomment these lines and the static network
+# configuration below.
+#d-i netcfg/dhcp_failed note
+#d-i netcfg/dhcp_options select Configure network manually
+
+# Static network configuration.
+#d-i netcfg/get_nameservers string 192.168.1.1
+#d-i netcfg/get_ipaddress string 192.168.1.42
+#d-i netcfg/get_netmask string 255.255.255.0
+#d-i netcfg/get_gateway string 192.168.1.1
+#d-i netcfg/confirm_static boolean true
+
+# Any hostname and domain names assigned from dhcp take precedence over
+# values set here. However, setting the values still prevents the questions
+# from being shown, even if values come from dhcp.
+d-i netcfg/get_hostname string stack
+d-i netcfg/get_domain string stackpass
+
+# Disable that annoying WEP key dialog.
+d-i netcfg/wireless_wep string
+# The wacky dhcp hostname that some ISPs use as a password of sorts.
+#d-i netcfg/dhcp_hostname string radish
+
+# If non-free firmware is needed for the network or other hardware, you can
+# configure the installer to always try to load it, without prompting. Or
+# change to false to disable asking.
+#d-i hw-detect/load_firmware boolean true
+
+### Network console
+# Use the following settings if you wish to make use of the network-console
+# component for remote installation over SSH. This only makes sense if you
+# intend to perform the remainder of the installation manually.
+#d-i anna/choose_modules string network-console
+#d-i network-console/password password r00tme
+#d-i network-console/password-again password r00tme
+
+### Mirror settings
+# If you select ftp, the mirror/country string does not need to be set.
+#d-i mirror/protocol string ftp
+d-i mirror/country string manual
+d-i mirror/http/hostname string archive.ubuntu.com
+d-i mirror/http/directory string /ubuntu
+d-i mirror/http/proxy string
+
+# Alternatively: by default, the installer uses CC.archive.ubuntu.com where
+# CC is the ISO-3166-2 code for the selected country. You can preseed this
+# so that it does so without asking.
+#d-i mirror/http/mirror select CC.archive.ubuntu.com
+
+# Suite to install.
+#d-i mirror/suite string squeeze
+# Suite to use for loading installer components (optional).
+#d-i mirror/udeb/suite string squeeze
+# Components to use for loading installer components (optional).
+#d-i mirror/udeb/components multiselect main, restricted
+
+### Clock and time zone setup
+# Controls whether or not the hardware clock is set to UTC.
+d-i clock-setup/utc boolean true
+
+# You may set this to any valid setting for $TZ; see the contents of
+# /usr/share/zoneinfo/ for valid values.
+d-i time/zone string US/Pacific
+
+# Controls whether to use NTP to set the clock during the install
+d-i clock-setup/ntp boolean true
+# NTP server to use. The default is almost always fine here.
+d-i clock-setup/ntp-server string 0.us.pool.ntp.org
+
+### Partitioning
+## Partitioning example
+# If the system has free space you can choose to only partition that space.
+# This is only honoured if partman-auto/method (below) is not set.
+# Alternatives: custom, some_device, some_device_crypto, some_device_lvm.
+#d-i partman-auto/init_automatically_partition select biggest_free
+
+# Alternatively, you may specify a disk to partition. If the system has only
+# one disk the installer will default to using that, but otherwise the device
+# name must be given in traditional, non-devfs format (so e.g. /dev/hda or
+# /dev/sda, and not e.g. /dev/discs/disc0/disc).
+# For example, to use the first SCSI/SATA hard disk:
+#d-i partman-auto/disk string /dev/sda
+# In addition, you'll need to specify the method to use.
+# The presently available methods are:
+# - regular: use the usual partition types for your architecture
+# - lvm:     use LVM to partition the disk
+# - crypto:  use LVM within an encrypted partition
+d-i partman-auto/method string regular
+
+# If one of the disks that are going to be automatically partitioned
+# contains an old LVM configuration, the user will normally receive a
+# warning. This can be preseeded away...
+d-i partman-lvm/device_remove_lvm boolean true
+# The same applies to pre-existing software RAID array:
+d-i partman-md/device_remove_md boolean true
+# And the same goes for the confirmation to write the lvm partitions.
+d-i partman-lvm/confirm boolean true
+
+# For LVM partitioning, you can select how much of the volume group to use
+# for logical volumes.
+#d-i partman-auto-lvm/guided_size string max
+#d-i partman-auto-lvm/guided_size string 10GB
+#d-i partman-auto-lvm/guided_size string 50%
+
+# You can choose one of the three predefined partitioning recipes:
+# - atomic: all files in one partition
+# - home:   separate /home partition
+# - multi:  separate /home, /usr, /var, and /tmp partitions
+d-i partman-auto/choose_recipe select atomic
+
+# Or provide a recipe of your own...
+# If you have a way to get a recipe file into the d-i environment, you can
+# just point at it.
+#d-i partman-auto/expert_recipe_file string /hd-media/recipe
+
+# If not, you can put an entire recipe into the preconfiguration file in one
+# (logical) line. This example creates a small /boot partition, suitable
+# swap, and uses the rest of the space for the root partition:
+#d-i partman-auto/expert_recipe string                         \
+#      boot-root ::                                            \
+#              40 50 100 ext3                                  \
+#                      $primary{ } $bootable{ }                \
+#                      method{ format } format{ }              \
+#                      use_filesystem{ } filesystem{ ext3 }    \
+#                      mountpoint{ /boot }                     \
+#              .                                               \
+#              500 10000 1000000000 ext3                       \
+#                      method{ format } format{ }              \
+#                      use_filesystem{ } filesystem{ ext3 }    \
+#                      mountpoint{ / }                         \
+#              .                                               \
+#              64 512 300% linux-swap                          \
+#                      method{ swap } format{ }                \
+#              .
+
+# If you just want to change the default filesystem from ext3 to something
+# else, you can do that without providing a full recipe.
+d-i partman/default_filesystem string ext3
+
+# The full recipe format is documented in the file partman-auto-recipe.txt
+# included in the 'debian-installer' package or available from D-I source
+# repository. This also documents how to specify settings such as file
+# system labels, volume group names and which physical devices to include
+# in a volume group.
+
+# This makes partman automatically partition without confirmation, provided
+# that you told it what to do using one of the methods above.
+d-i partman-partitioning/confirm_write_new_label boolean true
+d-i partman/choose_partition select finish
+d-i partman/confirm boolean true
+d-i partman/confirm_nooverwrite boolean true
+
+## Partitioning using RAID
+# The method should be set to "raid".
+#d-i partman-auto/method string raid
+# Specify the disks to be partitioned. They will all get the same layout,
+# so this will only work if the disks are the same size.
+#d-i partman-auto/disk string /dev/sda /dev/sdb
+
+# Next you need to specify the physical partitions that will be used. 
+#d-i partman-auto/expert_recipe string \
+#      multiraid ::                                         \
+#              1000 5000 4000 raid                          \
+#                      $primary{ } method{ raid }           \
+#              .                                            \
+#              64 512 300% raid                             \
+#                      method{ raid }                       \
+#              .                                            \
+#              500 10000 1000000000 raid                    \
+#                      method{ raid }                       \
+#              .
+
+# Last you need to specify how the previously defined partitions will be
+# used in the RAID setup. Remember to use the correct partition numbers
+# for logical partitions. RAID levels 0, 1, 5, 6 and 10 are supported;
+# devices are separated using "#".
+# Parameters are:
+# <raidtype> <devcount> <sparecount> <fstype> <mountpoint> \
+#          <devices> <sparedevices>
+
+#d-i partman-auto-raid/recipe string \
+#    1 2 0 ext3 /                    \
+#          /dev/sda1#/dev/sdb1       \
+#    .                               \
+#    1 2 0 swap -                    \
+#          /dev/sda5#/dev/sdb5       \
+#    .                               \
+#    0 2 0 ext3 /home                \
+#          /dev/sda6#/dev/sdb6       \
+#    .
+
+# For additional information see the file partman-auto-raid-recipe.txt
+# included in the 'debian-installer' package or available from D-I source
+# repository.
+
+# This makes partman automatically partition without confirmation.
+d-i partman-md/confirm boolean true
+d-i partman-partitioning/confirm_write_new_label boolean true
+d-i partman/choose_partition select finish
+d-i partman/confirm boolean true
+d-i partman/confirm_nooverwrite boolean true
+
+## Controlling how partitions are mounted
+# The default is to mount by UUID, but you can also choose "traditional" to
+# use traditional device names, or "label" to try filesystem labels before
+# falling back to UUIDs.
+#d-i partman/mount_style select uuid
+
+### Base system installation
+# Configure APT to not install recommended packages by default. Use of this
+# option can result in an incomplete system and should only be used by very
+# experienced users.
+#d-i base-installer/install-recommends boolean false
+
+# The kernel image (meta) package to be installed; "none" can be used if no
+# kernel is to be installed.
+#d-i base-installer/kernel/image string linux-generic
+
+### Account setup
+# Skip creation of a root account (normal user account will be able to
+# use sudo). The default is false; preseed this to true if you want to set
+# a root password.
+d-i passwd/root-login boolean true
+# Alternatively, to skip creation of a normal user account.
+d-i passwd/make-user boolean false
+
+# Root password, either in clear text
+d-i passwd/root-password password stackpass
+d-i passwd/root-password-again password stackpass
+# or encrypted using an MD5 hash.
+#d-i passwd/root-password-crypted password [MD5 hash]
+
+# To create a normal user account.
+#d-i passwd/user-fullname string Ubuntu User
+#d-i passwd/username string ubuntu
+# Normal user's password, either in clear text
+#d-i passwd/user-password password insecure
+#d-i passwd/user-password-again password insecure
+# or encrypted using an MD5 hash.
+#d-i passwd/user-password-crypted password [MD5 hash]
+# Create the first user with the specified UID instead of the default.
+#d-i passwd/user-uid string 1010
+# The installer will warn about weak passwords. If you are sure you know
+# what you're doing and want to override it, uncomment this.
+d-i user-setup/allow-password-weak boolean true
+
+# The user account will be added to some standard initial groups. To
+# override that, use this.
+#d-i passwd/user-default-groups string audio cdrom video
+
+# Set to true if you want to encrypt the first user's home directory.
+d-i user-setup/encrypt-home boolean false
+
+### Apt setup
+# You can choose to install restricted and universe software, or to install
+# software from the backports repository.
+#d-i apt-setup/restricted boolean true
+#d-i apt-setup/universe boolean true
+#d-i apt-setup/backports boolean true
+# Uncomment this if you don't want to use a network mirror.
+#d-i apt-setup/use_mirror boolean false
+# Select which update services to use; define the mirrors to be used.
+# Values shown below are the normal defaults.
+#d-i apt-setup/services-select multiselect security
+#d-i apt-setup/security_host string security.ubuntu.com
+#d-i apt-setup/security_path string /ubuntu
+
+# Additional repositories, local[0-9] available
+#d-i apt-setup/local0/repository string \
+#       http://local.server/ubuntu squeeze main
+#d-i apt-setup/local0/comment string local server
+# Enable deb-src lines
+#d-i apt-setup/local0/source boolean true
+# URL to the public key of the local repository; you must provide a key or
+# apt will complain about the unauthenticated repository and so the
+# sources.list line will be left commented out
+#d-i apt-setup/local0/key string http://local.server/key
+
+# By default the installer requires that repositories be authenticated
+# using a known gpg key. This setting can be used to disable that
+# authentication. Warning: Insecure, not recommended.
+#d-i debian-installer/allow_unauthenticated boolean true
+
+### Package selection
+#tasksel tasksel/first multiselect ubuntu-desktop
+#tasksel tasksel/first multiselect lamp-server, print-server
+#tasksel tasksel/first multiselect kubuntu-desktop
+tasksel tasksel/first multiselect openssh-server
+
+# Individual additional packages to install
+#d-i pkgsel/include string openssh-server build-essential
+# Whether to upgrade packages after debootstrap.
+# Allowed values: none, safe-upgrade, full-upgrade
+#d-i pkgsel/upgrade select none
+
+# Language pack selection
+#d-i pkgsel/language-packs multiselect de, en, zh
+
+# Policy for applying updates. May be "none" (no automatic updates),
+# "unattended-upgrades" (install security updates automatically), or
+# "landscape" (manage system with Landscape).
+d-i pkgsel/update-policy select unattended-upgrades
+
+# Some versions of the installer can report back on what software you have
+# installed, and what software you use. The default is not to report back,
+# but sending reports helps the project determine what software is most
+# popular and include it on CDs.
+#popularity-contest popularity-contest/participate boolean false
+
+# By default, the system's locate database will be updated after the
+# installer has finished installing most packages. This may take a while, so
+# if you don't want it, you can set this to "false" to turn it off.
+d-i pkgsel/updatedb boolean false
+
+### Boot loader installation
+# Grub is the default boot loader (for x86). If you want lilo installed
+# instead, uncomment this:
+#d-i grub-installer/skip boolean true
+# To also skip installing lilo, and install no bootloader, uncomment this
+# too:
+#d-i lilo-installer/skip boolean true
+
+# With a few exceptions for unusual partitioning setups, GRUB 2 is now the
+# default. If you need GRUB Legacy for some particular reason, then
+# uncomment this:
+#d-i grub-installer/grub2_instead_of_grub_legacy boolean false
+
+# This is fairly safe to set, it makes grub install automatically to the MBR
+# if no other operating system is detected on the machine.
+d-i grub-installer/only_debian boolean true
+
+# This one makes grub-installer install to the MBR if it also finds some other
+# OS, which is less safe as it might not be able to boot that other OS.
+d-i grub-installer/with_other_os boolean true
+
+# Alternatively, if you want to install to a location other than the mbr,
+# uncomment and edit these lines:
+#d-i grub-installer/only_debian boolean false
+#d-i grub-installer/with_other_os boolean false
+#d-i grub-installer/bootdev  string (hd0,0)
+# To install grub to multiple disks:
+#d-i grub-installer/bootdev  string (hd0,0) (hd1,0) (hd2,0)
+
+# Optional password for grub, either in clear text
+#d-i grub-installer/password password r00tme
+#d-i grub-installer/password-again password r00tme
+# or encrypted using an MD5 hash, see grub-md5-crypt(8).
+#d-i grub-installer/password-crypted password [MD5 hash]
+
+# Use the following option to add additional boot parameters for the
+# installed system (if supported by the bootloader installer).
+# Note: options passed to the installer will be added automatically.
+#d-i debian-installer/add-kernel-opts string nousb
+
+### Finishing up the installation
+# During installations from serial console, the regular virtual consoles
+# (VT1-VT6) are normally disabled in /etc/inittab. Uncomment the next
+# line to prevent this.
+d-i finish-install/keep-consoles boolean true
+
+# Avoid that last message about the install being complete.
+d-i finish-install/reboot_in_progress note
+
+# This will prevent the installer from ejecting the CD during the reboot,
+# which is useful in some situations.
+#d-i cdrom-detect/eject boolean false
+
+# This is how to make the installer shutdown when finished, but not
+# reboot into the installed system.
+#d-i debian-installer/exit/halt boolean true
+# This will power off the machine instead of just halting it.
+#d-i debian-installer/exit/poweroff boolean true
+
+### X configuration
+# X can detect the right driver for some cards, but if you're preseeding,
+# you override whatever it chooses. Still, vesa will work most places.
+#xserver-xorg xserver-xorg/config/device/driver select vesa
+
+# A caveat with mouse autodetection is that if it fails, X will retry it
+# over and over. So if it's preseeded to be done, there is a possibility of
+# an infinite loop if the mouse is not autodetected.
+#xserver-xorg xserver-xorg/autodetect_mouse boolean true
+
+# Monitor autodetection is recommended.
+xserver-xorg xserver-xorg/autodetect_monitor boolean true
+# Uncomment if you have an LCD display.
+#xserver-xorg xserver-xorg/config/monitor/lcd boolean true
+# X has three configuration paths for the monitor. Here's how to preseed
+# the "medium" path, which is always available. The "simple" path may not
+# be available, and the "advanced" path asks too many questions.
+xserver-xorg xserver-xorg/config/monitor/selection-method \
+       select medium
+xserver-xorg xserver-xorg/config/monitor/mode-list \
+       select 1024x768 @ 60 Hz
+
+### Preseeding other packages
+# Depending on what software you choose to install, or if things go wrong
+# during the installation process, it's possible that other questions may
+# be asked. You can preseed those too, of course. To get a list of every
+# possible question that could be asked during an install, do an
+# installation, and then run these commands:
+#   debconf-get-selections --installer > file
+#   debconf-get-selections >> file
+
+
+#### Advanced options
+### Running custom commands during the installation
+# d-i preseeding is inherently not secure. Nothing in the installer checks
+# for attempts at buffer overflows or other exploits of the values of a
+# preconfiguration file like this one. Only use preconfiguration files from
+# trusted locations! To drive that home, and because it's generally useful,
+# here's a way to run any shell command you'd like inside the installer,
+# automatically.
+
+# This first command is run as early as possible, just after
+# preseeding is read.
+#d-i preseed/early_command string anna-install some-udeb
+# This command is run immediately before the partitioner starts. It may be
+# useful to apply dynamic partitioner preseeding that depends on the state
+# of the disks (which may not be visible when preseed/early_command runs).
+#d-i partman/early_command \
+#       string debconf-set partman-auto/disk "$(list-devices disk | head -n1)"
+# This command is run just before the install finishes, but when there is
+# still a usable /target directory. You can chroot to /target and use it
+# directly, or use the apt-install and in-target commands to easily install
+# packages and run commands in the target system.
+#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh
diff --git a/tools/xen/build_domU.sh b/tools/xen/install_os_domU.sh
similarity index 69%
rename from tools/xen/build_domU.sh
rename to tools/xen/install_os_domU.sh
index 5fa7aa8..54c93c7 100755
--- a/tools/xen/build_domU.sh
+++ b/tools/xen/install_os_domU.sh
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+# Exit on errors
+set -o errexit
+
 # Abort if localrc is not set
 if [ ! -e ../../localrc ]; then
     echo "You must have a localrc with ALL necessary passwords defined before proceeding."
@@ -19,25 +22,29 @@
 # Echo commands
 set -o xtrace
 
-# Check for xva file
-if [ ! -e $XVA ]; then
-    echo "Missing xva file.  Please run build_xva.sh (ideally on a non dom0 host since the build can require lots of space)."
-    echo "Place the resulting xva file in $XVA"
-    exit 1
-fi
+xe_min()
+{
+  local cmd="$1"
+  shift
+  xe "$cmd" --minimal "$@"
+}
 
-# Make sure we have git
-if ! which git; then
-    GITDIR=/tmp/git-1.7.7
-    cd /tmp
-    rm -rf $GITDIR*
-    wget http://git-core.googlecode.com/files/git-1.7.7.tar.gz
-    tar xfv git-1.7.7.tar.gz
-    cd $GITDIR
-    ./configure --with-curl --with-expat
-    make install
-    cd $TOP_DIR
+cd $TOP_DIR
+if [ -f ./master ]
+then
+    rm -rf ./master
+    rm -rf ./nova
 fi
+wget https://github.com/openstack/nova/zipball/master --no-check-certificate
+unzip -o master -d ./nova
+cp -pr ./nova/*/plugins/xenserver/xenapi/etc/xapi.d /etc/
+chmod a+x /etc/xapi.d/plugins/*
+
+mkdir -p /boot/guest
+
+GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"}
+SNAME="ubuntusnapshot"
+TNAME="ubuntuready"
 
 # Helper to create networks
 # Uses echo trickery to return network uuid
@@ -48,23 +55,23 @@
     netname=$4
     if [ -z $br ]
     then
-        pif=$(xe pif-list --minimal device=$dev VLAN=$vlan)
+        pif=$(xe_min pif-list device=$dev VLAN=$vlan)
         if [ -z $pif ]
         then
             net=$(xe network-create name-label=$netname)
         else
-            net=$(xe network-list --minimal PIF-uuids=$pif)
+            net=$(xe_min network-list  PIF-uuids=$pif)
         fi
         echo $net
         return 0
     fi
-    if [ ! $(xe network-list --minimal params=bridge | grep -w --only-matching $br) ]
+    if [ ! $(xe_min network-list  params=bridge | grep -w --only-matching $br) ]
     then
         echo "Specified bridge $br does not exist"
         echo "If you wish to use defaults, please keep the bridge name empty"
         exit 1
     else
-        net=$(xe network-list --minimal bridge=$br)
+        net=$(xe_min network-list  bridge=$br)
         echo $net
     fi
 }
@@ -95,13 +102,13 @@
     then
         return
     fi
-    if [ -z $(xe vlan-list --minimal tag=$vlan) ]
+    if [ -z $(xe_min vlan-list  tag=$vlan) ]
     then
-        pif=$(xe pif-list --minimal network-uuid=$net)
+        pif=$(xe_min pif-list  network-uuid=$net)
         # We created a brand new network this time
         if [ -z $pif ]
         then
-            pif=$(xe pif-list --minimal device=$dev VLAN=-1)
+            pif=$(xe_min pif-list  device=$dev VLAN=-1)
             xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
         else
             echo "VLAN does not exist but PIF attached to this network"
@@ -133,24 +140,11 @@
 # Enable ip forwarding at runtime as well
 echo 1 > /proc/sys/net/ipv4/ip_forward
 
-# Set local storage il8n
-SR_UUID=`xe sr-list --minimal name-label="Local storage"`
-xe sr-param-set uuid=$SR_UUID other-config:i18n-key=local-storage
-
-# Checkout nova
-git_clone $NOVA_REPO $TOP_DIR/nova $NOVA_BRANCH
-
-# Install plugins
-cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/
-chmod a+x /etc/xapi.d/plugins/*
-yum --enablerepo=base install -y parted
-mkdir -p /boot/guest
-
 # Shutdown previous runs
 DO_SHUTDOWN=${DO_SHUTDOWN:-1}
 if [ "$DO_SHUTDOWN" = "1" ]; then
     # Shutdown all domU's that created previously
-    xe vm-list --minimal name-label="$LABEL" | xargs ./scripts/uninstall-os-vpx.sh
+    xe_min vm-list  name-label="$GUEST_NAME" | xargs ./scripts/uninstall-os-vpx.sh
 
     # Destroy any instances that were launched
     for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
@@ -168,18 +162,55 @@
 
 # Start guest
 if [ -z $VM_BR ]; then
-    VM_BR=$(xe network-list --minimal uuid=$VM_NET params=bridge)
+    VM_BR=$(xe_min network-list  uuid=$VM_NET params=bridge)
 fi
 if [ -z $MGT_BR ]; then
-    MGT_BR=$(xe network-list --minimal uuid=$MGT_NET params=bridge)
+    MGT_BR=$(xe_min network-list  uuid=$MGT_NET params=bridge)
 fi
 if [ -z $PUB_BR ]; then
-    PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge)
+    PUB_BR=$(xe_min network-list  uuid=$PUB_NET params=bridge)
 fi
-$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -w -k "flat_network_bridge=${VM_BR}"
+
+templateuuid=$(xe template-list name-label="$TNAME")
+if [ -n "$templateuuid" ]
+then
+        vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME")
+else
+    template=$(xe_min template-list name-label="Ubuntu 11.10 (64-bit)")
+    if [ -z "$template" ]
+    then
+        cp $TOP_DIR/devstackubuntupreseed.cfg /opt/xensource/www/
+        $TOP_DIR/scripts/xenoneirictemplate.sh "${HOST_IP}/devstackubuntupreseed.cfg"
+    fi
+    $TOP_DIR/scripts/install-os-vpx.sh -t "Ubuntu 11.10 (64-bit)" -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -r $OSDOMU_MEM_MB -k "flat_network_bridge=${VM_BR}"
+
+    # Wait for install to finish
+    while true
+    do
+        state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted)
+        if [ -n "$state" ]
+        then
+            break
+        else
+            echo "Waiting for "$GUEST_NAME" to finish installation..."
+            sleep 30
+        fi
+    done
+
+    vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME")
+    xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid"
+
+    # Make template from VM
+    snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME")
+    template_uuid=$(xe snapshot-clone uuid=$snuuid new-name-label="$TNAME")
+fi
+
+$TOP_DIR/build_xva.sh "$GUEST_NAME"
+
+xe vm-start vm="$GUEST_NAME"
 
 if [ $PUB_IP == "dhcp" ]; then
-    PUB_IP=$(xe vm-list --minimal name-label=$GUEST_NAME params=networks |  sed -ne 's,^.*3/ip: \([0-9.]*\).*$,\1,p')
+    PUB_IP=$(xe_min vm-list  name-label=$GUEST_NAME params=networks |  sed -ne 's,^.*3/ip: \([0-9.]*\).*$,\1,p')
 fi
 
 # If we have copied our ssh credentials, use ssh to monitor while the installation runs
diff --git a/tools/xen/prepare_guest.sh b/tools/xen/prepare_guest.sh
old mode 100644
new mode 100755
index 77ce54a..5d39ac6
--- a/tools/xen/prepare_guest.sh
+++ b/tools/xen/prepare_guest.sh
@@ -6,13 +6,6 @@
 GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
 STAGING_DIR=${STAGING_DIR:-stage}
 DO_TGZ=${DO_TGZ:-1}
-KERNEL_VERSION=3.0.0-12-virtual
-
-# Debootstrap base system
-if [ ! -d $STAGING_DIR ]; then
-    apt-get install debootstrap
-    debootstrap --arch amd64 oneiric $STAGING_DIR http://us.archive.ubuntu.com/ubuntu/
-fi
 
 # Sources.list
 cat <<EOF >$STAGING_DIR/etc/apt/sources.list
@@ -28,7 +21,6 @@
 
 # Install basics
 chroot $STAGING_DIR apt-get update
-chroot $STAGING_DIR apt-get install -y linux-image-$KERNEL_VERSION
 chroot $STAGING_DIR apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool
 chroot $STAGING_DIR apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo
 chroot $STAGING_DIR pip install xenapi
diff --git a/tools/xen/scripts/install-os-vpx.sh b/tools/xen/scripts/install-os-vpx.sh
index d45c370..fe5e810 100755
--- a/tools/xen/scripts/install-os-vpx.sh
+++ b/tools/xen/scripts/install-os-vpx.sh
@@ -38,7 +38,7 @@
 cat << EOF
 
   Usage: $0 [-f FILE_PATH] [-d DISK_SIZE] [-v BRIDGE_NAME] [-m BRIDGE_NAME] [-p BRIDGE_NAME]
-            [-k PARAMS] [-r RAM] [-i|-c] [-w] [-b] [-l NAME_LABEL]
+            [-k PARAMS] [-r RAM] [-i|-c] [-w] [-b] [-l NAME_LABEL] [-t TEMPLATE_NW_INSTALL]
 
   Installs XenServer OpenStack VPX.
 
@@ -61,6 +61,7 @@
      -r MiB       Specifies RAM used by the VPX, in MiB.
                   By default it will take the value from the XVA.
      -l name      Specifies the name label for the VM.
+     -t template  Network install an openstack domU from this template
 
   EXAMPLES:
 
@@ -88,7 +89,7 @@
 
 get_params()
 {
-  while getopts "hicwbf:d:v:m:p:k:r:l:" OPTION;
+  while getopts "hicwbf:d:v:m:p:k:r:l:t:" OPTION;
   do
     case $OPTION in
       h) usage
@@ -127,9 +128,12 @@
       v)
          BRIDGE_V=$OPTARG
          ;;
-     l)
+      l)
          NAME_LABEL=$OPTARG
          ;;
+      t)
+         TEMPLATE_NAME=$OPTARG
+         ;;
       ?)
          usage
          exit
@@ -328,17 +332,11 @@
 {
   local v="$1"
   local args=$KERNEL_PARAMS
-  local cmdline=$(cat /proc/cmdline)
-  for word in $cmdline
-  do
-    if echo "$word" | grep -q "geppetto"
-    then
-      args="$word $args"
-    fi
-  done
   if [ "$args" != "" ]
   then
     echo "Passing Geppetto args to VPX: $args."
+    pvargs=$(xe vm-param-get param-name=PV-args uuid="$v")
+    args="$pvargs $args"
     xe vm-param-set PV-args="$args" uuid="$v"
   fi
 }
@@ -422,6 +420,20 @@
 
   destroy_vifs "$vm_uuid"
   set_all "$vm_uuid"
+elif [ "$TEMPLATE_NAME" ]
+then
+  echo $TEMPLATE_NAME
+  vm_uuid=$(xe_min vm-install template="$TEMPLATE_NAME" new-name-label="$NAME_LABEL")
+  destroy_vifs "$vm_uuid"
+  set_auto_start "$vm_uuid"
+  create_gi_vif "$vm_uuid"
+  create_vm_vif "$vm_uuid"
+  create_management_vif "$vm_uuid"
+  create_public_vif "$vm_uuid"
+  set_kernel_params "$vm_uuid"
+  xe vm-param-set other-config:os-vpx=true uuid="$vm_uuid"
+  xe vm-param-set actions-after-reboot=Destroy uuid="$vm_uuid"
+  set_memory "$vm_uuid"
 else
   if [ ! -f "$VPX_FILE" ]
   then
diff --git a/tools/xen/scripts/manage-vdi b/tools/xen/scripts/manage-vdi
new file mode 100755
index 0000000..a0a27e8
--- /dev/null
+++ b/tools/xen/scripts/manage-vdi
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+set -eux
+
+action="$1"
+vm="$2"
+device="${3-0}"
+part="${4-}"
+
+xe_min()
+{
+  local cmd="$1"
+  shift
+  xe "$cmd" --minimal "$@"
+}
+
+vm_uuid=$(xe_min vm-list name-label="$vm")
+vdi_uuid=$(xe_min vbd-list params=vdi-uuid vm-uuid="$vm_uuid" \
+                           userdevice="$device")
+
+dom0_uuid=$(xe_min vm-list is-control-domain=true)
+
+open_vdi()
+{
+  vbd_uuid=$(xe vbd-create vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid" \
+                         device=autodetect)
+  mp=$(mktemp -d)
+  xe vbd-plug uuid="$vbd_uuid"
+
+  udevsettle
+  dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
+  mount "/dev/$dev$part" "$mp"
+  echo "Your vdi is mounted at $mp"
+}
+
+close_vdi()
+{
+  vbd_uuid=$(xe_min vbd-list vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid")
+  dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
+  umount "/dev/$dev$part"
+
+  xe vbd-unplug uuid=$vbd_uuid
+  xe vbd-destroy uuid=$vbd_uuid
+}
+
+if [ "$action" == "open" ]
+then
+  open_vdi
+elif [ "$action" == "close" ]
+then
+  close_vdi
+fi
diff --git a/tools/xen/scripts/xenoneirictemplate.sh b/tools/xen/scripts/xenoneirictemplate.sh
new file mode 100755
index 0000000..1d9ec5e
--- /dev/null
+++ b/tools/xen/scripts/xenoneirictemplate.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+## makeubuntu.sh, this creates Ubuntu server 11.10 32 and 64 bit templates
+## on Xenserver 6.0.2 Net install only
+## Original Author: David Markey <david.markey@citrix.com>
+## Author: Renuka Apte <renuka.apte@citrix.com>
+## This is not an officially supported guest OS on XenServer 6.02
+
+BASE_DIR=$(cd $(dirname "$0") && pwd)
+source $BASE_DIR/../../../localrc
+
+LENNY=$(xe template-list name-label=Debian\ Lenny\ 5.0\ \(32-bit\) --minimal)
+
+if [[ -z $LENNY ]] ; then
+    echo "Cant find lenny 32bit template, is this on 6.0.2?"
+    exit 1
+fi
+
+distro="Ubuntu 11.10"
+arches=("32-bit" "64-bit")
+
+preseedurl=${1:-"http://images.ansolabs.com/devstackubuntupreseed.cfg"}
+
+for arch in ${arches[@]} ; do
+    echo "Attempting $distro ($arch)"
+    if [[ -n $(xe template-list name-label="$distro ($arch)" params=uuid --minimal) ]] ; then
+        echo "$distro ($arch)" already exists, Skipping
+    else
+        if [ -z $NETINSTALLIP ]
+        then
+            echo "NETINSTALLIP not set in localrc"
+            exit 1
+        fi
+        pvargs="-- quiet console=hvc0 partman/default_filesystem=ext3 locale=en_US console-setup/ask_detect=false keyboard-configuration/layoutcode=us netcfg/choose_interface=eth3 netcfg/get_hostname=os netcfg/get_domain=os auto url=${preseedurl}"
+        if [ "$NETINSTALLIP" != "dhcp" ]
+        then
+            netcfgargs="netcfg/disable_autoconfig=true netcfg/get_nameservers=${NAMESERVERS} netcfg/get_ipaddress=${NETINSTALLIP} netcfg/get_netmask=${NETMASK} netcfg/get_gateway=${GATEWAY} netcfg/confirm_static=true"
+            pvargs="${pvargs} ${netcfgargs}"
+        fi
+        NEWUUID=$(xe vm-clone uuid=$LENNY new-name-label="$distro ($arch)")
+        xe template-param-set uuid=$NEWUUID other-config:install-methods=http,ftp \
+         other-config:install-repository=http://archive.ubuntu.net/ubuntu \
+         PV-args="$pvargs" \
+         other-config:debian-release=oneiric \
+         other-config:default_template=true
+
+        if [[ "$arch" == "32-bit" ]] ; then
+            xe template-param-set uuid=$NEWUUID other-config:install-arch="i386"
+        else
+            xe template-param-set uuid=$NEWUUID other-config:install-arch="amd64"
+        fi
+        echo "Success"
+    fi
+done
+
+echo "Done"
diff --git a/tools/xen/xenrc b/tools/xen/xenrc
index 58fda31..f434b11 100644
--- a/tools/xen/xenrc
+++ b/tools/xen/xenrc
@@ -1,10 +1,10 @@
 #!/bin/bash
 
 # Name of this guest
-GUEST_NAME=${GUEST_NAME:-ALLINONE}
+GUEST_NAME=${GUEST_NAME:-DevStackOSDomU}
 
 # Size of image
-VDI_MB=${VDI_MB:-2500}
+VDI_MB=${VDI_MB:-5000}
 
 # VM Password
 GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
@@ -35,11 +35,7 @@
 MGT_VLAN=${MGT_VLAN:-101}
 MGT_DEV=${MGT_DEV:-eth0}
 
-# XVA Directory
-XVA_DIR=${XVA_DIR:-`pwd`/xvas}
-
-# Path to xva file
-XVA=${XVA:-$XVA_DIR/$GUEST_NAME.xva }
+OSDOMU_MEM_MB=1024
 
 # Source params
 cd ../.. && source ./stackrc && cd $TOP_DIR