Blob Blame History Raw
From 5cb174f204865d7ffe6d9edbfe8177b54bd61b49 Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac@redhat.com>
Date: Wed, 3 Sep 2014 14:22:38 +0200
Subject: [PATCH] fence_ilo_ssh: New fence agent for HP iLO3/4 via SSH

Resolves: rhbz#1121122
---
 configure.ac                          |  1 +
 fence/agents/ilo_ssh/Makefile.am      | 20 ++++++++++
 fence/agents/ilo_ssh/fence_ilo_ssh.py | 73 +++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
 create mode 100644 fence/agents/ilo_ssh/Makefile.am
 create mode 100644 fence/agents/ilo_ssh/fence_ilo_ssh.py

diff --git a/configure.ac b/configure.ac
index 0569dfe..b603878 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,7 @@ AC_CONFIG_FILES([Makefile
 		 fence/agents/ilo/Makefile
 		 fence/agents/ilo_moonshot/Makefile
 		 fence/agents/ilo_mp/Makefile
+		 fence/agents/ilo_ssh/Makefile
 		 fence/agents/intelmodular/Makefile
 		 fence/agents/ipmilan/Makefile
 		 fence/agents/kdump/Makefile
diff --git a/fence/agents/ilo_ssh/Makefile.am b/fence/agents/ilo_ssh/Makefile.am
new file mode 100644
index 0000000..d67d7d1
--- /dev/null
+++ b/fence/agents/ilo_ssh/Makefile.am
@@ -0,0 +1,20 @@
+MAINTAINERCLEANFILES	= Makefile.in
+
+TARGET			= fence_ilo_ssh
+
+SRC			= $(TARGET).py
+
+EXTRA_DIST		= $(SRC)
+
+sbin_SCRIPTS		= $(TARGET)
+
+man_MANS		= $(TARGET).8
+
+FENCE_TEST_ARGS         = -p test -a test
+
+include $(top_srcdir)/make/fencebuild.mk
+include $(top_srcdir)/make/fenceman.mk
+include $(top_srcdir)/make/agentpycheck.mk
+
+clean-local: clean-man
+	rm -f $(TARGET)
diff --git a/fence/agents/ilo_ssh/fence_ilo_ssh.py b/fence/agents/ilo_ssh/fence_ilo_ssh.py
new file mode 100644
index 0000000..f75ac25
--- /dev/null
+++ b/fence/agents/ilo_ssh/fence_ilo_ssh.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python -tt
+
+import sys, re
+import atexit
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION=""
+REDHAT_COPYRIGHT=""
+BUILD_DATE=""
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+	conn.send_eol("show /system1")
+
+	re_state = re.compile('EnabledState=(.*)', re.IGNORECASE)
+	conn.log_expect(options, re_state, int(options["--shell-timeout"]))
+
+	status = conn.match.group(1).lower()
+
+	if status.startswith("enabled"):
+		return "on"
+	else:
+		return "off"
+
+def set_power_status(conn, options):
+	if options["--action"] == "on":
+		conn.send_eol("start /system1")
+	else:
+		conn.send_eol("power off hard")
+
+	conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
+
+	return
+
+def reboot_cycle(conn, options):
+	conn.send_eol("reset hard /system1")
+	conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
+	return
+
+def main():
+	device_opt = ["ipaddr", "login", "passwd", "secure", "cmd_prompt", "method"]
+
+	atexit.register(atexit_handler)
+
+	all_opt["cmd_prompt"]["default"] = ["MP>", "hpiLO->"]
+	all_opt["power_wait"]["default"] = 5
+	all_opt["method"]["default"] = "onoff"
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	docs = {}
+	docs["shortdesc"] = "Fence agent for HP iLO over SSH"
+	docs["longdesc"] = "fence_ilo_ssh is a fence agent that connects to iLO device. It logs into \
+device via ssh and reboot a specified outlet. "
+	docs["vendorurl"] = "http://www.hp.com"
+	docs["symlink"] = [("fence_ilo3_ssh", "Fence agent for HP iLO3 over SSH"),
+		("fence_ilo4_ssh", "Fence agent for HP iLO4 over SSH")]
+	show_docs(options, docs)
+
+	conn = fence_login(options)
+	conn.send_eol("SMCLP")
+
+	##
+	## Fence operations
+	####
+	result = fence_action(conn, options, set_power_status, get_power_status, None, reboot_cycle)
+	fence_logout(conn, "exit")
+	sys.exit(result)
+
+if __name__ == "__main__":
+	main()
-- 
1.9.3