Skip to content

Commit 63ee0fe

Browse files
author
Dan
committed
Updated documentation. Renamed host logger to be in pssh package namespace
1 parent c5634bd commit 63ee0fe

File tree

1 file changed

+19
-41
lines changed

1 file changed

+19
-41
lines changed

pssh.py

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import paramiko
3838
import os
3939

40-
host_logger = logging.getLogger('host_logger')
40+
host_logger = logging.getLogger('pssh.host_logger')
4141
handler = logging.StreamHandler()
4242
host_log_format = logging.Formatter('%(message)s')
4343
handler.setFormatter(host_log_format)
@@ -494,33 +494,14 @@ def run_command(self, *args, **kwargs):
494494
def exec_command(self, *args, **kwargs):
495495
"""Run command on all hosts in parallel, honoring self.pool_size
496496
497-
**Superseeded by :mod:`ParallelSSH.run_command`**
497+
**Deprecated by :mod:`pssh.ParallelSSH.run_command` **
498498
499499
:param args: Position arguments for command
500500
:type args: tuple
501501
:param kwargs: Keyword arguments for command
502502
:type kwargs: dict
503503
504-
:rtype: List of :mod:`gevent.Greenlet`
505-
506-
**Example**:
507-
508-
>>> cmds = client.exec_command('ls -ltrh')
509-
510-
Wait for completion, no stdout:
511-
512-
>>> for cmd in cmds:
513-
>>> cmd.join()
514-
515-
Alternatively/in addition print stdout for each command:
516-
517-
>>> print [get_stdout(cmd) for cmd in cmds]
518-
519-
Retrieving stdout implies join, meaning get_stdout will wait
520-
for completion of all commands before returning output.
521-
522-
You may call get_stdout on already completed greenlets to re-get
523-
their output as many times as you want."""
504+
:rtype: List of :mod:`gevent.Greenlet`"""
524505
warnings.warn("This method is being deprecated and will be removed in \
525506
future releases - use self.run_command instead", DeprecationWarning)
526507
return [self.pool.spawn(self._exec_command, host, *args, **kwargs)
@@ -541,36 +522,35 @@ def _exec_command(self, host, *args, **kwargs):
541522

542523
def get_output(self, commands=None):
543524
"""Get output from running commands.
544-
525+
526+
:param commands: (Optional) Override commands to get output from.\
527+
Uses running commands in pool if not given.
528+
:type commands: :mod:`gevent.Greenlet`
529+
:rtype: Dictionary with host as key as in:\
530+
\
531+
::
532+
533+
{'myhost1': {'exit_code': exit code if ready else None,
534+
'channel' : SSH channel of command,
535+
'stdout' : <iterable>,
536+
'stderr' : <iterable>,
537+
'cmd' : <greenlet>}}
538+
545539
Stdout and stderr are also logged via the logger named ``host_logger``
546540
which is enabled by default.
547541
``host_logger`` output can be disabled by removing its handler.
548542
549-
>>> logger = logging.getLogger('host_logger')
543+
>>> logger = logging.getLogger('pssh.host_logger')
550544
>>> for handler in logger.handlers: logger.removeHandler(handler)
551545
552546
**Example usage**:
553-
547+
554548
>>> output = client.get_output()
555549
>>> for host in output: print output[host]['stdout']
556550
<stdout>
557551
>>> # Get exit code after command has finished
558552
>>> self.get_exit_code(output[host])
559553
0
560-
561-
:param commands: (Optional) Override commands to get output from.
562-
Uses running commands in pool if not given
563-
:type commands: :mod:`gevent.Greenlet`
564-
:rtype: Dictionary with host as key as in:
565-
566-
::
567-
568-
{'myhost1': {'exit_code': exit code if ready else None,
569-
'channel' : SSH channel of command,
570-
'stdout' : <iterable>,
571-
'stderr' : <iterable>,
572-
'cmd' : <greenlet>}}
573-
574554
"""
575555
if not commands:
576556
commands = list(self.pool.greenlets)
@@ -610,11 +590,9 @@ def get_stdout(self, greenlet, return_buffers=False):
610590
:param greenlet: Greenlet object containing an \
611591
SSH channel reference, hostname, stdout and stderr buffers
612592
:type greenlet: :mod:`gevent.Greenlet`
613-
614593
:param return_buffers: Flag to turn on returning stdout and stderr \
615594
buffers along with exit code. Defaults to off.
616595
:type return_buffers: bool
617-
618596
:rtype: Dictionary containing ``{host: {'exit_code': exit code}}`` entry \
619597
for example ``{'myhost1': {'exit_code': 0}}``
620598
:rtype: With ``return_buffers=True``: ``{'myhost1': {'exit_code': 0,

0 commit comments

Comments
 (0)