Cluster Project branch, STABLE2, updated. cluster-2.03.01-35-ga1c4508

fabbione@sourceware.org fabbione@sourceware.org
Fri Apr 25 12:51:00 GMT 2008


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Cluster Project".

http://sources.redhat.com/git/gitweb.cgi?p=cluster.git;a=commitdiff;h=a1c4508cc0f8fbad39e3769f9e812d773dc43010

The branch, STABLE2 has been updated
       via  a1c4508cc0f8fbad39e3769f9e812d773dc43010 (commit)
       via  40500d1308b4d5c25adc61127cb08e29428ff7fc (commit)
       via  c6f398d6a7f562f72c9f87369780a6ed09a4fc94 (commit)
       via  3dbb69dde3e1c5ec59ef9eb0077bb026a1c906bf (commit)
       via  ca31f682c99033a4b200896bc02ee31766c8fbb4 (commit)
       via  41bf99b6a7c5f612e2e35417cfb81f62b25f12d7 (commit)
       via  9957de81e2216225bb15e2810487345221f86769 (commit)
       via  a7c08962a5dd4c0893e01794dcd5014deb0e9c9e (commit)
       via  7793a1dcdb25e29d91858d8fb03ecb4b672ef438 (commit)
       via  2910f3ccbfbfd01bad004613670ba225ad04281e (commit)
       via  0241887d15738cd59b5374420d908a4d5ce38001 (commit)
       via  9e4b66772171683279ad3682780d09920e6e15f8 (commit)
       via  4771a07ee7e9c1efcb58753d863404b6a3a1ba24 (commit)
       via  d8b58867e89df7bff358a4d3e70d219c512dd1b6 (commit)
       via  565f473b3e4809ed252f18afb7d6a1ac2a479092 (commit)
       via  9f32ca6ee209beef889a437b1b931459f6aa17d8 (commit)
       via  7b15cdeaeef5d2816e2bb7e6bab76f98d077915d (commit)
       via  4b6835f18045883df3c742478b6ed8112f6b627e (commit)
       via  0c0948b5a078ac298446bc6f1795256416de865b (commit)
       via  08d5fe761dacb819c8f44e4044f2714fc74f9a50 (commit)
       via  e55866e9e0011ce8b319e3cd17d1ddbf587bcaf6 (commit)
      from  523acee2a3aa7340acc04a28e43164f090b615df (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a1c4508cc0f8fbad39e3769f9e812d773dc43010
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date:   Fri Apr 25 11:10:17 2008 +0200

    [BUILD] Fix fence lib install target
    
    Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

commit 40500d1308b4d5c25adc61127cb08e29428ff7fc
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date:   Wed Apr 23 09:06:47 2008 +0200

    [BUILD] Fix install/uninstall targets for fence/agents/lib
    
    Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

commit c6f398d6a7f562f72c9f87369780a6ed09a4fc94
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date:   Fri Apr 25 14:08:11 2008 +0200

    [RGMANAGER] Fix uninstall target
    
    Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

commit 3dbb69dde3e1c5ec59ef9eb0077bb026a1c906bf
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date:   Fri Apr 25 13:54:38 2008 +0200

    [FENCE] Enable new fence agents by default
    
    Remove enable_fence_experimental_agents configure option in favour of
    "crack_of_the_day"
    
    Rename files around as agreed with Marek.
    
    Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

commit ca31f682c99033a4b200896bc02ee31766c8fbb4
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date:   Wed Apr 23 08:52:05 2008 +0200

    [BUILD] Deal with the new libfence properly
    
    configure, make/defines.mk.input:
      - rename fencelibdir to fenceagentslibdir to avoid name space collision.
    
    make/fencebuild.mk, make/install.mk, make/uninstall.mk, fence/agents/apc/apc.py,
    fence/agents/bladecenter/bladecenter.py, fence/agents/drac/drac5.py,
    fence/agents/ilo/ilo.py, fence/agents/lib/Makefile, fence/agents/wti/wti.py:
      - rename fencelibdir to fenceagentslibdir.
    
    Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

commit 41bf99b6a7c5f612e2e35417cfb81f62b25f12d7
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
Date:   Tue Apr 22 20:33:31 2008 +0200

    [MISC] Update copyright headers
    
    Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

commit 9957de81e2216225bb15e2810487345221f86769
Author: Lon Hohberger <lhh@redhat.com>
Date:   Wed Apr 16 10:11:35 2008 -0400

    [fence] Preliminary TPS/NBB/NPS support in new WTI agent.

commit a7c08962a5dd4c0893e01794dcd5014deb0e9c9e
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 8 22:46:19 2008 +0200

    [BUILD] Fix clean target for experimental fence/agents/lib
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 7793a1dcdb25e29d91858d8fb03ecb4b672ef438
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 22:53:09 2008 +0200

    [FENCE] Make sure to version and copyright all built files
    
    Like all fence agents, those info can be useful. Store them
    in the modules even if only the libs print them out.
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 2910f3ccbfbfd01bad004613670ba225ad04281e
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 22:50:28 2008 +0200

    [FENCE] Fix fencelib to pring version and copyright
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 0241887d15738cd59b5374420d908a4d5ce38001
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 22:24:15 2008 +0200

    [BUILD] Enable build and install of experimental fence agents
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 9e4b66772171683279ad3682780d09920e6e15f8
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 22:18:12 2008 +0200

    [BUILD] Royal cleanup of the fence agents build system
    
    Collapse fenceperl and fencepy into fencebuild.
    
    fencebuild now use a much simpler and slightly more clever
    shell script scripts/fenceparse instead of scripts/define2var
    that was no longer used anywhere in the tree.
    
    update all the fence/agents/ Makefile to use fencebuild.mk.
    
    make fencebuild understand more than one target at a time.
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 4771a07ee7e9c1efcb58753d863404b6a3a1ba24
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 22:09:53 2008 +0200

    [FENCE] Remove obsoleted fence_apc perl implementation
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit d8b58867e89df7bff358a4d3e70d219c512dd1b6
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 22:09:17 2008 +0200

    [FENCE] Move apc_snmp README where it belongs
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 565f473b3e4809ed252f18afb7d6a1ac2a479092
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 22:07:55 2008 +0200

    [FENCE] Move apc_snmp README where it belongs
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 9f32ca6ee209beef889a437b1b931459f6aa17d8
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Tue Apr 1 10:34:23 2008 +0200

    [BUILD] Add fencelibdir support
    
    The new fence agents share a common python library.
    
    Make it's location configurable at build time (default to /usr/lib/fence).
    
    Update all targets required to handle it.
    
    Update the agents accordingly.
    
    NOTE: you will need to re-run configure to propagate the new configuration
    option. The new agents are not used/build/installed yet. This will happen
    shortly.
    
    NOTE to packagers: the new library depends on pexpect.
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 7b15cdeaeef5d2816e2bb7e6bab76f98d077915d
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Sat Mar 29 07:14:44 2008 +0100

    [FENCE] apc_snmp: allow paths to snmp binaries to be configurable
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 4b6835f18045883df3c742478b6ed8112f6b627e
Author: Fabio M. Di Nitto <fabbione@fabbione.net>
Date:   Sat Mar 29 06:47:15 2008 +0100

    [FENCE] Enable fence_apc_snmp
    
    Separate fence_apc_snmp from apc in its own directory.
    
    Update the build system to understand --mibdir and propagate it
    down to fence_apc_snmp and the install targets.
    
    Signed-off-by: Fabio M. Di Nitto <fabbione@fabbione.net>

commit 0c0948b5a078ac298446bc6f1795256416de865b
Author: Marek 'marx' Grac <mgrac@redhat.com>
Date:   Fri Mar 28 18:20:06 2008 +0100

    fence/agents:	Add obsolete options
    
    Added obsolete/dual options like hostname/ippaddr, action/option. These
    options are either translated to new or they are not used anymore/yet in
    new agents (eg. version of firmware).

commit 08d5fe761dacb819c8f44e4044f2714fc74f9a50
Author: Marek 'marx' Grac <mgrac@redhat.com>
Date:   Fri Mar 28 17:18:42 2008 +0100

    fence/agents:	WTI agents merged
    
    Fencing devices from WTI can use password or login/password for loging in.
    This patch merge two fencing agents together so it will be same as old agent.

commit e55866e9e0011ce8b319e3cd17d1ddbf587bcaf6
Author: Marek 'marx' Grac <mgrac@redhat.com>
Date:   Fri Mar 28 16:11:31 2008 +0100

    fence/agents:	New fencings agents
    
    There are new fencing agents based on a new library. They need a 'pexpect' package. If it is possible there is support for both telnet and ssh. In this patch there are agents for: APC, BladeCenter, Drac 5, ILo and WTI. It is possible that backward compatibility is broken (to be fixed).

-----------------------------------------------------------------------

Summary of changes:
 Makefile                                         |    2 +-
 configure                                        |   22 +
 fence/agents/Makefile                            |    2 +-
 fence/agents/apc/Makefile                        |    5 +-
 fence/agents/apc/fence_apc.pl                    |  469 -----------
 fence/agents/apc/fence_apc.py                    |  899 ++--------------------
 fence/agents/{apc => apc_snmp}/Makefile          |    5 +-
 fence/agents/{apc => apc_snmp}/README            |    0 
 fence/agents/{apc => apc_snmp}/fence_apc_snmp.py |   20 +-
 fence/agents/{apc => apc_snmp}/powernet369.mib   |    0 
 fence/agents/baytech/Makefile                    |    2 +-
 fence/agents/bladecenter/Makefile                |    5 +-
 fence/agents/bladecenter/fence_bladecenter.pl    |  402 ++--------
 fence/agents/brocade/Makefile                    |    2 +-
 fence/agents/bullpap/Makefile                    |    2 +-
 fence/agents/cpint/Makefile                      |    2 +-
 fence/agents/drac/Makefile                       |    7 +-
 fence/agents/drac/fence_drac5.py                 |   79 ++
 fence/agents/egenera/Makefile                    |    2 +-
 fence/agents/ibmblade/Makefile                   |    2 +-
 fence/agents/ilo/Makefile                        |    5 +-
 fence/agents/ilo/fence_ilo.pl                    |  655 ----------------
 fence/agents/ilo/fence_ilo.py                    |   77 ++
 fence/agents/{apc => lib}/Makefile               |   16 +-
 fence/agents/lib/fencing.py.py                   |  347 +++++++++
 fence/agents/mcdata/Makefile                     |    2 +-
 fence/agents/rsa/Makefile                        |    2 +-
 fence/agents/rsb/Makefile                        |    2 +-
 fence/agents/sanbox2/Makefile                    |    2 +-
 fence/agents/scsi/Makefile                       |   32 +-
 fence/agents/vixel/Makefile                      |    2 +-
 fence/agents/vmware/Makefile                     |    2 +-
 fence/agents/wti/Makefile                        |    5 +-
 fence/agents/wti/fence_wti.pl                    |  384 ---------
 fence/agents/wti/fence_wti.py                    |  109 +++
 fence/agents/xcat/Makefile                       |    2 +-
 fence/agents/zvm/Makefile                        |    2 +-
 make/clean.mk                                    |    2 +-
 make/defines.mk.input                            |    6 +-
 make/fencebuild.mk                               |   26 +
 make/fenceperl.mk                                |   18 -
 make/fencepy.mk                                  |   18 -
 make/install.mk                                  |    8 +
 make/uninstall.mk                                |    6 +
 rgmanager/src/resources/Makefile                 |    5 +-
 scripts/define2var                               |   71 --
 scripts/fenceparse                               |   47 ++
 47 files changed, 955 insertions(+), 2827 deletions(-)
 delete mode 100755 fence/agents/apc/fence_apc.pl
 mode change 100644 => 100755 fence/agents/apc/fence_apc.py
 copy fence/agents/{apc => apc_snmp}/Makefile (88%)
 rename fence/agents/{apc => apc_snmp}/README (100%)
 rename fence/agents/{apc => apc_snmp}/fence_apc_snmp.py (94%)
 rename fence/agents/{apc => apc_snmp}/powernet369.mib (100%)
 create mode 100755 fence/agents/drac/fence_drac5.py
 delete mode 100755 fence/agents/ilo/fence_ilo.pl
 create mode 100755 fence/agents/ilo/fence_ilo.py
 copy fence/agents/{apc => lib}/Makefile (71%)
 create mode 100644 fence/agents/lib/fencing.py.py
 delete mode 100755 fence/agents/wti/fence_wti.pl
 create mode 100755 fence/agents/wti/fence_wti.py
 create mode 100644 make/fencebuild.mk
 delete mode 100644 make/fenceperl.mk
 delete mode 100644 make/fencepy.mk
 delete mode 100755 scripts/define2var
 create mode 100755 scripts/fenceparse

diff --git a/Makefile b/Makefile
index 7346272..63c03c3 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ all: scripts ${SUBDIRS}
 
 # Fix scripts permissions
 scripts:
-	chmod 755 ${SRCDIR}/scripts/*.pl ${SRCDIR}/scripts/define2var
+	chmod 755 ${SRCDIR}/scripts/*.pl ${SRCDIR}/scripts/fenceparse
 
 ${SUBDIRS}:
 	[ -n "${without_$@}" ] || ${MAKE} -C $@ all
diff --git a/configure b/configure
index 9160e10..787b67d 100755
--- a/configure
+++ b/configure
@@ -77,9 +77,12 @@ my %options = (
 	prefix => \$prefix,
 	sbindir => \$sbindir,
 	sharedir => \$sharedir,
+	mibdir => \$mibdir,
+	snmpbin => \$snmpbin,
 	confdir => \$confdir,
 	conffile => \$conffile,
 	fence_agents => \$fence_agents,
+	fenceagentslibdir => \$fenceagentslibdir,
 	enable_xen => \$enable_xen,
 	somajor => \$somajor,
 	sominor => \$sominor,
@@ -143,12 +146,15 @@ my $err = &GetOptions (\%options,
 		    'prefix=s',
 		    'sbindir=s',
 		    'sharedir=s',
+		    'mibdir=s',
+		    'snmpbin=s',
 		    'confdir=s',
 		    'conffile=s',
 		    'somajor=s',
 		    'sominor=s',
 		    'release_version=s',
 		    'fence_agents=s',
+		    'fenceagentslibdir=s',
 		    'enable_xen',
 		    'without_ccs',
 		    'without_cman',
@@ -178,6 +184,8 @@ if ($help || !$err) {
   print "--libdir=\tthe base directory for libraries.  (Default: {prefix}/lib)\n";
   print "--libexecdir=\tthe base directory for executable components.  (Default: {prefix}/libexec)\n";
   print "--sharedir=\tthe base directory for misc cluster files.  (Default: {prefix}/share/cluster)\n";
+  print "--mibdir=\tthe base directory for snmp mibs.  (Default: {prefix}/share/snmp/mibs)\n";
+  print "--snmpbin=\tthe base directory for snmp binaries (Ex: /usr/bin/snmpwalk).  (Default: {prefix}/bin)\n";
   print "--confdir=\tthe cluster config directory.  (Default: /etc/cluster)\n";
   print "--conffile=\tthe cluster config file.  (Default: cluster.conf)\n";
   print "--mandir=\tthe base directory for man pages.  (Default: {prefix}/share/man)\n";
@@ -221,6 +229,7 @@ if ($help || !$err) {
   print "--xenlibdir=\tthe base directory for xen libraries.  (Default: {libdir})\n";
   print "--fence_agents=\tlist of fence agents to configure.  (Default: all)\n";
   print "\t\tUse --fence_agents=help for a list\n";
+  print "--fenceagentslibdir=\tspecify directory where to install common fence python lib.  (Default: /usr/lib/fence)\n";
   print "--enable_xen\tEnable building of Xen-specific pieces\n";
   print "--without_ccs\tDisable ccs building  (Default: enabled)\n";
   print "--without_cman\tDisable cman building  (Default: enabled)\n";
@@ -478,6 +487,12 @@ if (!$sbindir) {
 if (!$sharedir) {
   $sharedir="${prefix}/share/cluster";
 }
+if (!$mibdir) {
+  $mibdir="${prefix}/share/snmp/mibs";
+}
+if (!$snmpbin) {
+  $snmpbin="${prefix}/bin";
+}
 if (!$confdir) {
   $confdir="/etc/cluster";
 }
@@ -487,6 +502,9 @@ if (!$conffile) {
 if (!$fence_agents) {
   $fence_agents="all";
 }
+if (!$fenceagentslibdir) {
+  $fenceagentslibdir="/usr/lib/fence";
+}
 if (!$enable_xen) {
   $enable_xen="";
 }
@@ -535,6 +553,7 @@ open (IFILE, "@args |");
 while (<IFILE>) {
   chomp;
   s|fence\/agents\/| |g;
+  s|lib ||g;
   $all_fence = $_;
 }
 close IFILE;
@@ -599,9 +618,12 @@ while (<IFILE>) {
   $_ =~ s/\@MANDIR\@/$mandir/;
   $_ =~ s/\@SBINDIR\@/$sbindir/;
   $_ =~ s/\@SHAREDIR\@/$sharedir/;
+  $_ =~ s/\@MIBDIR\@/$mibdir/;
+  $_ =~ s/\@SNMPBIN\@/$snmpbin/;
   $_ =~ s/\@CONFDIR\@/$confdir/;
   $_ =~ s/\@CONFFILE\@/$conffile/;
   $_ =~ s/\@FENCE_AGENTS\@/$fence_agents/;
+  $_ =~ s/\@FENCEAGENTSLIBDIR\@/$fenceagentslibdir/;
   $_ =~ s/\@ENABLE_XEN\@/$enable_xen/;
   $_ =~ s/\@DISABLE_CCS\@/$without_ccs/;
   $_ =~ s/\@DISABLE_CMAN\@/$without_cman/;
diff --git a/fence/agents/Makefile b/fence/agents/Makefile
index a349cea..c90dcb3 100644
--- a/fence/agents/Makefile
+++ b/fence/agents/Makefile
@@ -13,7 +13,7 @@
 
 include ../../make/defines.mk
 
-SUBDIRS = ${fence_agents}
+SUBDIRS = ${fence_agents} lib
 
 all: ${SUBDIRS}
 
diff --git a/fence/agents/apc/Makefile b/fence/agents/apc/Makefile
index 7292eb8..0299a61 100644
--- a/fence/agents/apc/Makefile
+++ b/fence/agents/apc/Makefile
@@ -11,7 +11,8 @@
 ###############################################################################
 ###############################################################################
 
+include ../../../make/defines.mk
+
 TARGET= fence_apc
 
-include ../../../make/defines.mk
-include $(OBJDIR)/make/fencepy.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/apc/fence_apc.pl b/fence/agents/apc/fence_apc.pl
deleted file mode 100755
index 7ab2060..0000000
--- a/fence/agents/apc/fence_apc.pl
+++ /dev/null
@@ -1,469 +0,0 @@
-#!/usr/bin/perl
-
-###############################################################################
-###############################################################################
-##
-##  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
-##  Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
-##  
-##  This copyrighted material is made available to anyone wishing to use,
-##  modify, copy, or redistribute it subject to the terms and conditions
-##  of the GNU General Public License v.2.
-##
-###############################################################################
-###############################################################################
-
-use Getopt::Std;
-use Net::Telnet ();
-
-# Get the program name from $0 and strip directory names
-$_=$0;
-s/.*\///;
-my $pname = $_;
-
-# Change these if the text returned by your equipment is different.
-# Test by running script with options -t -v and checking /tmp/apclog
-
-my $immediate = 'immediate'; # # Or 'delayed' - action string prefix on menu
-my $masterswitch = 'masterswitch plus '; # 'Device Manager' option to choose
-my $login_prompt = '/: /';
-my $cmd_prompt = '/> $/';
-
-my $max_open_tries = 3;      # How many telnet attempts to make.  Because the 
-                             # APC can fail repeated login attempts, this number
-                             # should be more than 1
-my $open_wait = 5;           # Seconds to wait between each telnet attempt
-my $telnet_timeout = 2;      # Seconds to wait for matching telent response
-my $debuglog = '/tmp/apclog';# Location of debugging log when in verbose mode
-$opt_o = 'reboot';           # Default fence action.  
-
-my $logged_in = 0;
-
-my $t = new Net::Telnet;
-
-
-
-# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and 
-# "#END_VERSION_GENERATION"  It is generated by the Makefile
-
-#BEGIN_VERSION_GENERATION
-$RELEASE_VERSION="";
-$REDHAT_COPYRIGHT="";
-$BUILD_DATE="";
-#END_VERSION_GENERATION
-
-sub usage 
-{
-	print "Usage:\n";
-	print "\n";
-	print "$pname [options]\n";
-	print "\n";
-	print "Options:\n";
-	print "  -a <ip>          IP address or hostname of MasterSwitch\n";
-	print "  -h               usage\n";
-	print "  -l <name>        Login name\n";
-	print "  -n <num>         Outlet number to change: [<switch>:]<outlet> \n";
-	print "  -o <string>      Action: Reboot (default), Off or On\n";
-	print "  -p <string>      Login password\n";
-	print "  -q               quiet mode\n";
-	print "  -T               Test mode (cancels action)\n";
-	print "  -V               version\n";
-	print "  -v               Log to file /tmp/apclog\n";
-	
-	exit 0;
-}
-
-sub fail
-{
-	($msg)=@_;
-	print $msg."\n" unless defined $opt_q;
-
-	if (defined $t)
-	{
-		# make sure we don't get stuck in a loop due to errors
-		$t->errmode('return');  
-
-		logout() if $logged_in;
-		$t->close();
-	}
-	exit 1;
-}
-
-sub fail_usage
-{
-	($msg)=@_;
-	print STDERR $msg."\n" if $msg;
-	print STDERR "Please use '-h' for usage.\n";
-	exit 1;
-}
-
-sub version
-{
-	print "$pname $RELEASE_VERSION $BUILD_DATE\n";
-	print "$REDHAT_COPYRIGHT\n" if ( $REDHAT_COPYRIGHT );
-	exit 0;
-}
-
-
-sub login
-{
-	for (my $i=0; $i<$max_open_tries; $i++)
-	{
-		$t->open($opt_a);
-		($_) = $t->waitfor($login_prompt);
-  
-		# Expect 'User Name : ' 
-		if (! /name/i) {
-			$t->close();
-			sleep($open_wait);
-			next;        
-		}
-
-		$t->print($opt_l);
-		($_) = $t->waitfor($login_prompt);
-
-		# Expect 'Password  : ' 
-		if (! /password/i ) {
-			$t->close();
-			sleep($open_wait);
-			next;         
-		}
-  
-		# Send password
-		$t->print($opt_p);  
-
-		(my $dummy, $_) = $t->waitfor('/(>|(?i:user name|password)\s*:) /');
-		if (/> /)
-		{
-			$logged_in = 1;
-
-			# send newline to flush prompt
-			$t->print("");  
-
-			return;
-		}
-		else
-		{
-			fail "invalid username or password";
-		}
-	}
-	fail "failed: telnet failed: ". $t->errmsg."\n" 
-}
-
-# print_escape_char() -- utility subroutine for sending the 'Esc' character
-sub print_escape_char
-{
-	# The APC menu uses "<esc>" to go 'up' menues.  We must set
-	# the output_record_separator to "" so that "\n" is not printed
-	# after the "<esc>" character
-
-	$ors=$t->output_record_separator;
-	$t->output_record_separator("");
-	$t->print("\x1b"); # send escape
-	$t->output_record_separator("$ors");
-}
-
-
-# Determine if the switch is a working state.  Also check to make sure that 
-# the switch has been specified in the case that there are slave switches
-# present.  This assumes that we are at the main menu.
-sub identify_switch
-{
-
-	($_) = $t->waitfor($cmd_prompt);
-	print_escape_char();
-
-	# determine what type of switch we are dealling with
-	($_) = $t->waitfor($cmd_prompt);
-	if ( /Switched Rack PDU: Communication Established/i)
-	{
-		# No further test needed
-	}
-	elsif ( /MS plus 1 : Serial Communication Established/i )
-	{
-		if ( defined $switchnum )
-		{
-			$masterswitch = $masterswitch . $switchnum;
-		}
-		elsif ( /MS plus [^1] : Serial Communication Established/i )
-		{
-			fail "multiple switches detected.  'switch' must be defined.";
-		}
-		else
-		{
-			$switchnum = 1;
-		}
-	}
-	else
-	{
-		fail "APC is in undetermined state"
-	}	
-
-	# send a newline to cause APC to reprint the menu
-	$t->print("");
-}
-
-
-# Navigate through menus to the appropriate outlet control menu of the apc
-# MasterSwitch and 79xx series switches.  Uses multi-line (mostly) 
-# case-insensitive matches to recognise menus and works out what option number 
-# to select from each menu.
-sub navigate
-{
-	# Limit the ammount of menu depths to 20.  We should never be this deep
-	for(my $i=20; $i ; $i--)
-	{
-		# Get the new text from the menu
-		(($_) = $t->waitfor($cmd_prompt)) or next;
-
-		# Identify next option 
-		if ( 
-			# "Control Console", "1- Device Manager"
-			/--\s*control console.*(\d+)\s*-\s*device manager/is  ||
-
-			# 
-			# APC MasterSwitch Menus
-			#
-			# "Device Manager", "1- MasterSwitch plus 1"
-			/--\s*device manager.*(\d+)\s*-\s*$masterswitch/is ||
-
-			# "Device Manager", "1- Cluster Node 0   ON"
-			/--\s*(?:device manager|$masterswitch).*(\d+)\s*-\s+Outlet\s+$switchnum:$opt_n\D[^\n]*\s(?-i:ON|OFF)\*?\s/ism ||
-
-			# "MasterSwitch plus 1", "1- Outlet 1:1  Outlet #1  ON"
-			/--\s*$masterswitch.*(\d+)\s*-\s*Outlet\s+$switchnum:$opt_n\s[^\n]*\s(?-i:ON|OFF)\*?\s/ism ||
-	
-			# Administrator outlet control menu
-			/--\s*Outlet $switchnum:$opt_n\D.*(\d+)\s*-\s*outlet control\s*$switchnum:?$opt_n\D/ism || 
-
-
-			#
-			# APC 79XX Menus
-			#
-			# "3- Outlet Control/Configuration"
-			/--\s*device manager.*(\d+)\s*-\s*Outlet Control/is ||
-
-			# "Device Manager", "1- Cluster Node 0   ON"
-			/--\s*Outlet Control.*\s+?(\d+)\s*-\s+[^\n\r]*\s*Outlet\s+$opt_n\D[^\n]*\s(?-i:ON|OFF)\*?\s/ism ||
-
-			# Administrator Outlet Control menu
-			/--[^\n\r]*Outlet\s+$opt_n\D.*(\d+)\s*-\s*control\s*outlet\s+$opt_n\D/ism ||
-			/--[^\n\r]*Outlet\s+$opt_n\D.*(\d+)\s*-\s*control\s*outlet/ism
-		) {
-			$t->print($1);
-			next;
-		}
-
-		if (/.*Press ([^\n\r]+) to continue.*$/) {
-			$t->print("");
-			next;
-		}
-
-		# "Outlet Control X:N", "4- Immediate Reboot"
-		if ( /(\d+)\s*-\s*$immediate $opt_o/i || 
-                     /--\s*Control Outlet\D.*(\d+)\s*-\s*Immediate\s*$opt_o/is ) {
-			$t->print($1);
-			last;
-		}
-
-		fail "failed: unrecognised menu response\n";
-	}
-}
-
-
-sub logout 
-{
-	# send a newline to make sure that we refresh the menus 
-	# ($t->waitfor() can hang otherwise)
-	$t->print("");
-
-	# Limit the ammount of menu depths to 20.  We should never be this deep
-	for(my $i=20; $i ; $i--)
-	{
-
-		# Get the new text from the menu
-		($_) = $t->waitfor($cmd_prompt);
-
-		if ( 
-			# "Control Console", "4- Logout"	 
-			/--\s*control console.*(\d+)\s*-\s*Logout/is
-		) {
-			$t->print($1);
-			last;
-		}
-		else 
-		{
-			print_escape_char();
-			next;
-		}
-	}
-}
-
-
-sub action
-{
-	# "Enter 'YES' to continue or <ENTER> to cancel : "
-	($_) = $t->waitfor('/: /');
-	if (! /$immediate $opt_o.*outlet $opt_n\s.*YES.*to continue/si ) {
-		fail "failed: unrecognised $opt_o response\n";
-	}
-
-	# Test mode?
-	$t->print($opt_T?'NO':'YES');
-
-	# "Success", "Press <ENTER> to continue..." 
-	($_) = $t->waitfor('/continue/');
-	$t->print('');
-
-	if (defined $opt_T) {
-		logout(); 
-		print "success: test outlet $opt_n $opt_o\n" unless defined $opt_q; 
-		$t->close();
-
-		# Allow the APC some time to clean connection
-		# before next login.
-		sleep 1;
-
-		exit 0;
-	} elsif ( /Success/i ) {
-		logout();
-		print "success: outlet $opt_n $opt_o\n" unless defined $opt_q; 
-		$t->close();
-
-		# Allow the APC some time to clean connection
-		# before next login.
-		sleep 1;
-
-		exit 0;
-	} 
-
-	fail "failed: unrecognised action response\n";
-}
-
-
-sub get_options_stdin
-{
-	my $opt;
-	my $line = 0;
-	while( defined($in = <>) )
-	{
-		$_ = $in;
-		chomp;
-
-		# strip leading and trailing whitespace
-		s/^\s*//;
-		s/\s*$//;
-
-		# skip comments
-		next if /^#/;
-	
-		$line+=1;
-		$opt=$_;
-		next unless $opt;
-
-		($name,$val)=split /\s*=\s*/, $opt;
-
-		if ( $name eq "" )
-		{
-			print STDERR "parse error: illegal name in option $line\n";
-			exit 2;
-		} 
-		# DO NOTHING -- this field is used by fenced 
-		elsif ($name eq "agent" ) 
-		{
-		} 
-		elsif ($name eq "ipaddr" ) 
-		{
-			$opt_a = $val;
-		} 
-		elsif ($name eq "login" ) 
-		{
-			$opt_l = $val;
-		} 
-		elsif ($name eq "option" ) 
-		{
-			$opt_o = $val;
-		} 
-		elsif ($name eq "passwd" ) 
-		{
-			$opt_p = $val;
-		} 
-		elsif ($name eq "port" ) 
-		{
-			$opt_n = $val;
-		} 
-		elsif ($name eq "switch" ) 
-		{
-			$switchnum = $val;
-		} 
-		elsif ($name eq "test" ) 
-		{
-			$opt_T = $val;
-		} 
-		elsif ($name eq "verbose" ) 
-		{
-			$opt_v = $val;
-		} 
-	}
-}
-		
-
-sub telnet_error
-{
-	if ($t->errmsg ne "pattern match timed-out") {
-		fail "failed: telnet returned: ".$t->errmsg."\n";
-	} else {
-		$t->print("");
-	}
-}
-
-
-### MAIN #######################################################
-
-if (@ARGV > 0) {
-	getopts("a:hl:n:o:p:qTvV") || fail_usage ;
-	
-	usage if defined $opt_h;
-	version if defined $opt_V;
-
-	fail_usage "Unkown parameter." if (@ARGV > 0);
-
-	fail_usage "No '-a' flag specified." unless defined $opt_a;
-	fail_usage "No '-n' flag specified." unless defined $opt_n;
-	fail_usage "No '-l' flag specified." unless defined $opt_l;
-	fail_usage "No '-p' flag specified." unless defined $opt_p;
-	fail_usage "Unrecognised action '$opt_o' for '-o' flag"
-	unless $opt_o =~ /^(Off|On|Reboot)$/i;
-
-	if ( $opt_n =~ /(\d+):(\d+)/ ) {
-		$switchnum=($1);
-		$opt_n = ($2);
-	}
-} else {
-	get_options_stdin();
-
-	fail "failed: no IP address" unless defined $opt_a;
-	fail "failed: no plug number" unless defined $opt_n;
-	fail "failed: no login name" unless defined $opt_l;
-	fail "failed: no password" unless defined $opt_p;
-	fail "failed: unrecognised action: $opt_o"
-	unless $opt_o =~ /^(Off|On|Reboot)$/i;
-} 
-
-$t->timeout($telnet_timeout);
-$t->input_log($debuglog) if $opt_v;
-$t->errmode('return');  
-
-&login;
-
-&identify_switch;
-
-# Abort on failure beyond here
-$t->errmode(\&telnet_error);  
-
-&navigate;
-&action;
-
-exit 0;
-
-
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
old mode 100644
new mode 100755
index 90b2c30..59c5083
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -1,829 +1,100 @@
 #!/usr/bin/python
 
