From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15230 invoked by alias); 25 Apr 2008 12:51:58 -0000 Received: (qmail 15145 invoked by uid 9702); 25 Apr 2008 12:51:56 -0000 Date: Fri, 25 Apr 2008 12:51:00 -0000 Message-ID: <20080425125156.15129.qmail@sourceware.org> From: fabbione@sourceware.org To: cluster-cvs@sources.redhat.com, cluster-devel@redhat.com Subject: Cluster Project branch, STABLE2, updated. cluster-2.03.01-35-ga1c4508 X-Git-Refname: refs/heads/STABLE2 X-Git-Reftype: branch X-Git-Oldrev: 523acee2a3aa7340acc04a28e43164f090b615df X-Git-Newrev: a1c4508cc0f8fbad39e3769f9e812d773dc43010 Mailing-List: contact cluster-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cluster-cvs-owner@sourceware.org X-SW-Source: 2008-q2/txt/msg00190.txt.bz2 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 Date: Fri Apr 25 11:10:17 2008 +0200 [BUILD] Fix fence lib install target Signed-off-by: Fabio M. Di Nitto commit 40500d1308b4d5c25adc61127cb08e29428ff7fc Author: Fabio M. Di Nitto 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 commit c6f398d6a7f562f72c9f87369780a6ed09a4fc94 Author: Fabio M. Di Nitto Date: Fri Apr 25 14:08:11 2008 +0200 [RGMANAGER] Fix uninstall target Signed-off-by: Fabio M. Di Nitto commit 3dbb69dde3e1c5ec59ef9eb0077bb026a1c906bf Author: Fabio M. Di Nitto 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 commit ca31f682c99033a4b200896bc02ee31766c8fbb4 Author: Fabio M. Di Nitto 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 commit 41bf99b6a7c5f612e2e35417cfb81f62b25f12d7 Author: Fabio M. Di Nitto Date: Tue Apr 22 20:33:31 2008 +0200 [MISC] Update copyright headers Signed-off-by: Fabio M. Di Nitto commit 9957de81e2216225bb15e2810487345221f86769 Author: Lon Hohberger 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 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 commit 7793a1dcdb25e29d91858d8fb03ecb4b672ef438 Author: Fabio M. Di Nitto 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 commit 2910f3ccbfbfd01bad004613670ba225ad04281e Author: Fabio M. Di Nitto Date: Tue Apr 1 22:50:28 2008 +0200 [FENCE] Fix fencelib to pring version and copyright Signed-off-by: Fabio M. Di Nitto commit 0241887d15738cd59b5374420d908a4d5ce38001 Author: Fabio M. Di Nitto 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 commit 9e4b66772171683279ad3682780d09920e6e15f8 Author: Fabio M. Di Nitto 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 commit 4771a07ee7e9c1efcb58753d863404b6a3a1ba24 Author: Fabio M. Di Nitto Date: Tue Apr 1 22:09:53 2008 +0200 [FENCE] Remove obsoleted fence_apc perl implementation Signed-off-by: Fabio M. Di Nitto commit d8b58867e89df7bff358a4d3e70d219c512dd1b6 Author: Fabio M. Di Nitto Date: Tue Apr 1 22:09:17 2008 +0200 [FENCE] Move apc_snmp README where it belongs Signed-off-by: Fabio M. Di Nitto commit 565f473b3e4809ed252f18afb7d6a1ac2a479092 Author: Fabio M. Di Nitto Date: Tue Apr 1 22:07:55 2008 +0200 [FENCE] Move apc_snmp README where it belongs Signed-off-by: Fabio M. Di Nitto commit 9f32ca6ee209beef889a437b1b931459f6aa17d8 Author: Fabio M. Di Nitto 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 commit 7b15cdeaeef5d2816e2bb7e6bab76f98d077915d Author: Fabio M. Di Nitto 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 commit 4b6835f18045883df3c742478b6ed8112f6b627e Author: Fabio M. Di Nitto 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 commit 0c0948b5a078ac298446bc6f1795256416de865b Author: Marek 'marx' Grac 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 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 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 () { chomp; s|fence\/agents\/| |g; + s|lib ||g; $all_fence = $_; } close IFILE; @@ -599,9 +618,12 @@ while () { $_ =~ 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 address or hostname of MasterSwitch\n"; - print " -h usage\n"; - print " -l Login name\n"; - print " -n Outlet number to change: [:] \n"; - print " -o Action: Reboot (default), Off or On\n"; - print " -p 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 "" to go 'up' menues. We must set - # the output_record_separator to "" so that "\n" is not printed - # after the "" 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 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 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 to cancel :" -CONTINUE = "Press to continue..." -SCREEN_END = "- Main Menu, - Refresh, - Event Log" -SCREEN_END_2 = "- Back, - Refresh, - 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 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 " ], 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 " ], 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 to cancel :", SHELL_TIMEOUT) + conn.send("YES\r\n") + conn.log_expect(options, "Press 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 address or hostname of blade center\n"; - print " -h usage\n"; - print " -l Login name\n"; - print " -n blade number to operate on\n"; - print " -o Action: on, off, reboot (default) or status\n"; - print " -p Password for login\n"; - print " -S 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 address or hostname of iLO card\n"; - print " -h usage\n"; - print " -l Login name\n"; - print " -o Action: reboot (default), off, on or status\n"; - print " -p Login password\n"; - print " -S 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 "" or "" -# RIBCL VERSION=1.2 -> -# RIBCL VERSION=2.0 -> -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 =~ /$/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 =~ /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, "\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, "\n"; - } - else - { - # It seems the firmware can't handle the tag - # RIBCL VERSION=2.0 - #> sendsock $socket, "\n"; - sendsock $socket, "\n"; - } - sendsock $socket, "\n"; - sendsock $socket, "\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, "\n"; - } else { - sendsock $socket, "\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, "\n"; - } - else - { - if ($state eq "Y" ) - { - sendsock $socket, "\n"; - } - else - { - sendsock $socket, "\n"; - } - } - - sendsock $socket, "\n"; - sendsock $socket, "\n"; - sendsock $socket, "\n"; - - # It seems the firmware can't handle the tag - # RIBCL VERSION=2.0 - #> sendsock $socket, "\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, "\r\n"; - $response = receive_response($socket,1); - - print "Sending get-status\n" if ($verbose); - - if ($ribcl_vers < 2 ) - { - sendsock $socket, "\n"; - } - else - { - # It seems the firmware can't handle the tag - # RIBCL VERSION=2.0 - #> sendsock $socket, "\n"; - sendsock $socket, "\n"; - } - sendsock $socket, "\n"; - if ($ribcl_vers >= 2) { - sendsock $socket, "\n"; - } - sendsock $socket, "\n"; - sendsock $socket, "\n"; - sendsock $socket, "\n"; - sendsock $socket, "\n"; - sendsock $socket, "\n"; - - # It seems the firmware can't handle the tag - # RIBCL VERSION=2.0 - #> sendsock $socket, "\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 ## ## 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 Debugging to output file", + "order" : 52 }, + "agent" : { + "getopt" : "", + "help" : "", + "order" : 1 }, + "action" : { + "getopt" : "o:", + "help" : "-o Action: status, reboot (default), off or on", + "order" : 1 }, + "ipaddr" : { + "getopt" : "a:", + "help" : "-a IP address or hostname of fencing device", + "order" : 1 }, + "login" : { + "getopt" : "l:", + "help" : "-l Login name", + "order" : 1 }, + "no_login" : { + "getopt" : "", + "help" : "", + "order" : 1 }, + "passwd" : { + "getopt" : "p:", + "help" : "-p Login password", + "order" : 1 }, + "passwd_script" : { + "getopt" : "S:", + "help" : "-S