Skip to contentSkip to conversation

fence_ipal: Introduce ipal fence agent

PATCH New Andrea Bucci 2 participants 2 messages Apr 17, 2014 – Apr 23, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fence_ipal: Introduce ipal fence agent

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
configure.ac +1 -0
index c24198c..fc9e117 100644
@@ -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
fence/agents/ipal/Makefile.am new file +18 -0
new file mode 100644
index 0000000..0a45e8e
@@ -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)
fence/agents/ipal/fence_ipal new file +20 -0
new file mode 100755
index 0000000..3b073e5
@@ -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))
fence/agents/ipal/ipal new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 fence_ipal: Introduce ipal fence agent

Hi,

Unfortunately, this fence agent can not be accepted without additional changes. I have no major problem of 'expect' file but fence agent has to produce at least valid xml metadata, support not only stdin-options but also command line options. There is a fencing library that provides a lot
of required features and it should not be difficult to port your python part to it, you can run your expect file from there too. We alredy use that approach for amt or ipmi

m,

Quoted 130 lines · Andrea Bucci

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

configure.ac +1 -0
index c24198c..fc9e117 100644
@@ -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
fence/agents/ipal/Makefile.am new file +18 -0
new file mode 100644
index 0000000..0a45e8e
@@ -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)
fence/agents/ipal/fence_ipal new file +20 -0
new file mode 100755
index 0000000..3b073e5
@@ -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))
fence/agents/ipal/ipal new file +51 -0
new file mode 100755
index 0000000..62de7a6
@@ -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
+    }
+}