From: Jan Friesse <jfriesse@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 1/2] fence_ipmilan: port fencing agent to fencing library
Date: Mon, 25 Nov 2013 09:35:12 +0100 [thread overview]
Message-ID: <52930BC0.8090105@redhat.com> (raw)
In-Reply-To: <356610666.2341611.1385047003114.JavaMail.root@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)
>
prev parent reply other threads:[~2013-11-25 8:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 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=52930BC0.8090105@redhat.com \
--to=jfriesse@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.