Determine the system_type based upon hostname 87/38887/1
authorAndrew Grimberg <agrimberg@linuxfoundation.org>
Fri, 13 May 2016 19:27:04 +0000 (12:27 -0700)
committerAndrew Grimberg <agrimberg@linuxfoundation.org>
Fri, 13 May 2016 19:27:04 +0000 (12:27 -0700)
Use the slave host name to determine the system_type that should be used
for the final spin-up control script.

If a slave name should map to a different one, then a spin-up script of
the correct name should be created which then calls the appropriate
script.

Change-Id: I511362d3f762970c2ea6c3b2ee457b01833723fd
Signed-off-by: Andrew Grimberg <agrimberg@linuxfoundation.org>
jenkins-scripts/system_type.sh [new file with mode: 0755]

diff --git a/jenkins-scripts/system_type.sh b/jenkins-scripts/system_type.sh
new file mode 100755 (executable)
index 0000000..201f34f
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
+##############################################################################
+# Copyright (c) 2016 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+HOST=$(/usr/bin/hostname)
+SYSTEM_TYPE=''
+
+# We use a separator character of - for the slave parts
+IFS='-' read -r -a HOSTPARTS <<< "${HOST}"
+
+# slurp in the control scripts
+FILES=($(find . -maxdepth 1 -type f -iname '*.sh' -exec basename -s '.sh' {} \;))
+# remap into an associative array
+declare -A A_FILES
+for key in "${!FILES[@]}"
+do
+    A_FILES[${FILES[$key]}]="${key}"
+done
+
+# Find our system_type control script if possible
+for i in "${HOSTPARTS[@]}"
+do
+    if [ "${A_FILES[${i}]}" != "" ]
+    then
+        SYSTEM_TYPE=${i}
+        break
+    fi
+done
+
+# Write out the system type to an environment file to then be sourced
+echo "SYSTEM_TYPE=${SYSTEM_TYPE}" > /tmp/system_type.sh
+
+# vim: sw=4 ts=4 sts=4 et :