cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 2/2] fence_amt: new fence agent for Intel AMT
       [not found] <930308315.2340076.1385046294848.JavaMail.root@redhat.com>
@ 2013-11-21 15:16 ` Ondrej Mular
  0 siblings, 0 replies; 3+ messages in thread
From: Ondrej Mular @ 2013-11-21 15:16 UTC (permalink / raw)
  To: cluster-devel.redhat.com

New fence agent for Intel AMT.

---
 fence/agents/amt/fence_amt.py | 120 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)
 create mode 100755 fence/agents/amt/fence_amt.py

diff --git a/fence/agents/amt/fence_amt.py b/fence/agents/amt/fence_amt.py
new file mode 100755
index 0000000..8fe2dbc
--- /dev/null
+++ b/fence/agents/amt/fence_amt.py
@@ -0,0 +1,120 @@
+#!/usr/bin/python
+
+import sys, subprocess, re
+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(EC_TOOL_FAIL)
+
+    process.wait()
+
+    output = process.communicate()
+
+    process.stdout.close()
+
+    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")
+
+    null = open('/dev/null', 'w')
+    try:
+        process = subprocess.Popen(cmd, stdout=null, stderr=null, shell=True)
+    except OSError:
+        null.close()
+        fail(EC_TOOL_FAIL)
+
+    process.wait()
+    null.close()
+
+    return
+
+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"
+    if action in ["on", "off"] and options.has_key("--boot-options"):
+        cmd += options["--boot-options"]
+
+    # --use-sudo / -d
+    if options.has_key("--use-sudo"):
+        cmd = SUDO_PATH + " " + cmd
+
+    return cmd
+
+def main():
+
+    atexit.register(atexit_handler)
+
+    device_opt = [ "ipaddr", "no_login", "passwd", "boot_option", "no_port", "sudo"]
+
+    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
+        }
+
+    options = check_input(device_opt, process_input(device_opt))
+
+    options["amttool_path"] = "/usr/bin/amttool"
+
+    docs = { }
+    docs["shortdesc"] = "Fence agent for AMT"
+    docs["longdesc"] = "Fence agent for AMT"
+    docs["vendorurl"] = "http://www.intel.com/"
+    show_docs(options, docs)
+
+    result = fence_action(None, options, set_power_status, get_power_status, None)
+
+    sys.exit(result)
+
+if __name__ == "__main__":
+    main()
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Cluster-devel] [PATCH 2/2] fence_amt: new fence agent for Intel AMT
       [not found] <956669175.3277212.1386083353560.JavaMail.root@redhat.com>
@ 2013-12-03 15:28 ` Ondrej Mular
  2013-12-19 15:40   ` Marek Grac
  0 siblings, 1 reply; 3+ messages in thread
From: Ondrej Mular @ 2013-12-03 15:28 UTC (permalink / raw)
  To: cluster-devel.redhat.com

New fence agent for Intel AMT.

---
 fence/agents/amt/fence_amt.py | 161 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 161 insertions(+)
 create mode 100755 fence/agents/amt/fence_amt.py

diff --git a/fence/agents/amt/fence_amt.py b/fence/agents/amt/fence_amt.py
new file mode 100755
index 0000000..6f00727
--- /dev/null
+++ b/fence/agents/amt/fence_amt.py
@@ -0,0 +1,161 @@
+#!/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()
+
+    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")
+
+    null = open('/dev/null', 'w')
+    try:
+        process = subprocess.Popen(cmd, stdout=null, stderr=null, shell=True)
+    except OSError:
+        null.close()
+        fail_usage("Amttool not found or not accessible")
+
+    process.wait()
+    null.close()
+
+    return
+
+def reboot_cycle(_, options):
+    cmd = create_command(options, "cycle")
+
+    if options["log"] >= LOG_MODE_VERBOSE:
+        options["debug_fh"].write("executing: " + cmd + "\n")
+
+    null = open('/dev/null', 'w')
+    try:
+        process = subprocess.Popen(cmd, stdout=null, stderr=null, shell=True)
+    except OSError:
+        null.close()
+        fail_usage("Amttool not found or not accessible")
+
+    status = process.wait()
+    null.close()
+
+    return not bool(status)
+
+def is_executable(path):
+    if os.path.exists(path):
+        stats = os.stat(path)
+        if stat.S_ISREG(stats.st_mode) and os.access(path, os.X_OK):
+            return True
+    return False
+
+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()
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Cluster-devel] [PATCH 2/2] fence_amt: new fence agent for Intel AMT
  2013-12-03 15:28 ` [Cluster-devel] [PATCH 2/2] fence_amt: new fence agent for Intel AMT Ondrej Mular
@ 2013-12-19 15:40   ` Marek Grac
  0 siblings, 0 replies; 3+ messages in thread
From: Marek Grac @ 2013-12-19 15:40 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi Ondrej,

On 12/03/2013 04:28 PM, Ondrej Mular wrote:
> +def reboot_cycle(_, options):
> +    cmd = create_command(options, "cycle")
> +
> +    if options["log"] >= LOG_MODE_VERBOSE:
> +        options["debug_fh"].write("executing: " + cmd + "\n")
> +
> +    null = open('/dev/null', 'w')
> +    try:
> +        process = subprocess.Popen(cmd, stdout=null, stderr=null, shell=True)
> +    except OSError:
> +        null.close()
> +        fail_usage("Amttool not found or not accessible")
> +
I would suggest to stdout/stderr point to options["debug_fh"] so we can 
use this information.

> +def is_executable(path):
> +    if os.path.exists(path):
> +        stats = os.stat(path)
> +        if stat.S_ISREG(stats.st_mode) and os.access(path, os.X_OK):
> +            return True
> +    return False
imho this function is not needed because you have to check and control 
this after each subprocess.Popen() ; if you believe it is a good idea to 
have such function (I'm not totally against it) then put it in fencing 
library.

I have no other comments, good work

m,



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-19 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <956669175.3277212.1386083353560.JavaMail.root@redhat.com>
2013-12-03 15:28 ` [Cluster-devel] [PATCH 2/2] fence_amt: new fence agent for Intel AMT Ondrej Mular
2013-12-19 15:40   ` Marek Grac
     [not found] <930308315.2340076.1385046294848.JavaMail.root@redhat.com>
2013-11-21 15:16 ` Ondrej Mular

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).