Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=f37a64bd3... Commit: f37a64bd3f53f95358139b175d70269cf4f17850 Parent: 821478ebcd1b6ee31636e7910bc35fb41b4834b1 Author: Ondrej Mular omular@redhat.com AuthorDate: Mon Dec 30 11:24:54 2013 -0500 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Mon Jan 6 17:05:00 2014 +0100
fence_amt: new fence agent for Intel AMT
New fence agent for Intel AMT. --- fence/agents/amt/fence_amt.py | 149 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 149 insertions(+), 0 deletions(-)
diff --git a/fence/agents/amt/fence_amt.py b/fence/agents/amt/fence_amt.py new file mode 100755 index 0000000..c164c66 --- /dev/null +++ b/fence/agents/amt/fence_amt.py @@ -0,0 +1,149 @@ +#!/usr/bin/python + +import sys, subprocess, re, os, stat +from pipes import quote +sys.path.append("@FENCEAGENTSLIBDIR@") +from fencing import * + +#BEGIN_VERSION_GENERATION +RELEASE_VERSION="Fence agent for Intel AMT" +REDHAT_COPYRIGHT="" +BUILD_DATE="" +#END_VERSION_GENERATION + +def get_power_status(_, options): + + cmd = create_command(options, "status") + + if options["log"] >= LOG_MODE_VERBOSE: + options["debug_fh"].write("executing: " + cmd + "\n") + + try: + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + except OSError: + fail_usage("Amttool not found or not accessible") + + process.wait() + + output = process.communicate() + process.stdout.close() + options["debug_fh"].write(output) + + match = re.search('Powerstate:[\s]*(..)', str(output)) + status = match.group(1) if match else None + + if (status == None): + return "fail" + elif (status == "S0"): # SO = on; S3 = sleep; S5 = off + return "on" + else: + return "off" + +def set_power_status(_, options): + + cmd = create_command(options, options["--action"]) + + if options["log"] >= LOG_MODE_VERBOSE: + options["debug_fh"].write("executing: " + cmd + "\n") + + try: + process = subprocess.Popen(cmd, stdout=options["debug_fh"], stderr=options["debug_fh"], shell=True) + except OSError: + fail_usage("Amttool not found or not accessible") + + process.wait() + + return + +def reboot_cycle(_, options): + cmd = create_command(options, "cycle") + + if options["log"] >= LOG_MODE_VERBOSE: + options["debug_fh"].write("executing: " + cmd + "\n") + + try: + process = subprocess.Popen(cmd, stdout=options["debug_fh"], stderr=options["debug_fh"], shell=True) + except OSError: + fail_usage("Amttool not found or not accessible") + + status = process.wait() + + return not bool(status) + +def create_command(options, action): + + # --password / -p + cmd = "AMT_PASSWORD=" + quote(options["--password"]) + + cmd += " " + options["--amttool-path"] + + # --ip / -a + cmd += " " + options["--ip"] + + # --action / -o + if action == "status": + cmd += " info" + elif action == "on": + cmd = "echo "y"|" + cmd + cmd += " powerup" + elif action == "off": + cmd = "echo "y"|" + cmd + cmd += " powerdown" + elif action == "cycle": + cmd = "echo "y"|" + cmd + cmd += " powercycle" + if action in ["on", "off", "cycle"] and options.has_key("--boot-option"): + cmd += options["--boot-option"] + + # --use-sudo / -d + if options.has_key("--use-sudo"): + cmd = SUDO_PATH + " " + cmd + + return cmd + +def define_new_opts(): + all_opt["boot_option"] = { + "getopt" : "b:", + "longopt" : "boot-option", + "help" : "-b, --boot-option=[option] Change the default boot behavior of the machine. (pxe|hd|hdsafe|cd|diag)", + "required" : "0", + "shortdesc" : "Change the default boot behavior of the machine.", + "choices" : ["pxe", "hd", "hdsafe", "cd", "diag"], + "order" : 1 + } + all_opt["amttool_path"] = { + "getopt" : "i:", + "longopt" : "amttool-path", + "help" : "--amttool-path=[path] Path to amttool binary", + "required" : "0", + "shortdesc" : "Path to amttool binary", + "default" : "@AMTTOOL_PATH@", + "order": 200 + } + +def main(): + + atexit.register(atexit_handler) + + device_opt = [ "ipaddr", "no_login", "passwd", "boot_option", "no_port", + "sudo", "amttool_path", "method" ] + + define_new_opts() + + options = check_input(device_opt, process_input(device_opt)) + + docs = { } + docs["shortdesc"] = "Fence agent for AMT" + docs["longdesc"] = "Fence agent for AMT" + docs["vendorurl"] = "http://www.intel.com/" + show_docs(options, docs) + + if not is_executable(options["--amttool-path"]): + fail_usage("Amttool not found or not accessible") + + result = fence_action(None, options, set_power_status, get_power_status, None, reboot_cycle) + + sys.exit(result) + +if __name__ == "__main__": + main()
cluster-commits@lists.fedorahosted.org