Worker

ClusterShell worker interface.

A worker is a generic object which provides "grouped" work in a specific task.

class ClusterShell.Worker.Worker.Worker(handler)

Worker is an essential base class for the ClusterShell library. The goal of a worker object is to execute a common work on a single or several targets (abstract notion) in parallel. Concrete targets and also the notion of local or distant targets are managed by Worker's subclasses (for example, see the DistantWorker base class).

A configured Worker object is associated to a specific ClusterShell Task, which can be seen as a single-threaded Worker supervisor. Indeed, the work to be done is executed in parallel depending on other Workers and Task's current parameters, like current fanout value.

ClusterShell is designed to write event-driven applications, and the Worker class is key here as Worker objects are passed as parameter of most event handlers (see the ClusterShell.Event.EventHandler class).

Example of use:

>>> from ClusterShell.Event import EventHandler
>>> class MyOutputHandler(EventHandler):
...     def ev_read(self, worker, node, sname, msg):
...             print "%s: %s" % (node, line)
...
SNAME_STDERR = 'stderr'

stream name usually used for stderr

SNAME_STDIN = 'stdin'

stream name usually used for stdin

SNAME_STDOUT = 'stdout'

stream name usually used for stdout

__init__(handler)

Initializer. Should be called from derived classes.

__weakref__

list of weak references to the object (if defined)

abort()

Abort processing any action by this worker.

Safe to call on an already closing or aborting worker.

current_errmsg = None

set to stderr message in event handler; DEPRECATED: use EventHandler method argument msg if sname==SNAME_STDERR

current_msg = None

set to stdout in event handler; DEPRECATED: use EventHandler method argument msg if sname==SNAME_STDOUT

current_node = None

set to node in event handler; DEPRECATED: use EventHandler method argument node

current_rc = None

set to return code in event handler; DEPRECATED: use EventHandler method argument rc

current_sname = None

set to stream name in event handler; DEPRECATED: use EventHandler method argument sname

did_timeout()

Return whether this worker has aborted due to timeout.

eh = None

associated EventHandler

flush_buffers()

Flush any messages associated to this worker.

flush_errors()

Flush any error messages associated to this worker.

read(node=None, sname='stdout')

Read worker stream buffer.

Return stream read buffer of current worker.

Arguments: :param node: node name, can also be set to None for simple worker having worker.key defined (default is None) :param sname: stream name (default is 'stdout')

started = None

set to True when worker has started

task = None

worker's task when scheduled or None

class ClusterShell.Worker.Worker.DistantWorker(handler)

Base class DistantWorker.

DistantWorker provides a useful set of setters/getters to use with distant workers like ssh or pdsh.

iter_buffers(match_keys=None)

Returns an iterator over available buffers and associated NodeSet. If the optional parameter match_keys is defined, only keys found in match_keys are returned.

iter_errors(match_keys=None)

Returns an iterator over available error buffers and associated NodeSet. If the optional parameter match_keys is defined, only keys found in match_keys are returned.

iter_keys_timeout()

Iterate over timed out keys (ie. nodes) for a specific worker.

iter_node_buffers(match_keys=None)

Returns an iterator over each node and associated buffer.

iter_node_errors(match_keys=None)

Returns an iterator over each node and associated error buffer.

iter_node_retcodes()

Returns an iterator over each node and associated return code.

iter_retcodes(match_keys=None)

Returns an iterator over return codes and associated NodeSet. If the optional parameter match_keys is defined, only keys found in match_keys are returned.

node_buffer(node)

Get specific node buffer.

node_error(node)

Get specific node error buffer.

node_error_buffer(node)

Get specific node error buffer.

node_rc(node)

Get specific node return code.

Raises:KeyError -- command on node has not yet finished (no return code available), or this node is not known by this worker
node_retcode(node)

Get specific node return code.

Raises:KeyError -- command on node has not yet finished (no return code available), or this node is not known by this worker
num_timeout()

Return the number of timed out "keys" (ie. nodes) for this worker.