summaryrefslogtreecommitdiffstats
path: root/agents/ilo
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--agents/ilo/fence_ilo.py143
-rw-r--r--agents/ilo_moonshot/fence_ilo_moonshot.py65
-rw-r--r--agents/ilo_mp/fence_ilo_mp.py58
-rw-r--r--agents/ilo_ssh/fence_ilo_ssh.py77
4 files changed, 343 insertions, 0 deletions
diff --git a/agents/ilo/fence_ilo.py b/agents/ilo/fence_ilo.py
new file mode 100644
index 0000000..6124505
--- /dev/null
+++ b/agents/ilo/fence_ilo.py
@@ -0,0 +1,143 @@
+#!@PYTHON@ -tt
+
+#####
+##
+## The Following Agent Has Been Tested On:
+##
+## iLO Version
+## +---------------------------------------------+
+## iLO / firmware 1.91 / RIBCL 2.22
+## iLO2 / firmware 1.22 / RIBCL 2.22
+## iLO2 / firmware 1.50 / RIBCL 2.22
+#####
+
+import sys, re, pexpect
+import atexit
+from xml.sax.saxutils import quoteattr
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+from fencing import fail, EC_LOGIN_DENIED
+
+def get_power_status(conn, options):
+ conn.send("<LOGIN USER_LOGIN = " + quoteattr(options["--username"]) + \
+ " PASSWORD = " + quoteattr(options["--password"]) + ">\r\n")
+ conn.send("<SERVER_INFO MODE = \"read\"><GET_HOST_POWER_STATUS/>\r\n")
+ conn.send("</SERVER_INFO></LOGIN>\r\n")
+ conn.log_expect("HOST_POWER=\"(.*?)\"", int(options["--power-timeout"]))
+
+ status = conn.match.group(1)
+ return status.lower().strip()
+
+def set_power_status(conn, options):
+ conn.send("<LOGIN USER_LOGIN = " + quoteattr(options["--username"]) + \
+ " PASSWORD = " + quoteattr(options["--password"]) + ">\r\n")
+ conn.send("<SERVER_INFO MODE = \"write\">")
+
+ if options.get("fw_processor", None) == "iLO2":
+ if options["fw_version"] > 1.29:
+ conn.send("<HOLD_PWR_BTN TOGGLE=\"yes\" />\r\n")
+ else:
+ conn.send("<HOLD_PWR_BTN />\r\n")
+ elif options["--ribcl-version"] < 2.21:
+ conn.send("<SET_HOST_POWER HOST_POWER = \"" + options["--action"] + "\" />\r\n")
+ else:
+ if options["--action"] == "off":
+ conn.send("<HOLD_PWR_BTN/>\r\n")
+ else:
+ conn.send("<PRESS_PWR_BTN/>\r\n")
+ conn.send("</SERVER_INFO></LOGIN>\r\n")
+
+ return
+
+def define_new_opts():
+ all_opt["ribcl"] = {
+ "getopt" : "r:",
+ "longopt" : "ribcl-version",
+ "help" : "-r, --ribcl-version=[version] Force ribcl version to use",
+ "required" : "0",
+ "shortdesc" : "Force ribcl version to use",
+ "order" : 1}
+
+def main():
+ device_opt = ["ipaddr", "login", "passwd", "ssl", "notls", "tls1.0", "ribcl"]
+
+ atexit.register(atexit_handler)
+
+ define_new_opts()
+
+ all_opt["login_timeout"]["default"] = "10"
+ all_opt["retry_on"]["default"] = "3"
+ all_opt["ssl"]["default"] = "1"
+
+ options = check_input(device_opt, process_input(device_opt))
+
+ docs = {}
+ docs["shortdesc"] = "Fence agent for HP iLO"
+ docs["longdesc"] = "fence_ilo is an I/O Fencing agent \
+used for HP servers with the Integrated Light Out (iLO) PCI card.\
+The agent opens an SSL connection to the iLO card. Once the SSL \
+connection is established, the agent is able to communicate with \
+the iLO card through an XML stream."
+ docs["vendorurl"] = "http://www.hp.com"
+ docs["symlink"] = [("fence_ilo2", "Fence agent for HP iLO2")]
+ show_docs(options, docs)
+
+ ##
+ ## Login and get version number
+ ####
+ conn = fence_login(options)
+ try:
+ conn.send("<?xml version=\"1.0\"?>\r\n")
+ conn.log_expect(["</RIBCL>", "<END_RIBCL/>"], int(options["--login-timeout"]))
+ except pexpect.TIMEOUT:
+ fail(EC_LOGIN_DENIED)
+ except pexpect.EOF:
+ if "--tls1.0" in options:
+ fail(EC_LOGIN_DENIED)
+ options["--tls1.0"] = "1"
+ conn.close()
+ conn = fence_login(options)
+ try:
+ conn.send("<?xml version=\"1.0\"?>\r\n")
+ conn.log_expect(["</RIBCL>", "<END_RIBCL/>"], int(options["--login-timeout"]))
+ except pexpect.TIMEOUT:
+ fail(EC_LOGIN_DENIED)
+ except pexpect.EOF:
+ fail(EC_LOGIN_DENIED)
+
+ try:
+ version = re.compile("<RIBCL VERSION=\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1)
+ if "--ribcl-version" not in options:
+ options["--ribcl-version"] = float(version)
+
+ if options["--ribcl-version"] >= 2:
+ conn.send("<RIBCL VERSION=\"2.0\">\r\n")
+ else:
+ conn.send("<RIBCL VERSION=\"1.2\">\r\n")
+
+ conn.send("<LOGIN USER_LOGIN = " + quoteattr(options["--username"]) + \
+ " PASSWORD = " + quoteattr(options["--password"]) + ">\r\n")
+ if options["--ribcl-version"] >= 2:
+ conn.send("<RIB_INFO MODE=\"read\"><GET_FW_VERSION />\r\n")
+ conn.send("</RIB_INFO>\r\n")
+ conn.log_expect(r"<GET_FW_VERSION\s*\n", int(options["--shell-timeout"]))
+ conn.log_expect("/>", int(options["--shell-timeout"]))
+ options["fw_version"] = float(re.compile(r"FIRMWARE_VERSION\s*=\s*\"(.*?)\"",
+ re.IGNORECASE).search(conn.before).group(1))
+ options["fw_processor"] = re.compile(r"MANAGEMENT_PROCESSOR\s*=\s*\"(.*?)\"",
+ re.IGNORECASE).search(conn.before).group(1)
+ conn.send("</LOGIN>\r\n")
+ except pexpect.TIMEOUT:
+ fail(EC_LOGIN_DENIED)
+ except pexpect.EOF:
+ fail(EC_LOGIN_DENIED)
+
+ ##
+ ## Fence operations
+ ####
+ result = fence_action(conn, options, set_power_status, get_power_status, None)
+
+ sys.exit(result)
+
+if __name__ == "__main__":
+ main()
diff --git a/agents/ilo_moonshot/fence_ilo_moonshot.py b/agents/ilo_moonshot/fence_ilo_moonshot.py
new file mode 100644
index 0000000..1923eeb
--- /dev/null
+++ b/agents/ilo_moonshot/fence_ilo_moonshot.py
@@ -0,0 +1,65 @@
+#!@PYTHON@ -tt
+
+import sys
+import logging
+import atexit
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+from fencing import fail, EC_STATUS
+
+def get_power_status(conn, options):
+ conn.send_eol("show node list")
+ conn.log_expect(options["--command-prompt"], int(options["--shell-timeout"]))
+
+ nodes = {}
+ for line in conn.before.splitlines():
+ if len(line.split()) == 10:
+ nodes[line.split()[1]] = ("", line.split()[8].lower().strip())
+
+ if ["list", "monitor"].count(options["--action"]) == 1:
+ return nodes
+ else:
+ try:
+ (_, status) = nodes[options["--plug"]]
+ return status.lower()
+ except KeyError as e:
+ logging.error("Failed: {}".format(str(e)))
+ fail(EC_STATUS)
+
+def set_power_status(conn, options):
+ if options["--action"] == "on":
+ conn.send_eol("set node power on %s" % (options["--plug"]))
+ else:
+ conn.send_eol("set node power off force %s" % (options["--plug"]))
+
+ conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
+
+ return
+
+def main():
+ device_opt = ["ipaddr", "login", "passwd", "secure", "cmd_prompt", "port"]
+
+ atexit.register(atexit_handler)
+
+ all_opt["secure"]["default"] = "1"
+ all_opt["cmd_prompt"]["default"] = ["MP>", "hpiLO->"]
+
+ options = check_input(device_opt, process_input(device_opt))
+
+ docs = {}
+ docs["shortdesc"] = "Fence agent for HP Moonshot iLO"
+ docs["longdesc"] = ""
+ docs["vendorurl"] = "http://www.hp.com"
+ show_docs(options, docs)
+
+ conn = fence_login(options)
+
+ ##
+ ## Fence operations
+ ####
+ result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
+ fence_logout(conn, "exit")
+ sys.exit(result)
+
+if __name__ == "__main__":
+ main()
diff --git a/agents/ilo_mp/fence_ilo_mp.py b/agents/ilo_mp/fence_ilo_mp.py
new file mode 100644
index 0000000..1ae4d3e
--- /dev/null
+++ b/agents/ilo_mp/fence_ilo_mp.py
@@ -0,0 +1,58 @@
+#!@PYTHON@ -tt
+
+import sys, re
+import atexit
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+def get_power_status(conn, options):
+ conn.send_eol("show /system1")
+
+ re_state = re.compile('EnabledState=(.*)', re.IGNORECASE)
+ conn.log_expect(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("stop -f /system1")
+
+ conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
+
+ return
+
+def main():
+ device_opt = ["ipaddr", "login", "passwd", "secure", "cmd_prompt", "telnet"]
+
+ atexit.register(atexit_handler)
+
+ all_opt["cmd_prompt"]["default"] = ["MP>", "hpiLO->"]
+ all_opt["power_wait"]["default"] = 5
+
+ options = check_input(device_opt, process_input(device_opt))
+
+ docs = {}
+ docs["shortdesc"] = "Fence agent for HP iLO MP"
+ docs["longdesc"] = ""
+ docs["vendorurl"] = "http://www.hp.com"
+ 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)
+ fence_logout(conn, "exit")
+ sys.exit(result)
+
+if __name__ == "__main__":
+ main()
diff --git a/agents/ilo_ssh/fence_ilo_ssh.py b/agents/ilo_ssh/fence_ilo_ssh.py
new file mode 100644
index 0000000..a27e341
--- /dev/null
+++ b/agents/ilo_ssh/fence_ilo_ssh.py
@@ -0,0 +1,77 @@
+#!@PYTHON@ -tt
+
+import sys, re
+import atexit
+import logging
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+def get_power_status(conn, options):
+ conn.send_eol("show /system1")
+
+ re_state = re.compile('EnabledState=(.*)', re.IGNORECASE)
+ conn.log_expect(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["--command-prompt"], int(options["--power-timeout"]))
+
+ return
+
+def reboot_cycle(conn, options):
+ conn.send_eol("reset /system1 hard")
+ conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
+
+ if get_power_status(conn, options) == "off":
+ logging.error("Timed out waiting to power ON\n")
+
+ return True
+
+def main():
+ device_opt = ["ipaddr", "login", "passwd", "secure", "cmd_prompt", "method", "telnet"]
+
+ atexit.register(atexit_handler)
+
+ all_opt["cmd_prompt"]["default"] = ["MP>", "hpiLO->"]
+ all_opt["power_wait"]["default"] = 5
+
+ 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.\
+\n.P\n\
+WARNING: The monitor-action is prone to timeouts. Use the fence_ilo-equivalent \
+to avoid this issue."
+ 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"),
+ ("fence_ilo5_ssh", "Fence agent for HP iLO5 over SSH")]
+ show_docs(options, docs)
+
+ options["eol"] = "\r"
+
+ 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()