cluster: RHEL55 - fencing: Set default port to apc_snmp
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 396d6cf068f8844e08e76bf6471b28504b0b129b
Parent: 3bc496c348bbb3e0fe2448ae09c7265c9da14ada
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 19:05:19 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 19:05:19 2009 +0100
fencing: Set default port to apc_snmp
Problem already solved for fence_cisco_mds (commit
1b6691dd00e8098b429d147b52dfa0b9172f0139).
Resolves: rhbz#528916
---
fence/agents/apc_snmp/fence_apc_snmp.py | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
index a74b863..943902c 100755
--- a/fence/agents/apc_snmp/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -174,6 +174,7 @@ def main():
atexit.register(atexit_handler)
+ snmp_define_defaults()
apc_snmp_define_defaults()
options=check_input(device_opt,process_input(device_opt))
14 years, 4 months
cluster: RHEL55 - fencing: Fence agent for RSB ends with traceback
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 3bc496c348bbb3e0fe2448ae09c7265c9da14ada
Parent: 840cd254516025031f1005c9b5b34e1ea2142990
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 18:28:26 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 18:28:26 2009 +0100
fencing: Fence agent for RSB ends with traceback
RSB changed so it don't print 'CLOSING CONNECTION' and 'Power status:'
was changed to 'Power status :'
Resolves: rhbz#545054
---
fence/agents/rsb/fence_rsb.py | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py
index 1f5592e..25a2826 100755
--- a/fence/agents/rsb/fence_rsb.py
+++ b/fence/agents/rsb/fence_rsb.py
@@ -73,6 +73,8 @@ def main():
standard_err = 2
+ completed_action = 0
+
#set up regex list
USERNAME = 0
PASSWORD = 1
@@ -87,7 +89,7 @@ def main():
regex_list.append("user name\s*:")
regex_list.append("pass phrase\s*:")
regex_list.append("[Ee]nter\s+[Ss]election[^\r\n]*:")
- regex_list.append("[pP]ower Status:")
+ regex_list.append("[pP]ower Status\s*:")
regex_list.append("[Ee]rror\s*:")
regex_list.append("[Pp]ress any key to continue")
regex_list.append("really want to")
@@ -274,7 +276,15 @@ def main():
sock.close()
sys.exit(1)
- buf = sock.read_eager()
+ try:
+ buf = sock.read_eager()
+ except EOFError:
+ if completed_action == 1:
+ # action was completed succesfully, connection closed is OK
+ sys.exit(result)
+ else:
+ raise
+
if i == USERNAME:
if verbose:
print "Sending login: %s\n" % login
@@ -315,6 +325,7 @@ def main():
if verbose:
print "Power off was successful"
if action == POWER_OFF:
+ completed_action = 1
depth += 1
sock.write("0\r")
else:
@@ -342,6 +353,7 @@ def main():
elif power_command_issued and power_state == 1:
if verbose:
print "Power on was successful"
+ completed_action = 1
depth += 1
sock.write("0\r")
elif tries > 0:
@@ -376,6 +388,7 @@ def main():
os.write(standard_err, ("FENCE: Cannot determine power state: %s" % buf))
sys.exit(1)
depth = 2
+ completed_action = 1
elif i == DONE:
break
14 years, 4 months
cluster: STABLE3 - fencing: Version information not shown
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 82fff3bae8f627470cea7e04c2fbe1f93620937e
Parent: bcac91aadf00a7c1c1d5855f2f3380943467041d
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 17:34:16 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 17:34:16 2009 +0100
fencing: Version information not shown
Option '-V' (get version info) is not working because attributes where
not properly named, so they result in empty strings.
---
fence/agents/lib/fencing.py.py | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 8c702b8..70bdd34 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -4,6 +4,7 @@ import sys, getopt, time, os
import pexpect, re
import telnetlib
import atexit
+import __main__
## do not add code here.
#BEGIN_VERSION_GENERATION
@@ -693,8 +694,8 @@ def show_docs(options, docs = None):
sys.exit(0)
if options.has_key("-V"):
- print RELEASE_VERSION, BUILD_DATE
- print REDHAT_COPYRIGHT
+ print __main__.RELEASE_VERSION, __main__.BUILD_DATE
+ print __main__.REDHAT_COPYRIGHT
sys.exit(0)
def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None):
14 years, 4 months
cluster: RHEL55 - fencing: Version information not shown
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 840cd254516025031f1005c9b5b34e1ea2142990
Parent: e854270ef11f94db8ff481b7de896bdcc029beb4
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 17:30:13 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 17:30:13 2009 +0100
fencing: Version information not shown
Option '-V' (get version info) is not working because attributes where
not properly named, so they result in empty strings.
Resolves: rhbz#549113
---
fence/agents/lib/fencing.py.py | 5 +++--
fence/agents/lib/telnet_ssl.py | 2 +-
fence/agents/rsa/fence_rsa.py | 2 +-
fence/agents/sanbox2/fence_sanbox2.py | 4 ++--
fence/agents/virsh/fence_virsh.py | 2 +-
5 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index fced23c..647011a 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -8,6 +8,7 @@ import sys, getopt, time, os
import pexpect, re
import telnetlib
import atexit
+import __main__
## do not add code here.
#BEGIN_VERSION_GENERATION
@@ -706,8 +707,8 @@ def show_docs(options, docs = None):
sys.exit(0)
if options.has_key("-V"):
- print RELEASE_VERSION, BUILD_DATE
- print REDHAT_COPYRIGHT
+ print __main__.FENCE_RELEASE_NAME, __main__.BUILD_DATE
+ print __main__.REDHAT_COPYRIGHT
sys.exit(0)
def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None):
diff --git a/fence/agents/lib/telnet_ssl.py b/fence/agents/lib/telnet_ssl.py
index 5d0c981..52c9d82 100755
--- a/fence/agents/lib/telnet_ssl.py
+++ b/fence/agents/lib/telnet_ssl.py
@@ -10,7 +10,7 @@ import sys, socket, string, fcntl, os , time
from OpenSSL import SSL
#BEGIN_VERSION_GENERATION
-RELEASE_VERSION=""
+FENCE_RELEASE_NAME=""
REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py
index 9237f67..7611298 100755
--- a/fence/agents/rsa/fence_rsa.py
+++ b/fence/agents/rsa/fence_rsa.py
@@ -12,7 +12,7 @@ sys.path.append("/usr/lib/fence")
from fencing import *
#BEGIN_VERSION_GENERATION
-RELEASE_VERSION="New RSA2 Agent - test release on steroids"
+FENCE_RELEASE_NAME="New RSA2 Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2009"
#END_VERSION_GENERATION
diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py
index d1e65cf..4581974 100644
--- a/fence/agents/sanbox2/fence_sanbox2.py
+++ b/fence/agents/sanbox2/fence_sanbox2.py
@@ -9,11 +9,11 @@
#####
import sys, re, pexpect
-sys.path.append("@FENCEAGENTSLIBDIR@")
+sys.path.append("/usr/lib/fence")
from fencing import *
#BEGIN_VERSION_GENERATION
-RELEASE_VERSION="New Sanbox2 Agent - test release on steroids"
+FENCE_RELEASE_NAME="New Sanbox2 Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index 9174ac6..057a7c6 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -11,7 +11,7 @@ sys.path.append("/usr/lib/fence")
from fencing import *
#BEGIN_VERSION_GENERATION
-RELEASE_VERSION="Virsh fence agent"
+FENCE_RELEASE_NAME="Virsh fence agent"
REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
14 years, 4 months
fence-agents: master - fencing: Version information not shown
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=com...
Commit: 611802d969a10bc442b877ea3e759e03b0760aaf
Parent: 3a47f5c32fe9c428aa87b85943c33ed58a30fff9
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 17:24:36 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 17:24:36 2009 +0100
fencing: Version information not shown
Option '-V' (get version info) is not working because attributes where
not properly named, so they result in empty strings.
---
fence/agents/ilo_mp/fence_ilo_mp.py | 2 +-
fence/agents/lib/fencing.py.py | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py
index 2ddd733..3aac36d 100644
--- a/fence/agents/ilo_mp/fence_ilo_mp.py
+++ b/fence/agents/ilo_mp/fence_ilo_mp.py
@@ -5,7 +5,7 @@ sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
-FENCE_RELEASE_NAME=""
+RELEASE_VERSION=""
REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index d37498f..c4556d5 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -4,6 +4,7 @@ import sys, getopt, time, os
import pexpect, re
import telnetlib
import atexit
+import __main__
## do not add code here.
#BEGIN_VERSION_GENERATION
@@ -693,8 +694,8 @@ def show_docs(options, docs = None):
sys.exit(0)
if options.has_key("-V"):
- print RELEASE_VERSION, BUILD_DATE
- print REDHAT_COPYRIGHT
+ print __main__.RELEASE_VERSION, __main__.BUILD_DATE
+ print __main__.REDHAT_COPYRIGHT
sys.exit(0)
def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None):
14 years, 4 months
cluster: RHEL55 - fencing: Change default timeout values for LPAR and IPMI
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: e854270ef11f94db8ff481b7de896bdcc029beb4
Parent: 5cf593269f8731855274a2fb593e07b0f2ede20d
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 17:15:55 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 17:15:55 2009 +0100
fencing: Change default timeout values for LPAR and IPMI
Resolves: rhbz#549124, rhbz#546340
---
fence/agents/ipmilan/ipmilan.c | 2 +-
fence/agents/lpar/fence_lpar.py | 10 ++++------
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/fence/agents/ipmilan/ipmilan.c b/fence/agents/ipmilan/ipmilan.c
index ee6ae82..d8d76ff 100644
--- a/fence/agents/ipmilan/ipmilan.c
+++ b/fence/agents/ipmilan/ipmilan.c
@@ -53,7 +53,7 @@ do { \
#define ST_GENERIC_RESET 3
#define ST_CYCLE 4
-#define DEFAULT_TIMEOUT 10
+#define DEFAULT_TIMEOUT 20
#define DEFAULT_METHOD "onoff"
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index cfb78b0..3a22edc 100755
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -139,9 +139,10 @@ def main():
atexit.register(atexit_handler)
- pinput = process_input(device_opt)
- pinput["-x"] = 1
- options = check_input(device_opt, pinput)
+ all_opt["login_timeout"]["default"] = 15
+ all_opt["secure"]["default"] = 1
+
+ options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific defaults
@@ -152,9 +153,6 @@ def main():
if 0 == options.has_key("-H"):
options["-H"] = "4"
- if 0 == options.has_key("-x"):
- fail_usage("Failed: You have to use ssh connection (-x) to fence device")
-
show_docs(options)
if 0 == options.has_key("-s"):
14 years, 4 months
cluster: STABLE3 - fencing: Change default timeout values for LPAR and IPMI
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: bcac91aadf00a7c1c1d5855f2f3380943467041d
Parent: a26a9856c295be1de37186299eb52034a1c9cd66
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 17:13:08 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 17:13:08 2009 +0100
fencing: Change default timeout values for LPAR and IPMI
Resolves: rhbz#549124, rhbz#546340
---
fence/agents/ipmilan/ipmilan.c | 2 +-
fence/agents/lpar/fence_lpar.py | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/fence/agents/ipmilan/ipmilan.c b/fence/agents/ipmilan/ipmilan.c
index e0b92fb..58a86c9 100644
--- a/fence/agents/ipmilan/ipmilan.c
+++ b/fence/agents/ipmilan/ipmilan.c
@@ -27,7 +27,7 @@
#define ST_GENERIC_RESET 3
#define ST_CYCLE 4
-#define DEFAULT_TIMEOUT 10
+#define DEFAULT_TIMEOUT 20
#define DEFAULT_METHOD "onoff"
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index 823837b..52711d8 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -138,9 +138,10 @@ def main():
atexit.register(atexit_handler)
- pinput = process_input(device_opt)
- pinput["-x"] = 1
- options = check_input(device_opt, pinput)
+ all_opt["login_timeout"]["default"] = 15
+ all_opt["secure"]["default"] = 1
+
+ options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific settings and default values
14 years, 4 months
fence-agents: master - fencing: Change default timeout values for LPAR and IPMI
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=com...
Commit: 3a47f5c32fe9c428aa87b85943c33ed58a30fff9
Parent: b8f0c9eefc0a3b2a387b8b678a42d56c38e10687
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 17:05:28 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 17:05:28 2009 +0100
fencing: Change default timeout values for LPAR and IPMI
---
fence/agents/ipmilan/ipmilan.c | 2 +-
fence/agents/lpar/fence_lpar.py | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/fence/agents/ipmilan/ipmilan.c b/fence/agents/ipmilan/ipmilan.c
index 4c9aca3..48f15d3 100644
--- a/fence/agents/ipmilan/ipmilan.c
+++ b/fence/agents/ipmilan/ipmilan.c
@@ -30,7 +30,7 @@
#define ST_GENERIC_RESET 3
#define ST_CYCLE 4
-#define DEFAULT_TIMEOUT 10
+#define DEFAULT_TIMEOUT 20
#define DEFAULT_METHOD "onoff"
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index 37ff2b4..dd01b50 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -138,9 +138,9 @@ def main():
atexit.register(atexit_handler)
- pinput = process_input(device_opt)
- pinput["-x"] = 1
- options = check_input(device_opt, pinput)
+ all_opt["login_timeout"]["default"] = 15
+ all_opt["secure"]["default"] = 1
+ options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific settings and default values
14 years, 4 months
cluster: RHEL55 - fencing: New fence agent for APC SNMP
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 5cf593269f8731855274a2fb593e07b0f2ede20d
Parent: 964daeeb59eb1458c792af0ba2088d06367147f4
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 16:44:47 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 16:44:47 2009 +0100
fencing: New fence agent for APC SNMP
New implementation of fence_apc_snmp based on fencing library. Agent
took from STABLE3 branch.
Resolves: rhbz#532922 (apc_snmp part)
---
fence/agents/apc_snmp/fence_apc_snmp.py | 628 +++++++++----------------------
1 files changed, 181 insertions(+), 447 deletions(-)
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
index d2db854..a74b863 100755
--- a/fence/agents/apc_snmp/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -1,31 +1,17 @@
#!/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.
-##
-#############################################################################
-## 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/
-#############################################################################
-#############################################################################
-
-
-
-import getopt, sys
-import os
-import datetime
-import select
-import signal
-from glob import glob
+# The Following agent has been tested on:
+# - APC Switched Rack PDU (MB:v3.7.0 PF:v2.7.0 PN:apc_hw02_aos_270.bin AF1:v2.7.3 AN1:apc_hw02_aos_270.bin
+# AF1:v2.7.3 AN1:apc_hw02_rpdu_273.bin MN:AP7930 HR:B2) - SNMP v1
+# - APC Web/SNMP Management Card (MB:v3.8.6 PF:v3.5.8 PN:apc_hw02_aos_358.bin AF1:v3.5.7 AN1:apc_hw02_aos_358.bin
+# AF1:v3.5.7 AN1:apc_hw02_rpdu_357.bin MN:AP7900 HR:B2) - SNMP v1 and v3 (noAuthNoPrivacy,authNoPrivacy, authPrivacy)
+# - APC Switched Rack PDU (MB:v3.7.0 PF:v2.7.0 PN:apc_hw02_aos_270.bin AF1:v2.7.3 AN1:apc_hw02_rpdu_273.bin
+# MN:AP7951 HR:B2) - SNMP v1
+
+import sys, re, pexpect
+sys.path.append("/usr/lib/fence")
+from fencing import *
+from fencing_snmp import *
#BEGIN_VERSION_GENERATION
FENCE_RELEASE_NAME=""
@@ -33,431 +19,179 @@ REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
-POWER_ON="outletOn"
-POWER_OFF="outletOff"
-POWER_REBOOT="outletReboot"
-
-
-# oid defining fence device
-oid_sysObjectID = '.1.3.6.1.2.1.1.2.0'
-
-class SNMP:
- def __init__(self, params):
- self.hostname = params['ipaddr']
- self.udpport = params['udpport']
- self.community = params['community']
-
- def get(self, oid):
- args = ['/usr/bin/snmpget']
- args.append('-Oqn')
- args.append('-v')
- args.append('1')
- args.append('-c')
- args.append(self.community)
- args.append('-m')
- args.append('ALL')
- args.append(self.hostname + ':' + self.udpport)
- args.append(oid)
- strr, code = execWithCaptureStatus("/usr/bin/snmpget", args)
- if code:
- raise Exception, 'snmpget failed'
- l = strr.strip().split()
- return l[0], ' '.join(l[1:])
-
- def set_int(self, oid, value):
- args = ['/usr/bin/snmpset']
- args.append('-Oqn')
- args.append('-v')
- args.append('1')
- args.append('-c')
- args.append(self.community)
- args.append('-m')
- args.append('ALL')
- args.append(self.hostname + ':' + self.udpport)
- args.append(oid)
- args.append('i')
- args.append(str(value))
- strr,code = execWithCaptureStatus("/usr/bin/snmpset", args)
- if code:
- raise Exception, 'snmpset failed'
-
- def walk(self, oid):
- args = ['/usr/bin/snmpwalk']
- args.append('-Oqn')
- args.append('-v')
- args.append('1')
- args.append('-c')
- args.append(self.community)
- args.append('-m')
- args.append('ALL')
- args.append(self.hostname + ':' + self.udpport)
- args.append(oid)
- strr,code = execWithCaptureStatus("/usr/bin/snmpwalk", args)
- if code:
- raise Exception, 'snmpwalk failed'
- lines = strr.strip().splitlines()
- ret = []
- for line in lines:
- l = line.strip().split()
- ret.append((l[0], ' '.join(l[1:]).strip('"')))
- return ret
-
-
-
-class FenceAgent:
-
- def __init__(self, params):
- self.snmp = SNMP(params)
-
- def resolve_outlet(self):
- raise Exception, 'resolve_outlet() not implemented'
-
- def status(self):
- oid = self.status_oid % self.resolve_outlet()
- dummy, stat = self.snmp.get(oid)
- if stat == self.state_on or stat == "outletStatusOn":
- return 'on'
- elif stat == self.state_off or stat == "outletStatusOff":
- return 'off'
- else:
- raise Exception, 'invalid status ' + stat
-
- def power_off(self):
- oid = self.control_oid % self.resolve_outlet()
- self.snmp.set_int(oid, self.turn_off)
-
- def power_on(self):
- oid = self.control_oid % self.resolve_outlet()
- self.snmp.set_int(oid, self.turn_on)
-
-
-
-
-
-
-
-
-class MasterSwitch(FenceAgent):
-
- def __init__(self, params):
- FenceAgent.__init__(self, params)
-
- self.status_oid = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.4.%s'
- self.control_oid = '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.%s'
- self.outlet_table_oid = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.2'
-
- self.state_on = '1'
- self.state_off = '2'
-
- self.turn_on = '1'
- self.turn_off = '2'
-
- self.port = params['port']
-
- def resolve_outlet(self):
- outlet = None
- try:
- outlet = str(int(self.port))
- except:
- table = self.snmp.walk(self.outlet_table_oid)
- for row in table:
- if row[1] == self.port:
- t = row[0].strip().split('.')
- outlet = t[len(t)-1]
- if outlet == None:
- raise Exception, 'unable to resolve ' + self.port
- else:
- self.port = outlet
- return outlet
-
-
-class MasterSwitchPlus(FenceAgent):
- def __init__(self, params):
- FenceAgent.__init__(self, params)
-
- self.status_oid = '.1.3.6.1.4.1.318.1.1.6.7.1.1.5.%s.1.%s'
- self.control_oid = '.1.3.6.1.4.1.318.1.1.6.5.1.1.5.%s.1.%s'
- self.outlet_table_oid = '.1.3.6.1.4.1.318.1.1.6.7.1.1.4'
-
- self.state_on = '1'
- self.state_off = '2'
-
- self.turn_on = '1'
- self.turn_off = '3'
-
- try:
- self.switch = params['switch']
- except:
- self.switch = ''
- self.port = params['port']
-
- def resolve_outlet(self):
- switch = None
- outlet = None
- try:
- switch = str(int(self.switch))
- outlet = str(int(self.port))
- except:
- table = self.snmp.walk(self.outlet_table_oid)
- for row in table:
- if row[1] == self.port:
- t = row[0].strip().split('.')
- outlet = t[len(t)-1]
- switch = t[len(t)-3]
- if outlet == None:
- raise Exception, 'unable to resolve ' + self.port
- else:
- self.switch = switch
- self.port = outlet
- return (switch, outlet)
-
-
-
-
-
-
-def usage():
- print "Usage:"
- print ""
- print "Options:"
- print " -h Usage"
- print " -a <ip> IP address or hostname of fence device"
- print " -u <udpport> UDP port to use (default 161)"
- print " -c <community> SNMP community (default 'private')"
- print " -n <num> Outlet name/number to act on"
- print " -o <string> Action: Reboot (default), on, off and status"
- print " -v <filename> Verbose mode - write to file"
- print " -V Version"
-
- sys.exit(0)
-
-
-
-file_log = None
-def set_logging(verbose, verbose_filename):
- global file_log
- if verbose:
- file_log = open(verbose_filename, 'a')
- file_log.write('\n----------- ')
- file_log.write(datetime.datetime.today().ctime())
- file_log.write(' -----------\n')
-def log(msg, error=False):
- global file_log
- if msg.rfind('\n') != len(msg)-1:
- msg += '\n'
- if file_log != None:
- file_log.write(msg)
- if error:
- o = sys.stderr
+### CONSTANTS ###
+# oid defining fence device
+OID_SYS_OBJECT_ID='.1.3.6.1.2.1.1.2.0'
+
+### GLOBAL VARIABLES ###
+# Device - see ApcRPDU, ApcMSP, ApcMS
+device=None
+
+# Port ID
+port_id=None
+# Switch ID
+switch_id=None
+
+# Classes describing Device params
+class ApcRPDU:
+ # Rack PDU
+ status_oid= '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.4.%d'
+ control_oid= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.%d'
+ outlet_table_oid='.1.3.6.1.4.1.318.1.1.12.3.5.1.1.2'
+ ident_str="APC rPDU"
+ state_on=1
+ state_off=2
+ turn_on=1
+ turn_off=2
+ has_switches=False
+
+class ApcMSP:
+ # Master Switch+
+ status_oid= '.1.3.6.1.4.1.318.1.1.6.7.1.1.5.%d.1.%d'
+ control_oid= '.1.3.6.1.4.1.318.1.1.6.5.1.1.5.%d.1.%d'
+ outlet_table_oid='.1.3.6.1.4.1.318.1.1.6.7.1.1.4'
+ ident_str="APC Master Switch+"
+ state_on=1
+ state_off=2
+ turn_on=1
+ turn_off=3
+ has_switches=True
+
+class ApcMS:
+ # Master Switch - seems oldest, but supported on every APC PDU
+ status_oid= '.1.3.6.1.4.1.318.1.1.4.4.2.1.3.%d'
+ control_oid= '.1.3.6.1.4.1.318.1.1.4.4.2.1.3.%d'
+ outlet_table_oid='.1.3.6.1.4.1.318.1.1.4.4.2.1.4'
+ ident_str="APC Master Switch (fallback)"
+ state_on=1
+ state_off=2
+ turn_on=1
+ turn_off=2
+ has_switches=False
+
+### FUNCTIONS ###
+def apc_set_device(conn,options):
+ global device
+
+ agents_dir={'.1.3.6.1.4.1.318.1.3.4.5':ApcRPDU,
+ '.1.3.6.1.4.1.318.1.3.4.4':ApcMSP,
+ None:ApcMS}
+
+ # First resolve type of APC
+ apc_type=conn.walk(OID_SYS_OBJECT_ID)
+
+ if (not ((len(apc_type)==1) and (agents_dir.has_key(apc_type[0][1])))):
+ apc_type=[[None,None]]
+
+ device=agents_dir[apc_type[0][1]]
+
+ conn.log_command("Trying %s"%(device.ident_str))
+
+def apc_resolv_port_id(conn,options):
+ global port_id,switch_id,device
+
+ if (device==None):
+ apc_set_device(conn,options)
+
+ # Now we resolv port_id/switch_id
+ if ((options["-n"].isdigit()) and ((not device.has_switches) or (options["-s"].isdigit()))):
+ port_id=int(options["-n"])
+
+ if (device.has_switches):
+ switch_id=int(options["-s"])
else:
- o = sys.stdout
- o.write(msg)
+ table=conn.walk(device.outlet_table_oid,30)
+ for x in table:
+ if (x[1].strip('"')==options["-n"]):
+ t=x[0].split('.')
+ if (device.has_switches):
+ port_id=int(t[len(t)-1])
+ switch_id=int(t[len(t)-3])
+ else:
+ port_id=int(t[len(t)-1])
+ if (port_id==None):
+ fail_usage("Can't find port with name %s!"%(options["-n"]))
+def get_power_status(conn,options):
+ global port_id,switch_id,device
+
+ if (port_id==None):
+ apc_resolv_port_id(conn,options)
+
+ oid=((device.has_switches) and device.status_oid%(switch_id,port_id) or device.status_oid%(port_id))
+
+ (oid,status)=conn.get(oid)
+ return (status==str(device.state_on) and "on" or "off")
+
+def set_power_status(conn, options):
+ global port_id,switch_id,device
+
+ if (port_id==None):
+ apc_resolv_port_id(conn,options)
+
+ oid=((device.has_switches) and device.control_oid%(switch_id,port_id) or device.control_oid%(port_id))
+
+ conn.set(oid,(options["-o"]=="on" and device.turn_on or device.turn_off))
+
+
+def get_outlets_status(conn, options):
+ global device
+
+ result={}
+
+ if (device==None):
+ apc_set_device(conn,options)
+
+ res_ports=conn.walk(device.outlet_table_oid,30)
+
+ for x in res_ports:
+ t=x[0].split('.')
+
+ port_num=((device.has_switches) and "%s:%s"%(t[len(t)-3],t[len(t)-1]) or "%s"%(t[len(t)-1]))
+
+ port_name=x[1].strip('"')
+ port_status=""
+ result[port_num]=(port_name,port_status)
+
+ return result
+
+# Define new options
+def apc_snmp_define_defaults():
+ all_opt["snmp_version"]["default"]="1"
+ all_opt["community"]["default"]="private"
+
+# Main agent method
def main():
- try:
- main2()
- return 0
- except Exception, e:
- log(str(e), True)
- sys.exit(1)
-def main2():
-
- agents_dir = {'.1.3.6.1.4.1.318.1.3.4.5' : MasterSwitch,
- '.1.3.6.1.4.1.318.1.3.4.4' : MasterSwitchPlus}
-
- verbose = False
- verbose_filename = ""
- params = {}
-
- if len(sys.argv) > 1:
- try:
- opts, args = getopt.getopt(sys.argv[1:], "ha:u:c:n:o:v:V", ["help", "output="])
- except getopt.GetoptError:
- usage()
- sys.exit(2)
-
- for o, a in opts:
- o = o.strip()
- a = a.strip()
- if o == "-v":
- verbose = True
- verbose_filename = a
- if o == "-V":
- print "%s\n" % FENCE_RELEASE_NAME
- print "%s\n" % REDHAT_COPYRIGHT
- print "%s\n" % BUILD_DATE
- sys.exit(0)
- if o in ("-h", "--help"):
- usage()
- sys.exit(0)
- if o == "-a":
- params['ipaddr'] = a
- if o == "-u":
- params['udpport'] = a
- if o == "-c":
- params['community'] = a
- if o == "-n":
- switch = ''
- port = a
- if ':' in port:
- idx = port.find(':')
- switch = port[:idx]
- port = port[idx+1:]
- params['switch'] = switch
- params['port'] = port
- if o == "-o":
- params['option'] = a.lower()
-
- else: #Get opts from stdin
- for line in sys.stdin:
- val = line.strip().split("=")
- if len(val) == 2:
- o = val[0].strip().lower()
- a = val[1].strip()
- if o == 'verbose':
- if a.lower() == 'on' or a.lower() == 'true' or a == '1':
- verbose = True
- else:
- params[o] = a
-
-
- set_logging(verbose, verbose_filename)
-
-
- ### validation ###
-
- try:
- if params['ipaddr'] == '':
- raise Exception, 'missing ipadddr'
- except:
- log("FENCE: Missing ipaddr param for fence_apc_snmp...exiting", True)
- sys.exit(1)
- if 'udpport' not in params:
- params['udpport'] = '161'
- try:
- t = int(params['udpport'])
- if t >= 65536 or t < 0:
- raise Exception, 'invalid udpport'
- except:
- log("FENCE: Invalid udpport for fence_apc_snmp...exiting", True)
- sys.exit(1)
- if 'community' not in params:
- params['community'] = 'private'
- try:
- port = params['port']
- if len(port) == 0:
- raise Exception, 'missing port'
- except:
- log("FENCE: Missing port param for fence_apc_snmp...exiting", True)
- sys.exit(1)
- if 'switch' not in params:
- params['switch'] = ''
- try:
- act = params['option'].lower()
- if act in ['on', 'off', 'reboot', 'status']:
- params['option'] = act
- else:
- usage()
- sys.exit(3)
- except:
- params['option'] = 'reboot'
-
- ### End of validation ###
-
- if verbose:
- log('called with ' + str(params))
-
- agent = None
- dummy, sys_id = SNMP(params).get(oid_sysObjectID)
- if sys_id not in agents_dir:
- log('Fence device with \'oid_sysObjectID=' + sys_id + '\' is not supported', True)
- sys.exit(1)
- agent = agents_dir[sys_id](params)
-
- if params['option'] == 'status':
- log('Outlet "%s" - %s is %s' % (params['port'],
- str(agent.resolve_outlet()),
- agent.status()))
- elif params['option'] == 'on':
- agent.power_on()
- if agent.status() != 'on':
- raise Exception, 'Error turning outlet on'
- elif params['option'] == 'off':
- agent.power_off()
- if agent.status() != 'off':
- raise Exception, 'Error turning outlet off'
- elif params['option'] == 'reboot':
- agent.power_off()
- if agent.status() != 'off':
- raise Exception, 'Error turning outlet off'
- agent.power_on()
- if agent.status() != 'on':
- raise Exception, 'Error turning outlet on'
- else:
- print 'nothing to do'
- sys.exit(1)
- pass
-
-
-
-def execWithCaptureStatus(command, argv, searchPath = 0, root = '/', stdin = 0,
- catchfd = 1, closefd = -1):
-
- if not os.access (root + command, os.X_OK):
- raise Exception, command + " cannot be run"
-
- (read, write) = os.pipe()
-
- childpid = os.fork()
- if (not childpid):
- if (root and root != '/'): os.chroot (root)
- if isinstance(catchfd, tuple):
- for fd in catchfd:
- os.dup2(write, fd)
- else:
- os.dup2(write, catchfd)
- os.close(write)
- os.close(read)
-
- if closefd != -1:
- os.close(closefd)
-
- if stdin:
- os.dup2(stdin, 0)
- os.close(stdin)
-
- if (searchPath):
- os.execvp(command, argv)
- else:
- os.execv(command, argv)
-
- sys.exit(1)
-
- os.close(write)
-
- rc = ""
- s = "1"
- while (s):
- select.select([read], [], [])
- s = os.read(read, 1000)
- rc = rc + s
-
- os.close(read)
-
- try:
- (pid, status) = os.waitpid(childpid, 0)
- except OSError, (errno, msg):
- print __name__, "waitpid:", msg
-
- if os.WIFEXITED(status) and (os.WEXITSTATUS(status) == 0):
- status = os.WEXITSTATUS(status)
- else:
- status = -1
-
- return (rc, status)
+ device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
+ "action", "ipaddr", "login", "passwd", "passwd_script",
+ "test", "port", "separator", "no_login", "no_password",
+ "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level",
+ "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script",
+ "udpport","inet4_only","inet6_only",
+ "power_timeout", "shell_timeout", "login_timeout", "power_wait" ]
+
+ atexit.register(atexit_handler)
+
+ apc_snmp_define_defaults()
+
+ options=check_input(device_opt,process_input(device_opt))
+
+ ## Support for -n [switch]:[plug] notation that was used before
+ if ((options.has_key("-n")) and (-1 != options["-n"].find(":"))):
+ (switch, plug) = options["-n"].split(":", 1)
+ if ((switch.isdigit()) and (plug.isdigit())):
+ options["-s"] = switch
+ options["-n"] = plug
+
+ if (not (options.has_key("-s"))):
+ options["-s"]="1"
+
+ show_docs(options)
+
+ # Operate the fencing device
+ fence_action(FencingSnmp(options), options, set_power_status, get_power_status, get_outlets_status)
if __name__ == "__main__":
- ret = main()
- sys.exit(ret)
+ main()
14 years, 4 months
cluster: RHEL55 - fencing: New fence agent for IBM BladeCenter
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 964daeeb59eb1458c792af0ba2088d06367147f4
Parent: 1441b5d066bc362b44573bee69d793403067ef2e
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 16:37:54 2009 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Sun Dec 20 16:37:54 2009 +0100
fencing: New fence agent for IBM BladeCenter
New implementation of fence_ibmblade based on fencing library. Agent took
from STABLE3 branch.
Resolves: rhbz#532922 (ibm_bladecenter part)
---
fence/agents/ibmblade/Makefile | 2 +-
fence/agents/ibmblade/fence_ibmblade.pl | 286 -------------------------------
fence/agents/ibmblade/fence_ibmblade.py | 79 +++++++++
3 files changed, 80 insertions(+), 287 deletions(-)
diff --git a/fence/agents/ibmblade/Makefile b/fence/agents/ibmblade/Makefile
index ad29a48..ec8e62b 100644
--- a/fence/agents/ibmblade/Makefile
+++ b/fence/agents/ibmblade/Makefile
@@ -11,7 +11,7 @@
###############################################################################
###############################################################################
-SOURCE= fence_ibmblade.pl
+SOURCE= fence_ibmblade.py
TARGET= fence_ibmblade
top_srcdir=../..
diff --git a/fence/agents/ibmblade/fence_ibmblade.pl b/fence/agents/ibmblade/fence_ibmblade.pl
deleted file mode 100755
index bc1efc8..0000000
--- a/fence/agents/ibmblade/fence_ibmblade.pl
+++ /dev/null
@@ -1,286 +0,0 @@
-#!/usr/bin/perl
-
-###############################################################################
-###############################################################################
-##
-## 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.
-##
-###############################################################################
-###############################################################################
-
-use Getopt::Std;
-use Net::SNMP;
-
-my $ME = $0;
-
-END {
- defined fileno STDOUT or return;
- close STDOUT and return;
- warn "$ME: failed to close standard output: $!\n";
- $? ||= 1;
-}
-
-# Get the program name from $0 and strip directory names
-$_=$0;
-s/.*\///;
-my $pname = $_;
-
-my $sleep_time = 5;
-my $snmp_timeout = 10;
-$opt_o = "reboot";
-$opt_u = 161;
-
-my $oid_powerState = ".1.3.6.1.4.1.2.3.51.2.22.1.5.1.1.4"; # remoteControlBladePowerState
-my $oid_powerChange = ".1.3.6.1.4.1.2.3.51.2.22.1.6.1.1.7"; # powerOnOffBlade
-my $oid_resetPower = ".1.3.6.1.4.1.2.3.51.2.22.1.6.1.1.8"; # restartBlade
-
-# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and
-# "#END_VERSION_GENERATION" It is generated by the Makefile
-
-#BEGIN_VERSION_GENERATION
-$FENCE_RELEASE_NAME="";
-$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 BladeCenter\n";
- print " -h usage\n";
- print " -c <community> SNMP Community\n";
- print " -n <num> Port number to disable\n";
- print " -o <string> Action: Reboot (default), On or Off\n";
- print " -u <udpport> UDP port to use (default: 161)\n";
- print " -q quiet mode\n";
- print " -t test power state\n";
- print " -V version\n";
-
- exit 0;
-}
-
-sub fail_usage
-{
- ($msg)=@_;
- print STDERR $msg."\n" if $msg;
- print STDERR "Please use '-h' for usage.\n";
- exit 1;
-}
-
-sub fail
-{
- ($msg) = @_;
- print $msg."\n" unless defined $opt_q;
- $t->close if defined $t;
- exit 1;
-}
-
-sub version
-{
- print "$pname $FENCE_RELEASE_NAME $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" )
- {
- $opt_a = $val;
- }
- elsif ($name eq "community" )
- {
- $opt_c = $val;
- }
-
- elsif ($name eq "option" )
- {
- $opt_o = $val;
- }
- elsif ($name eq "port" )
- {
- $opt_n = $val;
- }
- elsif ($name eq "udpport" )
- {
- $opt_u = $val;
- }
-
- # FIXME should we do more error checking?
- # Excess name/vals will be eaten for now
- else
- {
- fail "parse error: unknown option \"$opt\"";
- }
- }
-}
-
-# ---------------------------- MAIN --------------------------------
-
-if (@ARGV > 0) {
- getopts("a:hc:n:o:qu:tV") || fail_usage ;
-
- usage if defined $opt_h;
- version if defined $opt_V;
-
- fail_usage "Unknown 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 '-c' flag specified." unless defined $opt_c;
- fail_usage "Unrecognised action '$opt_o' for '-o' flag"
- unless $opt_o =~ /^(reboot|on|off)$/i;
-
-} 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 SNMP community" unless defined $opt_c;
- fail "failed: unrecognised action: $opt_o"
- unless $opt_o =~ /^(reboot|on|off)$/i;
-}
-
-my ($snmpsess, $error) = Net::SNMP->session (
- -hostname => $opt_a,
- -version => "snmpv1",
- -port => $opt_u,
- -community => $opt_c,
- -timeout => $snmp_timeout);
-
-if (!defined ($snmpsess)) {
- printf("$FENCE_RELEASE_NAME ERROR: %s.\n", $error);
- exit 1;
-};
-
-# first check in what state are we now
-my $oid = $oid_powerState . "." . $opt_n;
-my $oid_val = "";
-my $result = $snmpsess->get_request (
- -varbindlist => [$oid]
-);
-if (!defined($result)) {
- printf("$FENCE_RELEASE_NAME ERROR: %s.\n", $snmpsess->error);
- $snmpsess->close;
- exit 1;
-}
-
-if (defined ($opt_t)) {
- printf ("$FENCE_RELEASE_NAME STATE: Port %d on %s returned %d\n", $opt_n, $opt_a, $result->{$oid});
- exit 1;
-};
-
-if ($opt_o =~ /^(reboot|off)$/i) {
- if ($result->{$oid} == "0") {
- printf ("$FENCE_RELEASE_NAME WARNING: Port %d on %s already down.\n", $opt_n, $opt_a);
- $snmpsess->close;
- exit 0;
- };
-} else {
- if ($result->{$oid} == "1") {
- printf ("$FENCE_RELEASE_NAME WARNING: Port %d on %s already up.\n", $opt_n, $opt_a);
- $snmpsess->close;
- exit 0;
- };
-};
-
-# excellent, now change the state
-if ($opt_o =~ /^reboot$/i) {
- # reboot
- $oid = $oid_resetPower . "." . $opt_n;
- $oid_val = "1";
-} elsif ($opt_o =~ /^on$/i) {
- # power on
- $oid = $oid_powerChange . "." . $opt_n;
- $oid_val = "1";
-} else {
- # power down
- $oid = $oid_powerChange . "." . $opt_n;
- $oid_val = "0";
-};
-
-$result = $snmpsess->set_request (
- -varbindlist => [$oid, INTEGER, $oid_val]
-);
-
-if (!defined ($result)) {
- # ignore this for now, seems like IBM BladeCenter has a broken SNMPd
- # it almost always timeouts
-};
-
-# now, wait a bit and see if we have done it
-sleep($sleep_time);
-
-$oid = $oid_powerState . "." . $opt_n;
-
-undef $result;
-$result = $snmpsess->get_request (
- -varbindlist => [$oid]
-);
-
-if (!defined($result)) {
- # this is a real error
- printf("$FENCE_RELEASE_NAME ERROR: %s.\n", $snmpsess->error);
- $snmpsess->close;
- exit 1;
-};
-
-if ($opt_o =~ /^(off)$/i) {
- if ($result->{$oid} == "1") {
- printf ("$FENCE_RELEASE_NAME ERROR: Port %d on %s still up.\n", $opt_n, $opt_a);
- $snmpsess->close;
- exit 1;
- };
-} else {
- if ($result->{$oid} == "0") {
- printf ("$FENCE_RELEASE_NAME ERROR: Port %d on %s still down.\n", $opt_n, $opt_a);
- $snmpsess->close;
- exit 1;
- };
-};
-
-# everything's a ok :)
-$snmpsess->close;
-
-printf ("$FENCE_RELEASE_NAME SUCCESS: Port %d on %s changed state to %s\n", $opt_n, $opt_a, $opt_o) unless defined $opt_q;
-exit 0;
-
diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py
new file mode 100644
index 0000000..08022ea
--- /dev/null
+++ b/fence/agents/ibmblade/fence_ibmblade.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python
+
+import sys, re, pexpect
+sys.path.append("/usr/lib/fence")
+from fencing import *
+from fencing_snmp import *
+
+#BEGIN_VERSION_GENERATION
+FENCE_RELEASE_NAME="IBM Blade SNMP fence agent"
+REDHAT_COPYRIGHT=""
+BUILD_DATE=""
+#END_VERSION_GENERATION
+
+### CONSTANTS ###
+# From fence_ibmblade.pl
+STATUSES_OID=".1.3.6.1.4.1.2.3.51.2.22.1.5.1.1.4" # remoteControlBladePowerState
+CONTROL_OID=".1.3.6.1.4.1.2.3.51.2.22.1.6.1.1.7" # powerOnOffBlade
+
+# Status constants returned as value from SNMP
+STATUS_DOWN=0
+STATUS_UP=1
+
+# Status constants to set as value to SNMP
+STATUS_SET_OFF=0
+STATUS_SET_ON=1
+
+### FUNCTIONS ###
+
+def get_power_status(conn,options):
+ (oid,status)=conn.get("%s.%s"%(STATUSES_OID,options["-n"]))
+ return (status==str(STATUS_UP) and "on" or "off")
+
+def set_power_status(conn, options):
+ conn.set("%s.%s"%(CONTROL_OID,options["-n"]),(options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
+
+def get_outlets_status(conn, options):
+ result={}
+
+ res_blades=conn.walk(STATUSES_OID,30)
+
+ for x in res_blades:
+ port_num=x[0].split('.')[-1]
+
+ port_alias=""
+ port_status=(x[1]==str(STATUS_UP) and "on" or "off")
+
+ result[port_num]=(port_alias,port_status)
+
+ return result
+
+# Define new options
+def ibmblade_define_defaults():
+ all_opt["snmp_version"]["default"]="1"
+
+# Main agent method
+def main():
+ global port_oid
+
+ device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
+ "action", "ipaddr", "login", "passwd", "passwd_script",
+ "test", "port", "separator", "no_login", "no_password",
+ "snmp_version", "community", "snmp_auth_prot", "snmp_sec_level",
+ "snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script",
+ "udpport","inet4_only","inet6_only",
+ "power_timeout", "shell_timeout", "login_timeout", "power_wait" ]
+
+ atexit.register(atexit_handler)
+
+ ibmblade_define_defaults()
+
+ options=check_input(device_opt,process_input(device_opt))
+
+ show_docs(options)
+
+ # Operate the fencing device
+ fence_action(FencingSnmp(options), options, set_power_status, get_power_status, get_outlets_status)
+
+if __name__ == "__main__":
+ main()
14 years, 4 months