Blame SOURCES/bz1121122-1-fence_ilo_ssh.patch

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