* [Cluster-devel] [PATCH 2/3] fence_ipmilan: option --method and new option --ipmitool-path [not found] <541560872.3047918.1385742157830.JavaMail.root@redhat.com> @ 2013-11-29 16:32 ` Ondrej Mular 2013-11-29 21:36 ` Fabio M. Di Nitto 2013-11-29 21:39 ` Fabio M. Di Nitto 0 siblings, 2 replies; 3+ messages in thread From: Ondrej Mular @ 2013-11-29 16:32 UTC (permalink / raw) To: cluster-devel.redhat.com Add support for option --method and new option --ipmitool-path --- fence/agents/ipmilan/fence_ipmilan.py | 80 +++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/fence/agents/ipmilan/fence_ipmilan.py b/fence/agents/ipmilan/fence_ipmilan.py index 5c32690..4d33234 100644 --- a/fence/agents/ipmilan/fence_ipmilan.py +++ b/fence/agents/ipmilan/fence_ipmilan.py @@ -11,14 +11,6 @@ REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION -PATHS = ["/usr/local/bull/NSMasterHW/bin/ipmitool", - "/usr/bin/ipmitool", - "/usr/sbin/ipmitool", - "/bin/ipmitool", - "/sbin/ipmitool", - "/usr/local/bin/ipmitool", - "/usr/local/sbin/ipmitool"] - def get_power_status(_, options): cmd = create_command(options, "status") @@ -28,9 +20,8 @@ def get_power_status(_, options): try: process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError, ex: - print ex - fail(EC_TOOL_FAIL) + except OSError: + fail_usage("Ipmitool not found or not accessible") process.wait() @@ -54,13 +45,31 @@ def set_power_status(_, options): process = subprocess.Popen(shlex.split(cmd), stdout=null, stderr=null) except OSError: null.close() - fail(EC_TOOL_FAIL) + fail_usage("Ipmitool 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") + + try: + process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + except OSError: + fail_usage("Ipmitool not found or not accessible") + + process.wait() + + out = process.communicate() + process.stdout.close() + + return bool(re.search('chassis power control: cycle', str(out).lower())) + def is_executable(path): if os.path.exists(path): stats = os.stat(path) @@ -68,13 +77,17 @@ def is_executable(path): return True return False -def get_ipmitool_path(): - for path in PATHS: - if is_executable(path): - return path +def get_ipmitool_path(options): + if type(options["--ipmitool-path"]) == type(list()): + for path in options["--ipmitool-path"]: + if is_executable(path): + return path + else: + if is_executable(options["--ipmitool-path"]): + return options["--ipmitool-path"] return None -def create_command(options, action): +def create_command(options, action): cmd = options["ipmitool_path"] # --lanplus / -L @@ -120,7 +133,7 @@ def define_new_opts(): all_opt["lanplus"] = { "getopt" : "L", "longopt" : "lanplus", - "help" : "-L, --lanplus Use Lanplus to improve security of connection", + "help" : "-L, --lanplus Use Lanplus to improve security of connection", "required" : "0", "shortdesc" : "Use Lanplus to improve security of connection", "order": 1 @@ -128,7 +141,7 @@ def define_new_opts(): all_opt["auth"] = { "getopt" : "A:", "longopt" : "auth", - "help" : "-A, --auth=[auth] IPMI Lan Auth type (md5|password|none)", + "help" : "-A, --auth=[auth] IPMI Lan Auth type (md5|password|none)", "required" : "0", "shortdesc" : "IPMI Lan Auth type.", "default" : "none", @@ -138,7 +151,7 @@ def define_new_opts(): all_opt["cipher"] = { "getopt" : "C:", "longopt" : "cipher", - "help" : "-C, --cipher=[cipher] Ciphersuite to use (same as ipmitool -C parameter)", + "help" : "-C, --cipher=[cipher] Ciphersuite to use (same as ipmitool -C parameter)", "required" : "0", "shortdesc" : "Ciphersuite to use (same as ipmitool -C parameter)", "default" : "0", @@ -147,28 +160,44 @@ def define_new_opts(): all_opt["privlvl"] = { "getopt" : "P:", "longopt" : "privlvl", - "help" : "-P, --privlvl=[level] Privilege level on IPMI device (callback|user|operator|administrator)", + "help" : "-P, --privlvl=[level] Privilege level on IPMI device (callback|user|operator|administrator)", "required" : "0", "shortdesc" : "Privilege level on IPMI device", "default" : "administrator", "choices" : ["callback", "user", "operator", "administrator"], "order": 1 } + all_opt["ipmitool_path"] = { + "getopt" : "i:", + "longopt" : "ipmitool-path", + "help" : "--ipmitool-path=[path] Path to ipmitool binary", + "required" : "0", + "shortdesc" : "Path to ipmitool binary", + "default" : ["/usr/local/bull/NSMasterHW/bin/ipmitool", + "/usr/bin/ipmitool", + "/usr/sbin/ipmitool", + "/bin/ipmitool", + "/sbin/ipmitool", + "/usr/local/bin/ipmitool", + "/usr/local/sbin/ipmitool"], + "order": 200 + } def main(): atexit.register(atexit_handler) - device_opt = [ "ipaddr", "login", "no_login", "no_password", "passwd", "lanplus", "auth", "cipher", "privlvl", "sudo"] + device_opt = ["ipaddr", "login", "no_login", "no_password", "passwd", + "lanplus", "auth", "cipher", "privlvl", "sudo", "ipmitool_path", "method"] define_new_opts() all_opt["ipport"]["default"] = "623" options = check_input(device_opt, process_input(device_opt)) - options["ipmitool_path"] = get_ipmitool_path() + options["ipmitool_path"] = get_ipmitool_path(options) if options["ipmitool_path"] is None: - fail(EC_TOOL_FAIL) + fail_usage("Ipmitool not found or not accessible") docs = { } docs["shortdesc"] = "Fence agent for IPMI" @@ -176,8 +205,7 @@ def main(): docs["vendorurl"] = "" show_docs(options, docs) - result = fence_action(None, options, set_power_status, get_power_status, None) - + result = fence_action(None, options, set_power_status, get_power_status, None, reboot_cycle) sys.exit(result) if __name__ == "__main__": -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Cluster-devel] [PATCH 2/3] fence_ipmilan: option --method and new option --ipmitool-path 2013-11-29 16:32 ` [Cluster-devel] [PATCH 2/3] fence_ipmilan: option --method and new option --ipmitool-path Ondrej Mular @ 2013-11-29 21:36 ` Fabio M. Di Nitto 2013-11-29 21:39 ` Fabio M. Di Nitto 1 sibling, 0 replies; 3+ messages in thread From: Fabio M. Di Nitto @ 2013-11-29 21:36 UTC (permalink / raw) To: cluster-devel.redhat.com On 11/29/2013 05:32 PM, Ondrej Mular wrote: > Add support for option --method and new option --ipmitool-path > > --- > fence/agents/ipmilan/fence_ipmilan.py | 80 +++++++++++++++++++++++------------ > 1 file changed, 54 insertions(+), 26 deletions(-) > > diff --git a/fence/agents/ipmilan/fence_ipmilan.py b/fence/agents/ipmilan/fence_ipmilan.py > index 5c32690..4d33234 100644 > --- a/fence/agents/ipmilan/fence_ipmilan.py > +++ b/fence/agents/ipmilan/fence_ipmilan.py > @@ -11,14 +11,6 @@ REDHAT_COPYRIGHT="" > BUILD_DATE="" > #END_VERSION_GENERATION > > -PATHS = ["/usr/local/bull/NSMasterHW/bin/ipmitool", > - "/usr/bin/ipmitool", > - "/usr/sbin/ipmitool", > - "/bin/ipmitool", > - "/sbin/ipmitool", > - "/usr/local/bin/ipmitool", > - "/usr/local/sbin/ipmitool"] > - > def get_power_status(_, options): > > cmd = create_command(options, "status") > @@ -28,9 +20,8 @@ def get_power_status(_, options): > > try: > process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) > - except OSError, ex: > - print ex > - fail(EC_TOOL_FAIL) > + except OSError: > + fail_usage("Ipmitool not found or not accessible") > > process.wait() > > @@ -54,13 +45,31 @@ def set_power_status(_, options): > process = subprocess.Popen(shlex.split(cmd), stdout=null, stderr=null) > except OSError: > null.close() > - fail(EC_TOOL_FAIL) > + fail_usage("Ipmitool 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") > + > + try: > + process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) > + except OSError: > + fail_usage("Ipmitool not found or not accessible") > + > + process.wait() > + > + out = process.communicate() > + process.stdout.close() > + > + return bool(re.search('chassis power control: cycle', str(out).lower())) > + > def is_executable(path): > if os.path.exists(path): > stats = os.stat(path) > @@ -68,13 +77,17 @@ def is_executable(path): > return True > return False > > -def get_ipmitool_path(): > - for path in PATHS: > - if is_executable(path): > - return path > +def get_ipmitool_path(options): > + if type(options["--ipmitool-path"]) == type(list()): > + for path in options["--ipmitool-path"]: > + if is_executable(path): > + return path > + else: > + if is_executable(options["--ipmitool-path"]): > + return options["--ipmitool-path"] > return None > > -def create_command(options, action): > +def create_command(options, action): > cmd = options["ipmitool_path"] > > # --lanplus / -L > @@ -120,7 +133,7 @@ def define_new_opts(): > all_opt["lanplus"] = { > "getopt" : "L", > "longopt" : "lanplus", > - "help" : "-L, --lanplus Use Lanplus to improve security of connection", > + "help" : "-L, --lanplus Use Lanplus to improve security of connection", > "required" : "0", > "shortdesc" : "Use Lanplus to improve security of connection", > "order": 1 > @@ -128,7 +141,7 @@ def define_new_opts(): > all_opt["auth"] = { > "getopt" : "A:", > "longopt" : "auth", > - "help" : "-A, --auth=[auth] IPMI Lan Auth type (md5|password|none)", > + "help" : "-A, --auth=[auth] IPMI Lan Auth type (md5|password|none)", > "required" : "0", > "shortdesc" : "IPMI Lan Auth type.", > "default" : "none", > @@ -138,7 +151,7 @@ def define_new_opts(): > all_opt["cipher"] = { > "getopt" : "C:", > "longopt" : "cipher", > - "help" : "-C, --cipher=[cipher] Ciphersuite to use (same as ipmitool -C parameter)", > + "help" : "-C, --cipher=[cipher] Ciphersuite to use (same as ipmitool -C parameter)", > "required" : "0", > "shortdesc" : "Ciphersuite to use (same as ipmitool -C parameter)", > "default" : "0", > @@ -147,28 +160,44 @@ def define_new_opts(): > all_opt["privlvl"] = { > "getopt" : "P:", > "longopt" : "privlvl", > - "help" : "-P, --privlvl=[level] Privilege level on IPMI device (callback|user|operator|administrator)", > + "help" : "-P, --privlvl=[level] Privilege level on IPMI device (callback|user|operator|administrator)", > "required" : "0", > "shortdesc" : "Privilege level on IPMI device", > "default" : "administrator", > "choices" : ["callback", "user", "operator", "administrator"], > "order": 1 > } > + all_opt["ipmitool_path"] = { > + "getopt" : "i:", > + "longopt" : "ipmitool-path", > + "help" : "--ipmitool-path=[path] Path to ipmitool binary", > + "required" : "0", > + "shortdesc" : "Path to ipmitool binary", > + "default" : ["/usr/local/bull/NSMasterHW/bin/ipmitool", > + "/usr/bin/ipmitool", > + "/usr/sbin/ipmitool", > + "/bin/ipmitool", > + "/sbin/ipmitool", > + "/usr/local/bin/ipmitool", > + "/usr/local/sbin/ipmitool"], Ondrej, this search path must go away and you should only use the OS defined PATH. Fabio ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cluster-devel] [PATCH 2/3] fence_ipmilan: option --method and new option --ipmitool-path 2013-11-29 16:32 ` [Cluster-devel] [PATCH 2/3] fence_ipmilan: option --method and new option --ipmitool-path Ondrej Mular 2013-11-29 21:36 ` Fabio M. Di Nitto @ 2013-11-29 21:39 ` Fabio M. Di Nitto 1 sibling, 0 replies; 3+ messages in thread From: Fabio M. Di Nitto @ 2013-11-29 21:39 UTC (permalink / raw) To: cluster-devel.redhat.com On 11/29/2013 05:32 PM, Ondrej Mular wrote: > @@ -147,28 +160,44 @@ def define_new_opts(): > all_opt["privlvl"] = { > "getopt" : "P:", > "longopt" : "privlvl", > - "help" : "-P, --privlvl=[level] Privilege level on IPMI device (callback|user|operator|administrator)", > + "help" : "-P, --privlvl=[level] Privilege level on IPMI device (callback|user|operator|administrator)", All the reformatting and cosmetic changes should be in a separate commit. Also, this patch assumes that the first patch you posted is applied to the tree. It's not. Sending incremental patches over patches makes it difficult to rebuild the final binary and test it (yes I have ipmi devices at home :)) Fabio ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-29 21:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <541560872.3047918.1385742157830.JavaMail.root@redhat.com>
2013-11-29 16:32 ` [Cluster-devel] [PATCH 2/3] fence_ipmilan: option --method and new option --ipmitool-path Ondrej Mular
2013-11-29 21:36 ` Fabio M. Di Nitto
2013-11-29 21:39 ` Fabio M. Di Nitto
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.