group¶
-
class
fabric.group.Group(*hosts)¶ A collection of
Connectionobjects whose API operates on its contents.Warning
This is a partially abstract class; you need to use one of its concrete subclasses (such as
SerialGrouporThreadingGroup) or you’ll getNotImplementedErroron most of the methods.Most methods in this class mirror those of
Connection, taking the same arguments; however their return values and exception-raising behavior differs:- Return values are dict-like objects (
GroupResult) mappingConnectionobjects to the return value for the respective connections:Group.runreturns a map ofConnectiontorunners.Result,Group.getreturns a map ofConnectiontotransfer.Result, etc. - If any connections encountered exceptions, a
GroupExceptionis raised, which is a thin wrapper around what would otherwise have been theGroupResultreturned; within that wrappedGroupResult, the excepting connections map to the exception that was raised, in place of aResult(as noResultwas obtained.) Any non-excepting connections will have aResultvalue, as normal.
For example, when no exceptions occur, a session might look like this:
>>> group = SerialGroup('host1', 'host2') >>> group.run("this is fine") { <Connection host='host1'>: <Result cmd='this is fine' exited=0>, <Connection host='host2'>: <Result cmd='this is fine' exited=0>, }
With exceptions (anywhere from 1 to “all of them”), it looks like so; note the different exception classes, e.g.
UnexpectedExitfor a completed session whose command exited poorly, versussocket.gaierrorfor a host that had DNS problems:>>> group = SerialGroup('host1', 'host2', 'notahost') >>> group.run("will it blend?") { <Connection host='host1'>: <Result cmd='will it blend?' exited=0>, <Connection host='host2'>: <UnexpectedExit: cmd='...' exited=1>, <Connection host='notahost'>: gaierror(...), }
New in version 2.0.
-
__init__(*hosts)¶ Create a group of connections from one or more shorthand strings.
See
Connectionfor details on the format of these strings - they will be used as the first positional argument ofConnectionconstructors.
-
__weakref__¶ list of weak references to the object (if defined)
-
classmethod
from_connections(connections)¶ Alternate constructor accepting
Connectionobjects.New in version 2.0.
-
get(*args, **kwargs)¶ Executes
Connection.geton all memberConnections.Returns: a GroupResult.New in version 2.0.
-
run(*args, **kwargs)¶ Executes
Connection.runon all memberConnections.Returns: a GroupResult.New in version 2.0.
- Return values are dict-like objects (
-
class
fabric.group.GroupResult(*args, **kwargs)¶ Collection of results and/or exceptions arising from
Groupmethods.Acts like a dict, but adds a couple convenience methods, to wit:
- Keys are the individual
Connectionobjects from within theGroup. - Values are either return values / results from the called method (e.g.
runners.Resultobjects), or an exception object, if one prevented the method from returning. - Subclasses
dict, so has all dict methods. - Has
succeededandfailedattributes containing sub-dicts limited to just those key/value pairs that succeeded or encountered exceptions, respectively.- Of note, these attributes allow high level logic, e.g.
if mygroup.run('command').failedand so forth.
- Of note, these attributes allow high level logic, e.g.
New in version 2.0.
-
__weakref__¶ list of weak references to the object (if defined)
-
failed¶ A sub-dict containing only failed results.
New in version 2.0.
-
succeeded¶ A sub-dict containing only successful results.
New in version 2.0.
- Keys are the individual