Skip to content

Commit 2134b70

Browse files
author
Dan
committed
Updated setup.py, docstrings
1 parent 2a0e7d1 commit 2134b70

File tree

3 files changed

+71
-44
lines changed

3 files changed

+71
-44
lines changed

README.rst

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
parallel-ssh
22
============
33

4-
Library for running asynchronous parallel SSH commands over many hosts.
4+
Asynchronous parallel SSH client library.
55

6-
parallel-ssh uses asychronous network requests - there is *no* multi-threading or multi-processing used.
7-
8-
This is a *requirement* for commands on many (hundreds/thousands/hundreds of thousands) of hosts which would grind a system to a halt simply by having so many processes/threads all wanting to execute if done with multi-threading/processing.
6+
Run commands via SSH over tens/hundreds/thousands+ number of servers asynchronously and with minimal system load on the client host.
97

108
.. image:: https://img.shields.io/pypi/v/parallel-ssh.svg
119
:target: https://pypi.python.org/pypi/parallel-ssh
@@ -26,35 +24,50 @@ Installation
2624

2725
::
2826

29-
$ pip install parallel-ssh
27+
pip install parallel-ssh
3028

3129
*************
3230
Usage Example
3331
*************
3432

3533
See documentation on `read the docs`_ for more complete examples.
3634

37-
Run `ls` on two remote hosts in parallel.
35+
Run `ls` on two remote hosts in parallel with `sudo`.
36+
37+
::
3838

39-
>>> from pssh import ParallelSSHClient
40-
>>> hosts = ['myhost1', 'myhost2']
41-
>>> client = ParallelSSHClient(hosts)
42-
>>> output = client.run_command('ls -ltrh /tmp/', sudo=True)
43-
>>> print output
44-
{'myhost1': {'exit_code': 0, 'stdout': <generator>, 'stderr': <generator>, 'channel': <channel>, 'cmd' : <greenlet>, 'exception' : None},
45-
'myhost2': {'exit_code': 0, 'stdout': <generator>, 'stderr': <generator>, 'channel': <channel>, 'cmd' : <greenlet>, 'exception' : None}}
39+
from pssh import ParallelSSHClient
40+
hosts = ['myhost1', 'myhost2']
41+
client = ParallelSSHClient(hosts)
42+
output = client.run_command('ls -ltrh /tmp/', sudo=True)
43+
print output
44+
{'myhost1': {'exit_code': None, 'stdout': <generator>, 'stderr': <generator>, 'channel': <channel>, 'cmd' : <greenlet>, 'exception' : None},
45+
'myhost2': {'exit_code': None, 'stdout': <generator>, 'stderr': <generator>, 'channel': <channel>, 'cmd' : <greenlet>, 'exception' : None}}
4646

4747
Stdout and stderr buffers are available in output. Iterating on them can be used to get output as it becomes available. Iteration ends *only when command has finished*.
4848

49-
>>> for host in output:
50-
>>> for line in output[host]['stdout']:
51-
>>> print "Host %s - output: %s" % (host, line)
52-
Host myhost1 - output: drwxr-xr-x 6 xxx xxx 4.0K Jan 1 00:00 xxx
53-
Host myhost2 - output: drwxr-xr-x 6 xxx xxx 4.0K Jan 1 00:00 xxx
49+
::
50+
51+
for host in output:
52+
for line in output[host]['stdout']:
53+
print("Host %s - output: %s" % (host, line))
54+
Host myhost1 - output: drwxr-xr-x 6 xxx xxx 4.0K Jan 1 00:00 xxx
55+
Host myhost1 - output: <..>
56+
Host myhost2 - output: drwxr-xr-x 6 xxx xxx 4.0K Jan 1 00:00 xxx
57+
Host myhost2 - output: <..>
5458

55-
Joining on the connection pool can be used to block and wait for all parallel commands to finish if reading stdout/stderr is not required.
59+
Exit codes become available once stdout/stderr is iterated on or `client.join(output)` is called.
5660

57-
>>> client.pool.join()
61+
::
62+
63+
for host in output:
64+
print output[host]['exit_code']
65+
0
66+
0
67+
68+
Joining on the connection pool can be used to block and wait for all parallel commands to finish if output is not required. ::
69+
70+
client.pool.join()
5871

5972

6073
**************************
@@ -75,7 +88,7 @@ Frequently asked questions
7588
Is Windows supported?
7689

7790
:A:
78-
The library installs and works on Windows though not formally supported as unit tests are currently posix system only.
91+
The library installs and works on Windows though not formally supported as unit tests are currently Posix system based.
7992

