From: Fabio M. Di Nitto <fdinitto@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 3/3] fence_amt: option --method and new option --amttool-path
Date: Fri, 29 Nov 2013 22:37:14 +0100 [thread overview]
Message-ID: <5299090A.60601@redhat.com> (raw)
In-Reply-To: <326443307.3048712.1385742746687.JavaMail.root@redhat.com>
On 11/29/2013 05:32 PM, Ondrej Mular wrote:
> Add support for option --method and new option --amttool-path
>
> ---
> fence/agents/amt/fence_amt.py | 72 ++++++++++++++++++++++++++++++++++---------
> 1 file changed, 57 insertions(+), 15 deletions(-)
>
> diff --git a/fence/agents/amt/fence_amt.py b/fence/agents/amt/fence_amt.py
> index 8fe2dbc..7077828 100755
> --- a/fence/agents/amt/fence_amt.py
> +++ b/fence/agents/amt/fence_amt.py
> @@ -1,6 +1,6 @@
> #!/usr/bin/python
>
> -import sys, subprocess, re
> +import sys, subprocess, re, os, stat
> from pipes import quote
> sys.path.append("@FENCEAGENTSLIBDIR@")
> from fencing import *
> @@ -21,12 +21,11 @@ def get_power_status(_, options):
> try:
> process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
> except OSError:
> - fail(EC_TOOL_FAIL)
> + fail_usage("Amttool not found or not accessible")
>
> process.wait()
>
> output = process.communicate()
> -
> process.stdout.close()
>
> match = re.search('Powerstate:[\\s]*(..)', str(output))
> @@ -51,19 +50,44 @@ def set_power_status(_, options):
> process = subprocess.Popen(cmd, stdout=null, stderr=null, shell=True)
> except OSError:
> null.close()
> - fail(EC_TOOL_FAIL)
> + 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"]
> + cmd += " " + options["--amttool-path"]
>
> # --ip / -a
> cmd += " " + options["--ip"]
> @@ -77,7 +101,10 @@ def create_command(options, action):
> elif action == "off":
> cmd = "echo \"y\"|" + cmd
> cmd += " powerdown"
> - if action in ["on", "off"] and options.has_key("--boot-options"):
> + elif action == "cycle":
> + cmd = "echo \"y\"|" + cmd
> + cmd += " powercycle"
> + if action in ["on", "off", "cycle"] and options.has_key("--boot-options"):
> cmd += options["--boot-options"]
>
> # --use-sudo / -d
> @@ -86,25 +113,40 @@ def create_command(options, action):
>
> return cmd
>
> -def main():
> -
> - atexit.register(atexit_handler)
> -
> - device_opt = [ "ipaddr", "no_login", "passwd", "boot_option", "no_port", "sudo"]
> -
> +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)",
> + "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" : "/usr/bin/amttool",
similar here. Hardcoding paths is bad.
Fabio
prev parent reply other threads:[~2013-11-29 21:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1078693570.3048094.1385742338995.JavaMail.root@redhat.com>
2013-11-29 16:32 ` [Cluster-devel] [PATCH 3/3] fence_amt: option --method and new option --amttool-path Ondrej Mular
2013-11-29 21:37 ` Fabio M. Di Nitto [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5299090A.60601@redhat.com \
--to=fdinitto@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.