-###############################################################################
-###############################################################################
 ##
-##  Copyright (C) 2006 Red Hat, Inc.  All rights reserved.
+## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
 ##
-##  This copyrighted material is made available to anyone wishing to use,
-##  modify, copy, or redistribute it subject to the terms and conditions
-##  of the GNU General Public License v.2.
+## The Following Agent Has Been Tested On:
 ##
-###############################################################################
-###############################################################################
-
-import getopt, sys
-import os
-import socket
-import time
-
-from telnetlib import Telnet
-
-TELNET_TIMEOUT=5  #How long to wait for a response from a telnet try
+##  Model       Firmware
+## +---------------------------------------------+
+##  AP7951	AOS v2.7.0, PDU APP v2.7.3
+##
+## @note: ssh is very slow on AP7951 device
+#####
 
-# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and
-# "#END_VERSION_GENERATION"  It is generated by the Makefile
+import sys, re, pexpect
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
 
 #BEGIN_VERSION_GENERATION
-RELEASE_VERSION="New APC Agent - test release"
+RELEASE_VERSION="New APC Agent - test release on steroids"
 REDHAT_COPYRIGHT=""
-BUILD_DATE="September 21, 2006"
+BUILD_DATE="March, 2008"
 #END_VERSION_GENERATION
 
