Added new cluster scripts.
Modified onos.sh to use host-specific config file by default.
Modified onos.sh interactive prompt to ignore the letter case.
Moved old cluster scripts to old-scripts dir.

Change-Id: I2d580bedeaec7dde2bab8a4a39a49752fbb3de0c
diff --git a/cluster-mgmt/conf/onos-cluster.conf b/cluster-mgmt/conf/onos-cluster.conf
new file mode 100644
index 0000000..73b228d
--- /dev/null
+++ b/cluster-mgmt/conf/onos-cluster.conf
@@ -0,0 +1,60 @@
+### Cluster-wide settings ###
+# List of host names/addresses constitute ONOS cluster
+# NOTE: Order of names affects ZooKeeper myid
+cluster.hosts.names = onosdev1, onosdev2, onosdev3, onosdev4
+
+# Back-end module to store topology/flows
+cluster.hosts.backend = ramcloud
+#cluster.hosts.backend = hazelcast
+
+# Protocol used by RAMCloud cluster (fast+udp by default)
+#cluster.hosts.ramcloud.protocol = fast+udp
+
+# Communication method used for Hazelcast communication
+#cluster.hosts.hazelcast.network = multicast
+cluster.hosts.hazelcast.network = tcp-ip
+
+# Multicast address used by Hazelcast datagrid (224.2.2.3 by default)
+# Valid only if cluster.hosts.hazelcast.network is set to "multicast"
+#cluster.hosts.hazelcast.multicast.address = 224.2.2.3
+
+# Multicast port used by Hazelcast datagrid (54327 by default)
+# Valid only if cluster.hosts.hazelcast.network is set to "multicast"
+#cluster.hosts.hazelcast.multicast.port = 54327
+
+### Host-specific settings ###
+# IP address of host used for ONOS communication (resolved hostname by default)
+#cluster.onosdev1.ip = 192.168.56.11
+
+# Role of host
+cluster.onosdev1.role = rc-coord-and-server
+
+# IP address or hostname of host used for ZooKeeper communication (cluster.onosdev1.ip by default)
+#cluster.onosdev1.zk.host = 192.168.56.11
+
+# IP address of host used for RAMCloud communication (cluster.onosdev1.ip by default)
+#cluster.onosdev1.ramcloud.ip = 192.168.56.11
+
+# Port number used by RAMCloud coordinator (12246 by default)
+#cluster.onosdev1.ramcloud.coordinator.port = 12246
+
+# Port number used by RAMCloud server (12242 by default)
+#cluster.onosdev1.ramcloud.server.port = 12242
+
+# IP address of host used for Hazelcast communication (cluster.onosdev1.ip by default)
+# Valid only if cluster.hosts.hazelcast.network is set to "tcp-ip"
+#cluster.onosdev1.hazelcast.ip = 192.168.56.11
+
+# At least role must be specified for all hosts
+cluster.onosdev2.role = rc-server
+cluster.onosdev3.role = rc-server
+cluster.onosdev4.role = rc-server
+
+
+### SSH settings used for delivering config files ###
+# Common username used to login host (current user by default)
+#remote.common.ssh.user = mininet
+
+# Host-specific username settings
+#remote.onosdev1.ssh.user = mininet
+#remote.onosdev2.ssh.user = mininet
diff --git a/cluster-mgmt/conf/template/onos_node.conf.template b/cluster-mgmt/conf/template/onos_node.conf.template
new file mode 100644
index 0000000..b6e069d
--- /dev/null
+++ b/cluster-mgmt/conf/template/onos_node.conf.template
@@ -0,0 +1,44 @@
+# Name of this host (`hostname` by default)
+host.name = __HOST_NAME__
+
+# IP address of this host used for ONOS communication
+host.ip = __HOST_IP__
+
+# Role of this host
+host.role = __ONOS_ROLE__
+
+# Back-end module to store topology/flows
+host.backend = __BACKEND__
+
+# List of host name/IPs that constitute ZooKeeper cluster
+# myid will be assigned incrementally according to order of list
+zookeeper.hosts = __ZK_HOSTS__
+
+# Protocol used by RAMCloud coordinator (fast+udp by default)
+ramcloud.coordinator.protocol = __RAMCLOUD_PROTOCOL__
+
+# IP address of RAMCloud coordinator (host.ip by default)
+ramcloud.coordinator.ip = __RAMCLOUD_IP__
+
+# Port number of RAMCloud coordinator (12246 by default)
+ramcloud.coordinator.port = __RAMCLOUD_COORD_PORT__
+
+# Protocol used by RAMCloud server (fast+udp by default)
+ramcloud.server.protocol = __RAMCLOUD_PROTOCOL__
+
+# IP address of RAMCloud server (host.ip by default)
+ramcloud.server.ip = __RAMCLOUD_IP__
+
+# Port number of RAMCloud server (12242 by default)
+ramcloud.server.port = __RAMCLOUD_SERVER_PORT__
+
+# List of hostname/ip[:port] which forms Hazelcast datagrid
+# If this value is empty, Hazelcast will be set to multicast mode.
+# Inversely, if this value is set, multicast settings will be ignored.
+hazelcast.tcp-ip.members = __HAZELCAST_MEMBERS__
+
+# Multicast address used by Hazelcast. (224.2.2.3 by default)
+hazelcast.multicast.group = __HAZELCAST_MULTICAST_GROUP__
+
+# Multicast port used by Hazelcast. (54327 by default)
+#hazelcast.multicast.port = __HAZELCAST_MULTICAST_PORT__
\ No newline at end of file
diff --git a/cluster-mgmt/onos-cluster.sh b/cluster-mgmt/onos-cluster.sh
new file mode 100755
index 0000000..e1cceb8
--- /dev/null
+++ b/cluster-mgmt/onos-cluster.sh
@@ -0,0 +1,328 @@
+#! /bin/bash
+
+set -e
+
+### Env vars used by this script. (default value) ###
+# $ONOS_HOME         : path of root directory of ONOS repository (~/ONOS)
+# $ONOS_CLUSTER_HOME : path of ONOS cluster tools directory (this script's dir)
+# $REMOTE_ONOS_HOME  : path of root directory of ONOS repository in remote hosts (ONOS)
+# $SSH               : command name to access host
+# $PSSH              : command name to access hosts in parallel
+# $SCP               : command name to copy config file to each host
+#####################################################
+
+
+### Variables read from ONOS config file ###
+ONOS_HOME=${ONOS_HOME:-${HOME}/ONOS}
+
+source ${ONOS_HOME}/scripts/common/utils.sh
+
+CLUSTER_HOME=${ONOS_CLUSTER_HOME:-$(cd `dirname $0`; pwd)}
+CLUSTER_CONF_DIR=${CLUSTER_HOME}/conf
+CLUSTER_CONF=${ONOS_CLUSTER_CONF:-${CLUSTER_CONF_DIR}/onos-cluster.conf}
+CLUSTER_TEMPLATE_DIR=${CLUSTER_CONF_DIR}/template
+
+REMOTE_ONOS_HOME=${REMOTE_ONOS_HOME:-ONOS}
+REMOTE_ONOS_CONF_DIR=${REMOTE_ONOS_HOME}/conf
+
+if [ ! -f ${CLUSTER_CONF} ]; then
+  echo "${CLUSTER_CONF} not found."
+  exit 1
+fi
+CLUSTER_HOSTS=$(read-conf ${CLUSTER_CONF}       cluster.hosts.names             `hostname` | tr ',' ' ')
+CLUSTER_BACKEND=$(read-conf ${CLUSTER_CONF}     cluster.hosts.backend)
+CLUSTER_RC_PROTOCOL=$(read-conf ${CLUSTER_CONF} cluster.hosts.ramcloud.protocol "fast+udp")
+CLUSTER_HC_NETWORK=$(read-conf ${CLUSTER_CONF}  cluster.hosts.hazelcast.network)
+CLUSTER_HC_ADDR=$(read-conf ${CLUSTER_CONF}     cluster.hosts.hazelcast.multicast.address "224.2.2.3")
+CLUSTER_HC_PORT=$(read-conf ${CLUSTER_CONF}     cluster.hosts.hazelcast.multicast.port    "54327")
+############################################
+
+
+ONOS_CONF_TEMPLATE=${CLUSTER_TEMPLATE_DIR}/onos_node.conf.template
+
+
+### Parallel SSH settings ###
+SSH=${SSH:-ssh}
+PSSH=${PSSH:-parallel-ssh}
+PSSH_CONF=${CLUSTER_CONF_DIR}/pssh.hosts
+SCP=${SCP:-scp}
+#############################
+
+
+############# Common functions #############
+function print_usage {
+  local filename=`basename ${ONOS_CLUSTER_CONF}`
+  local usage="Usage: setup/deploy/start/stop/status ONOS cluster.
+ \$ $0 setup [-f]
+    Set up ONOS cluster using ${filename}.
+    If -f option is used, all existing files will be overwritten without confirmation.
+ \$ $0 deploy [-f]
+    Deliver node config files to cluster nodes.
+    If -f option is used, all existing files will be overwritten without confirmation.
+ \$ $0 start
+    Start ONOS cluster
+ \$ $0 stop
+    Stop ONOS cluster
+ \$ $0 status
+    Show status of ONOS-cluster"
+  
+  echo "${usage}"	
+}
+
+############################################
+
+
+############# Setup functions ##############
+
+function list-zk-hosts {
+  local list=()
+  for host in ${CLUSTER_HOSTS}; do 
+    local zk_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.zk.host")
+    
+    if [ -z ${zk_host_string} ]; then
+      # falling back to ip
+      zk_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.ip")
+    fi
+    if [ -z ${zk_host_string} ]; then
+      # falling back to hostname
+      zk_host_string=${host}
+    fi
+    
+    list=("${list[@]}" ${zk_host_string})
+  done
+  
+  # join with comma
+  local IFS=,
+  echo "${list[*]}"
+}
+
+function list-hc-hosts {
+  local list=()
+  for host in ${CLUSTER_HOSTS}; do 
+    local hc_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.hazelcast.ip")
+    
+    if [ -z ${hc_host_string} ]; then
+      # falling back to ip
+      hc_host_string=$(read-conf ${CLUSTER_CONF} "cluster.${host}.ip")
+    fi
+    
+    if [ -z ${hc_host_string} ]; then
+      # falling back to hostname
+      hc_host_string=${host}
+    fi
+    
+    list=("${list[@]}" ${hc_host_string})
+  done
+  
+  local IFS=,
+  echo "${list[*]}"
+}
+
+function create-pssh-conf {
+  local tempfile=`begin-conf-creation ${PSSH_CONF}`
+  
+  # creation of pssh config file
+  for host in ${CLUSTER_HOSTS}; do
+    local user=$(read-conf ${CLUSTER_CONF} remote.${host}.ssh.user)
+    if [ -z ${user} ]; then
+      # falling back to common setting
+      user=$(read-conf ${CLUSTER_CONF} remote.common.ssh.user)
+    fi
+    
+    if [ -z ${user} ]; then
+      echo ${host} >> ${tempfile}
+    else
+      echo ${user}@${host} >> ${tempfile}
+    fi
+  done
+  
+  end-conf-creation ${PSSH_CONF}
+}
+
+# create-onos-conf {hostname}
+function create-onos-conf {
+  local host_name=${1}
+  
+  if [ -z ${host_name} ]; then
+    echo "FAILED"
+    echo "[ERROR] invalid hostname ${host_name}"
+    exit 1
+  fi
+  
+  local onos_conf="${CLUSTER_CONF_DIR}/onos_node.${host_name}.conf"
+  local tempfile=`begin-conf-creation ${onos_conf}`
+
+  cp ${ONOS_CONF_TEMPLATE} ${tempfile}
+  
+  local prefix="cluster.${host}"
+  
+  local host_ip=$(read-conf ${CLUSTER_CONF} "${prefix}.ip")
+  local host_string=${host_ip}
+  if [ -z "${host_string}" ]; then
+    host_string=${host_name}
+  fi
+  local host_role=$(read-conf ${CLUSTER_CONF} "${prefix}.role")
+  local zk_hosts=`list-zk-hosts`
+  local rc_ip=$(read-conf ${CLUSTER_CONF} "${prefix}.ramcloud.ip" ${host_string})
+  local rc_coord_port=$(read-conf ${CLUSTER_CONF} "${prefix}.ramcloud.coordinator.port" 12246)
+  local rc_server_port=$(read-conf ${CLUSTER_CONF} "${prefix}.ramcloud.server.port" 12242)
+  local hc_hosts=`list-hc-hosts`
+  
+  # creation of ONOS node config file
+  sed -i -e "s|__HOST_NAME__|${host_name}|" ${tempfile}
+  if [ -z "${host_ip}" ]; then
+    # comment out
+    sed -i -e "s|^\(.*__HOST_IP__.*\)$|#\1|" ${tempfile}
+  else
+    sed -i -e "s|__HOST_IP__|${host_ip}|" ${tempfile}
+  fi
+  sed -i -e "s|__ONOS_ROLE__|${host_role}|" ${tempfile}
+  sed -i -e "s|__BACKEND__|${CLUSTER_BACKEND}|" ${tempfile}
+  sed -i -e "s|__ZK_HOSTS__|${zk_hosts}|" ${tempfile}
+  sed -i -e "s|__RAMCLOUD_PROTOCOL__|${CLUSTER_RC_PROTOCOL}|" ${tempfile}
+  sed -i -e "s|__RAMCLOUD_IP__|${rc_ip}|" ${tempfile}
+  sed -i -e "s|__RAMCLOUD_COORD_PORT__|${rc_coord_port}|" ${tempfile}
+  sed -i -e "s|__RAMCLOUD_SERVER_PORT__|${rc_server_port}|" ${tempfile}
+  
+  if [ ${CLUSTER_HC_NETWORK} = "tcp-ip" ]; then
+    sed -i -e "s|__HAZELCAST_MEMBERS__|${hc_hosts}|" ${tempfile}
+    
+    # Comment out unused parameters
+    sed -i -e "s|^\(.*__HAZELCAST_MULTICAST_GROUP__.*\)$|#\1|" ${tempfile}
+    sed -i -e "s|^\(.*__HAZELCAST_MULTICAST_PORT__.*\)$|#\1|" ${tempfile}
+  elif [ ${CLUSTER_HC_NETWORK} = "multicast" ]; then
+    sed -i -e "s|__HAZELCAST_MULTICAST_GROUP__|${CLUSTER_HC_ADDR}|" ${tempfile}
+    sed -i -e "s|__HAZELCAST_MULTICAST_PORT__|${CLUSTER_HC_PORT}|" ${tempfile}
+    
+    sed -i -e "s|^\(.*__HAZELCAST_MEMBERS__.*\)$|#\1|" ${tempfile}
+  fi
+ 
+  end-conf-creation ${onos_conf}
+}
+
+# setup -f : force overwrite existing files
+function setup {
+  if [ "${1}" = "-f" ]; then
+    create-pssh-conf
+    
+    for host in ${CLUSTER_HOSTS}; do 
+      create-onos-conf ${host}
+    done
+  else
+    create-conf-interactive ${PSSH_CONF} create-pssh-conf
+    
+    for host in ${CLUSTER_HOSTS}; do 
+      local filename="${CLUSTER_CONF_DIR}/onos_node.${host}.conf"
+      create-conf-interactive ${filename} create-onos-conf ${host}
+    done
+  fi
+}
+
+############################################
+
+
+############ Deploy functions ##############
+
+function deploy {
+  if [ ! -f ${PSSH_CONF} ]; then
+    echo "[ERROR] ${PSSH_CONF} not found"
+    local command=`basename ${0}`
+    echo "[ERROR] Try \"${command} setup\" to create files."
+    exit 1
+  fi
+
+  for host in ${CLUSTER_HOSTS}; do
+    local conf=${CLUSTER_CONF_DIR}/onos_node.${host}.conf
+    if [ ! -f ${conf} ]; then
+      echo "[ERROR] ${conf} not found"
+      local command=`basename ${0}`
+      echo "[ERROR] Try \"${command} setup\" to create files."
+      exit 1
+    fi
+      
+    local user=$(read-conf ${CLUSTER_CONF} "remote.${host}.ssh.user")
+    if [ -z ${user} ]; then
+      # falling back to common setting
+      user=$(read-conf ${CLUSTER_CONF} "remote.common.ssh.user")
+    fi
+      
+    ${SCP} ${conf} ${user}@${host}:${REMOTE_ONOS_CONF_DIR}
+    ${SSH} ${user}@${host} "cd ${REMOTE_ONOS_HOME}; ./onos.sh setup -f"
+  done
+ 
+# TODO: Replacing per-host ssh command with pssh command below.
+#       Need to solve concurrency problem when ONOS directory is shared among hosts.
+#  ${PSSH} -i -h ${PSSH_CONF} "cd ${REMOTE_ONOS_HOME}; ./onos.sh setup -f"
+}
+############################################
+
+
+############# Start functions ##############
+
+function start {
+  if [ ! -f ${PSSH_CONF} ]; then
+    echo "[ERROR] ${PSSH_CONF} not found"
+    local command=`basename ${0}`
+    echo "[ERROR] Try \"${command} setup\" to create files."
+    exit 1
+  fi
+  
+  ${PSSH} -i -h ${PSSH_CONF} "cd ${REMOTE_ONOS_HOME}; ./onos.sh start"
+}
+
+############################################
+
+
+############# Stop functions $##############
+
+function stop {
+  if [ ! -f ${PSSH_CONF} ]; then
+    echo "[ERROR] ${PSSH_CONF} not found"
+    local command=`basename ${0}`
+    echo "[ERROR] Try \"${command} setup\" to create files."
+    exit 1
+  fi
+  
+  ${PSSH} -i -h ${PSSH_CONF} "cd ${REMOTE_ONOS_HOME}; ./onos.sh stop"
+}
+
+############################################
+
+
+############ Status functions ##############
+
+function status {
+  if [ ! -f ${PSSH_CONF} ]; then
+    echo "[ERROR] ${PSSH_CONF} not found"
+    local command=`basename ${0}`
+    echo "[ERROR] Try \"${command} setup\" to create files."
+    exit 1
+  fi
+  
+  ${PSSH} -i -h ${PSSH_CONF} "cd ${REMOTE_ONOS_HOME}; ./onos.sh status"
+}
+
+############################################
+
+
+################## Main ####################
+case "$1" in
+  setup)
+    setup $2
+    ;;
+  deploy)
+    deploy
+    ;;
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  stat*) # <- status
+    status
+    ;;
+  *)
+    print_usage
+    exit 1
+esac
diff --git a/cluster-mgmt/README.txt b/old-scripts/cluster-mgmt/README.txt
similarity index 100%
rename from cluster-mgmt/README.txt
rename to old-scripts/cluster-mgmt/README.txt
diff --git a/cluster-mgmt/bash_profile b/old-scripts/cluster-mgmt/bash_profile
similarity index 100%
rename from cluster-mgmt/bash_profile
rename to old-scripts/cluster-mgmt/bash_profile
diff --git a/cluster-mgmt/bin/bootup.sh b/old-scripts/cluster-mgmt/bin/bootup.sh
similarity index 100%
rename from cluster-mgmt/bin/bootup.sh
rename to old-scripts/cluster-mgmt/bin/bootup.sh
diff --git a/cluster-mgmt/bin/cassandra b/old-scripts/cluster-mgmt/bin/cassandra
similarity index 100%
rename from cluster-mgmt/bin/cassandra
rename to old-scripts/cluster-mgmt/bin/cassandra
diff --git a/cluster-mgmt/bin/check_status.py b/old-scripts/cluster-mgmt/bin/check_status.py
similarity index 100%
rename from cluster-mgmt/bin/check_status.py
rename to old-scripts/cluster-mgmt/bin/check_status.py
diff --git a/cluster-mgmt/bin/check_status_failover.py b/old-scripts/cluster-mgmt/bin/check_status_failover.py
similarity index 100%
rename from cluster-mgmt/bin/check_status_failover.py
rename to old-scripts/cluster-mgmt/bin/check_status_failover.py
diff --git a/cluster-mgmt/bin/cho-failover.py b/old-scripts/cluster-mgmt/bin/cho-failover.py
similarity index 100%
rename from cluster-mgmt/bin/cho-failover.py
rename to old-scripts/cluster-mgmt/bin/cho-failover.py
diff --git a/cluster-mgmt/bin/cho-link-failure.py b/old-scripts/cluster-mgmt/bin/cho-link-failure.py
similarity index 100%
rename from cluster-mgmt/bin/cho-link-failure.py
rename to old-scripts/cluster-mgmt/bin/cho-link-failure.py
diff --git a/cluster-mgmt/bin/cho-link-failure.sh b/old-scripts/cluster-mgmt/bin/cho-link-failure.sh
similarity index 100%
rename from cluster-mgmt/bin/cho-link-failure.sh
rename to old-scripts/cluster-mgmt/bin/cho-link-failure.sh
diff --git a/cluster-mgmt/bin/cmd b/old-scripts/cluster-mgmt/bin/cmd
similarity index 100%
rename from cluster-mgmt/bin/cmd
rename to old-scripts/cluster-mgmt/bin/cmd
diff --git a/cluster-mgmt/bin/comp-nwmap-sw.py b/old-scripts/cluster-mgmt/bin/comp-nwmap-sw.py
similarity index 100%
rename from cluster-mgmt/bin/comp-nwmap-sw.py
rename to old-scripts/cluster-mgmt/bin/comp-nwmap-sw.py
diff --git a/cluster-mgmt/bin/config.sh b/old-scripts/cluster-mgmt/bin/config.sh
similarity index 100%
rename from cluster-mgmt/bin/config.sh
rename to old-scripts/cluster-mgmt/bin/config.sh
diff --git a/cluster-mgmt/bin/demo-reset-hw.sh b/old-scripts/cluster-mgmt/bin/demo-reset-hw.sh
similarity index 100%
rename from cluster-mgmt/bin/demo-reset-hw.sh
rename to old-scripts/cluster-mgmt/bin/demo-reset-hw.sh
diff --git a/cluster-mgmt/bin/demo-scale-out-hw.sh b/old-scripts/cluster-mgmt/bin/demo-scale-out-hw.sh
similarity index 100%
rename from cluster-mgmt/bin/demo-scale-out-hw.sh
rename to old-scripts/cluster-mgmt/bin/demo-scale-out-hw.sh
diff --git a/cluster-mgmt/bin/func.sh b/old-scripts/cluster-mgmt/bin/func.sh
similarity index 100%
rename from cluster-mgmt/bin/func.sh
rename to old-scripts/cluster-mgmt/bin/func.sh
diff --git a/cluster-mgmt/bin/known_hosts.sh b/old-scripts/cluster-mgmt/bin/known_hosts.sh
similarity index 100%
rename from cluster-mgmt/bin/known_hosts.sh
rename to old-scripts/cluster-mgmt/bin/known_hosts.sh
diff --git a/cluster-mgmt/bin/onos b/old-scripts/cluster-mgmt/bin/onos
similarity index 100%
rename from cluster-mgmt/bin/onos
rename to old-scripts/cluster-mgmt/bin/onos
diff --git a/cluster-mgmt/bin/pingall-speedup.sh b/old-scripts/cluster-mgmt/bin/pingall-speedup.sh
similarity index 100%
rename from cluster-mgmt/bin/pingall-speedup.sh
rename to old-scripts/cluster-mgmt/bin/pingall-speedup.sh
diff --git a/cluster-mgmt/bin/ssh_exec b/old-scripts/cluster-mgmt/bin/ssh_exec
similarity index 100%
rename from cluster-mgmt/bin/ssh_exec
rename to old-scripts/cluster-mgmt/bin/ssh_exec
diff --git a/cluster-mgmt/bin/start.sh b/old-scripts/cluster-mgmt/bin/start.sh
similarity index 100%
rename from cluster-mgmt/bin/start.sh
rename to old-scripts/cluster-mgmt/bin/start.sh
diff --git a/cluster-mgmt/bin/status.sh b/old-scripts/cluster-mgmt/bin/status.sh
similarity index 100%
rename from cluster-mgmt/bin/status.sh
rename to old-scripts/cluster-mgmt/bin/status.sh
diff --git a/cluster-mgmt/bin/stop.sh b/old-scripts/cluster-mgmt/bin/stop.sh
similarity index 100%
rename from cluster-mgmt/bin/stop.sh
rename to old-scripts/cluster-mgmt/bin/stop.sh
diff --git a/cluster-mgmt/bin/switch b/old-scripts/cluster-mgmt/bin/switch
similarity index 100%
rename from cluster-mgmt/bin/switch
rename to old-scripts/cluster-mgmt/bin/switch
diff --git a/cluster-mgmt/bin/test-link-failure.sh b/old-scripts/cluster-mgmt/bin/test-link-failure.sh
similarity index 100%
rename from cluster-mgmt/bin/test-link-failure.sh
rename to old-scripts/cluster-mgmt/bin/test-link-failure.sh
diff --git a/cluster-mgmt/bin/zk b/old-scripts/cluster-mgmt/bin/zk
similarity index 100%
rename from cluster-mgmt/bin/zk
rename to old-scripts/cluster-mgmt/bin/zk
diff --git a/cluster-mgmt/common/authorized_keys b/old-scripts/cluster-mgmt/common/authorized_keys
similarity index 100%
rename from cluster-mgmt/common/authorized_keys
rename to old-scripts/cluster-mgmt/common/authorized_keys
diff --git a/cluster-mgmt/common/hosts b/old-scripts/cluster-mgmt/common/hosts
similarity index 100%
rename from cluster-mgmt/common/hosts
rename to old-scripts/cluster-mgmt/common/hosts
diff --git a/cluster-mgmt/common/known_hosts b/old-scripts/cluster-mgmt/common/known_hosts
similarity index 100%
rename from cluster-mgmt/common/known_hosts
rename to old-scripts/cluster-mgmt/common/known_hosts
diff --git a/cluster-mgmt/common/zoo.cfg b/old-scripts/cluster-mgmt/common/zoo.cfg
similarity index 100%
rename from cluster-mgmt/common/zoo.cfg
rename to old-scripts/cluster-mgmt/common/zoo.cfg
diff --git a/cluster-mgmt/cp-config.sh b/old-scripts/cluster-mgmt/cp-config.sh
similarity index 100%
rename from cluster-mgmt/cp-config.sh
rename to old-scripts/cluster-mgmt/cp-config.sh
diff --git a/cluster-mgmt/cp-mininet.sh b/old-scripts/cluster-mgmt/cp-mininet.sh
similarity index 100%
rename from cluster-mgmt/cp-mininet.sh
rename to old-scripts/cluster-mgmt/cp-mininet.sh
diff --git a/cluster-mgmt/make-config.sh b/old-scripts/cluster-mgmt/make-config.sh
similarity index 100%
rename from cluster-mgmt/make-config.sh
rename to old-scripts/cluster-mgmt/make-config.sh
diff --git a/cluster-mgmt/make-mininet.sh b/old-scripts/cluster-mgmt/make-mininet.sh
similarity index 100%
rename from cluster-mgmt/make-mininet.sh
rename to old-scripts/cluster-mgmt/make-mininet.sh
diff --git a/cluster-mgmt/ssh/authorized_keys b/old-scripts/cluster-mgmt/ssh/authorized_keys
similarity index 100%
rename from cluster-mgmt/ssh/authorized_keys
rename to old-scripts/cluster-mgmt/ssh/authorized_keys
diff --git a/cluster-mgmt/ssh/id_rsa.pub b/old-scripts/cluster-mgmt/ssh/id_rsa.pub
similarity index 100%
rename from cluster-mgmt/ssh/id_rsa.pub
rename to old-scripts/cluster-mgmt/ssh/id_rsa.pub
diff --git a/cluster-mgmt/start-mininet.sh b/old-scripts/cluster-mgmt/start-mininet.sh
similarity index 100%
rename from cluster-mgmt/start-mininet.sh
rename to old-scripts/cluster-mgmt/start-mininet.sh
diff --git a/cluster-mgmt/template/cassandra.yaml b/old-scripts/cluster-mgmt/template/cassandra.yaml
similarity index 100%
rename from cluster-mgmt/template/cassandra.yaml
rename to old-scripts/cluster-mgmt/template/cassandra.yaml
diff --git a/cluster-mgmt/template/hosts b/old-scripts/cluster-mgmt/template/hosts
similarity index 100%
rename from cluster-mgmt/template/hosts
rename to old-scripts/cluster-mgmt/template/hosts
diff --git a/cluster-mgmt/template/onsdemo_core.py b/old-scripts/cluster-mgmt/template/onsdemo_core.py
similarity index 100%
rename from cluster-mgmt/template/onsdemo_core.py
rename to old-scripts/cluster-mgmt/template/onsdemo_core.py
diff --git a/cluster-mgmt/template/onsdemo_core.py.devA b/old-scripts/cluster-mgmt/template/onsdemo_core.py.devA
similarity index 100%
rename from cluster-mgmt/template/onsdemo_core.py.devA
rename to old-scripts/cluster-mgmt/template/onsdemo_core.py.devA
diff --git a/cluster-mgmt/template/onsdemo_edge_template.py b/old-scripts/cluster-mgmt/template/onsdemo_edge_template.py
similarity index 100%
rename from cluster-mgmt/template/onsdemo_edge_template.py
rename to old-scripts/cluster-mgmt/template/onsdemo_edge_template.py
diff --git a/cluster-mgmt/template/tunnel_onsdemo_core_template.sh b/old-scripts/cluster-mgmt/template/tunnel_onsdemo_core_template.sh
similarity index 100%
rename from cluster-mgmt/template/tunnel_onsdemo_core_template.sh
rename to old-scripts/cluster-mgmt/template/tunnel_onsdemo_core_template.sh
diff --git a/cluster-mgmt/template/tunnel_onsdemo_edge_template.sh b/old-scripts/cluster-mgmt/template/tunnel_onsdemo_edge_template.sh
similarity index 100%
rename from cluster-mgmt/template/tunnel_onsdemo_edge_template.sh
rename to old-scripts/cluster-mgmt/template/tunnel_onsdemo_edge_template.sh
diff --git a/cluster-mgmt/template/zoo.cfg b/old-scripts/cluster-mgmt/template/zoo.cfg
similarity index 100%
rename from cluster-mgmt/template/zoo.cfg
rename to old-scripts/cluster-mgmt/template/zoo.cfg
diff --git a/onos.sh b/onos.sh
index d10f907..039f806 100755
--- a/onos.sh
+++ b/onos.sh
@@ -3,7 +3,7 @@
 ### Env vars used by this script. (default value) ###
 # $ONOS_HOME       : path of root directory of ONOS repository (this script's dir)
 # $ONOS_CONF_DIR   : path of ONOS config directory (~/ONOS/conf)
