Skip to content

Commit 1af2b32

Browse files
author
Dan
committed
Updated documentation
1 parent 08c7891 commit 1af2b32

File tree

6 files changed

+99
-32
lines changed

6 files changed

+99
-32
lines changed

doc/agent.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SSH Agent
2+
=========
3+
4+
.. automodule:: pssh.agent
5+
:member-order: groupwise

doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Parallel-SSH's documentation
1515

1616
pssh_client
1717
ssh_client
18+
output
19+
agent
1820
exceptions
1921

2022
Welcome to ParallelSSH's API documentation.

doc/output.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Host Output
2+
============
3+
4+
.. automodule:: pssh.output
5+
:member-order: groupwise

pssh/agent.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,35 @@
1515
# License along with this library; if not, write to the Free Software
1616
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717

18+
"""SSH agent module of ParallelSSH"""
19+
1820
import paramiko.agent
1921

2022
class SSHAgent(paramiko.agent.AgentSSH):
21-
""":mod:`paramiko.agent.AgentSSH` compatible class for programmatically
23+
""":py:class:`paramiko.agent.Agent` compatible class for programmatically
2224
supplying an SSH agent"""
2325

2426
def __init__(self):
27+
"""**Example Usage**
28+
29+
.. code-block:: python
30+
31+
from pssh.agent import SSHAgent
32+
from pssh.utils import load_private_key
33+
from pssh import ParallelSSHClient
34+
35+
agent = SSHAgent()
36+
agent.add_key(load_private_key('my_private_key_filename'))
37+
agent.add_key(load_private_key('my_other_private_key_filename'))
38+
hosts = ['my_host', 'my_other_host']
39+
40+
client = ParallelSSHClient(hosts, agent=agent)
41+
client.run_command('uname')
42+
"""
2543
paramiko.agent.AgentSSH.__init__(self)
2644
self._conn = None
2745
self.keys = []
28-
46+
2947
def add_key(self, key):
3048
"""Add key to agent.
3149
:param key: Key to add

pssh/output.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
# This file is part of parallel-ssh.
4+
5+
# Copyright (C) 2015- Panos Kittenis
6+
7+
# This library is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation, version 2.1.
10+
11+
# This library is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
16+
# You should have received a copy of the GNU Lesser General Public
17+
# License along with this library; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
20+
21+
"""Output module of ParallelSSH"""
22+
123
from os import linesep
224

25+
326
class HostOutput(dict):
27+
"""Class to hold host output"""
28+
429
__slots__ = ('host', 'cmd', 'channel', 'stdout', 'stderr', 'stdin', 'exit_code', 'exception')
530

