Multiple vpx for xen, post splitting of script

Ensure building, installing multiple nova vms works after we
split the build script as build nova vm, install nova vm.

Change-Id: Iadb6e181caec511325a30727bf9e9c79e8afea5a
diff --git a/tools/xen/build_domU.sh b/tools/xen/build_domU.sh
index 5ea03da..ce11b0a 100755
--- a/tools/xen/build_domU.sh
+++ b/tools/xen/build_domU.sh
@@ -182,7 +182,7 @@
 if [ -z $PUB_BR ]; then
     PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge)
 fi
-$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR
+$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -w
 
 # If we have copied our ssh credentials, use ssh to monitor while the installation runs
 WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
diff --git a/tools/xen/build_domU_multi.sh b/tools/xen/build_domU_multi.sh
index 130bec5..0285f42 100755
--- a/tools/xen/build_domU_multi.sh
+++ b/tools/xen/build_domU_multi.sh
@@ -17,19 +17,19 @@
 COMMON_VARS="$STACKSH_PARAMS MYSQL_HOST=$HEAD_MGT_IP RABBIT_HOST=$HEAD_MGT_IP GLANCE_HOSTPORT=$HEAD_MGT_IP:9292 FLOATING_RANGE=$FLOATING_RANGE"
 
 # Helper to launch containers
-function build_domU {
-    GUEST_NAME=$1 PUB_IP=$2 MGT_IP=$3 DO_SHUTDOWN=$4 TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $5" ./build_domU.sh
+function build_xva {
+    GUEST_NAME=$1 PUB_IP=$2 MGT_IP=$3 DO_SHUTDOWN=$4 TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $5" ./build_xva.sh
 }
 
 # Launch the head node - headnode uses a non-ip domain name,
 # because rabbit won't launch with an ip addr hostname :(
-build_domU HEADNODE $HEAD_PUB_IP $HEAD_MGT_IP 1 "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,horizon,mysql,rabbit"
+build_xva HEADNODE $HEAD_PUB_IP $HEAD_MGT_IP 1 "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,horizon,mysql,rabbit"
 
 # Wait till the head node is up
-while ! curl -L http://$HEAD_PUB_IP | grep -q username; do
-    echo "Waiting for head node ($HEAD_PUB_IP) to start..."
-    sleep 5
-done
+#while ! curl -L http://$HEAD_PUB_IP | grep -q username; do
+#    echo "Waiting for head node ($HEAD_PUB_IP) to start..."
+#    sleep 5
+#done
 
 # Build the HA compute host
-build_domU $COMPUTE_PUB_IP $COMPUTE_PUB_IP $COMPUTE_MGT_IP 0 "ENABLED_SERVICES=n-cpu,n-net,n-api"
+build_xva COMPUTENODE $COMPUTE_PUB_IP $COMPUTE_MGT_IP 0 "ENABLED_SERVICES=n-cpu,n-net,n-api"
diff --git a/tools/xen/install_domU_multi.sh b/tools/xen/install_domU_multi.sh
new file mode 100755
index 0000000..91129c5
--- /dev/null
+++ b/tools/xen/install_domU_multi.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+
+# Echo commands
+set -o xtrace
+
+# Head node host, which runs glance, api, keystone
+HEAD_PUB_IP=${HEAD_PUB_IP:-192.168.1.57}
+HEAD_MGT_IP=${HEAD_MGT_IP:-172.16.100.57}
+
+COMPUTE_PUB_IP=${COMPUTE_PUB_IP:-192.168.1.58}
+COMPUTE_MGT_IP=${COMPUTE_MGT_IP:-172.16.100.58}
+
+# Networking params
+FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30}
+
+# Variables common amongst all hosts in the cluster
+COMMON_VARS="$STACKSH_PARAMS MYSQL_HOST=$HEAD_MGT_IP RABBIT_HOST=$HEAD_MGT_IP GLANCE_HOSTPORT=$HEAD_MGT_IP:9292 FLOATING_RANGE=$FLOATING_RANGE"
+
+# Helper to launch containers
+function install_domU {
+    GUEST_NAME=$1 PUB_IP=$2 MGT_IP=$3 DO_SHUTDOWN=$4 TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $5" ./build_domU.sh
+}
+
+# Launch the head node - headnode uses a non-ip domain name,
+# because rabbit won't launch with an ip addr hostname :(
+install_domU HEADNODE $HEAD_PUB_IP $HEAD_MGT_IP 1 "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,horizon,mysql,rabbit"
+
+if [ $HEAD_PUB_IP == "dhcp" ]
+then
+    guestnet=$(xe vm-list --minimal name-label=HEADNODE params=networks)
+    HEAD_PUB_IP=$(echo $guestnet | grep -w -o --only-matching "3/ip: [0-9,.]*;" | cut -d ':' -f2 | cut -d ';' -f 1)
+fi
+# Wait till the head node is up
+while ! curl -L http://$HEAD_PUB_IP | grep -q username; do
+    echo "Waiting for head node ($HEAD_PUB_IP) to start..."
+    sleep 5
+done
+
+# Build the HA compute host
+install_domU COMPUTENODE $COMPUTE_PUB_IP $COMPUTE_MGT_IP 0 "ENABLED_SERVICES=n-cpu,n-net,n-api"
diff --git a/tools/xen/scripts/install-os-vpx.sh b/tools/xen/scripts/install-os-vpx.sh
index 9aebb13..f0dc3c2 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]
+            [-k PARAMS] [-r RAM] [-i|-c] [-w] [-b] [-l NAME_LABEL]
 
   Installs XenServer OpenStack VPX.
 
@@ -60,6 +60,7 @@
      -k params    Specifies kernel parameters.
      -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.
 
   EXAMPLES:
 
@@ -87,7 +88,7 @@
 
 get_params()
 {
-  while getopts "hicwbf:d:v:m:p:k:r:" OPTION; 
+  while getopts "hicwbf:d:v:m:p:k:r:l:" OPTION; 
   do
     case $OPTION in
       h) usage
@@ -126,6 +127,9 @@
       v)
          BRIDGE_V=$OPTARG
          ;;
+     l)
+         NAME_LABEL=$OPTARG
+         ;;
       ?)
          usage
          exit
@@ -443,7 +447,7 @@
 
   renumber_system_disk "$vm_uuid"
 
-  nl=$(xe_min vm-list params=name-label uuid=$vm_uuid)
+  nl=${NAME_LABEL:-$(xe_min vm-list params=name-label uuid=$vm_uuid)}
   xe vm-param-set \
     "name-label=${nl/ import/}" \
     other-config:os-vpx=true \