Commits

Anonymous committed ef80588

Added SSHJobMan.wait() method

  • Participants
  • Parent commits a255be9

Comments (0)

Files changed (3)

    * Basic functionality in one file using only Python 2.4 std libs.
 
 
+ As a Module:
+
+ You can use the SSHJobMan class from classh in your own code.  For example
+ here's a simple program to test that the time reported on a list of hosts
+ is consistent with the time on the localhost:
+
+
+	#!/usr/bin/env python
+	import sys 
+	from classh import SSHJobMan
+	from time import time
+
+	if __name__ == "__main__":
+	    job = SSHJobMan(sys.argv[1:], 'date +%s')
+	    job.wait()
+    
+	    for host, res in job.results.items():
+		if res.exitcode:
+		    print "Error getting date from %s" % host
+		    print res.errors
+		    print 
+		    continue 
+		else:
+		    try:
+			rtime = int(res.output.strip())
+		    except ValueError, e:
+			print "Couldn't parse output for %s" % host
+			print res.output
+			print 
+			continue 
+		    if (rtime - res.stopped) < 1 or res.started < rtime < res.stopped:
+			gap = res.stopped - res.started 
+			print "Time on %s is nominal (+/- %g)" % (host, gap)
+		    else:
+			print "Time error on %s" % host
+
+ Note that only three lines (one import and the first two lines in the 
+ __main__ block) are necessary to execute the job.  The rest is just
+ processing the results.
+
+
+
+
  Rhetorical Questions:
 
    * Why not multiprocessing module?
    * Why not Twisted/conch?
  
 
-
  Links to Related Packages:
 
  * http://vxargs.sourceforge.net/
 __author__  = '''Jim Dennis <answrguy@gmail.com>'''
 __url__     = '''http://bitbucket.org/jimd/classh/'''
 __license___= '''PSF (Python Software Foundation)'''
-__version__ = 0.05
+__version__ = 0.06
 
 
 import sys, os, string, signal, re
             except OSError:
                 debug('Ignoring os.kill OSError')
 
+
+    def wait(self, snooze=0.2):
+        '''
+        '''
+        debug ('wait called called with %g sleep interval' % snooze)
+        if not self.started:
+            self.start()
+        while not self.done():
+            sleep(snooze)
+            self.poll()
+
+
     def done(self):
         '''We're done when we have been started and
            we have zero remaining jobs in the pool
 __author__  = '''Jim Dennis <answrguy@gmail.com>'''
 __url__     = '''http://bitbucket.org/jimd/classh/'''
 __license___= '''PSF (Python Software Foundation)'''
-__version__ = 0.05
+__version__ = 0.06
 
 
 import sys, os, string, signal, re
             except OSError:
                 debug('Ignoring os.kill OSError')
 
+
+    def wait(self, snooze=0.2):
+        '''
+        '''
+        debug ('wait called called with %g sleep interval' % snooze)
+        if not self.started:
+            self.start()
+        while not self.done():
+            sleep(snooze)
+            self.poll()
+
+
     def done(self):
         '''We're done when we have been started and
            we have zero remaining jobs in the pool