summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJirka Hladky <hladky.jiri@gmail.com>2019-04-01 17:30:08 +0200
committerMartin Styk <mastyk@redhat.com>2019-05-10 11:24:38 +0000
commit25ca6b220a48e229d3436fef2c5db32006c92231 (patch)
treef5ca120bd6cae2ba55eb9784a782f3f4bb818d20
parent36f3c3ebda591e61a4817d515499a2a1536636f0 (diff)
Added amtc_bkr power script
-rwxr-xr-xLabController/src/bkr/labcontroller/power-scripts/amtc_bkr97
1 files changed, 97 insertions, 0 deletions
diff --git a/LabController/src/bkr/labcontroller/power-scripts/amtc_bkr b/LabController/src/bkr/labcontroller/power-scripts/amtc_bkr
new file mode 100755
index 0000000..1f65843
--- /dev/null
+++ b/LabController/src/bkr/labcontroller/power-scripts/amtc_bkr
@@ -0,0 +1,97 @@
+#!/bin/sh
+
+#Copyright (C) 2018,2019 Jirka Hladky (hladky DOT jiri AT gmail DOT com)
+
+#=============================================
+#Beaker agent for AMT 9.0+ hosts
+#
+#Usage:
+#power_mode=off power_pass=SECRET power_address=w541-mgmt.my_domain.com ./amtc_bkr
+#power_mode=on power_pass=SECRET power_address=w541-mgmt.my_domain.com ./amtc_bkr
+
+#It relies on the amtc tool :
+#https://github.com/schnoddelbotz/amtc
+#rpm packages: https://github.com/schnoddelbotz/amtc/releases
+#=============================================
+
+set -e
+set -x
+VERSION=1.0
+
+# amtc actions
+# -I(nfo) query powerstate via AMT [default]
+# -U(p) powerup given host(s)
+# -D(own) powerdown
+# -C(ycle) powercycle
+# -R(eset) reset
+# -X select PXE as device for next boot (AMT 9.0+)
+# -H select HDD as device for next boot (AMT 9.0+)
+# -S(hutdown) using AMT graceful shutdown (AMT 9.0+)
+# -(re)B(oot) using AMT graceful reset (AMT 9.0+)
+
+if [ "$power_mode" == interrupt ] ; then
+ echo "interrupt not supported by amtc" >&2
+ exit 1
+elif [ "$power_mode" = "on" ] ; then
+ operation="-U"
+else
+ operation="-D"
+fi
+
+
+target_mode="$power_mode"
+
+know_target_mode() {
+ [ "$power_mode" == "on" -o "$power_mode" == "off" ]
+}
+
+get_current_mode() {
+ current_mode=$(AMT_PASSWORD="$power_pass" amtc -I -d "$power_address" | grep -o "on\|off")
+}
+
+in_target_mode() {
+ get_current_mode
+ [ "$current_mode" == "$target_mode" ]
+}
+
+
+if know_target_mode && in_target_mode ; then
+ AMT_PASSWORD="$power_pass" amtc -R -d "$power_address"
+ sleep 20
+ echo "State as reported by amtc -I" >&2
+ AMT_PASSWORD="$power_pass" amtc -I -d "$power_address"
+ if know_target_mode && in_target_mode ; then
+ exit 0
+ fi
+fi
+
+AMT_PASSWORD="$power_pass" amtc ${operation} -d "$power_address"
+
+if know_target_mode ; then
+ for i in $(seq 20) ; do
+ if in_target_mode ; then
+ exit 0
+ fi
+ sleep 1
+ done
+ echo "Timed out waiting for $target_mode (Status: $current_mode)" >&2
+ echo "State as reported by amtc -I" >&2
+ AMT_PASSWORD="$power_pass" amtc -I -d "$power_address"
+ echo "Trying Power Reset as the last option"
+
+ AMT_PASSWORD="$power_pass" amtc -R -d "$power_address"
+ sleep 20
+ AMT_PASSWORD="$power_pass" amtc ${operation} -d "$power_address"
+
+ for i in $(seq 20) ; do
+ if in_target_mode ; then
+ exit 0
+ fi
+ sleep 1
+ done
+ echo "Timed out waiting for $target_mode (Status: $current_mode)" >&2
+ echo "Giving up" >&2
+ echo "State as reported by amtc -I" >&2
+ AMT_PASSWORD="$power_pass" amtc -I -d "$power_address"
+ echo "amtc_bkr version ${VERSION}" >&2
+fi