Blame SOURCES/bz1121122-1-fence_ilo_ssh.patch

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