-POWER_OFF = 0
-POWER_ON = 1
-POWER_STATUS = 2
-POWER_REBOOT = 3
-
-COMPLETE = 0
-NOT_COMPLETE = 1
-
-ON = "ON"
-OFF = "OFF"
-
-SUCCESS = "success"
-FAIL = "fail"
-
-address = ""
-login = ""
-passwd = ""
-passwd_script = ""
-port = ""
-switchnum = ""
-action = POWER_REBOOT   #default action
-verbose = False
-
-logfile = None
-
-#set up regex list
-CONTROL_CONSOLE = "Control Console -----"
-DEVICE_MANAGER = "Device Manager -----"
-OUTLET_CONTROL = "- Outlet Control/Configuration -----"
-OUTLET_MANAGE = "- Outlet Management -----"
-CONTROL_OUTLET = "- Control Outlet -----"
-CONTROL_OUTLET_2 = "- Outlet Control "
-COMMAND_SUCCESS = "Command successfully issued."
-COMMAND_SUCCESS_2 = " Success"
-CONFIRM = "Enter 'YES' to continue or <ENTER> to cancel :"
-CONTINUE = "Press <ENTER> to continue..."
-SCREEN_END = "<ESC>- Main Menu, <ENTER>- Refresh, <CTRL-L>- Event Log"
-SCREEN_END_2 = "<ESC>- Back, <ENTER>- Refresh, <CTRL-L>- Event Log"
-USERNAME = "User Name :"
-PASSWORD = "Password  :"
-MASTER = "------- MasterSwitch"
-FIRMWARE_STR = "Rack PDU APP"
-
-CONTINUE_INDEX = 0
-
-FIRMWARE_REV = 2
-
-regex_list = list()
-regex_list.append(CONTINUE)
-regex_list.append(SCREEN_END)
-regex_list.append(SCREEN_END_2)
-regex_list.append(USERNAME)
-regex_list.append(PASSWORD)
-
-def usage():
-  print "Usage:\n"
-  print "fence_apc [options]"
-  print "Options:"
-  print "   -a <ipaddress>           ip or hostname of APC switch"
-  print "   -h                       print out help"
-  print "   -l [login]               login name"
-  print "   -n [port]                switch port"
-  print "   -p [password]            password"
-  print "   -S [path]                script to run to retrieve password"
-  print "   -o [action]              Reboot (default), Off, On, or Status"
-  print "   -v Verbose               Verbose mode - writes file to /tmp/apclog"
-  print "   -V                       Print Version, then exit"
-
-  sys.exit (0)
-
-def version():
-  print "fence_apc %s  %s\n" % (RELEASE_VERSION, BUILD_DATE)
-  print "%s\n" % REDHAT_COPYRIGHT
-  sys.exit(0)
+def get_power_status(conn, options):
+	result = ""
+	try:
+		conn.send("1\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+		conn.send("2\r\n")
+		while 1 == conn.log_expect(options, [ options["-c"],  "Press <ENTER>" ], SHELL_TIMEOUT):
+			result += conn.before
+			conn.send("\r\n")
+		result += conn.before
+		conn.send(chr(03))		
+		conn.log_expect(options, "- Logout", SHELL_TIMEOUT)
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+	status = re.compile("\s*"+options["-n"]+"-.*(ON|OFF)", re.IGNORECASE).search(result).group(1)
+	return status.lower().strip()
+
+def set_power_status(conn, options):
+	action = {
+		'on' : "1",
+		'off': "2"
+	}[options["-o"]]
+
+	try:
+		conn.send("1\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+		conn.send("2\r\n")
+		while 1 == conn.log_expect(options, [ options["-c"],  "Press <ENTER>" ], SHELL_TIMEOUT):
+			conn.send("\r\n")
+		conn.send(options["-n"]+"\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+		conn.send(action+"\r\n")
+		conn.log_expect(options, "Enter 'YES' to continue or <ENTER> to cancel :", SHELL_TIMEOUT)
+		conn.send("YES\r\n")
+		conn.log_expect(options, "Press <ENTER> to continue...", SHELL_TIMEOUT)
+		conn.send("\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+		conn.send(chr(03))
+		conn.log_expect(options, "- Logout", SHELL_TIMEOUT)
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexcept.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexcept.TIMEOUT:
+		fail(EC_TIMED_OUT)
 
 def main():
-
-  global address, login, passwd, passwd_script, port, action, verbose, logfile, switchnum
-
-  if len(sys.argv) > 1:
-    try:
-      opts, args = getopt.getopt(sys.argv[1:], "a:hl:o:n:p:S:vV", ["help", "output="])
-    except getopt.GetoptError:
-      #print help info and quit
-      usage()
-      sys.exit(2)
-      
-    for o, a in opts:
-      if o == "-v":
-        verbose = True
-      if o == "-V":
-        version()
-      if o in ("-h", "--help"):
-        usage()
-        sys.exit()
-      if o == "-l":
-        login = a
-      if o == "-p":
-        passwd = a
-      if o == "-S":
-        passwd_script = a
-      if o == "-n":
-        dex = a.find(":")
-        if dex == (-1):
-          port = a
-        else:
-          switchnum = a[:dex]
-          port = a[(dex+1):]
-      if o  == "-o":
-        if a == "Off" or a == "OFF" or a == "off":
-          action = POWER_OFF
-        elif a == "On" or a == "ON" or a == "on":
-          action = POWER_ON
-        elif a == "Status" or a == "STATUS" or a == "status":
-          action = POWER_STATUS
-        elif a == "Reboot" or a == "REBOOT" or a == "reboot":
-          action = POWER_REBOOT
-        else:
-          usage()
-          sys.exit()
-      if o == "-a":
-        address = a
-    if address == "" or login == "" or (passwd == "" and passwd_script == "") or port == "":
-      usage()
-      sys.exit()
-    
-  else: #Take args from stdin...
-    params = {}
-    #place params in dict
-    for line in sys.stdin:
-      val = line.split("=")
-      if len(val) == 2:
-        params[val[0].strip()] = val[1].strip()
-
-    try:
-      address = params["ipaddr"]
-    except KeyError, e:
-      sys.stderr.write("FENCE: Missing ipaddr param for fence_apc...exiting")
-      sys.exit(1)
-    try:
-      login = params["login"]
-    except KeyError, e:
-      sys.stderr.write("FENCE: Missing login param for fence_apc...exiting")
-      sys.exit(1)
-    try:
-      if 'passwd' in params:
-        passwd = params["passwd"]
-      if 'passwd_script' in params:
-        passwd_script = params['passwd_script']
-      if passwd == "" and passwd_script == "":
-        raise "missing password"
-    except:
-      sys.stderr.write("FENCE: Missing passwd for fence_apc...exiting")
-      sys.exit(1)
-    try:
-      port = params["port"]
-    except KeyError, e:
-      sys.stderr.write("FENCE: Missing port param for fence_apc...exiting")
-      sys.exit(1)
-    try:
-      switchnum = params["switch"]
-    except KeyError, e:
-      pass
-    try:
-      verbose = params["verbose"]
-      verbose = (verbose == 'True' or verbose == 'true' or verbose == 'TRUE')
-    except KeyError, e:
-      pass
-    
-    try:
-      a = params["option"]
-      if a == "Off" or a == "OFF" or a == "off":
-        action = POWER_OFF
-      elif a == "On" or a == "ON" or a == "on":
-        action = POWER_ON
-      elif a == "Reboot" or a == "REBOOT" or a == "reboot":
-        action = POWER_REBOOT
-    except KeyError, e:
-      action = POWER_REBOOT
-    
-    #### End of stdin section
-  
-  
-  # retrieve passwd from passwd_script (if specified)
-  passwd_scr = ''
-  if len(passwd_script):
-    try:
-      if not os.access(passwd_script, os.X_OK):
-        raise 'script not executable'
-      p = os.popen(passwd_script, 'r', 1024)
-      passwd_scr = p.readline().strip()
-      if p.close() != None:
-        raise 'script failed'
-    except:
-      sys.stderr.write('password-script "%s" failed\n' % passwd_script)
-      passwd_scr = ''
-    
-  if passwd == "" and passwd_scr == "":
-    sys.stderr.write('password not available, exiting...')
-    sys.exit(1)
-  elif passwd == passwd_scr:
-    pass
-  elif passwd and passwd_scr:
-    # execute self, with password_scr as passwd,
-    # if that fails, continue with "passwd" argument as password
-    if len(sys.argv) > 1:
-      comm = sys.argv[0]
-      skip_next = False
-      for w in sys.argv[1:]:
-        if skip_next:
-          skip_next = False
-        elif w in ['-p', '-S']:
-          skip_next = True
-        else:
-          comm += ' ' + w
-      comm += ' -p ' + passwd_scr
-      ret = os.system(comm)
-      if ret != -1 and os.WIFEXITED(ret) and os.WEXITSTATUS(ret) == 0:
-        # success
-        sys.exit(0)
-      else:
-        sys.stderr.write('Use of password from "passwd_script" failed, trying "passwd" argument\n')
-    else: # use stdin
-      p = os.popen(sys.argv[0], 'w', 1024)
-      for par in params:
-        if par not in ['passwd', 'passwd_script']:
-          p.write(par + '=' + params[par] + '\n')
-      p.write('passwd=' + passwd_scr + '\n')
-      p.flush()
-      if p.close() == None:
-        # success
-        sys.exit(0)
-      else:
-        sys.stderr.write('Use of password from "passwd_script" failed, trying "passwd" argument\n')
-  elif passwd_scr:
-    passwd = passwd_scr
-  # passwd all set
-  
-  
-  
-  ### Order of events
-  # 0) If verbose, prepare log file handle
-  # 1) Open socket
-  # 2) Log in
-  # 3) Evaluate task. Task will be one of:
-  # 3a - Check status and print to stdout (or log file if verbose)
-  # 3b - Turn a port off, then confirm
-  # 3c - Turn a port on, then confirm
-  # 3d - Reboot by turning a port off, then on, and confirming each step.
-
-  if verbose:
-    setup_logging()
-
-  sock = setup_socket()
-
-  # Ok, now lets log in...
-  do_login(sock)
-
-  # Now we should be at the outside Control screen
-    
-  if action == POWER_STATUS:
-    # We should be at the Control screen, so we need to write a '1'
-    # to kick things off
-    sock.write("1\r")
-    statusval = do_status_check(sock)
-    backout(sock)
-    sock.write("4\r")  # Logs out
-    
-  elif action == POWER_OFF:
-    sock.write("1\r")
-    do_power_off(sock)
-    backout(sock) # Return to control screen
-    statusval = do_status_check(sock)
-    if statusval == OFF:
-      if verbose:
-        logit("Power Off successful\n")
-      print "Power Off successful"
-      backout(sock)
-      sock.write("4\r")  # Logs out
-      sock.close()
-      sys.exit(0)
-    else:
-      if verbose:
-        logit("Power Off unsuccessful\n")
-        logit("Undetermined error\n")
-      sys.stderr.write("Power Off unsuccessful")
-      backout(sock)
-      sock.write("4\r")  # Logs out
-      sock.close()
-      sys.exit(1)
-    
-  elif action == POWER_ON:
-    sock.write("1\r")
-    do_power_on(sock)
-    backout(sock) # Return to control screen
-    statusval = do_status_check(sock)
-    if statusval == ON:
-      if verbose:
-        logit("Power On successful\n")
-      print "Power On successful"
-      backout(sock)
-      sock.write("4\r")  # logs out
-      sock.close()
-      sys.exit(0)
-    else:
-      if verbose:
-        logit("Power On unsuccessful\n")
-        logit("Undetermined error\n")
-      sys.stderr.write("Power On unsuccessful")
-      backout(sock)
-      sock.write("4\r")  # Logs out
-      sock.close()
-      sys.exit(1)
-
-  elif action == POWER_REBOOT:
-    sock.write("1\r")
-    do_power_off(sock)
-    backout(sock) # Return to control screen
-    statusval = do_status_check(sock)
-    if statusval == OFF:
-      if verbose:
-        logit("Power Off successful\n")
-      print "Power Off successful"
-      backout(sock)
-    else:
-      if verbose:
-        logit("Power Off unsuccessful\n")
-        logit("Undetermined error\n")
-      sys.stderr.write("Power Off unsuccessful")
-      backout(sock)
-      sock.write("4\r")  # Logs out
-      sock.close()
-      sys.exit(1)
-    do_power_on(sock)
-    backout(sock) # Return to control screen
-    statusval = do_status_check(sock)
-    if statusval == ON:
-      if verbose:
-        logit("Power Reboot successful\n")
-      print "Power Reboot successful"
-      backout(sock)
-      sock.write("4\r")  # Logs out
-      sock.close()
-      sys.exit(0)
-    else:
-      if verbose:
-        logit("Power Reboot unsuccessful\n")
-        logit("Undetermined error\n")
-      sys.stderr.write("Power Reboot unsuccessful")
-      backout(sock)
-      sock.write("4\r")  # Logs out
-      sock.close()
-      sys.exit(1)
-    
-  sock.close()
-
-def backout(sock):
-  sock.write(chr(27))
-  
-  while (1):
-    i, mo, txt = sock.expect(regex_list, TELNET_TIMEOUT)
-
-    if regex_list[i] == SCREEN_END:
-      break
-    elif regex_list[i] == SCREEN_END_2:
-      sock.write(chr(27))
-
-def setup_socket():
-  ## Time to open telnet session and log in. 
-  try:
-    sock = Telnet(address.strip())
-  except socket.error, (errno, msg):
-    my_msg = "FENCE: A problem was encountered opening a telnet session with " + address
-    if verbose:
-      logit(my_msg)
-      logit("FENCE: Error number: %d -- Message: %s\n" % (errno, msg))
-      logit("Firewall issue? Correct address?\n")
-
-    sys.stderr.write(my_msg)
-    sys.stderr.write(("FENCE: Error number: %d -- Message: %s\n" % (errno, msg)))
-    sys.stderr.write("Firewall issue? Correct address?\n")
-    sys.exit(1)
-
-  if verbose:
-    logit("\nsocket open to %s\n" % address)
-
-  return sock
-
-def setup_logging( log_location="/tmp/apclog"):
-  global logfile
-  try:
-    logfile = open(log_location, 'a')
-    logfile.write("###############################################\n")
-    logfile.write("Telnetting to apc switch %s\n" % address)
-    now = time.localtime(time.time())
-    logfile.write(time.asctime(now))
-  except IOError, e:
-    sys.stderr.write("Failed to open log file %s" % log_location)
-    logfile = None
-
-def logit(instr):
-  if logfile != None:
-    logfile.write(instr)
-
-def do_login(sock):
-  result_code = 1
-
-  ## This loop tries to assemble complete telnet screens and passes
-  ## them to helper methods to handle responses accordingly.
-  while result_code:
-    try:
-      i, mo, txt = sock.expect(regex_list, TELNET_TIMEOUT)
-    except socket.error, (errno, msg):
-      my_msg = "FENCE: A problem was encountered opening a telnet session with " + address + "\n"
-      if verbose:
-        logit(my_msg)
-        logit("FENCE: Error number: %d -- Message: %s\n" % (errno, msg))
-
-      sys.stderr.write(my_msg)
-      sys.stderr.write(("FENCE: Error number: %d -- Message: %s\n" % (errno, msg)))
-      sys.exit(1)
-
-    if i == CONTINUE_INDEX: # Capture the rest of the screen...
-      sock.write("\r")
-      ii,moo,txtt = sock.expect(regex_list, TELNET_TIMEOUT)
-      txt = txt + txtt
-
-    ndbuf = sock.read_eager() # Scoop up remainder
-    if verbose:
-      logit(txt + ndbuf)
-    result_code,response = log_in(txt + ndbuf)
-    if result_code:
-      try:
-        sock.write(response)
-      except socket.error, (errno, msg):
-        if verbose:
-          logit("Error #%s" % errno)
-          logit(msg)
-        sys.stderr.write("Error #%s:  %s" % (errno,msg))
-        sys.exit(1)
-
-def log_in(buffer):
-  global FIRMWARE_REV
-  lines = buffer.splitlines()
-
-  for i in lines:
-    if i.find(USERNAME) != (-1):
-      if verbose:
-        logit("Sending login: %s\n" % login)
-      return (NOT_COMPLETE, login + "\r")
-    elif i.find(PASSWORD) != (-1):
-      if verbose:
-        logit("Sending password: %s\n" % passwd)
-      return (NOT_COMPLETE, passwd + "\r")
-    elif i.find(CONTROL_CONSOLE) != (-1):
-      #while we are here, grab the firmware revision
-      rev_search_lines = buffer.splitlines()
-      for rev_search_line in rev_search_lines: #search screen again
-        rev_dex = rev_search_line.find(FIRMWARE_STR)
-        if rev_dex != (-1): #found revision line
-          scratch_rev = rev_search_line[rev_dex:]
-          v_dex = scratch_rev.find("v")
-          if v_dex != (-1):
-            if scratch_rev[v_dex + 1] == "3": #format is v3.3.4
-              FIRMWARE_REV = 3
-              break
-      return (COMPLETE, "1\r") 
-
-def do_status_check(sock):
-  result_code = 1
-  while result_code:
-    i, mo, txt = sock.expect(regex_list, TELNET_TIMEOUT)
-    if i == CONTINUE_INDEX: # Capture the rest of the screen...
-      sock.write("\r")
-      ii,moo,txtt = sock.expect(regex_list, TELNET_TIMEOUT)
-      txt = txt + txtt
-
-    ndbuf = sock.read_eager() # Scoop up remainder
-    if verbose:
-      logit(txt + ndbuf)
-    (result_code,response,statusval) = return_status(txt + ndbuf)
-    if result_code:
-      try:
-        sock.write(response)
-      except socket.error, (errno, msg):
-        if verbose:
-          logit("Status check failed.")
-          logit("Error #%s" % errno)
-          logit(msg)
-        sys.stderr.write("Status check failed.")
-        sys.stderr.write("Error #%s:  %s" % (errno,msg))
-        sys.exit(1)
-  # Back from status check - value should be in status var
-  if response == SUCCESS:
-    if switchnum == "":
-      if verbose:
-        logit("Status check successful. Port %s is %s" % (port,statusval))
-      print "Status check successful. Port %s is %s" % (port,statusval)
-    else:
-      if verbose:
-        logit("Status check successful. Port %s:%s is %s" % (switchnum, port, statusval))
-      print "Status check successful. Port %s:%s is %s" % (switchnum, port, statusval)
-
-    return statusval
-  else:
-    if verbose:
-      logit("Status check failed, unknown reason.")
-    sys.stderr.write("Status check failed, unknown reason.\n")
-    sock.close()
-    sys.exit(1) 
-
-def return_status(buffer):
-  global switchnum, port
-
-  lines = buffer.splitlines()
-
-  for i in lines:
-    if i.find(CONTROL_CONSOLE) != (-1):
-      return (NOT_COMPLETE, "1\r", "Status Unknown")
-    elif i.find(DEVICE_MANAGER) != (-1):
-      if switchnum != "":
-        res = switchnum + "\r"
-      else:
-        if FIRMWARE_REV == 2:
-          res = "3\r"
-        elif FIRMWARE_REV == 3:
-          res = "2\r1\r"
-        else: #placeholder for future revisions 
-          res = "3\r"
-      return (NOT_COMPLETE, res, "Status Unknown")
-    elif i.find(OUTLET_CONTROL) != (-1):
-      ls = buffer.splitlines()
-      portval = port.strip()
-      portval = " " + portval + " "
-      portval2 = " " + port.strip() + "- "
-      found_portval = False
-      for l in ls:
-        if l.find(portval) != (-1) or l.find(portval2) != (-1):
-          found_portval = True
-          linesplit = l.split()
-          linelen = len(linesplit)
-          return (COMPLETE,SUCCESS,linesplit[linelen - 1])
-    elif i.find(MASTER) != (-1):
-      try:
-        e = int(port.strip())
-        portval = port.strip()
-        switchval = switchnum.strip()
-        portval = switchval + ":" + portval
-      except ValueError, e:
-        portval = port.strip()
-      ls = buffer.splitlines()
-      found_portval = False
-      for l in ls:
-        words = l.split()
-        if len(words) > 3:
-          if words[2] == portval or words[3] == portval:
-            found_portval = True
-            linesplit = l.split()
-            linelen = len(linesplit)
-            return (COMPLETE, SUCCESS, linesplit[linelen - 3])
-      return (COMPLETE, FAIL, "Incorrect port number")
-  return (NOT_COMPLETE, chr(27), "Status Unknown")
-
-def do_power_switch(sock, status):
-  result_code = 1
-
-  while result_code:
-    i, mo, txt = sock.expect(regex_list, TELNET_TIMEOUT)
-    if i == CONTINUE_INDEX: # Capture the rest of the screen...
-      sock.write("\r")
-      ii,moo,txtt = sock.expect(regex_list, TELNET_TIMEOUT)
-      txt = txt + txtt
-
-    ndbuf = sock.read_eager() # Scoop up remainder
-    if verbose:
-      logit(txt + ndbuf)
-
-    if status == "off":
-      result_code, response = power_off(txt + ndbuf)
-    elif status == "on":
-      result_code, response = power_on(txt + ndbuf)
-    else:
-      if verbose:
-        logit("Invalid status in do_power_switch() function")
-      sys.stderr.write("Invalid status in do_power_switch() function") 
-      sys.exit(1)
-
-    if result_code:
-      try:
-        sock.write(response)
-      except socket.error, (errno, msg):
-        if verbose:
-          logit("Error #%s" % errno)
-          logit(msg)
-        sys.stderr.write("Error #%s:  %s" % (errno,msg))
-        sys.exit(1)
-      # FIXME: always returns COMPLETE (0)
-    else:
-      try:
-        sock.write(response)
-      except socket.error, (errno, msg):
-        if verbose:
-          logit("Error #%s" % errno)
-          logit(msg)
-        sys.stderr.write("Error #%s:  %s" % (errno,msg))
-        sys.exit(1)
-      return COMPLETE
-
-
-def power_switch(buffer, escape, control_outlet, control_outlet2):
-  # If port is not aliased, then outlet control screen will have the word
-  # 'Outlet' in the header. If the name is aliased, it will only have the 
-  # alias in the header.
-
-  outlet_search_str1 = "Outlet " + port.strip() + " ------------"
-  outlet_search_str2 = port.strip() + " ------------"
-  outlet_search_str3 = "Outlet " + switchnum.strip() + ":" + port.strip() + " ------"
-  outlet_search_str4 = "        Outlet       : " + port.strip()
-  outlet_search_str5 = "        Outlet Name : " + port.strip()
-  master_search_str1 = "-------- Master"
-  lines = buffer.splitlines()
-
-  for i in lines:
-    if i.find(CONTROL_CONSOLE) != (-1):
-      return (NOT_COMPLETE,"1\r")
-
-    elif i.find(DEVICE_MANAGER) != (-1):
-      if switchnum != "":
-        res = switchnum + "\r"
-      else:
-        if FIRMWARE_REV == 2:
-          res = "3\r"
-        elif FIRMWARE_REV == 3:
-          res = "2\r1\r"
-        else: #placeholder for future revisions - sheesh
-          res = "3\r"
-      return (NOT_COMPLETE, res)
-      
-    elif (i.find(master_search_str1) != (-1)):
-      return (NOT_COMPLETE, port.strip() + "\r")
-      
-    elif i.find(outlet_search_str1) != (-1) and (switchnum == ""):
-      return (NOT_COMPLETE,"1\r")
-
-    elif i.find(outlet_search_str2) != (-1) and (switchnum == ""):
-      return (NOT_COMPLETE,"1\r")
-    
-    elif i.find(outlet_search_str3) != (-1):
-      return (NOT_COMPLETE, "1\r")
-    
-    elif i == outlet_search_str4:
-      return (NOT_COMPLETE, "1\r")
-    
-    elif i == outlet_search_str5:
-      return (NOT_COMPLETE, "1\r")
-    
-    elif i.find(OUTLET_MANAGE) != (-1):
-      #return (NOT_COMPLETE, "1\r")
-      return (NOT_COMPLETE, "\r")
-
-    #elif i.find(OUTLET_CONTROL) != (-1) or i.find(OUTLET_MANAGE) != (-1):
-    elif i.find(OUTLET_CONTROL) != (-1):
-      ls = buffer.splitlines()
-      portval = port.strip()
-      portval = " " + portval + " "
-      found_portval = False
-      i = 0
-      # look for aliased name 
-      for l in ls:
-        i = i + 1
-        if l.find(portval) != (-1):
-          found_portval = True
-          linesplit = l.split()
-          outlet_str = linesplit[0]
-          dex = outlet_str.find("-")
-          if dex <= (0):
-            if verbose:
-              logit("Problem identifying outlet\n")
-              logit("Looking for %s in string %s\n" % (portval,outlet_str))
-            sys.stderr.write("Problem identifying outlet\n")
-            sys.stderr.write("Looking for %s in string %s\n" % (portval,outlet_str))
-            sys.exit(1)
-          normalized_outlet_str = outlet_str[:dex]
-          return (NOT_COMPLETE, normalized_outlet_str + "\r")
-      # look for portnum
-      portval = " " + port.strip() + "-"
-      i = 0
-      for l in ls:
-        i = i + 1
-        if l.find(portval) != (-1):
-          found_portval = True
-          linesplit = l.split()
-          outlet_str = linesplit[0]
-          dex = outlet_str.find("-")
-          if dex <= (0):
-            if verbose:
-              logit("Problem identifying outlet\n")
-              logit("Looking for %s in string %s\n" % (portval,outlet_str))
-            sys.stderr.write("Problem identifying outlet\n")
-            sys.stderr.write("Looking for %s in string %s\n" % (portval,outlet_str))
-            sys.exit(1)
-          normalized_outlet_str = outlet_str[:dex]
-          return (NOT_COMPLETE, normalized_outlet_str + "\r")
-      if found_portval == False:
-        if verbose:
-          logit("Problem identifying outlet\n")
-          logit("Looking for '%s' in string '%s'\n" % (portval, ls))
-        sys.stderr.write("Problem identifying outlet\n")
-        sys.stderr.write("Looking for '%s' in string '%s'\n" % (portval, ls))
-        sys.exit(1)
-
-    elif i.find(MASTER) != (-1):
-      ls = buffer.splitlines()
-      found_portval = False
-      # look for aliased name
-      portval = port.strip()
-      for l in ls:
-        words = l.strip().split()
-        if len(words) > 3:
-          if '----' not in words[0] and words[3].strip() == portval:
-            outlet_str = words[0]
-            dex = outlet_str.find("-")
-            if dex <= (0):
-              if verbose:
-                logit("Problem identifying outlet\n")
-                logit("Looking for %s in string %s\n" % (portval, outlet_str))
-              sys.stderr.write("Problem identifying outlet\n")
-              sys.stderr.write("Looking for %s in string %s\n" % (portval, outlet_str))
-              sys.exit(1)
-            normalized_outlet_str = outlet_str[:dex]
-            return (NOT_COMPLETE, (normalized_outlet_str + "\r"))
-      # look for portnum
-      portval = port.strip()
-      portval = switchnum.strip() + ":" + portval + " "
-      i = 0
-      for l in ls:
-        i = i + 1
-        if l.find(portval) != (-1):
-          found_portval = True
-          linesplit = l.split()
-          outlet_str = linesplit[0]
-          dex = outlet_str.find("-")
-          if dex <= (0):
-            if verbose:
-              logit("Problem identifying outlet\n")
-              logit("Looking for %s in string %s\n" % (portval,outlet_str))
-            sys.stderr.write("Problem identifying outlet\n")
-            sys.stderr.write("Looking for %s in string %s\n" % (portval,outlet_str))
-            sys.exit(1)
-          normalized_outlet_str = outlet_str[:dex]
-          return (NOT_COMPLETE, (normalized_outlet_str + "\r"))
-      if found_portval == False:
-        if verbose:
-          logit("Problem identifying outlet\n")
-          logit("Looking for '%s' in string '%s'\n" % (portval, ls))
-        sys.stderr.write("Problem identifying outlet\n")
-        sys.stderr.write("Looking for '%s' in string '%s'\n" % (portval, ls))
-        sys.exit(1)
-
-    elif i.find(CONFIRM) != (-1):
-      return (NOT_COMPLETE,"YES\r")
-
-    elif i.find(COMMAND_SUCCESS) != (-1):
-      return (COMPLETE,"\r")
-
-    elif i.find(COMMAND_SUCCESS_2) != (-1):
-      return (COMPLETE,"\r")
-
-    elif i.find(CONTROL_OUTLET) != (-1):
-      return (NOT_COMPLETE, control_outlet + "\r")
-
-    elif i.find(CONTROL_OUTLET_2) != (-1):
-      return (NOT_COMPLETE, control_outlet2 + "\r")
-  
-  if (escape == True):
-    return (NOT_COMPLETE, chr(27))
-  else:
-    raise "unknown screen encountered in \n" + str(lines) + "\n"
-
-def do_power_off(sock):
-  x = do_power_switch(sock, "off")
-  return x
-
-def power_off(buffer):
-  x = power_switch(buffer, False, "2", "3");
-  return x
-
-def do_power_on(sock):
-  x = do_power_switch(sock, "on")
-  return x
-
-def power_on(buffer):
-  x = power_switch(buffer, True, "1", "1");
-  return x
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"secure", "port", "test" ]
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	## 
+	## Fence agent specific defaults
+	#####
+	if 0 == options.has_key("-c"):
+		options["-c"] = "\n>"
+
+	##
+	## Operate the fencing device
+	####
+	conn = fence_login(options)
+	fence_action(conn, options, set_power_status, get_power_status)
+
+	##
+	## Logout from system
+	######
+	conn.sendline("4")
+	conn.close()
 
 if __name__ == "__main__":
-  main()
+	main()
diff --git a/fence/agents/apc/Makefile b/fence/agents/apc_snmp/Makefile
similarity index 88%
copy from fence/agents/apc/Makefile
copy to fence/agents/apc_snmp/Makefile
index 7292eb8..8471db4 100644
--- a/fence/agents/apc/Makefile
+++ b/fence/agents/apc_snmp/Makefile
@@ -11,7 +11,8 @@
 ###############################################################################
 ###############################################################################
 
-TARGET= fence_apc
+TARGET= fence_apc_snmp
+MIBRESOURCE= powernet369.mib
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fencepy.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/apc/README b/fence/agents/apc_snmp/README
similarity index 100%
rename from fence/agents/apc/README
rename to fence/agents/apc_snmp/README
diff --git a/fence/agents/apc/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
similarity index 94%
rename from fence/agents/apc/fence_apc_snmp.py
rename to fence/agents/apc_snmp/fence_apc_snmp.py
index 4bb02d4..afb0ff9 100755
--- a/fence/agents/apc/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -14,7 +14,7 @@
 ## This APC Fence script uses snmp to control the APC power
 ## switch. This script requires that net-snmp-utils be installed
 ## on all nodes in the cluster, and that the powernet369.mib file be
-## located in /usr/share/snmp/mibs/
+## located in @MIBDIR@
 #############################################################################
 #############################################################################
 
@@ -67,8 +67,8 @@ def main():
   status_check = False
   verbose = False
 
-  if not glob('/usr/share/snmp/mibs/powernet*.mib'):
-    sys.stderr.write('This APC Fence script uses snmp to control the APC power switch. This script requires that net-snmp-utils be installed on all nodes in the cluster, and that the powernet369.mib file be located in /usr/share/snmp/mibs/\n')
+  if not glob('@MIBDIR@/powernet*.mib'):
+    sys.stderr.write('This APC Fence script uses snmp to control the APC power switch. This script requires that net-snmp-utils be installed on all nodes in the cluster, and that the powernet369.mib file be located in @MIBDIR@\n')
     sys.exit(1)
 
   if len(sys.argv) > 1:
@@ -169,7 +169,7 @@ def main():
   args_off = list()
   args_on = list()
 
-  args_status.append("/usr/bin/snmpget")
+  args_status.append("@SNMPBIN@/snmpget")
   args_status.append("-Oqu") #sets printing options
   args_status.append("-v")
   args_status.append("1")
@@ -180,7 +180,7 @@ def main():
   args_status.append(address)
   args_status.append(apc_command)
 
-  args_off.append("/usr/bin/snmpset")
+  args_off.append("@SNMPBIN@/snmpset")
   args_off.append("-Oqu") #sets printing options
   args_off.append("-v")
   args_off.append("1")
@@ -193,7 +193,7 @@ def main():
   args_off.append("i")
   args_off.append("outletOff")
 
-  args_on.append("/usr/bin/snmpset")
+  args_on.append("@SNMPBIN@/snmpset")
   args_on.append("-Oqu") #sets printing options
   args_on.append("-v")
   args_on.append("1")
@@ -235,7 +235,7 @@ def main():
         fd.write("Attempting the following command: %s\n" % cmdstr_off)
       strr = os.system(cmdstr_off)
       time.sleep(1)
-      strr,code = execWithCaptureStatus("/usr/bin/snmpget",args_status)
+      strr,code = execWithCaptureStatus("@SNMPBIN@/snmpget",args_status)
       if verbose:
         fd.write("Result: %s\n" % strr)
         fd.close()
@@ -254,7 +254,7 @@ def main():
         fd.write("Attempting the following command: %s\n" % cmdstr_on)
       strr = os.system(cmdstr_on)
       time.sleep(1)
-      strr,code = execWithCaptureStatus("/usr/bin/snmpget",args_status)
+      strr,code = execWithCaptureStatus("@SNMPBIN@/snmpget",args_status)
       #strr = os.system(cmdstr_status) 
       if verbose:
         fd.write("Result: %s\n" % strr)
@@ -276,7 +276,7 @@ def main():
         fd.write("Attempting the following command: %s\n" % cmdstr_off)
       strr = os.system(cmdstr_off)
       time.sleep(1)
-      strr,code = execWithCaptureStatus("/usr/bin/snmpget",args_status)
+      strr,code = execWithCaptureStatus("@SNMPBIN@/snmpget",args_status)
       #strr = os.system(cmdstr_status)
       if verbose:
         fd.write("Result: %s\n" % strr)
@@ -291,7 +291,7 @@ def main():
         fd.write("Attempting the following command: %s\n" % cmdstr_on)
       strr = os.system(cmdstr_on)
       time.sleep(1)
-      strr,code = execWithCaptureStatus("/usr/bin/snmpget",args_status)
+      strr,code = execWithCaptureStatus("@SNMPBIN@/snmpget",args_status)
       #strr = os.system(cmdstr_status)
       if verbose:
         fd.write("Result: %s\n" % strr)
diff --git a/fence/agents/apc/powernet369.mib b/fence/agents/apc_snmp/powernet369.mib
similarity index 100%
rename from fence/agents/apc/powernet369.mib
rename to fence/agents/apc_snmp/powernet369.mib
diff --git a/fence/agents/baytech/Makefile b/fence/agents/baytech/Makefile
index 97c2a89..00cf95c 100644
--- a/fence/agents/baytech/Makefile
+++ b/fence/agents/baytech/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_baytech
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/bladecenter/Makefile b/fence/agents/bladecenter/Makefile
index 4c4390c..e0700c8 100644
--- a/fence/agents/bladecenter/Makefile
+++ b/fence/agents/bladecenter/Makefile
@@ -11,7 +11,8 @@
 ###############################################################################
 ###############################################################################
 
+include ../../../make/defines.mk
+
 TARGET= fence_bladecenter
 
-include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/bladecenter/fence_bladecenter.pl b/fence/agents/bladecenter/fence_bladecenter.pl
index 13f81f8..e049735 100755
--- a/fence/agents/bladecenter/fence_bladecenter.pl
+++ b/fence/agents/bladecenter/fence_bladecenter.pl
@@ -1,328 +1,90 @@
-#!/usr/bin/perl
+#!/usr/bin/python
 
-###############################################################################
-###############################################################################
 ##
-##  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
-##  Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
-##  
-##  This copyrighted material is made available to anyone wishing to use,
-##  modify, copy, or redistribute it subject to the terms and conditions
-##  of the GNU General Public License v.2.
+## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
 ##
-###############################################################################
-###############################################################################
-#
-# Tested against:
-# Firmware Type     Build ID   File Name     Released  Revision
-# ----------------  --------   ------------  --------  --------
-# Main application  BRET67D    CNETMNUS.PKT  07-22-04  16
-# Boot ROM          BRBR67D    CNETBRUS.PKT  07-22-04  16  	
-# Remote control    BRRG67D    CNETRGUS.PKT  07-22-04  16   	
-#
-use Getopt::Std;
-use Net::Telnet ();
-
-# Get the program name from $0 and strip directory names
-$_=$0;
-s/.*\///;
-my $pname = $_;
-
-$action = "reboot"; # Default fence action
+## The Following Agent Has Been Tested On:
+##
+##  Model                 Firmware
+## +--------------------+---------------------------+
+## (1) Main application	  BRET85K, rev 16  
+##     Boot ROM           BRBR67D, rev 16
+##     Remote Control     BRRG67D, rev 16
+##
+#####
 
-# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and 
-# "#END_VERSION_GENERATION"  It is generated by the Makefile
+import sys, re, pexpect
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
 
 #BEGIN_VERSION_GENERATION
-$RELEASE_VERSION="";
-$REDHAT_COPYRIGHT="";
-$BUILD_DATE="";
+RELEASE_VERSION="New Bladecenter Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
 #END_VERSION_GENERATION
 
-
-sub usage
-{
-	print "Usage:\n";
-	print "\n";
-	print "$pname [options]\n";
-	print "\n";
-	print "Options:\n";
-	print "  -a <ip>          IP address or hostname of blade center\n";
-	print "  -h               usage\n";
-	print "  -l <name>        Login name\n";
-	print "  -n <num>         blade number to operate on\n";
-	print "  -o <string>      Action:  on, off, reboot (default) or status\n";
-	print "  -p <string>      Password for login\n";
-	print "  -S <path>        Script to run to retrieve password\n";
-	print "  -q               quiet mode\n";
-	print "  -V               version\n";
-
-	exit 0;
-}
-
-sub fail
-{
-	($msg) = @_;
-	print $msg."\n" unless defined $quiet;
-	$t->close if defined $t;
-	exit 1;
-}
-
-sub fail_usage
-{
-	($msg)=@_;
-	print STDERR $msg."\n" if $msg;
-	print STDERR "Please use '-h' for usage.\n";
-	exit 1;
-}
-
-sub version
-{
-	print "$pname $RELEASE_VERSION $BUILD_DATE\n";
-	print "$REDHAT_COPYRIGHT\n" if ( $REDHAT_COPYRIGHT );
-
-	exit 0;
-}
-
-sub get_options_stdin
-{
-	my $opt;
-	my $line = 0;
-	while( defined($in = <>) )
-	{
-		$_ = $in;
-		chomp;
-
-		# strip leading and trailing whitespace
-		s/^\s*//;
-		s/\s*$//;
-	
-		# skip comments
-		next if /^#/;
-
-		$line+=1;
-		$opt=$_;
-		next unless $opt;
-
-		($name,$val)=split /\s*=\s*/, $opt;
-
-		if ( $name eq "" )
-		{  
-			print STDERR "parse error: illegal name in option $line\n";
-			exit 2;
-		}
-	
-		# DO NOTHING -- this field is used by fenced
-		elsif ($name eq "agent" ) { } 
-
-		elsif ($name eq "ipaddr" ) 
-		{
-			$host = $val;
-		} 
-		elsif ($name eq "login" ) 
-		{
-			$login = $val;
-		} 
-		elsif ($name eq "option" )
-		{
-			$action = $val;
-		}
-		elsif ($name eq "passwd" ) 
-		{
-			$passwd = $val;
-		}
-		elsif ($name eq "passwd_script" ) {
-			$passwd_script = $val;
-		}
-		elsif ($name eq "blade" ) 
-		{
-			$bladenum = $val;
-		} 
-		elsif ($name eq "debuglog" ) 
-		{
-			$verbose = $val;
-		} 
-	}
-}
-
-sub get_power_state
-{
-	my ($junk) = @_;
-	fail "illegal argument to get_power_state()" if defined $junk;
-
-	my $state="";
-
-	$t->print("env -T system:blade[$bladenum]");
-	($text, $match) = $t->waitfor("/system:blade\\[$bladenum\\]>/");
-
-	$t->print("power -state");
-	($text, $match) = $t->waitfor("/system:blade\\[$bladenum\\]>/");
-
-	if ($text =~ /power -state\n(on|off)/im )
-	{
-		$state = $1;
-	}
-	else
-	{
-		fail "unexpected powerstate";
-	}
-
-	$t->print("env -T system");
-	($text, $match) = $t->waitfor("/system>/");
-
-	$_=$state;
-}
-
-sub set_power_state
-{
-	my ($set,$junk) = @_;
-	fail "missing argument to set_power_state()" unless defined $set;
-	fail "illegal argument to set_power_state()" if defined $junk;
-
-	my $state="";
-
-	$t->print("env -T system:blade[$bladenum]");
-	($text, $match) = $t->waitfor("/system:blade\\[$bladenum\\]>/");
-
-	$t->print("power -$set");
-	($text, $match) = $t->waitfor("/system:blade\\[$bladenum\\]>/");
-
-	fail "unexpected powerstate" unless ($text =~ /power -$set\nOK/im );
-
-	$t->print("env -T system");
-	($text, $match) = $t->waitfor("/system>/");
-
-	# need to sleep a few seconds to make sure that the bladecenter 
-	# has time to issue the power on/off command
-	sleep 5;
-
-	$_=$state;
-}
-
-# MAIN
-
-if (@ARGV > 0) 
-{
-	getopts("a:hl:n:o:p:S:qv:V") || fail_usage ;
-
-	usage if defined $opt_h;
-	version if defined $opt_V;
-
-	$host     = $opt_a if defined $opt_a;
-	$login    = $opt_l if defined $opt_l;
-	$passwd   = $opt_p if defined $opt_p;
-	$action   = $opt_o if defined $opt_o;
-	$bladenum = $opt_n if defined $opt_n;
-	$verbose  = $opt_v if defined $opt_v;
-	$quiet    = $opt_q if defined $opt_q;
-
-	if (defined $opt_S) {
-		$pwd_script_output = `$opt_S`;
-		chomp($pwd_script_output);
-		if ($pwd_script_output) {
-			$passwd = $pwd_script_output;
-		}
-	}
-
-	fail_usage "Unknown parameter." if (@ARGV > 0);
-
-	fail_usage "No '-a' flag specified." unless defined $host;
-	fail_usage "No '-n' flag specified." unless defined $bladenum;
-	fail_usage "No '-l' flag specified." unless defined $login;
-	fail_usage "No '-p' or '-S' flag specified." unless defined $passwd;
-	fail_usage "Unrecognised action '$action' for '-o' flag"
-		unless $action =~ /^(on|off|reboot|status)$/i;
-} 
-else 
-{
-	get_options_stdin();
-
-	fail "failed: no IP address" unless defined $host;
-	fail "failed: no blade number" unless defined $bladenum;
-	fail "failed: no login name" unless defined $login;
-	fail "failed: unrecognised action: $action"
-		unless $action =~ /^(on|off|reboot|status)$/i;
-
-	if (defined $passwd_script) {
-		$pwd_script_output = `$passwd_script`;
-		chomp($pwd_script_output);
-		if ($pwd_script_output) {
-			$passwd = $pwd_script_output;
-		}
-	}
-	fail "failed: no password" unless defined $passwd;
-}
-
-# convert $action to lower case 
-$_=$action;
-if    (/^on$/i)     { $action = "on"; }
-elsif (/^off$/i)    { $action = "off"; }
-elsif (/^reboot$/i) { $action = "reboot"; }
-elsif (/^status$/i) { $action = "status"; }
-
-#
-# Set up and log in
-#
-$t = new Net::Telnet;
-
-$t->input_log($verbose) if $verbose;
-$t->open($host);
-
-$t->waitfor('/username:/');
-$t->print($login);
-
-$t->waitfor('/password:/');
-$t->print($passwd);
-
-($text, $match) = $t->waitfor("/system>/");
-
-#
-# Do the command
-#
-$success=0;
-$_ = $action;
-if (/(on|off)/)
-{
-	set_power_state $action;
-	get_power_state;
-	$success = 1 if (/^$action$/i);
-}
-elsif (/reboot/)
-{
-	set_power_state off;
-	get_power_state;
-	
-	if (/^off$/i)
-	{
-		set_power_state on;
-		get_power_state;
-		$success = 1 if (/^on$/i);
-	}
-}
-elsif (/status/)
-{
-	get_power_state;
-	$state=$_;
-	$success = 1 if defined $state;
-}
-else
-{
-	fail "fail: illegal action";
-}
-
-$t->print("exit");
-sleep 1;
-$t->close();
-
-
-if ($success)
-{
-	print "success: blade$bladenum $action". ((defined $state) ? ": $state":"")
-		."\n" unless defined $quiet;
-	exit 0;
-}
-else
-{
-	fail "fail: blade$bladenum $action";	
-	exit 1
-}
+def get_power_status(conn, options):
+	try:
+		node_cmd = "system:blade\[" + options["-n"] + "\]>"
+
+		conn.send("env -T system:blade[" + options["-n"] + "]\r\n")
+		conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
+		conn.send("power -state\r\n")
+		conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
+		status = conn.before.splitlines()[-1]
+		conn.send("env -T system\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+	return status.lower().strip()
+
+def set_power_status(conn, options):
+	action = {
+		'on' : "powerup",
+		'off': "powerdown"
+	}[options["-o"]]
+
+	try:
+		node_cmd = "system:blade\[" + options["-n"] + "\]>"
+
+		conn.send("env -T system:blade[" + options["-n"] + "]\r\n")
+		conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
+		conn.send("power -"+options["-o"]+"\r\n")
+		conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
+		conn.send("env -T system\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexcept.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexcept.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"cmd_prompt", "secure", "port" ]
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	## 
+	## Fence agent specific defaults
+	#####
+	if 0 == options.has_key("-c"):
+		options["-c"] = "system>"
+
+	##
+	## Operate the fencing device
+	######
+	conn = fence_login(options)
+	fence_action(conn, options, set_power_status, get_power_status)
+
+	##
+	## Logout from system
+	######
+	conn.send("exit\r\n")
+	conn.close()
+
+if __name__ == "__main__":
+	main()
diff --git a/fence/agents/brocade/Makefile b/fence/agents/brocade/Makefile
index bc008e4..5b58409 100644
--- a/fence/agents/brocade/Makefile
+++ b/fence/agents/brocade/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_brocade
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/bullpap/Makefile b/fence/agents/bullpap/Makefile
index d4d0145..e303558 100644
--- a/fence/agents/bullpap/Makefile
+++ b/fence/agents/bullpap/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_bullpap
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/cpint/Makefile b/fence/agents/cpint/Makefile
index dd001cd..e6fb49e 100644
--- a/fence/agents/cpint/Makefile
+++ b/fence/agents/cpint/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_cpint
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/drac/Makefile b/fence/agents/drac/Makefile
index 390e210..e0267f3 100644
--- a/fence/agents/drac/Makefile
+++ b/fence/agents/drac/Makefile
@@ -11,7 +11,8 @@
 ###############################################################################
 ###############################################################################
 
-TARGET= fence_drac
-
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+
+TARGET= fence_drac fence_drac5
+
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/drac/fence_drac5.py b/fence/agents/drac/fence_drac5.py
new file mode 100755
index 0000000..f3e5a1d
--- /dev/null
+++ b/fence/agents/drac/fence_drac5.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python
+
+##
+## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
+##
+## The Following Agent Has Been Tested On:
+##
+##  DRAC Version       Firmware
+## +-----------------+---------------------------+
+##  DRAC 5             1.0  (Build 06.05.12)
+##  DRAC 5             1.21 (Build 07.05.04)
+##
+## @note: drac_version, modulename were removed
+#####
+
+import sys, re, pexpect
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New Drac5 Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+	try:
+		conn.sendline("racadm serveraction powerstatus")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+				
+	status = re.compile("Server power status: (.*)", re.IGNORECASE).search(conn.before).group(1)
+	return status.lower().strip()
+
+def set_power_status(conn, options):
+	action = {
+		'on' : "powerup",
+		'off': "powerdown"
+	}[options["-o"]]
+
+	try:
+		conn.sendline("racadm serveraction " + action)
+		conn.log_expect(options, options["-c"], POWER_TIMEOUT)
+	except pexcept.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexcept.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"cmd_prompt", "secure",
+			"drac_version", "module_name" ]
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	## 
+	## Fence agent specific defaults
+	#####
+	if 0 == options.has_key("-c"):
+		options["-c"] = "\$"
+
+	##
+	## Operate the fencing device
+	######
+	conn = fence_login(options)
+	fence_action(conn, options, set_power_status, get_power_status)
+
+	##
+	## Logout from system
+	######
+	conn.sendline("exit")
+	conn.close()
+
+if __name__ == "__main__":
+	main()
diff --git a/fence/agents/egenera/Makefile b/fence/agents/egenera/Makefile
index 7e15c87..c980b45 100644
--- a/fence/agents/egenera/Makefile
+++ b/fence/agents/egenera/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_egenera
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/ibmblade/Makefile b/fence/agents/ibmblade/Makefile
index dfa1d5a..50053a1 100644
--- a/fence/agents/ibmblade/Makefile
+++ b/fence/agents/ibmblade/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_ibmblade
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/ilo/Makefile b/fence/agents/ilo/Makefile
index eb51656..3926e01 100644
--- a/fence/agents/ilo/Makefile
+++ b/fence/agents/ilo/Makefile
@@ -11,7 +11,8 @@
 ###############################################################################
 ###############################################################################
 
+include ../../../make/defines.mk
+
 TARGET= fence_ilo
 
-include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/ilo/fence_ilo.pl b/fence/agents/ilo/fence_ilo.pl
deleted file mode 100755
index ba739e7..0000000
--- a/fence/agents/ilo/fence_ilo.pl
+++ /dev/null
@@ -1,655 +0,0 @@
-#!/usr/bin/perl 
-
-###############################################################################
-###############################################################################
-##
-##  Copyright (C) 2006-2007 Red Hat, Inc.  All rights reserved.
-##  
-##  This copyrighted material is made available to anyone wishing to use,
-##  modify, copy, or redistribute it subject to the terms and conditions
-##  of the GNU General Public License v.2.
-##
-###############################################################################
-###############################################################################
-
-$|=1;
-
-eval { $ssl_mod="Net::SSL" if require Net::SSL} || 
-eval { $ssl_mod="Net::SSLeay::Handle" if require Net::SSLeay::Handle } || 
-	die "Net::SSL.pm or Net::SSLeay::Handle.pm not found.\n".
-	    "Please install the perl-Crypt-SSLeay package from RHN (http://rhn.redhat.com)\n".
-	    "or Net::SSLeay from CPAN (http://www.cpan.org)\n";
-
-use IO::Socket;
-use Getopt::Std;
-
-# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and 
-# "#END_VERSION_GENERATION"  It is generated by the Makefile
-
-#BEGIN_VERSION_GENERATION
-$RELEASE_VERSION="";
-$REDHAT_COPYRIGHT="";
-$BUILD_DATE="";
-#END_VERSION_GENERATION
-
-# Get the program name from $0 and strip directory names
-$_=$0;
-s/.*\///;
-my $pname = $_;
-
-
-################################################################################
-sub usage 
-{
-	print "Usage:\n";
-	print "\n";
-	print "$pname [options]\n";
-	print "\n";
-	print "Options:\n";
-	print "  -a <ip>          IP address or hostname of iLO card\n";
-	print "  -h               usage\n";
-	print "  -l <name>        Login name\n";
-	print "  -o <string>      Action: reboot (default), off, on or status\n";
-	print "  -p <string>      Login password\n";
-	print "  -S <path>        Script to run to retrieve login password\n";
-	print "  -q               quiet mode\n";
-	print "  -V               version\n";
-	print "  -v               verbose\n";
-	exit 0;
-}
-
-
-sub fail
-{
-	($msg)=@_;
-	print $msg unless defined $quiet;
-	exit 1;
-}
-
-
-sub fail_usage
-{
-	($msg)=@_;
-	print STDERR $msg if $msg;
-	print STDERR "Please use '-h' for usage.\n";
-	exit 1;
-}
-
-
-sub version
-{
-	print "$pname $RELEASE_VERSION $BUILD_DATE\n";
-	print "$REDHAT_COPYRIGHT\n" if ( $REDHAT_COPYRIGHT );
-	exit 0;
-}
-
-
-sub sendsock
-{
-	my ($sock, $msg, $junk) = @_;
-
-	$sock->print($msg);
-	if ($verbose)
-	{
-		chomp $msg;
-		print "SEND: $msg\n" 
-	}
-}
-
-
-# This will slurp up all the data on the socket.  The SSL connection 
-# automatically times out after 10 seconds.  If $mode is defined, the 
-# function will return immediately following the initial packet 
-# terminator "<END_RIBCL/>" or "</RIBCL>" 
-#    RIBCL VERSION=1.2  -> <END_RIBCL/>
-#    RIBCL VERSION=2.0  -> </RIBCL>
-sub receive_response
-{
-	my ($sock,$mode) = @_;
-	$mode = 0 unless defined $mode;
-	my $count=0;
-
-	my $buf;
-	my $buffer = "";
-
-	### sock should automatically be closed by iLO after 10 seconds
-	### XXX read buf length of 256.  Is this enough?  Do I need to buffer?
-	while ($ssl_mod eq "Net::SSLeay::Handle" ? $buf=<$sock> : $sock->read($buf,256) )
-	{
-		$rd = length($buf);
-		last unless ($rd);
-
-		$buffer="$buffer$buf"; 
-		if ($verbose)
-		{
-			chomp $buf;
-			print "READ:($rd,$mode) $buf\n";
-		}
-
-		# RIBCL VERSION=1.2
-		last if ( $buffer =~ /<END_RIBCL\/>$/mi && $mode==1 );
-
-		# RIBCL VERSION=2.0
-		last if ( $buffer =~ /<\/RIBCL>$/mi && $mode==1 );
-	}
-
-	### Determine version of RIBCL if not already defined
-	if (!defined $ribcl_vers)
-	{
-		if ($buffer =~ /<RIBCL VERSION=\"([0-9.]+)\"/m)
-		{
-			$ribcl_vers=$1;
-			print "ribcl_vers=$ribcl_vers\n" if ($verbose);
-		}
-		else
-		{
-			fail "unable to detect RIBCL version\n";
-		}
-	}
-
-	return $buffer;
-}
-
-
-sub open_socket
-{
-	print "opening connection to $hostname:$port\n" if $verbose;
-
-	if ($ssl_mod eq "Net::SSLeay::Handle")
-	{
-		# neat little trick I found in the man page for Net::SSLeay::Handle
-		tie (*SSL,"Net::SSLeay::Handle",$hostname,$port)
-			or fail "unable to connect to $hostname:$port $@\n";
-		$ssl = \*SSL;
-	}
-	else
-	{
-		$ssl = Net::SSL->new( PeerAddr => $hostname,
-			              PeerPort => $port );
-		$ssl->configure();
-		$ssl->connect($port,inet_aton($hostname)) or 
-			fail "unable to connect to $hostname:$port $@\n";
-	}
-	return $ssl; 
-}
-
-
-sub close_socket
-{
-	my ($sock, $junk) = @_;
-	#shutdown ($sock,1);
-	close $sock;
-}
-
-
-# power_off() -- power off the node
-#   return 0 on success, non-zero on failure
-sub power_off
-{
-	my $response = set_power_state ("N");
-	my @response = split /\n/,$response;
-	my $no_err=0;
-	my $agent_status = -1;
-
-	foreach my $line (@response)
-	{
-		if ($line =~ /MESSAGE='(.*)'/)
-		{
-			my $msg = $1;
-			if ($msg eq "No error") 
-			{ 
-				$no_err++;
-				next; 
-			}
-			elsif ($msg eq "Host power is already OFF.")
-			{
-				$agent_status = 0;
-				print "warning: $msg\n" unless defined $quiet;
-			}
-			else
-			{
-				$agent_status = 1;
-				print STDERR "error: $msg\n";
-			}
-		}
-	}
-
-	# There should be about 6 or more response packets on a successful
-	# power off command.  
-	if ($agent_status<0)
-	{
-		$agent_status = ($no_err<5) ? 1 : 0;
-	} 
-
-	return $agent_status;
-}
-
-
-# power_on() -- power on the node
-#   return 0 on success, non-zero on failure
-sub power_on
-{
-	my $response = set_power_state ("Y");
-	my @response = split /\n/,$response;
-	my $no_err=0;
-	my $agent_status = -1;
-
-	foreach my $line (@response)
-	{
-		if ($line =~ /MESSAGE='(.*)'/)
-		{
-			my $msg = $1;
-			if ($msg eq "No error") 
-			{ 
-				$no_err++;
-				next; 
-			}
-			elsif ($msg eq "Host power is already ON.")
-			{
-				$agent_status = 0;
-				print "warning: $msg\n" unless defined $quiet;
-			}
-			else
-			{
-				$agent_status = 1;
-				print STDERR "error: $msg\n";
-			}
-		}
-	}
-
-	# There should be about 6 or more response packets on a successful
-	# power on command.  
-	if ($agent_status<0)
-	{
-		$agent_status = ($no_err<5) ? 1 : 0;
-	} 
-
-	return $agent_status;
-}
-
-# power_status() -- print the power status of the node
-#   return 0 on success, non-zero on failure 
-#   set $? to power status from ilo ("ON" or "OFF")
-sub power_status
-{
-	my $response = get_power_state ();
-	my @response = split /\n/,$response;
-	my $agent_status = -1;
-	my $power_status = "UNKNOWN";
-
-	foreach my $line (@response)
-	{
-		if ($line =~ /FIRMWARE_VERSION\s*=\s*\"(.*)\"/) {
-			$firmware_rev = $1;
-		}
-		if ($line =~ /MANAGEMENT_PROCESSOR\s*=\s*\"(.*)\"/) {
-			if ($1 eq "iLO2") {
-				$ilo_vers = 2;
-				print "power_status: reporting iLO2 $firmware_rev\n" if ($verbose);
-			}
-		}
-
-		if ($line =~ /MESSAGE='(.*)'/)
-		{
-			my $msg = $1;
-			if ($msg eq "No error") 
-			{ 
-				next; 
-			}
-			else
-			{
-				$agent_status = 1;
-				print STDERR "error: $msg\n";
-			}
-		}
-		# RIBCL VERSION=1.2   
-		elsif ($line =~ /HOST POWER=\"(.*)\"/)
-		{
-			$agent_status = 0;
-			$power_status = $1;
-		}
-
-		# RIBCL VERSION=2.0   
-		elsif ($line =~ /HOST_POWER=\"(.*)\"/)
-		{
-			$agent_status = 0;
-			$power_status = $1;
-		}
-
-	}
-	$_ = $power_status;
-	print "power_status: reporting power is $_\n" if ($verbose);
-	return $agent_status;
-}
-
-sub set_power_state
-{
-	my $state = shift;
-	my $response = "";
-
-	if (!defined $state || ( $state ne "Y" && $state ne "N") )
-	{
-		fail "illegal state\n";
-	}
-
-	$socket = open_socket;
-
-	sendsock $socket, "<?xml version=\"1.0\"?>\r\n";
-	$response = receive_response($socket,1);
-
-	print "Sending power-o".(($state eq "Y")?"n":"ff")."\n" if ($verbose);
-
-	if ($ribcl_vers < 2 )
-	{
-		sendsock $socket, "<RIBCL VERSION=\"1.2\">\n";
-	}
-	else
-	{
-		# It seems the firmware can't handle the <LOCFG> tag
-		# RIBCL VERSION=2.0
-		#> sendsock $socket, "<LOCFG VERSION=\"2.21\">\n";
-		sendsock $socket, "<RIBCL VERSION=\"2.0\">\n";
-	}
-	sendsock $socket, "<LOGIN USER_LOGIN = \"$username\" PASSWORD = \"$passwd\">\n";
-	sendsock $socket, "<SERVER_INFO MODE = \"write\">\n";
-
-	if ($ilo_vers == 2) {
-		# iLO2 with RIBCL v2.22 behaves differently from
-		# iLO with RIBCL v2.22. For the former, HOLD_PWR_BTN is
-		# used to both power the machine on and off; when the power
-		# is off, PRESS_PWR_BUTTON has no effect. For the latter,
-		# HOLD_PWR_BUTTON is used to power the machine off, and
-		# PRESS_PWR_BUTTON is used to power the machine on;
-		# when the power is off, HOLD_PWR_BUTTON has no effect.
-		if ($firmware_rev > 1.29) {
-			sendsock $socket, "<HOLD_PWR_BTN TOGGLE=\"Yes\" />\n";
-		} else {
-			sendsock $socket, "<HOLD_PWR_BTN/>\n";
-		}
-	}
-	# As of firmware version 1.71 (RIBCL 2.21) The SET_HOST_POWER command
-	# is no longer available.  HOLD_PWR_BTN and PRESS_PWR_BTN are used 
-	# instead now :(
-	elsif ($ribcl_vers < 2.21)
-	{
-		sendsock $socket, "<SET_HOST_POWER HOST_POWER = \"$state\"/>\n";
-	}
-	else
-	{
-		if ($state eq "Y" )
-		{ 
-			sendsock $socket, "<PRESS_PWR_BTN/>\n";
-		} 
-		else 
-		{
-			sendsock $socket, "<HOLD_PWR_BTN/>\n";
-		}
-	}
-
-	sendsock $socket, "</SERVER_INFO>\n";
-	sendsock $socket, "</LOGIN>\n";
-	sendsock $socket, "</RIBCL>\n";
-
-	# It seems the firmware can't handle the <LOCFG> tag
-	# RIBCL VERSION=2.0
-	#> sendsock $socket, "</LOCFG>\n" if ($ribcl_vers >= 2) ;
-
-	$response = receive_response($socket);
-
-	print "Closing connection\n" if ($verbose);
-	close_socket($socket);
-
-	return $response;
-}
-
-sub get_power_state
-{
-	my $response = "";
-
-	$socket = open_socket;
-
-	sendsock $socket, "<?xml version=\"1.0\"?>\r\n";
-	$response = receive_response($socket,1);
-
-	print "Sending get-status\n" if ($verbose);
-
-	if ($ribcl_vers < 2 )
-	{
-		sendsock $socket, "<RIBCL VERSION=\"1.2\">\n";
-	}
-	else
-	{
-		# It seems the firmware can't handle the <LOCFG> tag
-		# RIBCL VERSION=2.0
-		#> sendsock $socket, "<LOCFG VERSION=\"2.21\">\n";
-		sendsock $socket, "<RIBCL VERSION=\"2.0\">\n";
-	}
-	sendsock $socket, "<LOGIN USER_LOGIN = \"$username\" PASSWORD = \"$passwd\">\n";
-	if ($ribcl_vers >= 2) {
-	    sendsock $socket, "<RIB_INFO MODE=\"read\"><GET_FW_VERSION/></RIB_INFO>\n";
-	}
-	sendsock $socket, "<SERVER_INFO MODE = \"read\">\n";
-	sendsock $socket, "<GET_HOST_POWER_STATUS/>\n";
-	sendsock $socket, "</SERVER_INFO>\n";
-	sendsock $socket, "</LOGIN>\n";
-	sendsock $socket, "</RIBCL>\n";
-
-	# It seems the firmware can't handle the <LOCFG> tag
-	# RIBCL VERSION=2.0
-	#> sendsock $socket, "</LOCFG>\r\n" if ($ribcl_vers >= 2) ;
-
-	$response = receive_response($socket);
-
-	print "Closing connection\n" if ($verbose);
-	close_socket($socket);
-    
-	return $response;
-}
-
-
-sub get_options_stdin
-{
-	my $opt;
-	my $line = 0;
-	while( defined($in = <>) )
-	{
-		$_ = $in;
-
-		chomp;
-
-		# strip leading and trailing whitespace
-		s/^\s*//;
-		s/\s*$//;
-
-		# skip comments
-		next if /^#/;
-
-		$line+=1;
-		$opt=$_;
-		next unless $opt;
-
-		($name,$val)=split /\s*=\s*/, $opt;
-
-		if ( $name eq "" )
-		{
-			print STDERR "parse error: illegal name in option $line\n";
-			exit 2;
-		}
-
-		elsif ($name eq "action" || $name eq "option")
-		{
-				$action = $val;
-		}
-
-		# DO NOTHING -- this field is used by fenced or stomithd
-		elsif ($name eq "agent" ) { }
-
-		elsif ($name eq "hostname" )
-		{
-			$hostname = $val;
-		}
-		elsif ($name eq "login" )
-		{
-			$username = $val;
-		}
-		elsif ($name eq "passwd" )
-		{
-			$passwd = $val;
-		}
-		elsif ($name eq "passwd_script" )
-		{
-			$passwd_script = $val;
-		}
-		elsif ($name eq "ribcl" )
-		{
-			$ribcl_vers = $val;
-		}
-		elsif ($name eq "verbose" )
-		{
-			$verbose = $val;
-		}
-
-	}
-}
-
-################################################################################
-# MAIN
-
-$action = "reboot";
-$ribcl_vers = undef; # undef = autodetect
-$ilo_vers = 1;
-$firmware_rev = 0;
-
-if (@ARGV > 0) {
-	getopts("a:hl:n:o:p:S:r:qvV") || fail_usage ;
-
-	usage if defined $opt_h;
-	version if defined $opt_V;
-
-	fail_usage "Unkown parameter." if (@ARGV > 0);
-
-	fail_usage "No '-a' flag specified." unless defined $opt_a;
-	$hostname = $opt_a;
-
-	fail_usage "No '-l' flag specified." unless defined $opt_l;
-	$username = $opt_l;
-
-	if (defined $opt_S) {
-		$pwd_script_out = `$opt_S`;
-		chomp($pwd_script_out);
-		if ($pwd_script_out) {
-			$opt_p = $pwd_script_out;
-		}
-	}
-
-	fail_usage "No '-p' or '-S' flag specified." unless defined $opt_p;
-	$passwd   = $opt_p;
-
-	$action = $opt_o if defined $opt_o;
-	fail_usage "Unrecognised action '$action' for '-o' flag"
-		unless $action=~ /^(off|on|reboot|status)$/;
-
-	$localport = $opt_n if defined $opt_n;
-
-	$quiet = 1 if defined $opt_q;
-
-	$verbose = 1 if defined $opt_v;
-
-	$ribcl_vers = $opt_r if defined $opt_r;
-
-} else {
-	get_options_stdin();
-
-	fail "no host\n" unless defined $hostname;
-	fail "no login name\n" unless defined $username;
-
-	if (defined $passwd_script) {
-		$pwd_script_out = `$passwd_script`;
-		chomp($pwd_script_out);
-		if ($pwd_script_out) {
-			$passwd = $pwd_script_out;
-		}
-	}
-
-	fail "no password\n" unless defined $passwd;
-
-	fail "unrecognised action: $action\n"
-		unless $action=~ /^(off|on|reboot|status)$/;
-}
-
-# Parse user specified port from apaddr parameter
-($hostname_tmp,$port,$junk) = split(/:/,$hostname); 
-fail "bad hostname/ipaddr format: $hostname\n" if defined $junk;
-$hostname = $hostname_tmp;
-$port = 443 unless defined $port;
-
-print "ssl module: $ssl_mod\n" if $verbose;
-
-
-$_=$action;
-if (/on/)
-{
-	fail "power_status: unexpected error\n" if power_status;
-
-	if (! /^on$/i)
-	{
-		fail "power_on: unexpected error\n" if power_on;
-		fail "power_status: unexpected error\n" if power_status;
-		fail "failed to turn on\n" unless (/^on$/i); 
-	}
-	else
-	{
-		print "power is already on\n" unless defined $quiet;
-	}
-}
-elsif (/off/)
-{
-	fail "power_status: unexpected error\n" if power_status;
-
-	if (! /^off$/i)
-	{
-		fail "power_off: unexpected error\n" if power_off;
-		fail "power_status: unexpected error\n" if power_status;
-		fail "failed to turn off\n" unless (/^off$/i); 
-	}
-	else
-	{
-		print "power is already off\n" unless defined $quiet;
-	}
-}
-elsif (/reboot/)
-{
-	fail "power_status: unexpected error\n" if power_status;
-
-	if (! /^off$/i)
-	{
-		fail "power_off: unexpected error\n" if power_off;
-		fail "power_status: unexpected error\n" if power_status;
-		fail "failed to turn off\n" unless (/^off$/i); 
-	}
-
-	if (/^off$/i)
-	{
-		fail "power_on: unexpected error\n" if power_on;
-		fail "power_status: unexpected error\n" if power_status;
-		fail "failed to turn on\n" unless (/^on$/i); 
-	}
-	else
-	{
-		fail "unexpected power state: '$_'\n";
-	}
-}
-elsif (/status/)
-{
-	fail "power_status: unexpected error\n" if power_status;
-	print "power is $_\n";
-}
-else
-{
-	fail "illegal action: '$_'\n";
-}
-
-print "success\n" unless defined $quiet;
-exit 0
-
-################################################################################
diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py
new file mode 100755
index 0000000..dfc9d74
--- /dev/null
+++ b/fence/agents/ilo/fence_ilo.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+
+##
+## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
+##
+## The Following Agent Has Been Tested On:
+##
+##  iLO Version       
+## +---------------------------------------------+
+##  iLO Advanced 1.91 
+##
+## @note: We can't use conn.sendline because we need to send CR/LF
+#####
+
+import sys, re, pexpect
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New ILO Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+	try:
+		conn.send("POWER\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+				
+	status = re.compile("server power is currently: (.*)", re.IGNORECASE).search(conn.before).group(1)
+	return status.lower().strip()
+
+def set_power_status(conn, options):
+	action = {
+		'on' : "powerup",
+		'off': "powerdown"
+	}[options["-o"]]
+
+	try:
+		conn.send("power " + options["-o"] + "\r\n")
+		conn.log_expect(options, options["-c"], POWER_TIMEOUT)
+	except pexcept.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexcept.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"secure", "ribcl" ]
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	## 
+	## Fence agent specific defaults
+	#####
+	if 0 == options.has_key("-c"):
+		options["-c"] = "</>hpiLO->"
+
+	##
+	## Operate the fencing device
+	####
+	conn = fence_login(options)
+	fence_action(conn, options, set_power_status, get_power_status)
+
+	##
+	## Logout from system
+	######
+	conn.send("quit\r\n")
+	conn.close()
+
+if __name__ == "__main__":
+	main()
diff --git a/fence/agents/apc/Makefile b/fence/agents/lib/Makefile
similarity index 71%
copy from fence/agents/apc/Makefile
copy to fence/agents/lib/Makefile
index 7292eb8..4ea39e2 100644
--- a/fence/agents/apc/Makefile
+++ b/fence/agents/lib/Makefile
@@ -1,8 +1,9 @@
+##############################################################################
 ###############################################################################
-###############################################################################
 ##
-##  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
-##  Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
+##  Copyright (C) 2008 Red Hat, Inc.  All rights reserved.
+##
+##  Author: Fabio M. Di Nitto <fdinitto@redhat.com>
 ##  
 ##  This copyrighted material is made available to anyone wishing to use,
 ##  modify, copy, or redistribute it subject to the terms and conditions
@@ -11,7 +12,10 @@
 ###############################################################################
 ###############################################################################
 
-TARGET= fence_apc
-
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fencepy.mk
+
+TARGET= fencing.py
+
+FENCEAGENTSLIB= $(TARGET)
+
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
new file mode 100644
index 0000000..2a9393c
--- /dev/null
+++ b/fence/agents/lib/fencing.py.py
@@ -0,0 +1,347 @@
+#!/usr/bin/python
+
+##
+## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
+##
+#####
+import sys, getopt, time, os
+import pexpect, re
+import telnetlib
+
+## do not add code here.
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New fence lib agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
+#END_VERSION_GENERATION
+
+POWER_TIMEOUT = 20
+SHELL_TIMEOUT = 3
+LOGIN_TIMEOUT = 5
+
+LOG_MODE_VERBOSE = 100
+LOG_MODE_QUIET = 0
+
+EC_BAD_ARGS        = 2
+EC_LOGIN_DENIED    = 3
+EC_CONNECTION_LOST = 4
+EC_TIMED_OUT       = 5
+EC_WAITING_ON      = 6
+EC_WAITING_OFF     = 7
+
+all_opt = {
+	"help"    : {
+		"getopt" : "h",
+		"help" : "-h             Display this help and exit",
+		"order" : 54 },
+	"version" : { 
+		"getopt" : "V",
+		"help" : "-V             Output version information and exit",
+		"order" : 53 },
+	"quiet"   : {
+		"getopt" : "q",
+		"help" : "-q             Quiet mode",
+		"order" : 50 },
+	"verbose" : {
+		"getopt" : "v",
+		"help" : "-v             Verbose mode",
+		"order" : 51 },
+	"debug" : {
+		"getopt" : "D:",
+		"help" : "-D <debugfile> Debugging to output file",
+		"order" : 52 },
+	"agent"   : {
+		"getopt" : "",
+		"help" : "",
+		"order" : 1 },
+	"action" : {
+		"getopt" : "o:",
+		"help" : "-o <action>    Action: status, reboot (default), off or on",
+		"order" : 1 },
+	"ipaddr" : {
+		"getopt" : "a:",
+		"help" : "-a <ip>        IP address or hostname of fencing device",
+		"order" : 1 },
+	"login" : {
+		"getopt" : "l:",
+		"help" : "-l <name>      Login name",
+		"order" : 1 },
+	"no_login" : {
+		"getopt" : "",
+		"help" : "",
+		"order" : 1 },
+	"passwd" : {
+		"getopt" : "p:",
+		"help" : "-p <password>  Login password",
+		"order" : 1 },
+	"passwd_script" : {
+		"getopt" : "S:",
+		"help" : "-S <script>    Script to run to retrieve password",
+		"order" : 1 },
+	"module_name" : {
+		"getopt" : "m:",
+		"help" : "-m <module>    DRAC/MC module name",
+		"order" : 1 },
+	"drac_version" : {
+		"getopt" : "d:",
+		"help" : "-D <version>   Force DRAC version to use",
+		"order" : 1 },
+	"ribcl" : {
+		"getopt" : "r:",
+		"help" : "-r <version>   Force ribcl version to use",
+		"order" : 1 },
+	"cmd_prompt" : {
+		"getopt" : "c:",
+		"help" : "-c <prompt>    Force command prompt",
+		"order" : 1 },
+	"secure" : {
+		"getopt" : "x",
+		"help" : "-x             Use ssh connection",
+		"order" : 1 },
+	"port" : {
+		"getopt" : "n:",
+		"help" : "-n <id>        Physical plug number on device",
+		"order" : 1 },
+	"test" : {
+		"getopt" : "T",
+		"help" : "",
+		"order" : 1,
+		"obsolete" : "use -o status instead" }
+}
+
+class fspawn(pexpect.spawn):
+	def log_expect(self, options, pattern, timeout):
+		result = self.expect(pattern, timeout)
+		if options["log"] >= LOG_MODE_VERBOSE:
+			options["debug_fh"].write(self.before + self.after)
+		return result
+
+def version(command, release, build_date, copyright):
+	print command, " ", release, " ", build_date;
+	if len(copyright) > 0:
+		print copyright
+
+def fail_usage(message = ""):
+	if len(message) > 0:
+		sys.stderr.write(message+"\n")
+	sys.stderr.write("Please use '-h' for usage\n")
+	sys.exit(EC_BAD_ARGS)
+
+def fail(error_code):
+	message = {
+		EC_LOGIN_DENIED : "Unable to connect/login to fencing device",
+		EC_CONNECTION_LOST : "Connection lost",
+		EC_TIMED_OUT : "Connection timed out",
+		EC_WAITING_ON : "Failed: Timed out waiting to power ON",
+		EC_WAITING_OFF : "Failed: Timed out waiting to power OFF"
+	}[error_code] + "\n"
+	sys.stderr.write(message)
+	sys.exit(error_code)
+
+def usage(avail_opt):
+	global all_opt
+
+	print "Usage:"
+	print "\t" + os.path.basename(sys.argv[0]) + " [options]"
+	print "Options:"
+
+	sorted_list = [ (key, all_opt[key]) for key in avail_opt ]
+	sorted_list.sort(lambda x, y: cmp(x[1]["order"], y[1]["order"]))
+
+	for key, value in sorted_list:
+		if len(value["help"]) != 0:
+			print "   " + value["help"]
+
+def process_input(avail_opt):
+	global all_opt
+
+	##
+	## Set standard environment
+	#####
+	os.unsetenv("LANG")
+
+	##
+	## Prepare list of options for getopt
+	#####
+	getopt_string = ""
+	for k in avail_opt:
+		if all_opt.has_key(k):
+			getopt_string += all_opt[k]["getopt"]
+		else:
+			fail_usage("Parse error: unknown option '"+k+"'");
+
+	##
+	## Read options from command line or standard input
+	#####
+	if len(sys.argv) > 1:
+		try:
+			opt, args = getopt.gnu_getopt(sys.argv[1:], getopt_string)
+		except getopt.GetoptError, error:
+			fail_usage("Parse error: " + error.msg)
+
+		## Compatibility Layer
+		#####
+		z = dict(opt)
+		if z.has_key("-T") == 1:
+			z["-o"] = "status"
+
+		opt = z
+		##
+		#####
+	else:
+		opt = { }
+		name = ""
+		for line in sys.stdin.readlines():
+			line = line.strip()
+			if ((line.startswith("#")) or (len(line) == 0)): pass
+
+			(name, value) = (line + "=").split("=", 1)
+			value = value[:-1]
+
+			## Compatibility Layer
+			######
+			if name == "blade":
+				name = "port"
+			elif name == "option":
+				name = "action"
+			elif name == "fm":
+				name = "port"
+			elif name == "hostname":
+				name = "ipaddr"
+
+			##
+			######
+			if avail_opt.count(name) == 0:
+				fail_usage("Parse error: Unknown option '"+line+"'")
+
+			if all_opt[name]["getopt"].endswith(":"):
+				opt["-"+all_opt[name]["getopt"].rstrip(":")] = value
+			else:
+				opt["-"+all_opt[name]["getopt"].rstrip(":")] = 1
+	return opt
+
+##
+## This function checks input and answers if we want to have same answers 
+## in each of the fencing agents. It looks for possible errors and run
+## password script to set a correct password
+######
+def check_input(device_opt, opt):
+	options = dict(opt)
+
+	if options.has_key("-h"): 
+		usage(device_opt)
+		sys.exit(0)
+
+	if options.has_key("-V"):
+		print RELEASE_VERSION, BUILD_DATE
+		print REDHAT_COPYRIGHT
+		sys.exit(0)
+
+	if options.has_key("-v"):
+		options["log"] = LOG_MODE_VERBOSE
+	else:
+		options["log"] = LOG_MODE_QUIET
+
+	if 0 == options.has_key("-o"):
+		options["-o"] = "reboot"
+
+	if 0 == ["on", "off", "reboot", "status"].count(options["-o"].lower()):
+		fail_usage("Failed: Unrecognised action '" + options["-o"] + "'")
+
+	if (0 == options.has_key("-l")) and device_opt.count("login") and (device_opt.count("no_login") == 0):
+		fail_usage("Failed: You have to set login name")
+
+	if 0 == options.has_key("-a"):
+		fail_usage("Failed: You have to enter fence address")
+
+	if 0 == (options.has_key("-p") or options.has_key("-S")):
+		fail_usage("Failed: You have to enter password or password script")
+
+	if 1 == (options.has_key("-p") and options.has_key("-S")):
+		fail_usage("Failed: You have to enter password or password script")
+
+	if (0 == options.has_key("-n")) and (device_opt.count("plug_no")):
+		fail_usage("Failed: You have to enter plug number")
+
+	if options.has_key("-S"):
+		options["-p"] = os.popen(options["-S"]).read().rstrip()
+
+	if options.has_key("-D"):
+		try:
+			options["debug_fh"] = file (options["-D"], "w")
+		except IOError:
+			fail_usage("Failed: Unable to create file "+options["-D"])
+
+	if options.has_key("-v") and options.has_key("debug_fh") == 0:
+		options["debug_fh"] = sys.stderr
+
+	return options
+	
+def wait_power_status(tn, options, get_power_fn):
+	for x in range(POWER_TIMEOUT):
+		if get_power_fn(tn, options) != options["-o"]:
+			time.sleep(1)
+		else:
+			return 1
+	return 0
+
+def fence_action(tn, options, set_power_fn, get_power_fn):
+	status = get_power_fn(tn, options)
+
+	if options["-o"] == "on":
+		if status == "on":
+			print "Success: Already ON"
+		else:
+			set_power_fn(tn, options)
+			if wait_power_status(tn, options, get_power_fn):
+				print "Success: Powered ON"
+			else:
+				fail(EC_WAITING_ON)
+	elif options["-o"] == "off":
+		if status == "off":
+			print "Success: Already OFF"
+		else:
+			set_power_fn(tn, options)
+			if wait_power_status(tn, options, get_power_fn):
+				print "Success: Powered OFF"
+			else:
+				fail(EC_WAITING_OFF)
+	elif options["-o"] == "reboot":
+		if status != "off":
+			options["-o"] = "off"
+			set_power_fn(tn, options)
+			if wait_power_status(tn, options, get_power_fn) == 0:
+				fail(EC_WAITING_OFF)
+		options["-o"] = "on"
+		set_power_fn(tn, options)
+		if wait_power_status(tn, options, get_power_fn) == 0:
+			fail(EC_WAITING_ON)
+		print "Success: Rebooted"
+	elif options["-o"] == "status":
+		print "Status: " + status.upper()
+
+def fence_login(options):
+	try:
+		re_login = re.compile("(login: )|(Login Name:  )|(username: )|(User Name :)", re.IGNORECASE)
+		re_pass  = re.compile("password", re.IGNORECASE)
+
+		if options.has_key("-x"):
+			conn = fspawn ('ssh ' + options["-l"] + "@" + options["-a"])
+			result = conn.log_expect(options, [ "ssword: ", "Are you sure you want to continue connecting (yes/no)?" ], LOGIN_TIMEOUT)
+			if result == 1:
+				conn.sendline("yes")
+				conn.log_expect(options, "ssword: ", SHELL_TIMEOUT)
+			conn.sendline(options["-p"])
+			conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+		else:
+			conn = fspawn ('telnet ' + options["-a"])
+			conn.log_expect(options, re_login, LOGIN_TIMEOUT)
+			conn.send(options["-l"]+"\r\n")
+			conn.log_expect(options, re_pass, SHELL_TIMEOUT)
+			conn.send(options["-p"]+"\r\n")
+			conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_LOGIN_DENIED) 
+	except pexpect.TIMEOUT:
+		fail(EC_LOGIN_DENIED)
+	return conn
diff --git a/fence/agents/mcdata/Makefile b/fence/agents/mcdata/Makefile
index 453c176..91ca8d4 100644
--- a/fence/agents/mcdata/Makefile
+++ b/fence/agents/mcdata/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_mcdata
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/rsa/Makefile b/fence/agents/rsa/Makefile
index 509a991..1d29063 100644
--- a/fence/agents/rsa/Makefile
+++ b/fence/agents/rsa/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_rsa
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fencepy.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/rsb/Makefile b/fence/agents/rsb/Makefile
index 3f9ddfe..e4db9d8 100644
--- a/fence/agents/rsb/Makefile
+++ b/fence/agents/rsb/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_rsb
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fencepy.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/sanbox2/Makefile b/fence/agents/sanbox2/Makefile
index 2c7340b..04696c8 100644
--- a/fence/agents/sanbox2/Makefile
+++ b/fence/agents/sanbox2/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_sanbox2
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/scsi/Makefile b/fence/agents/scsi/Makefile
index f44886e..40491dd 100644
--- a/fence/agents/scsi/Makefile
+++ b/fence/agents/scsi/Makefile
@@ -10,35 +10,9 @@
 ###############################################################################
 ###############################################################################
 
-TARGET= fence_scsi
-
-SBINDIRT=$(TARGET) $(TARGET)_test
-INITDT= scsi_reserve
-
-all: $(TARGET) $(TARGET)_test
-
 include ../../../make/defines.mk
-include $(OBJDIR)/make/clean.mk
-include $(OBJDIR)/make/install.mk
-include $(OBJDIR)/make/uninstall.mk
 
+TARGET= fence_scsi fence_scsi_test
+INITDT= scsi_reserve
 
-$(TARGET):
-	: > $(TARGET)
-	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(S)/$(TARGET).pl >> $(TARGET)
-	echo "\$$RELEASE_VERSION=\"${RELEASE_VERSION}\";" >> $(TARGET)
-	${DEF2VAR} ${SRCDIR}/config/copyright.cf perl REDHAT_COPYRIGHT >> $(TARGET)
-	echo "\$$BUILD_DATE=\"(built `date`)\";" >> $(TARGET)
-	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(S)/$(TARGET).pl >> $(TARGET)
-	chmod +x $(TARGET)
-
-$(TARGET)_test: 
-	: > $(TARGET)_test
-	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(S)/$(TARGET)_test.pl >> $(TARGET)_test
-	echo "\$$RELEASE_VERSION=\"${RELEASE_VERSION}\";" >> $(TARGET)_test
-	${DEF2VAR} ${SRCDIR}/config/copyright.cf perl REDHAT_COPYRIGHT >> $(TARGET)_test
-	echo "\$$BUILD_DATE=\"(built `date`)\";" >> $(TARGET)_test
-	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(S)/$(TARGET)_test.pl >> $(TARGET)_test
-	chmod +x $(TARGET)_test
-
-clean: generalclean
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/vixel/Makefile b/fence/agents/vixel/Makefile
index 2bbc0fc..828f3ea 100644
--- a/fence/agents/vixel/Makefile
+++ b/fence/agents/vixel/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_vixel
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/vmware/Makefile b/fence/agents/vmware/Makefile
index cdf42bb..6c2b911 100644
--- a/fence/agents/vmware/Makefile
+++ b/fence/agents/vmware/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_vmware
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/wti/Makefile b/fence/agents/wti/Makefile
index 21716cc..414ad09 100644
--- a/fence/agents/wti/Makefile
+++ b/fence/agents/wti/Makefile
@@ -11,7 +11,8 @@
 ###############################################################################
 ###############################################################################
 
+include ../../../make/defines.mk
+
 TARGET= fence_wti
 
-include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/wti/fence_wti.pl b/fence/agents/wti/fence_wti.pl
deleted file mode 100755
index 6c1dc97..0000000
--- a/fence/agents/wti/fence_wti.pl
+++ /dev/null
@@ -1,384 +0,0 @@
-#!/usr/bin/perl
-
-###############################################################################
-###############################################################################
-##
-##  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
-##  Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
-##  
-##  This copyrighted material is made available to anyone wishing to use,
-##  modify, copy, or redistribute it subject to the terms and conditions
-##  of the GNU General Public License v.2.
-##
-###############################################################################
-###############################################################################
-
-use Getopt::Std;
-use Net::Telnet ();
-
-# Get the program name from $0 and strip directory names
-$_=$0;
-s/.*\///;
-my $pname = $_;
-
-
-# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and 
-# "#END_VERSION_GENERATION"  It is generated by the Makefile
-
-#BEGIN_VERSION_GENERATION
-$RELEASE_VERSION="";
-$REDHAT_COPYRIGHT="";
-$BUILD_DATE="";
-#END_VERSION_GENERATION
-
-
-sub usage
-{
-    print "Usage:\n";  
-    print "\n";
-    print "$pname [options]\n";
-    print "\n";
-    print "Options:\n";
-    print "  -a <ip>          IP address or hostname of NPS\n";
-    print "  -h               usage\n";
-    print "  -n <num>         Physical plug number on NPS\n";
-    print "  -p <string>      Password if NPS requires one\n";
-    print "  -S <path>        Script to run to retrieve login password\n";
-    print "  -o <operation>   Operation to perform (on, off, reboot)\n";
-    print "  -q               quiet mode\n";
-    print "  -T               test reports state of plug (no power cycle)\n";
-    print "  -V               Version\n";
-
-    exit 0;
-}
-
-sub fail
-{
-  ($msg)=@_;
-  print $msg."\n" unless defined $opt_q;
-  $t->close if defined $t;
-  exit 1;
-}
-
-sub fail_usage
-{
-  ($msg)=@_;
-  print STDERR $msg."\n" if $msg;
-  print STDERR "Please use '-h' for usage.\n";
-  exit 1;
-}
-
-sub version
-{
-  print "$pname $RELEASE_VERSION $BUILD_DATE\n";
-  print "$REDHAT_COPYRIGHT\n" if ( $REDHAT_COPYRIGHT );
-
-  exit 0;
-}
-
-$opt_o = "reboot";
-if (@ARGV > 0) {
-   getopts("a:hn:p:S:qTVo:") || fail_usage ;
-
-   usage if defined $opt_h;
-   version if defined $opt_V;
-
-   fail_usage "Unkown parameter." if (@ARGV > 0);
-
-   fail_usage "No '-a' flag specified." unless defined $opt_a;
-   fail_usage "No '-n' flag specified." unless defined $opt_n;
-
-   if (defined $opt_S) {
-       $pwd_script_out = `$opt_S`;
-       chomp($pwd_script_out);
-       if ($pwd_script_out) {
-           $opt_p = $pwd_script_out;
-       }
-   }
-
-   fail_usage "No '-p' or '-S' flag specified." unless defined $opt_p;
-
-} else {
-   get_options_stdin();
-
-   fail "failed: no IP address" unless defined $opt_a;
-   fail "failed: no plug number" unless defined $opt_n;
-
-   if (defined $opt_S) {
-       $pwd_script_out = `$opt_S`;
-       chomp($pwd_script_out);
-       if ($pwd_script_out) {
-           $opt_p = $pwd_script_out;
-       }
-   }
-
-   fail "failed: no password" unless defined $opt_p;
-}
-
-$t = new Net::Telnet;
-
-$t->open($opt_a);
-
-$expr = '/:|\n/';
-
-while (1)
-{
-  ($line, $match) = $t->waitfor($expr);
-
-  if ($line =~ /assword/)
-  {
-    fail "failed: no password" unless defined $opt_p;
-    $t->print($opt_p);
-    $expr = '/\n/';
-  }
-
-  elsif ($line =~ /v\d.\d+/)
-  {
-    $line =~ /\D*(\d)\.(\d+).*/;
-    $ver1 = $1;
-    $ver2 = $2;
-
-    $t->waitfor('/(TPS|IPS|RPC|NPS|NBB)\>/'); 
-    last;
-  }
-}
-
-
-if (defined $opt_T)
-{
-  &test($t);
-  exit 0;
-}
-
-
-# to be most certain of success, turn off, check for OFF status, turn ON, check
-# for ON status
-if (($opt_o eq "off") || ($opt_o eq "reboot")) {
-  $t->print("/off $opt_n");
-  ($line, $match) = $t->waitfor('/\(Y\/N\)|(TPS|IPS|RPC|NPS|NBB)\>/');
-
-  if ($match =~ /Y\/N/)
-  {
-    $t->print("y");
-    $t->waitfor('/(TPS|IPS|RPC|NPS|NBB)\>/');
-  }
-
-  $t->print("/s");
-
-  while (1)
-  {
-    ($line, $match) = $t->waitfor('/\n|(TPS|IPS|RPC|NPS|NBB)\>/');
-
-    if ($match =~ /(TPS|IPS|RPC|NPS|NBB)\>/)
-    {
-      print "failed: plug number \"$opt_n\" not found\n"
-         unless defined $opt_q;
-      exit 1;
-    }
-    
-    $line =~ /^\s+(\d+).*/;
-
-    if ($1 == $opt_n)
-    {
-      # For (TPS|IPS|RPC|NPS)
-      if($line =~ /^\s+(\d+)\s+\|\s+\S+\s+\|\s+(\w+).*/){
-        $state = $2;
-      # For NBB
-      } elsif($line =~ /^\s+(\d+)\s+\|\s+\S+\s+\|\s+\S+\s+\|\s+(\w+).*/){
-        $state = $2;
-      }
-
-      if ($state =~ /OFF/)
-      {
-        $t->waitfor('/(TPS|IPS|RPC|NPS|NBB)\>/');
-        last;
-      }
-
-      print "failed: plug not off ($state)\n"
-         unless defined $opt_q;
-      exit 1;
-    }
-  }
-}
-
-
-# at this point, failing to turn the machine back on shouldn't be a failure
-
-if (($opt_o eq "on") || ($opt_o eq "reboot")) {
-  sleep 5;
-  $t->print("/on $opt_n");
-  ($line, $match) = $t->waitfor('/\(Y\/N\)|(TPS|IPS|RPC|NPS|NBB)\>/');
-
-  if ($match =~ /Y\/N/)
-  {
-    $t->print("y");
-    $t->waitfor('/(TPS|IPS|RPC|NPS|NBB)\>/');
-  }
-
-  $t->print("/s");
-  
-  while (1)
-  {
-    ($line, $match) = $t->waitfor('/\n|(TPS|IPS|RPC|NPS|NBB)\>/');
-
-    if ($match =~ /(TPS|IPS|RPC|NPS|NBB)\>/)
-    {
-      print "success: plug-on warning\n"
-         unless defined $opt_q;
-      exit 0;
-    }
-
-    $line =~ /^\s+(\d+).*/;
-
-    if ($1 == $opt_n)
-    {
-      # For (TPS|IPS|RPC|NPS)
-      if($line =~ /^\s+(\d+)\s+\|\s+\S+\s+\|\s+(\w+).*/){
-        $state = $2;
-      # For NBB
-      } elsif($line =~ /^\s+(\d+)\s+\|\s+\S+\s+\|\s+\S+\s+\|\s+(\w+).*/){
-        $state = $2;
-      }
-
-      if ($state =~ /ON/)
-      {
-        $t->waitfor('/(TPS|IPS|RPC|NPS|NBB)\>/');
-        last;
-      }
-
-      print "success: plug state warning ($state)\n"  
-        unless defined $opt_q;
-
-      exit 0;
-    }
-  }
-}
-
-print "success: $opt_o operation on plug $opt_n\n" unless defined $opt_q;
-
-exit 0;
-
-
-
-sub test
-{
-  local($t) = @_;
-
-  $t->print("/s");
-
-  while (1)
-  {
-    ($line, $match) = $t->waitfor('/\n|(TPS|IPS|RPC|NPS|NBB)\>/');
-
-    if ($match =~ /(TPS|IPS|RPC|NPS|NBB)\>/)
-    {
-      print "failed: plug number \"$opt_n\" not found\n"
-          unless defined $opt_q;
-      exit 1;
-    }
-
-    $line =~ /^\s+(\d+).*/;
-
-    if ($1 == $opt_n)
-    {
-      # For (TPS|IPS|RPC|NPS)
-      if($line =~ /^\s+(\d+)\s+\|\s+\S+\s+\|\s+(\w+).*/){
-        $state = $2;
-      # For NBB
-      } elsif($line =~ /^\s+(\d+)\s+\|\s+\S+\s+\|\s+\S+\s+\|\s+(\w+).*/){
-        $state = $2;
-      }
-
-      if ($state =~ /ON|OFF/)
-      {
-        print "success: current plug state \"$state\"\n" 
-          unless defined $opt_q;
-      }
-
-      else
-      {
-        print "failed: unknown plug state \"$state\"\n"
-          unless defined $opt_q;
-      }
-    
-      last;
-    }
-  }
-}
-
-sub get_options_stdin
-{
-    my $opt;
-    my $line = 0;
-    while( defined($in = <>) )
-    {
-        $_ = $in;
-
-        chomp;
-
-        # strip leading and trailing whitespace
-        s/^\s*//;
-        s/\s*$//;
-
-        # skip comments
-        next if /^#/;
-
-        $line+=1;
-        $opt=$_;
-        next unless $opt;
-
-        ($name,$val)=split /\s*=\s*/, $opt;
-
-        if ( $name eq "" )
-        {
-           print STDERR "parse error: illegal name in option $line\n";
-           exit 2;
-        }
-
-        # DO NOTHING -- this field is used by fenced
-        elsif ($name eq "agent" ) { }
-
-        # FIXME -- deprecated.  use "port" instead.
-        elsif ($name eq "fm" )
-        {
-            (my $dummy,$opt_n) = split /\s+/,$val;
-            print STDERR "Deprecated \"fm\" entry detected.  refer to man page.\n";
-        }
-
-        elsif ($name eq "ipaddr" )
-        {
-            $opt_a = $val;
-        }
-
-	# FIXME -- depreicated residue of old fencing system
-        elsif ($name eq "name" ) { }
-
-        elsif ($name eq "passwd" )
-        {
-            $opt_p = $val;
-        }
-		elsif ($name eq "passwd_script" )
-		{
-			$opt_S = $val;
-		}
-        elsif ($name eq "port" )
-        {
-            $opt_n = $val;
-        }
-        elsif ($name eq "option" )
-        {
-            $opt_o = $val;
-        }
-        # elsif ($name eq "test" ) 
-        # {
-        #    $opt_T = $val;
-        # } 
-
-        # FIXME should we do more error checking?  
-        # Excess name/vals will be eaten for now
-        else
-        {
-           fail "parse error: unknown option \"$opt\"\n";
-        }
-    }
-}
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
new file mode 100755
index 0000000..e72d449
--- /dev/null
+++ b/fence/agents/wti/fence_wti.py
@@ -0,0 +1,109 @@
+#!/usr/bin/python
+
+##
+## Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
+##
+## The Following Agent Has Been Tested On:
+##
+##  Version            Firmware
+## +-----------------+---------------------------+
+##  WTI RSM-8R4         ?? unable to find out ??
+##  WTI MPC-??? 	?? unable to find out ??
+##  WTI IPS-800-CE     v1.40h		(no username)
+#####
+
+import sys, re, pexpect
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New WTI Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+	try:
+		conn.send("/S"+"\r\n")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+	
+	plug_section = 0
+	for line in conn.before.splitlines():
+		if (plug_section == 2) and line.find("|") >= 0:
+			plug_line = [x.strip().lower() for x in line.split("|")]
+			if len(plug_line) < len(plug_header):
+				plug_section = -1
+				pass
+			if options["-n"].lower() == plug_line[plug_index]:
+				return plug_line[status_index]
+		elif (plug_section == 1):
+			plug_section = 2
+			pass
+		elif (line.upper().startswith("PLUG")):
+			plug_section = 1
+			plug_header = [x.strip().lower() for x in line.split("|")]
+			plug_index = plug_header.index("plug")
+			status_index = plug_header.index("status")
+
+	return "PROBLEM"
+
+def set_power_status(conn, options):
+	action = {
+		'on' : "/on",
+		'off': "/off"
+	}[options["-o"]]
+
+	try:
+		conn.send(action + " " + options["-n"] + ",y\r\n")
+		conn.log_expect(options, options["-c"], POWER_TIMEOUT)
+	except pexcept.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexcept.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"cmd_prompt", "secure", "port", "no_login", "test" ]
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	## 
+	## Fence agent specific defaults
+	#####
+	if 0 == options.has_key("-c"):
+		options["-c"] = [ "RSM>", "MPC>", "IPS>", "TPS>", "NBB>", "NPS>" ]
+
+	##
+	## Operate the fencing device
+	##
+	## @note: if there is not a login name then we assume that it is WTI-IPS
+	##        where no login name is used
+	#####	
+	if (0 == options.has_key("-l")):
+		try:
+			conn = fspawn ('telnet ' + options["-a"])
+			conn.log_expect(options, "Password: ", SHELL_TIMEOUT)
+			conn.send(options["-p"]+"\r\n")
+			conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+		except pexpect.EOF:
+			fail(EC_LOGIN_DENIED) 
+		except pexpect.TIMEOUT:
+			fail(EC_LOGIN_DENIED)		
+	else:
+		conn = fence_login(options)
+
+	fence_action(conn, options, set_power_status, get_power_status)
+
+	##
+	## Logout from system
+	######
+	conn.send("/X"+"\r\n")
+	conn.close()
+
+if __name__ == "__main__":
+	main()
diff --git a/fence/agents/xcat/Makefile b/fence/agents/xcat/Makefile
index d45e0bd..6c1db95 100644
--- a/fence/agents/xcat/Makefile
+++ b/fence/agents/xcat/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_xcat
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/zvm/Makefile b/fence/agents/zvm/Makefile
index 64cc46b..2094a2b 100644
--- a/fence/agents/zvm/Makefile
+++ b/fence/agents/zvm/Makefile
@@ -14,4 +14,4 @@
 TARGET= fence_zvm
 
 include ../../../make/defines.mk
-include $(OBJDIR)/make/fenceperl.mk
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/make/clean.mk b/make/clean.mk
index ac5f603..560c4f9 100644
--- a/make/clean.mk
+++ b/make/clean.mk
@@ -1,5 +1,5 @@
 generalclean:
-	rm -rf *~* *.o *.a *.so *.so.* a.out *.po *.s *.d
+	rm -rf *~* *.o *.a *.so *.so.* a.out *.po *.s *.d *.pyc
 	rm -rf core core.* .depend cscope.* *.orig *.rej
 	rm -rf linux .*.o.cmd .*.ko.cmd *.mod.c .tmp_versions Module.symvers .*.o.d modules.order
 	rm -rf ${TARGET} ${TARGETS} ${TARGET}_test
diff --git a/make/defines.mk.input b/make/defines.mk.input
index f3c732c..7a2a123 100644
--- a/make/defines.mk.input
+++ b/make/defines.mk.input
@@ -19,6 +19,8 @@ sharedir ?= ${DESTDIR}@SHAREDIR@
 mandir ?= ${DESTDIR}@MANDIR@
 module_dir ?= @MODULE_DIR@
 incdir ?= ${DESTDIR}@INCDIR@
+mibdir ?= ${DESTDIR}@MIBDIR@
+snmpbin ?= @SNMPBIN@
 
 # Build information
 
@@ -65,6 +67,7 @@ xenlibdir ?= @XENLIBDIR@
 virtincdir ?= @VIRTINCDIR@
 virtlibdir ?= @VIRTLIBDIR@
 fence_agents ?= @FENCE_AGENTS@
+fenceagentslibdir ?= @FENCEAGENTSLIBDIR@
 enable_xen ?= @ENABLE_XEN@
 without_gnbd-kernel/src ?= @DISABLE_GNBD@
 without_gfs-kernel/src/gfs ?= @DISABLE_GFS@
@@ -86,5 +89,4 @@ CONFDIR=@CONFDIR@
 CONFFILE=@CONFFILE@
 
 UNINSTALL = @SRCDIR@/scripts/uninstall.pl
-DEF2VAR = @SRCDIR@/scripts/define2var
-
+FENCEPARSE = @SRCDIR@/scripts/fenceparse
diff --git a/make/fencebuild.mk b/make/fencebuild.mk
new file mode 100644
index 0000000..27880be
--- /dev/null
+++ b/make/fencebuild.mk
@@ -0,0 +1,26 @@
+ifndef FENCEAGENTSLIB
+ifdef TARGET
+SBINDIRT=$(TARGET)
+endif
+endif
+
+all: $(TARGET)
+
+include $(OBJDIR)/make/clean.mk
+include $(OBJDIR)/make/install.mk
+include $(OBJDIR)/make/uninstall.mk
+
+$(TARGET):
+	${FENCEPARSE} \
+		${SRCDIR}/config/copyright.cf REDHAT_COPYRIGHT \
+		${RELEASE_VERSION} \
+		$(S) $@ | \
+	sed \
+		-e 's#@FENCEAGENTSLIBDIR@#${fenceagentslibdir}#g' \
+		-e 's#@MIBDIR@#${mibdir}#g' \
+		-e 's#@SNMPBIN@#${snmpbin}#g' \
+	> $@
+
+	chmod +x $@
+
+clean: generalclean
diff --git a/make/fenceperl.mk b/make/fenceperl.mk
deleted file mode 100644
index 9c60726..0000000
--- a/make/fenceperl.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-SBINDIRT=$(TARGET)
-
-all: $(TARGET)
-
-include $(OBJDIR)/make/clean.mk
-include $(OBJDIR)/make/install.mk
-include $(OBJDIR)/make/uninstall.mk
-
-$(TARGET): 
-	: > $(TARGET)
-	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(S)/$(TARGET).pl >> $(TARGET)
-	echo "\$$RELEASE_VERSION=\"${RELEASE_VERSION}\";" >> $(TARGET)
-	${DEF2VAR} ${SRCDIR}/config/copyright.cf perl REDHAT_COPYRIGHT >> $(TARGET)
-	echo "\$$BUILD_DATE=\"(built `date`)\";" >> $(TARGET)
-	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(S)/$(TARGET).pl >> $(TARGET)
-	chmod +x $(TARGET)
-
-clean: generalclean
diff --git a/make/fencepy.mk b/make/fencepy.mk
deleted file mode 100644
index 26ed29e..0000000
--- a/make/fencepy.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-SBINDIRT=$(TARGET)
-
-all: $(TARGET)
-
-include $(OBJDIR)/make/clean.mk
-include $(OBJDIR)/make/install.mk
-include $(OBJDIR)/make/uninstall.mk
-
-$(TARGET):
-	: > $(TARGET)
-	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(S)/$(TARGET).py >> $(TARGET)
-	echo "RELEASE_VERSION=\"${RELEASE_VERSION}\";" >> $(TARGET)
-	${DEF2VAR} ${SRCDIR}/config/copyright.cf sh REDHAT_COPYRIGHT >> $(TARGET)
-	echo "BUILD_DATE=\"(built `date`)\";" >> $(TARGET)
-	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(S)/$(TARGET).py >> $(TARGET)
-	chmod +x $(TARGET)
-
-clean: generalclean
diff --git a/make/install.mk b/make/install.mk
index e954e85..9bc5f58 100644
--- a/make/install.mk
+++ b/make/install.mk
@@ -47,3 +47,11 @@ ifdef KHEADT
 	install -d ${incdir}/linux
 	install -m644 ${KHEADT} ${incdir}/linux
 endif
+ifdef MIBRESOURCE
+	install -d ${mibdir}
+	install -m644 $(S)/${MIBRESOURCE} ${mibdir}
+endif
+ifdef FENCEAGENTSLIB
+	install -d ${DESTDIR}/${fenceagentslibdir}
+	install -m644 $(S)/${FENCEAGENTSLIB} ${DESTDIR}/${fenceagentslibdir}
+endif
diff --git a/make/uninstall.mk b/make/uninstall.mk
index 14e575b..2d8094f 100644
--- a/make/uninstall.mk
+++ b/make/uninstall.mk
@@ -29,3 +29,9 @@ endif
 ifdef KHEADT
 	${UNINSTALL} ${KHEADT} ${incdir}/linux
 endif
+ifdef MIBRESOURCE
+	${UNINSTALL} ${MIBRESOURCE} ${mibdir}
+endif
+ifdef FENCEAGENTSLIB
+	${UNINSTALL} ${FENCEAGENTSLIB}* ${DESTDIR}/${fenceagentslibdir}
+endif
diff --git a/rgmanager/src/resources/Makefile b/rgmanager/src/resources/Makefile
index 2c17e16..5e5897b 100644
--- a/rgmanager/src/resources/Makefile
+++ b/rgmanager/src/resources/Makefile
@@ -56,7 +56,10 @@ install: all
 	install -m644 $(TARGET) ${sharedir}/utils
 
 uninstall:
-	${UNINSTALL} ${RESOURCES} ${GENERAL_TARGETS} ${METADATA} ${UTIL_TARGETS} ${sharedir}
+	${UNINSTALL} ${RESOURCES} ${GENERAL_TARGETS} \
+		     ${METADATA} ${UTIL_TARGETS} \
+		     $(TARGET) \
+		     ${sharedir}
 
 clean: generalclean
 
diff --git a/scripts/define2var b/scripts/define2var
deleted file mode 100755
index 6f0ef5b..0000000
--- a/scripts/define2var
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/perl
-
-###############################################################################
-###############################################################################
-##
-##  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
-##  Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
-##  
-##  This copyrighted material is made available to anyone wishing to use,
-##  modify, copy, or redistribute it subject to the terms and conditions
-##  of the GNU General Public License v.2.
-##
-###############################################################################
-###############################################################################
-
-##
-## This script will pull out #define's and convert them into variables that
-## can be used for shell or perl scripts.
-##
-## It takes 2 or 3 parameters.  The first parameter is the filename to search
-## in.  The second paramter is the desired output format.  Supported types
-## ar sh and perl.  An optional third parameter may be given.  If specified,
-## only that partiucular #define will be extracted, otherwise, all #defines
-## are extracted.   This script is not capable of handling condiitional rules.
-## 
-
-$usage = "usage: define2var <filename> <perl|sh> [define]";
-
-if (@ARGV != 2 && @ARGV != 3)
-{
-	die "$usage\n";	
-}
-
-my ($filename, $type, $define ) = @ARGV;
-my $pfx,$sfx;
-
-if ($type eq "sh") 
-{ 
-	($pfx,$sfx) = ("",""); i
-} 
-elsif ($type eq "perl" ) 
-{ 
-	($pfx,$sfx) = ("\$",";"); 
-}
-else 
-{ 
-	die "Unknown type: $type\n"; 
-}
-
-open FILE, "< $filename" or die "error opening $filename: $!\n";
-
-while (<FILE>)
-{
-	chomp;
-	if ($_ =~ /^#define\s+(\S+)\s+(.*)/)
-	{
-		if(! $define ) 
-		{
-			print "$pfx$1=$2$sfx\n";
-		}
-		elsif ($define eq $1 )
-		{
-			print "$pfx$1=$2$sfx\n";
-			exit 0;
-		}
-	}
-}
-
-die "\"$define\" not found\n" if ($define);
-
-exit 0;
diff --git a/scripts/fenceparse b/scripts/fenceparse
new file mode 100755
index 0000000..de2ec7a
--- /dev/null
+++ b/scripts/fenceparse
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+###############################################################################
+###############################################################################
+##
+##  Copyright (C) 2008 Fabio M. Di Nitto <fabbione@fabbione.net>
+##  
+##  This copyrighted material is made available to anyone wishing to use,
+##  modify, copy, or redistribute it subject to the terms and conditions
+##  of the GNU General Public License v.2.
+##
+###############################################################################
+###############################################################################
+
+set -e
+
+definefile="$1"
+define="$2"
+release="$3"
+srcdir="$4"
+infile="$5"
+
+definedata="$(cat $definefile | grep "^\#define $define" | sed -e 's/.*'$define' //')"
+
+realinfile="$(ls $srcdir/$infile.*)"
+
+interpreter="$(cat $realinfile | head -n 1 | awk -F "/" '{print $NF}')"
+interpreter="$(echo $interpreter)"
+
+case "$interpreter" in
+	perl)
+		start="\$"
+		end=";"
+	;;
+	*)
+		start=""
+		end=""
+	;;
+esac
+
+awk "{print}(\$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $realinfile
+echo ${start}RELEASE_VERSION=\"${release}\"${end}
+echo ${start}REDHAT_COPYRIGHT=${definedata}${end}
+echo ${start}BUILD_DATE=\"\(built $(date)\)\"${end}
+awk -v p=0 "(\$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $realinfile
+
+exit 0


hooks/post-receive
--
Cluster Project



More information about the Cluster-cvs mailing list