[Cluster-devel] cluster/fence/agents/apc_snmp fence_apc_snmp.py

kupcevic at sourceware.org kupcevic at sourceware.org
Tue Mar 6 15:27:31 UTC 2007


CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL4
Changes by:	kupcevic at sourceware.org	2007-03-06 15:27:30

Modified files:
	fence/agents/apc_snmp: fence_apc_snmp.py 

Log message:
	Fixed bz193065 (fence_apc_snmp usage has too much whitespace)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/apc_snmp/fence_apc_snmp.py.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.1.2.2&r2=1.1.2.3

--- cluster/fence/agents/apc_snmp/Attic/fence_apc_snmp.py	2006/05/16 21:49:31	1.1.2.2
+++ cluster/fence/agents/apc_snmp/Attic/fence_apc_snmp.py	2007/03/06 15:27:30	1.1.2.3
@@ -17,7 +17,7 @@
 ## located in /usr/share/snmp/mibs/
 #############################################################################
 #############################################################################
-                                                                                
+
 
 
 import getopt, sys
@@ -38,19 +38,19 @@
 POWER_REBOOT="outletReboot"
 
 def usage():
-        print "Usage:\n";
-        print "\n";
-        print "Options:\n";
-        print "  -a <ip>          IP address or hostname of MasterSwitch\n";
-        print "  -h               usage\n";
-        print "  -l <name>        Login name\n";
-        print "  -n <num>         Outlet number to change\n";
-        print "  -o <string>      Action: Reboot (default), Off or On\n";
-        print "  -p <string>      Login password\n";
-        print "  -q               quiet mode\n";
-        print "  -V               version\n";
-        print "  -v               Log to file /tmp/apclog\n";
-                                                                                
+        print "Usage:";
+        print "";
+        print "Options:";
+        print "  -a <ip>          IP address or hostname of MasterSwitch";
+        print "  -h               usage";
+        print "  -l <name>        Login name";
+        print "  -n <num>         Outlet number to change";
+        print "  -o <string>      Action: Reboot (default), Off or On";
+        print "  -p <string>      Login password";
+        print "  -q               quiet mode";
+        print "  -V               version";
+        print "  -v               Log to file /tmp/apclog";
+	
         sys.exit(0);
 
 
@@ -89,7 +89,7 @@
         sys.exit(0)
       if o in ("-h", "--help"):
         usage()
-        sys.exit()
+        sys.exit(0)
       if o == "-n":
         port = a
       if o  == "-o":
@@ -123,8 +123,9 @@
     #place params in dict
     for line in sys.stdin:
       val = line.split("=")
-      params[val[0]] = val[1][:-1]
-
+      if len(val) == 2:
+        params[val[0].strip()] = val[1].strip()
+    
     try:
       address = params["ipaddr"]
     except KeyError, e:
@@ -135,20 +136,20 @@
     except KeyError, e:
       sys.stderr.write("FENCE: Missing login param for fence_apc...exiting")
       sys.exit(1)
-                                                                                
+    
     try:
       passwd = params["passwd"]
     except KeyError, e:
       sys.stderr.write("FENCE: Missing passwd param for fence_apc...exiting")
       sys.exit(1)
-
+    
     try:
       port = params["port"]
     except KeyError, e:
-      os.write(standard_err, "FENCE: Missing port param for fence_apc...exiting")
+      sys.stderr.write("FENCE: Missing port param for fence_apc...exiting")
       sys.exit(1)
-
-                                                                                
+    
+    
     try:
       a = params["option"]
       if a == "Off" or a == "OFF" or a == "off":
@@ -307,13 +308,13 @@
         sys.exit(1)
         
 def execWithCaptureStatus(command, argv, searchPath = 0, root = '/', stdin = 0,
-                    catchfd = 1, closefd = -1):
-                                                                                
+			  catchfd = 1, closefd = -1):
+	
     if not os.access (root + command, os.X_OK):
-        raise RuntimeError, command + " can not be run"
-                                                                                
+        raise RuntimeError, command + " cannot be run"
+    
     (read, write) = os.pipe()
-                                                                                
+    
     childpid = os.fork()
     if (not childpid):
         if (root and root != '/'): os.chroot (root)
@@ -324,42 +325,42 @@
             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__":




More information about the Cluster-devel mailing list