[Cluster-devel] Cluster Project branch, RHEL5, updated. cmirror_1_1_15-28-g3183d50

cfeist at sourceware.org cfeist at sourceware.org
Mon Mar 31 19:57:22 UTC 2008


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

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

The branch, RHEL5 has been updated
       via  3183d505bd43e6d981686b86e97e92eea0f85341 (commit)
       via  618d11c7da095abc619790ab1043dc841050d7a7 (commit)
      from  c1b276c491b0d6e625035b5063532abc3ce23ca4 (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 3183d505bd43e6d981686b86e97e92eea0f85341
Author: Chris Feist <cfeist at redhat.com>
Date:   Fri Mar 28 14:57:46 2008 -0500

    Added apc_snmp to the main Makefile in the agents directory to make sure it
    is included in the build.  (bz#438905)

commit 618d11c7da095abc619790ab1043dc841050d7a7
Author: jparsons <jparsons at redhat.com>
Date:   Fri Mar 28 03:21:55 2008 -0400

    Adds APC snmp fence agent into distribution.
    
    This commit includes fence_apc_snmp in the fence package, and also places the
    apc mib file in /usr/share/snmp/mibs.

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

Summary of changes:
 fence/agents/Makefile                          |    3 +
 fence/agents/{apc => apc_snmp}/Makefile        |   12 +-
 fence/agents/apc_snmp/fence_apc_snmp.py        |  463 ++++++++++++++++++++++++
 fence/agents/{apc => apc_snmp}/powernet369.mib |    0 
 fence/configure                                |    7 +
 fence/make/defines.mk.input                    |    4 +
 6 files changed, 486 insertions(+), 3 deletions(-)
 copy fence/agents/{apc => apc_snmp}/Makefile (86%)
 create mode 100755 fence/agents/apc_snmp/fence_apc_snmp.py
 copy fence/agents/{apc => apc_snmp}/powernet369.mib (100%)

diff --git a/fence/agents/Makefile b/fence/agents/Makefile
index 37147cb..c41aedd 100644
--- a/fence/agents/Makefile
+++ b/fence/agents/Makefile
@@ -16,6 +16,7 @@ include ${top_srcdir}/make/defines.mk
 
 all:
 	${MAKE} -C apc all
+	${MAKE} -C apc_snmp all
 	${MAKE} -C bladecenter all
 	${MAKE} -C brocade all
 	${MAKE} -C bullpap all
@@ -41,6 +42,7 @@ all:
 
 install: all
 	${MAKE} -C apc install
+	${MAKE} -C apc_snmp install
 	${MAKE} -C bladecenter install
 	${MAKE} -C brocade install
 	${MAKE} -C bullpap install
@@ -66,6 +68,7 @@ install: all
 
 clean:
 	${MAKE} -C apc clean
+	${MAKE} -C apc_snmp clean
 	${MAKE} -C bladecenter clean
 	${MAKE} -C brocade clean
 	${MAKE} -C bullpap clean
diff --git a/fence/agents/apc/Makefile b/fence/agents/apc_snmp/Makefile
similarity index 86%
copy from fence/agents/apc/Makefile
copy to fence/agents/apc_snmp/Makefile
index c33350a..29a0df7 100644
--- a/fence/agents/apc/Makefile
+++ b/fence/agents/apc_snmp/Makefile
@@ -11,15 +11,16 @@
 ###############################################################################
 ###############################################################################
 
-SOURCE= fence_apc.py
-TARGET= fence_apc
+SOURCE= fence_apc_snmp.py
+TARGET= fence_apc_snmp
+RESOURCE= powernet369.mib
 
 top_srcdir=../..
 include ${top_srcdir}/make/defines.mk
 
 all: $(TARGET)
 
-fence_apc: fence_apc.py
+fence_apc_snmp: fence_apc_snmp.py
 	: > $(TARGET)
 	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(SOURCE) >> $(TARGET)
 	echo "FENCE_RELEASE_NAME=\"${RELEASE}\";" >> $(TARGET)
@@ -34,5 +35,10 @@ install: all
 	fi
 	install -m755 ${TARGET} ${sbindir}
 
+	if [ ! -d ${mibdir} ]; then \
+		install -d ${mibdir}; \
+	fi
+	install -m755 ${RESOURCE} ${mibdir}
+
 clean:
 	rm -f $(TARGET)
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
new file mode 100755
index 0000000..9fd0c14
--- /dev/null
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -0,0 +1,463 @@
+#!/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
+
+#BEGIN_VERSION_GENERATION
+FENCE_RELEASE_NAME=""
+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:
+			return 'on'
+		elif stat == self.state_off:
+			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               Verbose mode - write to /tmp/apclog"
+        print "  -V               Version"
+	
+        sys.exit(0)
+
+
+
+file_log = None
+def set_logging(verbose):
+	global file_log
+	if verbose:
+		file_log = open('/tmp/apclog', '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
+	else:
+		o = sys.stdout
+	o.write(msg)
+
+
+
+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
+  params = {}
+  
+  if len(sys.argv) > 1:
+    try:
+      opts, args = getopt.getopt(sys.argv[1:], "ha:u:c:n:o:vV", ["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
+      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)
+  
+  
+  ### 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)
+
+if __name__ == "__main__":
+	ret = main()
+	sys.exit(ret)
diff --git a/fence/agents/apc/powernet369.mib b/fence/agents/apc_snmp/powernet369.mib
similarity index 100%
copy from fence/agents/apc/powernet369.mib
copy to fence/agents/apc_snmp/powernet369.mib
diff --git a/fence/configure b/fence/configure
index 97d27e1..c40d098 100755
--- a/fence/configure
+++ b/fence/configure
@@ -33,6 +33,7 @@ $ret = 0;
 	mandir  => \$mandir,
 	prefix => \$prefix,
 	sbindir => \$sbindir,
+	mibdir => \$mibdir,
 	initdir => \$initdir,
 	enable_xen => \$enable_xen,
 	verbose => \$verbose
@@ -49,6 +50,7 @@ $err = &GetOptions (\%options,
 		    'mandir=s',
 		    'prefix=s',
 		    'sbindir=s',
+		    'mibdir=s',
 		    'initdir=s',
 		    'sharedir=s',
 		    'enable_xen',
@@ -75,6 +77,7 @@ if ($help || !$err) {
   print "--mandir=\tthe base directory for man pages.  (Default: /usr/share/man)\n";
   print "--prefix=\tthe base directory to install into.  (Default: /)\n";
   print "--sbindir=\tthe base directory for system binaries.  (Default: /sbin)\n";
+  print "--mibdir=\tthe base directory for snmp MIB files.  (Default: /usr/share/snmp/mibs)\n";
   print "--initdir=\tthe base directory for init scripts.  (Default: /etc/init.d)\n";
   print "--sharedir=\tthe base directory for misc cluster files.  (Default: /usr/share/cluster)\n";
   print "--enable_xen\t\tEnable building of Xen-specific pieces\n";
@@ -108,6 +111,9 @@ if (!$mandir) {
 if (!$sbindir) {
   $sbindir="${prefix}/sbin";
 }
+if (!$mibdir) {
+  $mibdir="${prefix}/usr/share/snmp/mibs";
+}
 if (!$initdir) {
   $initdir="${prefix}/etc/init.d";
 }
@@ -135,6 +141,7 @@ while (<IFILE>) {
   $_ =~ s/\@CCSLIBDIR\@/$ccslibdir/;
   $_ =~ s/\@MANDIR\@/$mandir/;
   $_ =~ s/\@SBINDIR\@/$sbindir/;
+  $_ =~ s/\@MIBDIR\@/$mibdir/;
   $_ =~ s/\@INITDIR\@/$initdir/;
   $_ =~ s/\@SHAREDIR\@/$sharedir/;
   $_ =~ s/\@ENABLE_XEN\@/$enable_xen/;
diff --git a/fence/make/defines.mk.input b/fence/make/defines.mk.input
index d19acf2..b270dea 100644
--- a/fence/make/defines.mk.input
+++ b/fence/make/defines.mk.input
@@ -22,6 +22,10 @@ ccsincdir ?= ${DESTDIR}@CCSINCDIR@
 enable_xen ?= @ENABLE_XEN@
 initdir ?= ${DESTDIR}/@INITDIR@
 
+# MIB directory used by apc snmp agent
+mibdir ?= ${DESTDIR}/@MIBDIR@
+
+
 # Where's the kernel?
 KERNEL_SRC = @KERNEL_SRC@
 


hooks/post-receive
--
Cluster Project




More information about the Cluster-devel mailing list