Merge "Uses keystone client instead of keystone-manage" into redux
diff --git a/files/swift/proxy-server.conf b/files/swift/proxy-server.conf
index da6b1fa..3ef0276 100644
--- a/files/swift/proxy-server.conf
+++ b/files/swift/proxy-server.conf
@@ -19,7 +19,7 @@
 use = egg:swiftkeystone2#keystone2
 keystone_admin_token = %SERVICE_TOKEN%
 keystone_url = http://localhost:35357/v2.0
-keystone_swift_operator_roles = Member,Admin
+keystone_swift_operator_roles = Member,admin
 
 [filter:tempauth]
 use = egg:swift#tempauth
diff --git a/functions b/functions
new file mode 100644
index 0000000..01c4758
--- /dev/null
+++ b/functions
@@ -0,0 +1,91 @@
+# functions - Common functions used by DevStack components
+
+
+# apt-get wrapper to set arguments correctly
+# apt_get package [package ...]
+function apt_get() {
+    [[ "$OFFLINE" = "True" ]] && return
+    local sudo="sudo"
+    [[ "$(id -u)" = "0" ]] && sudo="env"
+    $sudo DEBIAN_FRONTEND=noninteractive \
+        http_proxy=$http_proxy https_proxy=$https_proxy \
+        apt-get --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
+}
+
+
+# Gracefully cp only if source file/dir exists
+# cp_it source destination
+function cp_it {
+    if [ -e $1 ] || [ -d $1 ]; then
+        cp -pRL $1 $2
+    fi
+}
+
+
+# git clone only if directory doesn't exist already.  Since ``DEST`` might not
+# be owned by the installation user, we create the directory and change the
+# ownership to the proper user.
+# Set global RECLONE=yes to simulate a clone when dest-dir exists
+# git_clone remote dest-dir branch
+function git_clone {
+    [[ "$OFFLINE" = "True" ]] && return
+
+    GIT_REMOTE=$1
+    GIT_DEST=$2
+    GIT_BRANCH=$3
+
+    if echo $GIT_BRANCH | egrep -q "^refs"; then
+        # If our branch name is a gerrit style refs/changes/...
+        if [[ ! -d $GIT_DEST ]]; then
+            git clone $GIT_REMOTE $GIT_DEST
+        fi
+        cd $GIT_DEST
+        git fetch $GIT_REMOTE $GIT_BRANCH && git checkout FETCH_HEAD
+    else
+        # do a full clone only if the directory doesn't exist
+        if [[ ! -d $GIT_DEST ]]; then
+            git clone $GIT_REMOTE $GIT_DEST
+            cd $GIT_DEST
+            # This checkout syntax works for both branches and tags
+            git checkout $GIT_BRANCH
+        elif [[ "$RECLONE" == "yes" ]]; then
+            # if it does exist then simulate what clone does if asked to RECLONE
+            cd $GIT_DEST
+            # set the url to pull from and fetch
+            git remote set-url origin $GIT_REMOTE
+            git fetch origin
+            # remove the existing ignored files (like pyc) as they cause breakage
+            # (due to the py files having older timestamps than our pyc, so python
+            # thinks the pyc files are correct using them)
+            find $GIT_DEST -name '*.pyc' -delete
+            git checkout -f origin/$GIT_BRANCH
+            # a local branch might not exist
+            git branch -D $GIT_BRANCH || true
+            git checkout -b $GIT_BRANCH
+        fi
+    fi
+}
+
+
+# pip install wrapper to set cache and proxy environment variables
+# pip_install package [package ...]
+function pip_install {
+    [[ "$OFFLINE" = "True" ]] && return
+    sudo PIP_DOWNLOAD_CACHE=/var/cache/pip \
+        HTTP_PROXY=$http_proxy \
+        HTTPS_PROXY=$https_proxy \
+        pip install --use-mirrors $@
+}
+
+
+# Normalize config values to True or False
+# VAR=`trueorfalse default-value test-value`
+function trueorfalse() {
+    local default=$1
+    local testval=$2
+
+    [[ -z "$testval" ]] && { echo "$default"; return; }
+    [[ "0 no false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
+    [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
+    echo "$default"
+}
diff --git a/stack.sh b/stack.sh
index de6effa..cccde29 100755
--- a/stack.sh
+++ b/stack.sh
@@ -35,6 +35,9 @@
 # Keep track of the current devstack directory.
 TOP_DIR=$(cd $(dirname "$0") && pwd)
 
+# Import common functions
+. $TOP_DIR/functions
+
 # stack.sh keeps the list of **apt** and **pip** dependencies in external
 # files, along with config templates and other useful files.  You can find these
 # in the ``files`` directory (next to this script).  We will reference this
@@ -86,18 +89,8 @@
 # Destination path for installation ``DEST``
 DEST=${DEST:-/opt/stack}
 
-# apt-get wrapper to just get arguments set correctly
-function apt_get() {
-    [[ "$OFFLINE" = "True" ]] && return
-    local sudo="sudo"
-    [ "$(id -u)" = "0" ] && sudo="env"
-    $sudo DEBIAN_FRONTEND=noninteractive \
-        http_proxy=$http_proxy https_proxy=$https_proxy \
-        apt-get --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
-}
-
 # Check to see if we are already running a stack.sh
-if screen -ls | egrep -q "[0-9].stack"; then
+if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].stack"; then
     echo "You are already running a stack.sh session."
     echo "To rejoin this session type 'screen -x stack'."
     echo "To destroy this session, kill the running screen."
@@ -155,18 +148,6 @@
     sudo mv $TEMPFILE /etc/sudoers.d/stack_sh_nova
 fi
 
-# Normalize config values to True or False
-# VAR=`trueorfalse default-value test-value`
-function trueorfalse() {
-    local default=$1
-    local testval=$2
-
-    [[ -z "$testval" ]] && { echo "$default"; return; }
-    [[ "0 no false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
-    [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
-    echo "$default"
-}
-
 # Set True to configure stack.sh to run cleanly without Internet access.
 # stack.sh must have been previously run with Internet access to install
 # prerequisites and initialize $DEST.
@@ -542,14 +523,6 @@
     done
 }
 
-function pip_install {
-    [[ "$OFFLINE" = "True" ]] && return
-    sudo PIP_DOWNLOAD_CACHE=/var/cache/pip \
-        HTTP_PROXY=$http_proxy \
-        HTTPS_PROXY=$https_proxy \
-        pip install --use-mirrors $@
-}
-
 # install apt requirements
 apt_get update
 apt_get install $(get_packages)
@@ -557,48 +530,6 @@
 # install python requirements
 pip_install `cat $FILES/pips/* | uniq`
 
-# git clone only if directory doesn't exist already.  Since ``DEST`` might not
-# be owned by the installation user, we create the directory and change the
-# ownership to the proper user.
-function git_clone {
-    [[ "$OFFLINE" = "True" ]] && return
-
-    GIT_REMOTE=$1
-    GIT_DEST=$2
-    GIT_BRANCH=$3
-
-    if echo $GIT_BRANCH | egrep -q "^refs"; then
-        # If our branch name is a gerrit style refs/changes/...
-        if [ ! -d $GIT_DEST ]; then
-            git clone $GIT_REMOTE $GIT_DEST
-        fi
-        cd $GIT_DEST
-        git fetch $GIT_REMOTE $GIT_BRANCH && git checkout FETCH_HEAD
-    else
-        # do a full clone only if the directory doesn't exist
-        if [ ! -d $GIT_DEST ]; then
-            git clone $GIT_REMOTE $GIT_DEST
-            cd $GIT_DEST
-            # This checkout syntax works for both branches and tags
-            git checkout $GIT_BRANCH
-        elif [[ "$RECLONE" == "yes" ]]; then
-            # if it does exist then simulate what clone does if asked to RECLONE
-            cd $GIT_DEST
-            # set the url to pull from and fetch
-            git remote set-url origin $GIT_REMOTE
-            git fetch origin
-            # remove the existing ignored files (like pyc) as they cause breakage
-            # (due to the py files having older timestamps than our pyc, so python
-            # thinks the pyc files are correct using them)
-            find $GIT_DEST -name '*.pyc' -delete
-            git checkout -f origin/$GIT_BRANCH
-            # a local branch might not exist
-            git branch -D $GIT_BRANCH || true
-            git checkout -b $GIT_BRANCH
-        fi
-    fi
-}
-
 # compute service
 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
 # python client library to nova that horizon (and others) use
diff --git a/stackrc b/stackrc
index d30bf66..2274e62 100644
--- a/stackrc
+++ b/stackrc
@@ -15,8 +15,8 @@
 GLANCE_BRANCH=master
 
 # unified auth system (manages accounts/tokens)
-KEYSTONE_REPO=https://github.com/termie/keystonelight.git
-KEYSTONE_BRANCH=master
+KEYSTONE_REPO=https://github.com/openstack/keystone.git
+KEYSTONE_BRANCH=redux
 
 # a websockets/html5 or flash powered VNC console for vm instances
 NOVNC_REPO=https://github.com/cloudbuilders/noVNC.git
diff --git a/tools/build_ramdisk.sh b/tools/build_ramdisk.sh
index feaa8a9..7c1600b 100755
--- a/tools/build_ramdisk.sh
+++ b/tools/build_ramdisk.sh
@@ -47,7 +47,10 @@
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
-TOP_DIR=`cd $TOOLS_DIR/..; pwd`
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+. $TOP_DIR/functions
 
 # Store cwd
 CWD=`pwd`
@@ -170,35 +173,6 @@
     chroot $MNTDIR apt-get install -y linux-generic
 fi
 
-# git clone only if directory doesn't exist already.  Since ``DEST`` might not
-# be owned by the installation user, we create the directory and change the
-# ownership to the proper user.
-function git_clone {
-
-    # clone new copy or fetch latest changes
-    CHECKOUT=${MNTDIR}$2
-    if [ ! -d $CHECKOUT ]; then
-        mkdir -p $CHECKOUT
-        git clone $1 $CHECKOUT
-    else
-        pushd $CHECKOUT
-        git fetch
-        popd
-    fi
-
-    # FIXME(ja): checkout specified version (should works for branches and tags)
-
-    pushd $CHECKOUT
-    # checkout the proper branch/tag
-    git checkout $3
-    # force our local version to be the same as the remote version
-    git reset --hard origin/$3
-    popd
-
-    # give ownership to the stack user
-    chroot $MNTDIR chown -R stack $2
-}
-
 git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
 git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
 git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
diff --git a/tools/build_tempest.sh b/tools/build_tempest.sh
index aa44766..230e8f9 100755
--- a/tools/build_tempest.sh
+++ b/tools/build_tempest.sh
@@ -26,7 +26,10 @@
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
-TOP_DIR=`cd $TOOLS_DIR/..; pwd`
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+. $TOP_DIR/functions
 
 # Abort if localrc is not set
 if [ ! -e $TOP_DIR/localrc ]; then
@@ -43,42 +46,8 @@
 
 TEMPEST_DIR=$DEST/tempest
 
-DIST_NAME=${DIST_NAME:-oneiric}
-
-# git clone only if directory doesn't exist already.  Since ``DEST`` might not
-# be owned by the installation user, we create the directory and change the
-# ownership to the proper user.
-function git_clone {
-
-    GIT_REMOTE=$1
-    GIT_DEST=$2
-    GIT_BRANCH=$3
-
-    # do a full clone only if the directory doesn't exist
-    if [ ! -d $GIT_DEST ]; then
-        git clone $GIT_REMOTE $GIT_DEST
-        cd $2
-        # This checkout syntax works for both branches and tags
-        git checkout $GIT_BRANCH
-    elif [[ "$RECLONE" == "yes" ]]; then
-        # if it does exist then simulate what clone does if asked to RECLONE
-        cd $GIT_DEST
-        # set the url to pull from and fetch
-        git remote set-url origin $GIT_REMOTE
-        git fetch origin
-        # remove the existing ignored files (like pyc) as they cause breakage
-        # (due to the py files having older timestamps than our pyc, so python
-        # thinks the pyc files are correct using them)
-        find $GIT_DEST -name '*.pyc' -delete
-        git checkout -f origin/$GIT_BRANCH
-        # a local branch might not exist
-        git branch -D $GIT_BRANCH || true
-        git checkout -b $GIT_BRANCH
-    fi
-}
-
 # Install tests and prerequisites
-sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install --use-mirrors `cat $TOP_DIR/files/pips/tempest`
+pip_install `cat $TOP_DIR/files/pips/tempest`
 
 git_clone $TEMPEST_REPO $TEMPEST_DIR $TEMPEST_BRANCH
 
diff --git a/tools/build_uec.sh b/tools/build_uec.sh
index 04e1a45..ed5a017 100755
--- a/tools/build_uec.sh
+++ b/tools/build_uec.sh
@@ -8,7 +8,10 @@
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
-TOP_DIR=`cd $TOOLS_DIR/..; pwd`
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+. $TOP_DIR/functions
 
 cd $TOP_DIR
 
@@ -34,7 +37,7 @@
 
 # Install deps if needed
 DEPS="kvm libvirt-bin kpartx cloud-utils curl"
-apt-get install -y --force-yes $DEPS || true # allow this to fail gracefully for concurrent builds
+apt_get install -y --force-yes $DEPS || true # allow this to fail gracefully for concurrent builds
 
 # Where to store files and instances
 WORK_DIR=${WORK_DIR:-/opt/uecstack}
diff --git a/tools/build_uec_ramdisk.sh b/tools/build_uec_ramdisk.sh
index 174eaac..32f90c0 100755
--- a/tools/build_uec_ramdisk.sh
+++ b/tools/build_uec_ramdisk.sh
@@ -40,7 +40,10 @@
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
-TOP_DIR=`cd $TOOLS_DIR/..; pwd`
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+. $TOP_DIR/functions
 
 cd $TOP_DIR
 
@@ -68,7 +71,7 @@
 
 # Install deps if needed
 DEPS="kvm libvirt-bin kpartx cloud-utils curl"
-apt-get install -y --force-yes $DEPS
+apt_get install -y --force-yes $DEPS
 
 # Where to store files and instances
 CACHEDIR=${CACHEDIR:-/opt/stack/cache}
@@ -113,35 +116,6 @@
     chroot $MNT_DIR apt-get install -y linux-generic
 fi
 
-# git clone only if directory doesn't exist already.  Since ``DEST`` might not
-# be owned by the installation user, we create the directory and change the
-# ownership to the proper user.
-function git_clone {
-
-    # clone new copy or fetch latest changes
-    CHECKOUT=${MNT_DIR}$2
-    if [ ! -d $CHECKOUT ]; then
-        mkdir -p $CHECKOUT
-        git clone $1 $CHECKOUT
-    else
-        pushd $CHECKOUT
-        git fetch
-        popd
-    fi
-
-    # FIXME(ja): checkout specified version (should works for branches and tags)
-
-    pushd $CHECKOUT
-    # checkout the proper branch/tag
-    git checkout $3
-    # force our local version to be the same as the remote version
-    git reset --hard origin/$3
-    popd
-
-    # give ownership to the stack user
-    chroot $MNT_DIR chown -R stack $2
-}
-
 git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
 git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
 git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
diff --git a/tools/configure_tempest.sh b/tools/configure_tempest.sh
index 00add9a..f6ef0d3 100755
--- a/tools/configure_tempest.sh
+++ b/tools/configure_tempest.sh
@@ -30,7 +30,10 @@
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
-TOP_DIR=`cd $TOOLS_DIR/..; pwd`
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+. $TOP_DIR/functions
 
 # Abort if localrc is not set
 if [ ! -e $TOP_DIR/localrc ]; then
diff --git a/tools/copy_dev_environment_to_uec.sh b/tools/copy_dev_environment_to_uec.sh
index c949b32..d5687dc 100755
--- a/tools/copy_dev_environment_to_uec.sh
+++ b/tools/copy_dev_environment_to_uec.sh
@@ -8,7 +8,10 @@
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
-TOP_DIR=`cd $TOOLS_DIR/..; pwd`
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+. $TOP_DIR/functions
 
 # Change dir to top of devstack
 cd $TOP_DIR
@@ -47,13 +50,6 @@
 ( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \
     > $STAGING_DIR/etc/sudoers.d/50_stack_sh )
 
-# Gracefully cp only if source file/dir exists
-function cp_it {
-    if [ -e $1 ] || [ -d $1 ]; then
-        cp -pRL $1 $2
-    fi
-}
-
 # Copy over your ssh keys and env if desired
 cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
 cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
diff --git a/tools/get_uec_image.sh b/tools/get_uec_image.sh
index f66f2bc..0963074 100755
--- a/tools/get_uec_image.sh
+++ b/tools/get_uec_image.sh
@@ -6,7 +6,10 @@
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
-TOP_DIR=`cd $TOOLS_DIR/..; pwd`
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+. $TOP_DIR/functions
 
 # exit on error to stop unexpected errors
 set -o errexit
diff --git a/tools/xen/README.md b/tools/xen/README.md
index 63350ea..a3398a7 100644
--- a/tools/xen/README.md
+++ b/tools/xen/README.md
@@ -54,7 +54,16 @@
     ACTIVE_TIMEOUT=45
     EOF
 
-Step 4: Run ./build_domU.sh
+Step 4: Run ./build_xva.sh
+--------------------------
+This script prpares your nova xva image.  This script can be run on a separate machine
+and copied to dom0.  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)
+
+It is likely that for XS6 you will need to build_xva.sh on a separate machine due
+to dom0 space constraints.
+
+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:
@@ -63,7 +72,7 @@
 * 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!
 
-Step 5: Do cloudy stuff!
+Step 6: Do cloudy stuff!
 --------------------------
 * Play with horizon
 * Play with the CLI
diff --git a/tools/xen/build_domU.sh b/tools/xen/build_domU.sh
index 642b40f..cd28f15 100755
--- a/tools/xen/build_domU.sh
+++ b/tools/xen/build_domU.sh
@@ -10,42 +10,18 @@
 # This directory
 TOP_DIR=$(cd $(dirname "$0") && pwd)
 
-# Source params
-cd ../.. && source ./stackrc && cd $TOP_DIR
+# Source params - override xenrc params in your localrc to suite your taste
+source xenrc
 
 # Echo commands
 set -o xtrace
 
-# Name of this guest
-GUEST_NAME=${GUEST_NAME:-ALLINONE}
-
-# dom0 ip
-HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
-
-# Our nova host's network info 
-VM_IP=${VM_IP:-10.255.255.255} # A host-only ip that let's the interface come up, otherwise unused
-MGT_IP=${MGT_IP:-172.16.100.55}
-PUB_IP=${PUB_IP:-192.168.1.55}
-
-# Public network
-PUB_BR=${PUB_BR:-xenbr0}
-PUB_NETMASK=${PUB_NETMASK:-255.255.255.0}
-
-# VM network params
-VM_NETMASK=${VM_NETMASK:-255.255.255.0}
-VM_BR=${VM_BR:-xapi1}
-VM_VLAN=${VM_VLAN:-100}
-
-# MGMT network params
-MGT_NETMASK=${MGT_NETMASK:-255.255.255.0}
-MGT_BR=${MGT_BR:-xapi2}
-MGT_VLAN=${MGT_VLAN:-101}
-
-# VM Password
-GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
-
-# Size of image
-VDI_MB=${VDI_MB:-2500}
+# 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
 
 # Make sure we have git
 if ! which git; then
@@ -95,6 +71,9 @@
 create_vlan $PIF $VM_VLAN $VM_NET
 create_vlan $PIF $MGT_VLAN $MGT_NET
 
+# dom0 ip
+HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
+
 # Setup host-only nat rules
 HOST_NET=169.254.0.0/16
 if ! iptables -L -v -t nat | grep -q $HOST_NET; then
@@ -117,86 +96,9 @@
 # Enable ip forwarding at runtime as well
 echo 1 > /proc/sys/net/ipv4/ip_forward
 
-# 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
-
-# Make sure we have a stage
-if [ ! -d $STAGING_DIR/etc ]; then
-    echo "Stage is not properly set up!"
-    exit 1
-fi
-
-# Directory where our conf files are stored
-FILES_DIR=$TOP_DIR/files
-TEMPLATES_DIR=$TOP_DIR/templates
-
-# Directory for supporting script files
-SCRIPT_DIR=$TOP_DIR/scripts
-
-# Version of ubuntu with which we are working
-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-//"`
-
-# 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
-
-# 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
-
-# Directory for xvas
-XVA_DIR=$TOP_DIR/xvas
-
-# Create xva dir
-mkdir -p $XVA_DIR
+# 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
 
 # Clean nova if desired
 if [ "$CLEAN" = "1" ]; then
@@ -210,24 +112,12 @@
     git checkout $NOVA_BRANCH
 fi 
 
-# Run devstack on launch
-cat <<EOF >$STAGING_DIR/etc/rc.local
-GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ DO_TGZ=0 bash /opt/stack/devstack/tools/xen/prepare_guest.sh
-su -c "/opt/stack/run.sh > /opt/stack/run.sh.log" stack
-exit 0
-EOF
-
 # 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
 
-# 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
-
-
 # Shutdown previous runs
 DO_SHUTDOWN=${DO_SHUTDOWN:-1}
 if [ "$DO_SHUTDOWN" = "1" ]; then
@@ -248,68 +138,6 @@
     done
 fi
 
-# Path to head xva.  By default keep overwriting the same one to save space
-USE_SEPARATE_XVAS=${USE_SEPARATE_XVAS:-0}
-if [ "$USE_SEPARATE_XVAS" = "0" ]; then
-    XVA=$XVA_DIR/$UBUNTU_VERSION.xva 
-else
-    XVA=$XVA_DIR/$UBUNTU_VERSION.$GUEST_NAME.xva 
-fi
-
-# 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
-
-# Hostname must resolve for rabbit
-cat <<EOF >$STAGING_DIR/etc/hosts
-$MGT_IP $GUEST_NAME
-127.0.0.1 localhost localhost.localdomain
-EOF
-
-# Configure the network
-INTERFACES=$STAGING_DIR/etc/network/interfaces
-cp $TEMPLATES_DIR/interfaces.in  $INTERFACES
-sed -e "s,@ETH1_IP@,$VM_IP,g" -i $INTERFACES
-sed -e "s,@ETH1_NETMASK@,$VM_NETMASK,g" -i $INTERFACES
-sed -e "s,@ETH2_IP@,$MGT_IP,g" -i $INTERFACES
-sed -e "s,@ETH2_NETMASK@,$MGT_NETMASK,g" -i $INTERFACES
-sed -e "s,@ETH3_IP@,$PUB_IP,g" -i $INTERFACES
-sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
-
-# Gracefully cp only if source file/dir exists
-function cp_it {
-    if [ -e $1 ] || [ -d $1 ]; then
-        cp -pRL $1 $2
-    fi
-}
-
-# Copy over your ssh keys and env if desired
-COPYENV=${COPYENV:-1}
-if [ "$COPYENV" = "1" ]; then
-    cp_it ~/.ssh $STAGING_DIR/opt/stack/.ssh
-    cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/opt/stack/.ssh/authorized_keys
-    cp_it ~/.gitconfig $STAGING_DIR/opt/stack/.gitconfig
-    cp_it ~/.vimrc $STAGING_DIR/opt/stack/.vimrc
-    cp_it ~/.bashrc $STAGING_DIR/opt/stack/.bashrc
-fi
-
-# Configure run.sh
-cat <<EOF >$STAGING_DIR/opt/stack/run.sh
-#!/bin/bash
-cd /opt/stack/devstack
-killall screen
-UPLOAD_LEGACY_TTY=yes HOST_IP=$PUB_IP VIRT_DRIVER=xenserver FORCE=yes MULTI_HOST=1 $STACKSH_PARAMS ./stack.sh
-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
-
 # Start guest
 $TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR
 
diff --git a/tools/xen/build_xva.sh b/tools/xen/build_xva.sh
new file mode 100755
index 0000000..e4de2a1
--- /dev/null
+++ b/tools/xen/build_xva.sh
@@ -0,0 +1,164 @@
+#!/bin/bash
+
+# Abort if localrc is not set
+if [ ! -e ../../localrc ]; then
+    echo "You must have a localrc with ALL necessary passwords defined before proceeding."
+    echo "See the xen README for required passwords."
+    exit 1
+fi
+
+# This directory
+TOP_DIR=$(cd $(dirname "$0") && pwd)
+
+# Source params - override xenrc params in your localrc to suite your taste
+source xenrc
+
+# Echo commands
+set -o xtrace
+
+# 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
+
+# Make sure we have a stage
+if [ ! -d $STAGING_DIR/etc ]; then
+    echo "Stage is not properly set up!"
+    exit 1
+fi
+
+# Directory where our conf files are stored
+FILES_DIR=$TOP_DIR/files
+TEMPLATES_DIR=$TOP_DIR/templates
+
+# Directory for supporting script files
+SCRIPT_DIR=$TOP_DIR/scripts
+
+# Version of ubuntu with which we are working
+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
+
+# 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
+GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ DO_TGZ=0 bash /opt/stack/devstack/tools/xen/prepare_guest.sh
+su -c "/opt/stack/run.sh > /opt/stack/run.sh.log" 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
+
+# Hostname must resolve for rabbit
+cat <<EOF >$STAGING_DIR/etc/hosts
+$MGT_IP $GUEST_NAME
+127.0.0.1 localhost localhost.localdomain
+EOF
+
+# Configure the network
+INTERFACES=$STAGING_DIR/etc/network/interfaces
+cp $TEMPLATES_DIR/interfaces.in  $INTERFACES
+sed -e "s,@ETH1_IP@,$VM_IP,g" -i $INTERFACES
+sed -e "s,@ETH1_NETMASK@,$VM_NETMASK,g" -i $INTERFACES
+sed -e "s,@ETH2_IP@,$MGT_IP,g" -i $INTERFACES
+sed -e "s,@ETH2_NETMASK@,$MGT_NETMASK,g" -i $INTERFACES
+sed -e "s,@ETH3_IP@,$PUB_IP,g" -i $INTERFACES
+sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
+
+# Gracefully cp only if source file/dir exists
+function cp_it {
+    if [ -e $1 ] || [ -d $1 ]; then
+        cp -pRL $1 $2
+    fi
+}
+
+# Copy over your ssh keys and env if desired
+COPYENV=${COPYENV:-1}
+if [ "$COPYENV" = "1" ]; then
+    cp_it ~/.ssh $STAGING_DIR/opt/stack/.ssh
+    cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/opt/stack/.ssh/authorized_keys
+    cp_it ~/.gitconfig $STAGING_DIR/opt/stack/.gitconfig
+    cp_it ~/.vimrc $STAGING_DIR/opt/stack/.vimrc
+    cp_it ~/.bashrc $STAGING_DIR/opt/stack/.bashrc
+fi
+
+# Configure run.sh
+cat <<EOF >$STAGING_DIR/opt/stack/run.sh
+#!/bin/bash
+cd /opt/stack/devstack
+killall screen
+UPLOAD_LEGACY_TTY=yes HOST_IP=$PUB_IP VIRT_DRIVER=xenserver FORCE=yes MULTI_HOST=1 $STACKSH_PARAMS ./stack.sh
+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 $XVA.  If your dom0 is on a different machine, copy this to [devstackdir]/tools/xen/$XVA"
diff --git a/tools/xen/xenrc b/tools/xen/xenrc
new file mode 100644
index 0000000..246ac16
--- /dev/null
+++ b/tools/xen/xenrc
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+# Name of this guest
+GUEST_NAME=${GUEST_NAME:-ALLINONE}
+
+# Size of image
+VDI_MB=${VDI_MB:-2500}
+
+# VM Password
+GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
+
+# Our nova host's network info 
+VM_IP=${VM_IP:-10.255.255.255} # A host-only ip that let's the interface come up, otherwise unused
+MGT_IP=${MGT_IP:-172.16.100.55}
+PUB_IP=${PUB_IP:-192.168.1.55}
+
+# Public network
+PUB_BR=${PUB_BR:-xenbr0}
+PUB_NETMASK=${PUB_NETMASK:-255.255.255.0}
+
+# VM network params
+VM_NETMASK=${VM_NETMASK:-255.255.255.0}
+VM_BR=${VM_BR:-xapi1}
+VM_VLAN=${VM_VLAN:-100}
+
+# MGMT network params
+MGT_NETMASK=${MGT_NETMASK:-255.255.255.0}
+MGT_BR=${MGT_BR:-xapi2}
+MGT_VLAN=${MGT_VLAN:-101}
+
+# XVA Directory
+XVA_DIR=${XVA_DIR:-xvas}
+
+# Path to xva file
+XVA=${XVA:-$XVA_DIR/$GUEST_NAME.xva }
+
+# Source params
+cd ../.. && source ./stackrc && cd $TOP_DIR