[Cluster-devel] [PATCH] fence_ipal: Introduce ipal fence agent
Andrea Bucci
andreavb at linux.vnet.ibm.com
Thu Apr 17 13:07:13 UTC 2014
Based on 2012 code by Gustavo Rahal
---
configure.ac | 1 +
fence/agents/ipal/Makefile.am | 18 +++++++++++++++
fence/agents/ipal/fence_ipal | 20 ++++++++++++++++
fence/agents/ipal/ipal | 51 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 90 insertions(+)
create mode 100644 fence/agents/ipal/Makefile.am
create mode 100755 fence/agents/ipal/fence_ipal
create mode 100755 fence/agents/ipal/ipal
diff --git a/configure.ac b/configure.ac
index c24198c..fc9e117 100644
--- a/configure.ac
+++ b/configure.ac
@@ -268,6 +268,7 @@ AC_CONFIG_FILES([Makefile
fence/agents/eps/Makefile
fence/agents/hpblade/Makefile
fence/agents/ibmblade/Makefile
+ fence/agents/ipal/Makefile
fence/agents/ipdu/Makefile
fence/agents/ifmib/Makefile
fence/agents/ilo/Makefile
diff --git a/fence/agents/ipal/Makefile.am b/fence/agents/ipal/Makefile.am
new file mode 100644
index 0000000..0a45e8e
--- /dev/null
+++ b/fence/agents/ipal/Makefile.am
@@ -0,0 +1,18 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+TARGET = fence_ipal
+
+SYMTARGET = ipal
+
+SRC = $(TARGET).py
+
+EXTRA_DIST = $(SRC)
+
+sbin_SCRIPTS = $(TARGET)
+bin_SCRIPTS = $(SYMTARGET)
+
+include $(top_srcdir)/make/fencebuild.mk
+include $(top_srcdir)/make/fenceman.mk
+
+clean-local: clean-man
+ rm -f $(TARGET) $(SYMTARGET)
diff --git a/fence/agents/ipal/fence_ipal b/fence/agents/ipal/fence_ipal
new file mode 100755
index 0000000..3b073e5
--- /dev/null
+++ b/fence/agents/ipal/fence_ipal
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import sys
+import os
+
+# STDIN format:
+# "action=$power_mode\nlogin=$power_user\npasswd=$power_pass\nipaddr=$power_address\nport=$power_id"
+stdin_str = sys.stdin.read()
+#print "STDIN: " + stdin_str
+
+action_kv, login_kv, passwd_kv, ipaddr_kv, port_kv = stdin_str.split()
+
+action = action_kv.replace("action=", "")
+login = login_kv.replace("login=", "")
+passwd = passwd_kv.replace("passwd=", "")
+ipaddr = ipaddr_kv.replace("ipaddr=", "")
+port = port_kv.replace("port=", "")
+
+if action == "on":
+ os.system("ipal %s %s %s" % (ipaddr, port, passwd))
diff --git a/fence/agents/ipal/ipal b/fence/agents/ipal/ipal
new file mode 100755
index 0000000..62de7a6
--- /dev/null
+++ b/fence/agents/ipal/ipal
@@ -0,0 +1,51 @@
+#!/usr/bin/expect
+
+#@IMPROVEMENT port to python, as it is the most common programming language in
+# fence-agents and it removes the need of having two files for this agent
+
+if { [ llength $argv ] == 0 || [ llength $argv ] > 4} {
+ send_user "Usage: ipal <host> <outlet-portnumber> <passwd> \[ <toggles> \]\n"
+ exit 1
+}
+
+set host [lindex $argv 0]
+set outletnumber [lindex $argv 1]
+set passwd [lindex $argv 2]
+set toggles 2
+if { [ llength $argv ] == 4 } {
+ set toggles [ lindex $argv 3 ]
+}
+set remain $toggles
+
+spawn telnet $host
+set env(TERM) vt100
+set timeout 30
+
+expect timeout {
+ send_user "failed to contact $host\n"
+ exit
+} "Password >" {
+ # first password prompt, so just send a return
+ send "\r"
+}
+
+while {1} {
+ expect timeout {
+ send_user "failed to contact $host\n"
+ exit
+ } "Password >" {
+ # second password prompt, so send password
+ send "$passwd\r"
+ } "Enter >" {
+ # reboot prompt
+ if { $remain == 0 } {
+ send_user "\ntoggled outlet $outletnumber $toggles times\n"
+ exit 0
+ }
+ send "$outletnumber\r"
+ set remain [expr { $remain - 1 } ]
+ } eof {
+ send_user "failed to connect to power strip\n"
+ exit
+ }
+}
--
1.7.9.5
More information about the Cluster-devel
mailing list