Skip to content

Commit

Permalink
Added refresh output convenience function. WIP, missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkittenis committed Jan 27, 2015
1 parent 6328a1d commit 61ff77f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pssh.py
Expand Up @@ -528,8 +528,10 @@ def get_output(self, commands=None):
:param commands: (Optional) Override commands to get output from.\
Uses running commands in pool if not given.
:type commands: :mod:`gevent.Greenlet`
:rtype: Dictionary with host as key as in:
:rtype: Dictionary with host as key
**Example output**
::
{'myhost1': {'exit_code': exit code if ready else None,
Expand All @@ -545,7 +547,7 @@ def get_output(self, commands=None):
>>> logger = logging.getLogger('pssh.host_logger')
>>> for handler in logger.handlers: logger.removeHandler(handler)
**Example usage**:
**Example usage**
>>> output = client.get_output()
>>> for host in output: print output[host]['stdout']
Expand All @@ -567,6 +569,16 @@ def get_output(self, commands=None):
'cmd' : cmd, })
return output

def refresh_output(self, output):
"""Convenience function for updating existing host output.
Gathers exit codes if available and updates output given in-place.
:param output: Host output dictionary as returned by \
:mod:`pssh.ParallelSSHClient.get_output
:rtype: None"""
for host in output:
output[host].update({'exit_code': self.get_exit_code(output[host])})

def get_exit_code(self, host_output):
"""Get exit code from host output if available
:param host_output: Per host output as returned by `self.get_output`
Expand Down

0 comments on commit 61ff77f

Please sign in to comment.