#! /bin/bash -x
#
# ST - 2012-07-03
#
# Start the compute node model.
#
# Get the directory of the script.
SCRIPT_PATH=`dirname $0`
# Get the script name.
SCRIPT_NAME=`basename $0`
# Source the common configuration variables.
. $SCRIPT_PATH/c-i-a-b.common
#
CURRENT_HOST_NAME=$COMPUTE_NODE_MODEL_HOST_NAME
#
CPUS_LIST=$COMPUTE_NODE_MODEL_CPUS_LIST
CPUS=""
for i in $CPUS_LIST
  do
    if [ "x$CPUS" == "x" ]
      then
        CPUS=$i
      else
        CPUS="$CPUS,$i"
    fi
done
#
# Start the virtual machine
#
xm create $CONST_XEN_CONFIG_DIR/$CURRENT_HOST_NAME.cfg
#
# Wait until the virtual machine has started
#
IS_RUNNING=""
while [ -z "$IS_RUNNING" ]
  do
    IS_RUNNING=`xm list | grep $CURRENT_HOST_NAME`
    sleep 1
done
#
# Pin the VCPUs to "real" CPUs.
#
VCPU_NUM=0
for i in $CPUS_LIST
  do
    xm vcpu-pin $CURRENT_HOST_NAME $VCPU_NUM $i
    VCPU_NUM=$((VCPU_NUM + 1))
done
#
exit 0
