* [Cluster-devel] [PATCH] fence_ipal: Introduce ipal fence agent
@ 2014-04-17 13:07 Andrea Bucci
2014-04-23 9:35 ` Marek Grac
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Bucci @ 2014-04-17 13:07 UTC (permalink / raw)
To: cluster-devel.redhat.com
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Cluster-devel] [PATCH] fence_ipal: Introduce ipal fence agent
2014-04-17 13:07 [Cluster-devel] [PATCH] fence_ipal: Introduce ipal fence agent Andrea Bucci
@ 2014-04-23 9:35 ` Marek Grac
0 siblings, 0 replies; 2+ messages in thread
From: Marek Grac @ 2014-04-23 9:35 UTC (permalink / raw)
To: cluster-devel.redhat.com
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,
On 04/17/2014 03:07 PM, Andrea Bucci wrote:
> 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
> + }
> +}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-04-23 9:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-17 13:07 [Cluster-devel] [PATCH] fence_ipal: Introduce ipal fence agent Andrea Bucci
2014-04-23 9:35 ` Marek Grac
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).