cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library
       [not found] <1466780058.2338929.1385045970240.JavaMail.root@redhat.com>
@ 2013-11-21 15:16 ` Ondrej Mular
  2013-11-21 15:48   ` Fabio M. Di Nitto
  2013-11-25  8:35   ` Jan Friesse
  0 siblings, 2 replies; 5+ messages in thread
From: Ondrej Mular @ 2013-11-21 15:16 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This is port of fence_ipmilan to fencing library. Also added fail message to fencing library if tool (e.g. impitool, amttool...) is not accessible.

---
 fence/agents/ipmilan/fence_ipmilan.py | 184 ++++++++++++++++++++++++++++++++++
 fence/agents/lib/fencing.py.py        |   4 +-
 2 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 fence/agents/ipmilan/fence_ipmilan.py

diff --git a/fence/agents/ipmilan/fence_ipmilan.py b/fence/agents/ipmilan/fence_ipmilan.py
new file mode 100644
index 0000000..5c32690
--- /dev/null
+++ b/fence/agents/ipmilan/fence_ipmilan.py
@@ -0,0 +1,184 @@
+#!/usr/bin/python
+
+import sys, shlex, stat, subprocess, re, os
+from pipes import quote
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION=""
+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")
+
+    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, ex:
+        print ex
+        fail(EC_TOOL_FAIL)
+
+    process.wait()
+
+    out = process.communicate()
+    process.stdout.close()
+
+    match = re.search('[Cc]hassis [Pp]ower is [\\s]*([a-zA-Z]{2,3})', str(out))
+    status = match.group(1) if match else None
+
+    return status
+
+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(shlex.split(cmd), stdout=null, stderr=null)
+    except OSError:
+        null.close()
+        fail(EC_TOOL_FAIL)
+
+    process.wait()
+    null.close()
+
+    return
+
+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 get_ipmitool_path():
+    for path in PATHS:
+        if is_executable(path):
+            return path
+    return None
+
+def create_command(options, action):    
+    cmd = options["ipmitool_path"]
+
+    # --lanplus / -L
+    if options.has_key("--lanplus"):
+        cmd += " -I lanplus"
+    else:
+        cmd += " -I lan"
+    # --ip / -a
+    cmd += " -H " + options["--ip"]
+
+    # --username / -l
+    if options.has_key("--username") and len(options["--username"]) != 0:
+        cmd += " -U " + quote(options["--username"])
+
+    # --auth / -A
+    if options.has_key("--auth"):
+        cmd += " -A " + options["--auth"]
+
+    # --password / -p
+    if options.has_key("--password"):
+        cmd += " -P " + quote(options["--password"])
+
+    # --cipher / -C
+    cmd += " -C " + options["--cipher"]
+
+    # --port / -n
+    if options.has_key("--ipport"):
+        cmd += " -p " + options["--ipport"]
+
+    if options.has_key("--privlvl"):
+        cmd += " -L " + options["--privlvl"]
+
+    # --action / -o
+    cmd += " chassis power " + action
+
+     # --use-sudo / -d
+    if options.has_key("--use-sudo"):
+        cmd = SUDO_PATH + " " + cmd
+
+    return cmd
+
+def define_new_opts():
+    all_opt["lanplus"] = {
+        "getopt" : "L",
+        "longopt" : "lanplus",
+        "help" : "-L, --lanplus    Use Lanplus to improve security of connection",
+        "required" : "0",
+        "shortdesc" : "Use Lanplus to improve security of connection",
+        "order": 1
+        }
+    all_opt["auth"] = {
+        "getopt" : "A:",
+        "longopt" : "auth",
+        "help" : "-A, --auth=[auth]    IPMI Lan Auth type (md5|password|none)",
+        "required" : "0",
+        "shortdesc" : "IPMI Lan Auth type.",
+        "default" : "none",
+        "choices" : ["md5", "password", "none"],
+        "order": 1
+        }
+    all_opt["cipher"] = {
+        "getopt" : "C:",
+        "longopt" : "cipher",
+        "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",
+        "order": 1
+        }
+    all_opt["privlvl"] = {
+        "getopt" : "P:",
+        "longopt" : "privlvl",
+        "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
+        }
+
+def main():
+
+    atexit.register(atexit_handler)
+
+    device_opt = [ "ipaddr", "login", "no_login", "no_password", "passwd", "lanplus", "auth", "cipher", "privlvl", "sudo"]
+    define_new_opts()
+
+    all_opt["ipport"]["default"] = "623"
+
+    options = check_input(device_opt, process_input(device_opt))
+    options["ipmitool_path"] = get_ipmitool_path()
+
+    if options["ipmitool_path"] is None:
+        fail(EC_TOOL_FAIL)
+
+    docs = { }
+    docs["shortdesc"] = "Fence agent for IPMI"
+    docs["longdesc"] = "Fence agent for IPMI"
+    docs["vendorurl"] = ""
+    show_docs(options, docs)
+
+    result = fence_action(None, options, set_power_status, get_power_status, None)
+
+    sys.exit(result)
+
+if __name__ == "__main__":
+    main()
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 0a3b122..b4abfb2 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -25,6 +25,7 @@ EC_STATUS          = 8
 EC_STATUS_HMC      = 9
 EC_PASSWORD_MISSING = 10
 EC_INVALID_PRIVILEGES = 11
+EC_TOOL_FAIL	  = 12
 
 TELNET_PATH = "/usr/bin/telnet"
 SSH_PATH    = "/usr/bin/ssh"
@@ -412,7 +413,8 @@ def fail(error_code):
 		EC_STATUS_HMC :
 			"Failed: Either unable to obtain correct plug status, partition is not available or incorrect HMC version used",
 		EC_PASSWORD_MISSING : "Failed: You have to set login password",
-		EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action."
+		EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action.",
+		EC_TOOL_FAIL: "Failed: Required tool not found or not accessible."
 	}[error_code] + "\n"
 	sys.stderr.write(message)
 	syslog.syslog(syslog.LOG_ERR, message)
-- 
1.8.3.1



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

* [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library
  2013-11-21 15:16 ` [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library Ondrej Mular
@ 2013-11-21 15:48   ` Fabio M. Di Nitto
  2013-11-22 16:18     ` Jan Pokorný
  2013-11-25  8:35   ` Jan Friesse
  1 sibling, 1 reply; 5+ messages in thread
From: Fabio M. Di Nitto @ 2013-11-21 15:48 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi Ondrej,

On 11/21/2013 4:16 PM, Ondrej Mular wrote:
> This is port of fence_ipmilan to fencing library. Also added fail message to fencing library if tool (e.g. impitool, amttool...) is not accessible.
> 
> ---
>  fence/agents/ipmilan/fence_ipmilan.py | 184 ++++++++++++++++++++++++++++++++++
>  fence/agents/lib/fencing.py.py        |   4 +-
>  2 files changed, 187 insertions(+), 1 deletion(-)
>  create mode 100644 fence/agents/ipmilan/fence_ipmilan.py
> 
> diff --git a/fence/agents/ipmilan/fence_ipmilan.py b/fence/agents/ipmilan/fence_ipmilan.py
> new file mode 100644
> index 0000000..5c32690
> --- /dev/null
> +++ b/fence/agents/ipmilan/fence_ipmilan.py
> @@ -0,0 +1,184 @@
> +#!/usr/bin/python
> +
> +import sys, shlex, stat, subprocess, re, os
> +from pipes import quote
> +sys.path.append("@FENCEAGENTSLIBDIR@")
> +from fencing import *
> +
> +#BEGIN_VERSION_GENERATION
> +RELEASE_VERSION=""
> +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"]

this hard-cording it bad.

Always use OS define PATH and if really necessary allow user to override
with an option (for example: --pathtoipmitool=/usr/local....)

Fabio

> +
> +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(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> +    except OSError, ex:
> +        print ex
> +        fail(EC_TOOL_FAIL)
> +
> +    process.wait()
> +
> +    out = process.communicate()
> +    process.stdout.close()
> +
> +    match = re.search('[Cc]hassis [Pp]ower is [\\s]*([a-zA-Z]{2,3})', str(out))
> +    status = match.group(1) if match else None
> +
> +    return status
> +
> +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(shlex.split(cmd), stdout=null, stderr=null)
> +    except OSError:
> +        null.close()
> +        fail(EC_TOOL_FAIL)
> +
> +    process.wait()
> +    null.close()
> +
> +    return
> +
> +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 get_ipmitool_path():
> +    for path in PATHS:
> +        if is_executable(path):
> +            return path
> +    return None
> +
> +def create_command(options, action):    
> +    cmd = options["ipmitool_path"]
> +
> +    # --lanplus / -L
> +    if options.has_key("--lanplus"):
> +        cmd += " -I lanplus"
> +    else:
> +        cmd += " -I lan"
> +    # --ip / -a
> +    cmd += " -H " + options["--ip"]
> +
> +    # --username / -l
> +    if options.has_key("--username") and len(options["--username"]) != 0:
> +        cmd += " -U " + quote(options["--username"])
> +
> +    # --auth / -A
> +    if options.has_key("--auth"):
> +        cmd += " -A " + options["--auth"]
> +
> +    # --password / -p
> +    if options.has_key("--password"):
> +        cmd += " -P " + quote(options["--password"])
> +
> +    # --cipher / -C
> +    cmd += " -C " + options["--cipher"]
> +
> +    # --port / -n
> +    if options.has_key("--ipport"):
> +        cmd += " -p " + options["--ipport"]
> +
> +    if options.has_key("--privlvl"):
> +        cmd += " -L " + options["--privlvl"]
> +
> +    # --action / -o
> +    cmd += " chassis power " + action
> +
> +     # --use-sudo / -d
> +    if options.has_key("--use-sudo"):
> +        cmd = SUDO_PATH + " " + cmd
> +
> +    return cmd
> +
> +def define_new_opts():
> +    all_opt["lanplus"] = {
> +        "getopt" : "L",
> +        "longopt" : "lanplus",
> +        "help" : "-L, --lanplus    Use Lanplus to improve security of connection",
> +        "required" : "0",
> +        "shortdesc" : "Use Lanplus to improve security of connection",
> +        "order": 1
> +        }
> +    all_opt["auth"] = {
> +        "getopt" : "A:",
> +        "longopt" : "auth",
> +        "help" : "-A, --auth=[auth]    IPMI Lan Auth type (md5|password|none)",
> +        "required" : "0",
> +        "shortdesc" : "IPMI Lan Auth type.",
> +        "default" : "none",
> +        "choices" : ["md5", "password", "none"],
> +        "order": 1
> +        }
> +    all_opt["cipher"] = {
> +        "getopt" : "C:",
> +        "longopt" : "cipher",
> +        "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",
> +        "order": 1
> +        }
> +    all_opt["privlvl"] = {
> +        "getopt" : "P:",
> +        "longopt" : "privlvl",
> +        "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
> +        }
> +
> +def main():
> +
> +    atexit.register(atexit_handler)
> +
> +    device_opt = [ "ipaddr", "login", "no_login", "no_password", "passwd", "lanplus", "auth", "cipher", "privlvl", "sudo"]
> +    define_new_opts()
> +
> +    all_opt["ipport"]["default"] = "623"
> +
> +    options = check_input(device_opt, process_input(device_opt))
> +    options["ipmitool_path"] = get_ipmitool_path()
> +
> +    if options["ipmitool_path"] is None:
> +        fail(EC_TOOL_FAIL)
> +
> +    docs = { }
> +    docs["shortdesc"] = "Fence agent for IPMI"
> +    docs["longdesc"] = "Fence agent for IPMI"
> +    docs["vendorurl"] = ""
> +    show_docs(options, docs)
> +
> +    result = fence_action(None, options, set_power_status, get_power_status, None)
> +
> +    sys.exit(result)
> +
> +if __name__ == "__main__":
> +    main()
> diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
> index 0a3b122..b4abfb2 100644
> --- a/fence/agents/lib/fencing.py.py
> +++ b/fence/agents/lib/fencing.py.py
> @@ -25,6 +25,7 @@ EC_STATUS          = 8
>  EC_STATUS_HMC      = 9
>  EC_PASSWORD_MISSING = 10
>  EC_INVALID_PRIVILEGES = 11
> +EC_TOOL_FAIL	  = 12
>  
>  TELNET_PATH = "/usr/bin/telnet"
>  SSH_PATH    = "/usr/bin/ssh"
> @@ -412,7 +413,8 @@ def fail(error_code):
>  		EC_STATUS_HMC :
>  			"Failed: Either unable to obtain correct plug status, partition is not available or incorrect HMC version used",
>  		EC_PASSWORD_MISSING : "Failed: You have to set login password",
> -		EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action."
> +		EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action.",
> +		EC_TOOL_FAIL: "Failed: Required tool not found or not accessible."
>  	}[error_code] + "\n"
>  	sys.stderr.write(message)
>  	syslog.syslog(syslog.LOG_ERR, message)
> 



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

* [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library
  2013-11-21 15:48   ` Fabio M. Di Nitto
@ 2013-11-22 16:18     ` Jan Pokorný
  2013-11-22 18:35       ` Fabio M. Di Nitto
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Pokorný @ 2013-11-22 16:18 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On 21/11/13 16:48 +0100, Fabio M. Di Nitto wrote:
> On 11/21/2013 4:16 PM, Ondrej Mular wrote:
>> +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"]
> 
> this hard-cording it bad.
> 
> Always use OS define PATH and if really necessary allow user to override
> with an option (for example: --pathtoipmitool=/usr/local....)

see, e.g.,
http://git.engineering.redhat.com/users/jpokorny/clufter/tree/utils.py?id=d37db7470f4e44598af0b91d02221182178677ff#n22
that mimics "which" standard utility

Hope this helps

-- 
Jan



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

* [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library
  2013-11-22 16:18     ` Jan Pokorný
@ 2013-11-22 18:35       ` Fabio M. Di Nitto
  0 siblings, 0 replies; 5+ messages in thread
From: Fabio M. Di Nitto @ 2013-11-22 18:35 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On 11/22/2013 5:18 PM, Jan Pokorn? wrote:
> On 21/11/13 16:48 +0100, Fabio M. Di Nitto wrote:
>> On 11/21/2013 4:16 PM, Ondrej Mular wrote:
>>> +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"]
>>
>> this hard-cording it bad.
>>
>> Always use OS define PATH and if really necessary allow user to override
>> with an option (for example: --pathtoipmitool=/usr/local....)
> 
> see, e.g.,
> http://git.engineering.redhat.com/users/jpokorny/clufter/tree/utils.py?id=d37db7470f4e44598af0b91d02221182178677ff#n22
> that mimics "which" standard utility
> 
> Hope this helps
> 

I?d like to understand why we need a search path in the first place tho
and we can?t just rely on shell hitting the right tool :)

Fabio



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

* [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library
  2013-11-21 15:16 ` [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library Ondrej Mular
  2013-11-21 15:48   ` Fabio M. Di Nitto
@ 2013-11-25  8:35   ` Jan Friesse
  1 sibling, 0 replies; 5+ messages in thread
From: Jan Friesse @ 2013-11-25  8:35 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Ondrej,
there is missing --method parameter. This is needed by some IPMI devices
(there were BZs), because some devices turn off MANAGEMENT card instead
of computer -> no way how to turn it back on. Also this may be seen as a
regression. Also power cycle using cycle command is ... WAY faster (ipmi
is usually quite slow, and doing status / off / status / on / status is
slow).

Regards,
  Honza

Ondrej Mular napsal(a):
> This is port of fence_ipmilan to fencing library. Also added fail message to fencing library if tool (e.g. impitool, amttool...) is not accessible.
> 
> ---
>  fence/agents/ipmilan/fence_ipmilan.py | 184 ++++++++++++++++++++++++++++++++++
>  fence/agents/lib/fencing.py.py        |   4 +-
>  2 files changed, 187 insertions(+), 1 deletion(-)
>  create mode 100644 fence/agents/ipmilan/fence_ipmilan.py
> 
> diff --git a/fence/agents/ipmilan/fence_ipmilan.py b/fence/agents/ipmilan/fence_ipmilan.py
> new file mode 100644
> index 0000000..5c32690
> --- /dev/null
> +++ b/fence/agents/ipmilan/fence_ipmilan.py
> @@ -0,0 +1,184 @@
> +#!/usr/bin/python
> +
> +import sys, shlex, stat, subprocess, re, os
> +from pipes import quote
> +sys.path.append("@FENCEAGENTSLIBDIR@")
> +from fencing import *
> +
> +#BEGIN_VERSION_GENERATION
> +RELEASE_VERSION=""
> +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")
> +
> +    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, ex:
> +        print ex
> +        fail(EC_TOOL_FAIL)
> +
> +    process.wait()
> +
> +    out = process.communicate()
> +    process.stdout.close()
> +
> +    match = re.search('[Cc]hassis [Pp]ower is [\\s]*([a-zA-Z]{2,3})', str(out))
> +    status = match.group(1) if match else None
> +
> +    return status
> +
> +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(shlex.split(cmd), stdout=null, stderr=null)
> +    except OSError:
> +        null.close()
> +        fail(EC_TOOL_FAIL)
> +
> +    process.wait()
> +    null.close()
> +
> +    return
> +
> +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 get_ipmitool_path():
> +    for path in PATHS:
> +        if is_executable(path):
> +            return path
> +    return None
> +
> +def create_command(options, action):    
> +    cmd = options["ipmitool_path"]
> +
> +    # --lanplus / -L
> +    if options.has_key("--lanplus"):
> +        cmd += " -I lanplus"
> +    else:
> +        cmd += " -I lan"
> +    # --ip / -a
> +    cmd += " -H " + options["--ip"]
> +
> +    # --username / -l
> +    if options.has_key("--username") and len(options["--username"]) != 0:
> +        cmd += " -U " + quote(options["--username"])
> +
> +    # --auth / -A
> +    if options.has_key("--auth"):
> +        cmd += " -A " + options["--auth"]
> +
> +    # --password / -p
> +    if options.has_key("--password"):
> +        cmd += " -P " + quote(options["--password"])
> +
> +    # --cipher / -C
> +    cmd += " -C " + options["--cipher"]
> +
> +    # --port / -n
> +    if options.has_key("--ipport"):
> +        cmd += " -p " + options["--ipport"]
> +
> +    if options.has_key("--privlvl"):
> +        cmd += " -L " + options["--privlvl"]
> +
> +    # --action / -o
> +    cmd += " chassis power " + action
> +
> +     # --use-sudo / -d
> +    if options.has_key("--use-sudo"):
> +        cmd = SUDO_PATH + " " + cmd
> +
> +    return cmd
> +
> +def define_new_opts():
> +    all_opt["lanplus"] = {
> +        "getopt" : "L",
> +        "longopt" : "lanplus",
> +        "help" : "-L, --lanplus    Use Lanplus to improve security of connection",
> +        "required" : "0",
> +        "shortdesc" : "Use Lanplus to improve security of connection",
> +        "order": 1
> +        }
> +    all_opt["auth"] = {
> +        "getopt" : "A:",
> +        "longopt" : "auth",
> +        "help" : "-A, --auth=[auth]    IPMI Lan Auth type (md5|password|none)",
> +        "required" : "0",
> +        "shortdesc" : "IPMI Lan Auth type.",
> +        "default" : "none",
> +        "choices" : ["md5", "password", "none"],
> +        "order": 1
> +        }
> +    all_opt["cipher"] = {
> +        "getopt" : "C:",
> +        "longopt" : "cipher",
> +        "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",
> +        "order": 1
> +        }
> +    all_opt["privlvl"] = {
> +        "getopt" : "P:",
> +        "longopt" : "privlvl",
> +        "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
> +        }
> +
> +def main():
> +
> +    atexit.register(atexit_handler)
> +
> +    device_opt = [ "ipaddr", "login", "no_login", "no_password", "passwd", "lanplus", "auth", "cipher", "privlvl", "sudo"]
> +    define_new_opts()
> +
> +    all_opt["ipport"]["default"] = "623"
> +
> +    options = check_input(device_opt, process_input(device_opt))
> +    options["ipmitool_path"] = get_ipmitool_path()
> +
> +    if options["ipmitool_path"] is None:
> +        fail(EC_TOOL_FAIL)
> +
> +    docs = { }
> +    docs["shortdesc"] = "Fence agent for IPMI"
> +    docs["longdesc"] = "Fence agent for IPMI"
> +    docs["vendorurl"] = ""
> +    show_docs(options, docs)
> +
> +    result = fence_action(None, options, set_power_status, get_power_status, None)
> +
> +    sys.exit(result)
> +
> +if __name__ == "__main__":
> +    main()
> diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
> index 0a3b122..b4abfb2 100644
> --- a/fence/agents/lib/fencing.py.py
> +++ b/fence/agents/lib/fencing.py.py
> @@ -25,6 +25,7 @@ EC_STATUS          = 8
>  EC_STATUS_HMC      = 9
>  EC_PASSWORD_MISSING = 10
>  EC_INVALID_PRIVILEGES = 11
> +EC_TOOL_FAIL	  = 12
>  
>  TELNET_PATH = "/usr/bin/telnet"
>  SSH_PATH    = "/usr/bin/ssh"
> @@ -412,7 +413,8 @@ def fail(error_code):
>  		EC_STATUS_HMC :
>  			"Failed: Either unable to obtain correct plug status, partition is not available or incorrect HMC version used",
>  		EC_PASSWORD_MISSING : "Failed: You have to set login password",
> -		EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action."
> +		EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action.",
> +		EC_TOOL_FAIL: "Failed: Required tool not found or not accessible."
>  	}[error_code] + "\n"
>  	sys.stderr.write(message)
>  	syslog.syslog(syslog.LOG_ERR, message)
> 



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

end of thread, other threads:[~2013-11-25  8:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1466780058.2338929.1385045970240.JavaMail.root@redhat.com>
2013-11-21 15:16 ` [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library Ondrej Mular
2013-11-21 15:48   ` Fabio M. Di Nitto
2013-11-22 16:18     ` Jan Pokorný
2013-11-22 18:35       ` Fabio M. Di Nitto
2013-11-25  8:35   ` Jan Friesse

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).