8093
Pip versions >= 8.0 are required for binary package installation of `gevent` on Windows, a dependency of `ParallelSSH`.
8194

@@ -111,11 +124,11 @@ Frequently asked questions
111124
Is there a way to programmatically provide an SSH key?
112125

113126
:A:
114-
Yes, use the `pkey` parameter of the `ParallelSSHClient class <http://parallel-ssh.readthedocs.org/en/latest/#pssh.ParallelSSHClient>`_. There is a `load_private_key` helper function in `pssh.utils` that can be used to load any key type. For example:
127+
Yes, use the `pkey` parameter of the `ParallelSSHClient class <http://parallel-ssh.readthedocs.org/en/latest/#pssh.ParallelSSHClient>`_. There is a `load_private_key` helper function in `pssh.utils` that can be used to load any key type. For example::
115128

116-
>>> from pssh import ParallelSSHClient, utils
117-
>>> client_key = utils.load_private_key('user.key')
118-
>>> client = ParallelSSHClient(['myhost1', 'myhost2'], pkey=client_key)
129+
from pssh import ParallelSSHClient, utils
130+
client_key = utils.load_private_key('user.key')
131+
client = ParallelSSHClient(['myhost1', 'myhost2'], pkey=client_key)
119132

120133
:Q:
121134
Is there a user's group for feedback and discussion about ParallelSSH?
@@ -130,13 +143,14 @@ SFTP/SCP
130143

131144
SFTP is supported (SCP version 2) natively, no `scp` command required.
132145

133-
For example to copy a local file to remote hosts in parallel
146+
For example to copy a local file to remote hosts in parallel::
134147

135-
>>> from pssh import ParallelSSHClient, utils
136-
>>> utils.enable_logger(utils.logger)
137-
>>> hosts = ['myhost1', 'myhost2']
138-
>>> client = ParallelSSHClient(hosts)
139-
>>> client.copy_file('../test', 'test_dir/test')
140-
>>> client.pool.join()
141-
Copied local file ../test to remote destination myhost1:test_dir/test
142-
Copied local file ../test to remote destination myhost2:test_dir/test
148+
from pssh import ParallelSSHClient, utils
149+
utils.enable_logger(utils.logger)
150+
hosts = ['myhost1', 'myhost2']
151+
client = ParallelSSHClient(hosts)
152+
client.copy_file('../test', 'test_dir/test')
153+
client.pool.join()
154+
155+
Copied local file ../test to remote destination myhost1:test_dir/test
156+
Copied local file ../test to remote destination myhost2:test_dir/test

embedded_server/embedded_server.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@
1818
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919

2020
"""
21-
Fake SSH server to test our SSH clients.
22-
Supports execution of commands via exec_command. Does _not_ support interactive \
23-
shells, our clients do not use them.
24-
Server private key is hardcoded, server listen code inspired by demo_server.py in \
25-
paramiko repository
21+
Embedded SSH server to test our SSH clients.
22+
23+
Implements:
24+
* Execution of commands via exec_command
25+
* Public key and password auth
26+
* Direct TCP tunneling
27+
* SSH agent forwarding
28+
* Stub SFTP server from Paramiko
29+
* Forced authentication failure
30+
31+
Does _not_ support interactive shells, our clients do not use them.
32+
33+
Server private key is hardcoded. Server listen code inspired by demo_server.py in \
34+
Paramiko repository.
35+
36+
Server runs asynchronously in its own greenlet. Call `start_server` with a new `multiprocessing.Process` to run it on a new process with its own event loop.
37+
38+
*Warning* - Note that commands, with or without a shell, are actually run on the system running this server. Destructive commands will actually affect the system as permissions of user running the server allow. *Use at your own risk*.
2639
"""
2740

2841
import sys

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
convert_2_to_3['use_2to3'] = True
2222

2323
setup(name='parallel-ssh',
24-
version='0.91.1',
24+
version='0.91.2',
2525
description='Asynchronous parallel SSH library',
2626
author='Panos Kittenis',
2727
author_email='[email protected]',
28-
url = "https://github.com/pkittenis/parallel-ssh",
29-
packages = find_packages('.', exclude=(
28+
url="https://github.com/pkittenis/parallel-ssh",
29+
packages=find_packages('.', exclude=(
3030
'embedded_server', 'embedded_server.*')),
31-
install_requires = ['paramiko', 'gevent'],
32-
classifiers = [
31+
install_requires=['paramiko', 'gevent'],
32+
classifiers=[
3333
'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)',
3434
'Intended Audience :: Developers',
3535
'Programming Language :: Python :: 2',

0 commit comments

Comments
 (0)