6-
def __init__(self, host, cmd, channel, stdout, stderr, stdin, exit_code=None, exception=None):
31+
def __init__(self, host, cmd, channel, stdout, stderr, stdin,
32+
exit_code=None, exception=None):
733
dict.__init__(self, (('host', host), ('cmd', cmd), ('channel', channel),
834
('stdout', stdout), ('stderr', stderr),
935
('stdin', stdin), ('exit_code', exit_code),
@@ -22,6 +48,7 @@ def __setattr__(self, name, value):
2248
dict.__setitem__(self, name, value)
2349

2450
def update(self, update_dict):
51+
"""Override of dict update function for backwards compatibility"""
2552
dict.update(self, update_dict)
2653
for key in update_dict:
2754
object.__setattr__(self, key, update_dict[key])

pssh/pssh_client.py

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717

1818

19-
"""Package containing ParallelSSHClient class."""
19+
"""Package containing ParallelSSHClient class"""
2020

2121
import sys
2222
if 'threading' in sys.modules:
@@ -139,19 +139,23 @@ def __init__(self, hosts,
139139
.. code-block:: python
140140
141141
pprint(output)
142-
143-
{'myhost1': {'exit_code': None,
144-
'stdout' : <generator>,
145-
'stderr' : <generator>,
146-
'cmd' : <greenlet>,
147-
'exception' : None,
148-
},
149-
'myhost2': {'exit_code': None,
150-
'stdout' : <generator>,
151-
'stderr' : <generator>,
152-
'cmd' : <greenlet>,
153-
'exception' : None,
154-
}}
142+
{'myhost1':
143+
host=myhost1
144+
cmd=<Greenlet>
145+
channel=<channel>
146+
stdout=<generator>
147+
stderr=<generator>
148+
stdin=<channel>
149+
exception=None
150+
'myhost2':
151+
host=myhost2
152+
cmd=<Greenlet>
153+
channel=<channel>
154+
stdout=<generator>
155+
stderr=<generator>
156+
stdin=<channel>
157+
exception=None
158+
}
155159
156160
**Enabling host logger**
157161
@@ -378,8 +382,9 @@ def run_command(self, *args, **kwargs):
378382
host list - :py:class:`pssh.exceptions.HostArgumentException` is raised \
379383
otherwise
380384
:type host_args: tuple or list
381-
:rtype: Dictionary with host as key as per \
382-
:py:func:`pssh.pssh_client.ParallelSSHClient.get_output`
385+
:rtype: Dictionary with host as key and \
386+
:py:class:`pssh.output.HostOutput` as value as per \
387+
:py:func:`pssh.pssh_client.ParallelSSHClient.get_output`
383388
384389
:raises: :py:class:`pssh.exceptions.AuthenticationException` on \
385390
authentication error
@@ -528,13 +533,14 @@ def run_command(self, *args, **kwargs):
528533
529534
client.hosts = ['otherhost']
530535
print(client.run_command('exit 0'))
531-
{'otherhost': {'exit_code': None}, <..>}
536+
{'otherhost': exit_code=None, <..>}
532537
533538
**Run multiple commands in parallel**
534539
535-
This short example demonstrates running long running commands in
536-
parallel, how long it takes for all commands to start, blocking until
537-
they complete and how long it takes for all commands to complete.
540+
This short example demonstrates running multiple long running commands
541+
in parallel on the same host, how long it takes for all commands to
542+
start, blocking until they complete and how long it takes for all
543+
commands to complete.
538544
539545
See examples directory for complete script. ::
540546
@@ -562,7 +568,7 @@ def run_command(self, *args, **kwargs):
562568
Started 10 commands in 0:00:00.428629
563569
All commands finished in 0:00:05.014757
564570
565-
*Output dictionary*
571+
*Output format*
566572
567573
::
568574
@@ -668,7 +674,8 @@ def get_output(self, cmd, output):
668674
669675
:param cmd: Command to get output from
670676
:type cmd: :py:class:`gevent.Greenlet`
671-
:param output: Dictionary containing output to be updated with output \
677+
:param output: Dictionary containing \
678+
:py:class:`pssh.output.HostOutput` values to be updated with output \
672679
from cmd
673680
:type output: dict
674681
:rtype: None
@@ -677,12 +684,14 @@ def get_output(self, cmd, output):
677684
678685
::
679686
680-
{'myhost1': {'exit_code': exit code if ready else None,
681-
'channel' : SSH channel of command,
682-
'stdout' : <iterable>,
683-
'stderr' : <iterable>,
684-
'cmd' : <greenlet>,
685-
'exception' : <exception object if applicable>}}
687+
{'myhost1':
688+
exit_code=exit code if ready else None
689+
channel=SSH channel of command
690+
stdout=<iterable>
691+
stderr=<iterable>
692+
cmd=<greenlet>
693+
exception=<exception object if applicable>
694+
}
686695
687696
Stdout and stderr are also logged via the logger named ``host_logger``
688697
which can be enabled by calling ``enable_host_logger``
@@ -735,6 +744,7 @@ def _update_host_output(self, output, host, exit_code, channel, stdout,
735744
"key for %s to %s", host, host, new_host)
736745
host = new_host
737746
output[host] = HostOutput(host, cmd, channel, stdout, stderr, stdin,
747+
exit_code=exit_code,
738748
exception=exception)
739749

740750
def join(self, output):
@@ -782,7 +792,7 @@ def get_exit_code(self, host_output):
782792

783793
def _get_exit_code(self, channel):
784794
"""Get exit code from channel if ready"""
785-
if not channel or not channel.exit_status_ready():
795+
if channel is None or not channel.exit_status_ready():
786796
return
787797
channel.close()
788798
return channel.recv_exit_status()

0 commit comments

Comments
 (0)