-# $ONOS_CONF       : path of ONOS node config file (~/ONOS/conf/onos_node.conf)
+# $ONOS_CONF       : path of ONOS node config file (~/ONOS/conf/onos_node.`hostname`.conf or onos_node.conf)
 # $ONOS_PROPS      : path of ONOS properties file (~/ONOS/conf/onos.properties)
 # $ONOS_LOGBACK    : path of logback config file (~/ONOS/conf/logback.`hostname`.xml)
 # $LOGDIR          : path of log output directory (~/ONOS/onos-logs)
@@ -28,11 +28,15 @@
 
 ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)}
 ONOS_CONF_DIR=${ONOS_CONF_DIR:-${ONOS_HOME}/conf}
-ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.conf}
+ONOS_CONF=${ONOS_CONF:-${ONOS_CONF_DIR}/onos_node.`hostname`.conf}
 
 if [ ! -f ${ONOS_CONF} ]; then
-  echo "${ONOS_CONF} not found."
-  exit 1
+  # falling back to default config file
+  ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf
+  if [ ! -f ${ONOS_CONF} ]; then
+    echo "${ONOS_CONF} not found."
+    exit 1
+  fi
 fi
 
 
@@ -191,6 +195,16 @@
   done
 }
 
+function handle-error {
+  set -e
+  
+  revert-confs
+  
+  set +e
+  
+  exit 1
+}
+
 # revert-file {filename}
 # revert "filename" from "filename.bak" if "filename.tmp" exists.
 function revert-file {
@@ -208,8 +222,6 @@
 
 # revert-confs [error message]
 function revert-confs {
-  set -e
-  
   echo -n "ERROR occurred ... "
   
   revert-file `basename ${ZK_CONF}`
@@ -220,10 +232,6 @@
   if [ ! -z "$1" ]; then
     echo $1
   fi
-  
-  set +e
-  
-  exit 1
 }
 
 function create-zk-conf {
@@ -248,7 +256,7 @@
   local i=1
   local myid=
   for host in ${hostarr}; do
-    if [ ${host} = ${ONOS_HOST_NAME} ]; then
+    if [ "${host}" = "${ONOS_HOST_NAME}" -o "${host}" = "${ONOS_HOST_IP}" ]; then
       myid=$i
       break
     fi
@@ -257,7 +265,7 @@
   
   if [ -z "${myid}" ]; then
     local filename=`basename ${ONOS_CONF}`
-    revert-confs "[ERROR in ${filename}] zookeeper.hosts must have hostname \"${ONOS_HOST_NAME}\""
+    revert-confs "[ERROR in ${filename}] zookeeper.hosts must have hostname \"${ONOS_HOST_NAME}\" or IP address"
   fi
   
   if [ -f "${ZK_MY_ID}" ]; then
@@ -369,10 +377,10 @@
     echo -n "Overwriting ${filename} [Y/n]? "
     while [ 1 ]; do
       read key
-      if [ -z "${key}" -o "${key}" == "Y" ]; then
+      if [ -z "${key}" -o "${key}" == "Y" -o "${key}" == "y" ]; then
         ${func}
         break
-      elif [ "${key}" == "n" ]; then
+      elif [ "${key}" == "N" -o "${key}" == "n" ]; then
         break
       fi
       echo "[Y/n]?"
@@ -386,7 +394,7 @@
   local key
   local filename
   
-  trap revert-confs ERR
+  trap handle-error ERR
 
   if [ "$1" == "-f" ]; then
     create-zk-conf
@@ -397,7 +405,6 @@
     create-conf-interactive ${HC_CONF} create-hazelcast-conf
     create-conf-interactive ${ONOS_LOGBACK} create-logback-conf
   fi
-
   
   trap - ERR
 }
diff --git a/scripts/common/utils.sh b/scripts/common/utils.sh
new file mode 100644
index 0000000..0eaf0f8
--- /dev/null
+++ b/scripts/common/utils.sh
@@ -0,0 +1,79 @@
+#! /bin/bash
+
+# read-conf {filename} {parameter name} [default value]
+function read-conf {
+  local value=`grep ^${2} ${1} | cut -d "=" -f 2 | sed -e 's/^[ \t]*//'`
+  if [ -z "${value}" ]; then
+    echo $3
+  else
+    echo ${value}
+  fi
+}
+
+# revert-file {filename}
+# revert "filename" from "filename.bak" if "filename.tmp" exists.
+function revert-file {
+  local filename=$1
+  local temp="${filename}.tmp"
+  local backup="${filename}.bak"
+  
+  if [ -f "${temp}" ]; then
+    echo -n "reverting ${filename} ... "
+    mv ${backup} ${filename}
+    rm ${temp}
+    echo "DONE"
+  fi
+}
+
+# create-conf-interactive {filename} {function to create conf} [param to function]
+function create-conf-interactive {
+  local filepath=$1
+  local filename=`basename ${filepath}`
+  local func=$2
+  
+  if [ -f ${filepath} ]; then
+    # confirmation to overwrite existing config file
+    echo -n "Overwriting ${filename} [Y/n]? "
+    while [ 1 ]; do
+      read key
+      if [ -z "${key}" -o "${key}" == "Y" -o "${key}" == "y" ]; then
+        ${func} $3
+        break
+      elif [ "${key}" == "N" -o "${key}" == "n" ]; then
+        break
+      fi
+      echo "[Y/n]?"
+    done
+  else
+    ${func} $3
+  fi
+}
+
+# begin-conf-creation {config file name}
+function begin-conf-creation {
+  local conf=${1}
+  local backup="${conf}.bak"
+  local temp="${conf}.tmp"
+  
+  if [ -f ${conf} ]; then
+    mv ${conf} ${backup}
+    local filename=`basename ${backup}`
+  fi
+  
+  if [ -f ${temp} ]; then
+    rm ${temp}
+  fi
+  
+  touch ${temp}
+
+  echo ${temp}
+}
+
+
+# end-conf-creation {config file name}
+function end-conf-creation {
+  local conf=${1}
+  local temp="${conf}.tmp"
+  
+  mv ${temp} ${conf}
+}