Skip to main content

Asynchronous parallel SSH library

Project description

Non-blocking, asynchronous parallel SSH client library.

Run SSH commands over many - hundreds/hundreds of thousands - number of servers asynchronously and with minimal system load on the client host.

Native code based client with extremely high performance - based on libssh2 C library.

License Latest Version https://travis-ci.org/ParallelSSH/parallel-ssh.svg?branch=master https://codecov.io/gh/ParallelSSH/parallel-ssh/branch/master/graph/badge.svg https://img.shields.io/pypi/wheel/parallel-ssh.svg Latest documentation

Installation

pip install parallel-ssh

Usage Example

See documentation on read the docs for more complete examples.

Run uname on two remote hosts in parallel with sudo.

from pssh.pssh_client import ParallelSSHClient

hosts = ['myhost1', 'myhost2']
client = ParallelSSHClient(hosts)

output = client.run_command('uname')
for host, host_output in output.items():
    for line in host_output.stdout:
        print(line)
Output:
Linux
Linux

Native client

Starting from version 1.2.0, a new client is supported in parallel-ssh which offers much greater performance and reduced overhead than the current default client.

The new client is based on libssh2 via the ssh2-python extension library and supports non-blocking mode natively. Binary wheel packages with libssh2 included are provided for Linux, OSX and Windows platforms and all supported Python versions.

See this post for a performance comparison of the available clients.

To make use of this new client, ParallelSSHClient can be imported from pssh.pssh2_client instead. Their respective APIs are almost identical.

The new client will become the default and will replace the current pssh.pssh_client in a new major version of the library - 2.0.0 - once remaining features have been implemented. The native client should be considered as beta status until the 2.0.0 release when it is made the default.

The current default client will remain available as an option under a new name.

For example:

from pprint import pprint
from pssh.pssh2_client import ParallelSSHClient

hosts = ['myhost1', 'myhost2']
client = ParallelSSHClient(hosts)

output = client.run_command('uname')
for host, host_output in output.items():
    for line in host_output.stdout:
        print(line)

See documentation for a feature comparison of the two clients.

Native Code Client Features

  • Highest performance and least overhead of any Python SSH libraries

  • Thread safe - makes use of native threads for blocking calls like authentication

  • Natively non-blocking utilising libssh2 via ssh2-python - no monkey patching of the Python standard library

  • Significantly reduced overhead in CPU and memory usage

Exit codes

Once either standard output is iterated on to completion, or client.join(output) is called, exit codes become available in host output. Iteration ends only when remote command has completed, though it may be interrupted and resumed at any point.

for host in output:
    print(output[host].exit_code)
Output:
0
0

The client’s join function can be used to block and wait for all parallel commands to finish:

client.join(output)

Similarly, output and exit codes are available after client.join is called:

output = client.run_command('exit 0')

# Wait for commands to complete and gather exit codes.
# Output is updated in-place.
client.join(output)
pprint(output.values()[0].exit_code)

# Output remains available in output generators
for host, host_output in output.items():
    for line in host_output.stdout:
        pprint(line)
Output:
0
<..stdout..>

There is also a built in host logger that can be enabled to log output from remote hosts. The helper function pssh.utils.enable_host_logger will enable host logging to stdout.

To log output without having to iterate over output generators, the consume_output flag can be enabled - for example:

from pssh.utils import enable_host_logger
enable_host_logger()
client.join(client.run_command('uname'), consume_output=True)
Output:
[localhost]       Linux

SFTP/SCP

SFTP is supported natively, no scp binary required.

For example to copy a local file to remote hosts in parallel:

from pssh.pssh_client import ParallelSSHClient
from pssh import utils
from gevent import joinall

utils.enable_logger(utils.logger)
hosts = ['myhost1', 'myhost2']
client = ParallelSSHClient(hosts)
cmds = client.copy_file('../test', 'test_dir/test')
joinall(cmds, raise_error=True)
Output:
Copied local file ../test to remote destination myhost1:test_dir/test
Copied local file ../test to remote destination myhost2:test_dir/test

There is similar capability to copy remote files to local ones suffixed with the host’s name with the copy_remote_file function.

Directory recursion is supported in both cases via the recurse parameter - defaults to off.

See SFTP documentation for more examples.

Design And Goals

ParallelSSH’s design goals and motivation are to provide a library for running non-blocking asynchronous SSH commands in parallel with little to no load induced on the system by doing so with the intended usage being completely programmatic and non-interactive.

To meet these goals, API driven solutions are preferred first and foremost. This frees up developers to drive the library via any method desired, be that environment variables, CI driven tasks, command line tools, existing OpenSSH or new configuration files, from within an application et al.

Scaling

Some guide lines on scaling ParallelSSH client and pool size numbers.

In general, long lived commands with little or no output gathering will scale better. Pool sizes in the multiple thousands have been used successfully with little CPU overhead in the single process running them in these use cases.

Conversely, many short lived commands with output gathering will not scale as well. In this use case, smaller pool sizes in the hundreds are likely to perform better with regards to CPU overhead in the event loop. Multiple python processes, each with its own event loop, may be used to scale this use case further as CPU overhead allows.

Gathering is highlighted here as output generation does not affect scaling. Only when output is gathered either over multiple still running commands, or while more commands are being triggered, is overhead increased.

Technical Details

To understand why this is, consider that in co-operative multi tasking, which is being used in this project via the gevent library, a co-routine (greenlet) needs to yield the event loop to allow others to execute - co-operation. When one co-routine is constantly grabbing the event loop in order to gather output, or when co-routines are constantly trying to start new short-lived commands, it causes overhead with other co-routines that also want to use the event loop.

This manifests itself as increased CPU usage in the process running the event loop and reduced performance with regards to scaling improvements from increasing pool size.

On the other end of the spectrum, long lived remote commands that generate no output only need the event loop at the start, when they are establishing connections, and at the end, when they are finished and need to gather exit codes, which results in practically zero CPU overhead at any time other than start or end of command execution.

Output generation is done remotely and has no effect on the event loop until output is gathered - output buffers are iterated on. Only at that point does the event loop need to be held.

User’s group

here is a public ParallelSSH Google group setup for this purpose - both posting and viewing are open to the public.

https://ga-beacon.appspot.com/UA-9132694-7/parallel-ssh/README.rst?pixel

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

parallel_ssh-1.2.0b1-cp36-cp36m-win_amd64.whl (103.9 kB view details)

Uploaded CPython 3.6m Windows x86-64

parallel_ssh-1.2.0b1-cp36-cp36m-win32.whl (94.6 kB view details)

Uploaded CPython 3.6m Windows x86

parallel_ssh-1.2.0b1-cp36-cp36m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.6m

parallel_ssh-1.2.0b1-cp35-cp35m-win_amd64.whl (103.6 kB view details)

Uploaded CPython 3.5m Windows x86-64

parallel_ssh-1.2.0b1-cp35-cp35m-win32.whl (94.4 kB view details)

Uploaded CPython 3.5m Windows x86

parallel_ssh-1.2.0b1-cp35-cp35m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.5m

parallel_ssh-1.2.0b1-cp34-cp34m-win_amd64.whl (101.7 kB view details)

Uploaded CPython 3.4m Windows x86-64

parallel_ssh-1.2.0b1-cp34-cp34m-win32.whl (95.0 kB view details)

Uploaded CPython 3.4m Windows x86

parallel_ssh-1.2.0b1-cp34-cp34m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.4m

parallel_ssh-1.2.0b1-cp33-cp33m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.3m

parallel_ssh-1.2.0b1-cp27-cp27mu-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 2.7mu

parallel_ssh-1.2.0b1-cp27-cp27m-win_amd64.whl (102.7 kB view details)

Uploaded CPython 2.7m Windows x86-64

parallel_ssh-1.2.0b1-cp27-cp27m-win32.whl (94.8 kB view details)

Uploaded CPython 2.7m Windows x86

parallel_ssh-1.2.0b1-cp27-cp27m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 2.7m

parallel_ssh-1.2.0b1-cp27-cp27m-macosx_10_11_x86_64.whl (1.2 MB view details)

Uploaded CPython 2.7m macOS 10.11+ x86-64

parallel_ssh-1.2.0b1-cp26-cp26mu-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 2.6mu

parallel_ssh-1.2.0b1-cp26-cp26m-manylinux1_x86_64.whl (1.6 MB view details)

Uploaded CPython 2.6m

File details

Details for the file parallel_ssh-1.2.0b1-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b087afc6c92f4d0d131e5e1a19e03d38365f18fedaed0851ca948fe9af30b22a
MD5 b40fa4e4487227728c5b536c0cb20fed
BLAKE2b-256 188bf86e01089abf44d26f3cd83758e5a74ddd1510b0a16c10935973c0d58ec4

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 8b9534d0c3e25cc39a22b127036b8b00bf8f9b9749a46a1b143a20395573f6cf
MD5 5899171897fd69347a9853cd9afb354f
BLAKE2b-256 29cb8a08bc160380ed0f8d2c679ddff909d8c43d9992c91d501137fb2eab6703

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b3a01e2d5b7aacd6ed89af18bd1f0cb1d228584d885ca104329c01726a3c2660
MD5 78c6f2010a644c0c406750164d9b7f17
BLAKE2b-256 f10116199d8198ffe44306509db832906727ee989f079016e4d1c132abaa5a0d

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 b5ab58b3fb08c51bd8d436a1ae3bcbedd81d7060f2daa082fe46142c6ec675e8
MD5 9519bb89ab1b0fa6b8e4cd03c1dc88cc
BLAKE2b-256 66fba32b5f68c7eb99b30b930ac64db47d837362a7020ff339e1143bcbc2f39d

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 c61b3b2d97a984ce0d5f602d0888375625652b7d66b2f0a3ab93605d10ec18e7
MD5 17bc2bc090a6979263be1b84f8276a72
BLAKE2b-256 4072db98eda4ff9c754e394c46729bb5d8038e573d94ae497355c3ce87862f0e

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 06509a9911240910cf6ce00a634312765bb4b56e78118b3d8b940d3d86a27507
MD5 76c5a7d3cd838bef64fe9ccc247904de
BLAKE2b-256 feeb2ab9ad44f1dc1c0db634107b3b0c9f5397d70803c9f5fce79c281fae4007

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 acff31ed45b9770ad359ca972fe8a801dd4948994ab3e02874990a9b828cdf10
MD5 5dd40a1513943d078e006da11931cd96
BLAKE2b-256 2a60fe26f57eea8eab1033c1b90972629008148f6578f801bc2957483323fcfd

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 548430ec51150e0ab9a46f5fe5f5d2846e964de956a456f8302d93ec17957922
MD5 d89aefef7b5dc7c22a83e84db71786fc
BLAKE2b-256 24f074f173c59995bc32c872bc3d71cd1d55621f2a65677846f24e5ef332595b

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ca46b49e54b9e551936e40f21f0b2d8d5b369f11b6cb0fa87a2d05d4cf1f6ad9
MD5 64125a451270ad3ad4a5eba4039089fe
BLAKE2b-256 e20753848bc7304a449c79d6ad7173d842453ec71d96f30c29eccd4c17bebded

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp33-cp33m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp33-cp33m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 949dac8a28effccbdf21b4182ff105ba356abb04551705bca9697b39eccc7693
MD5 de8bc9248e53897f7f6858ad8fbe998c
BLAKE2b-256 61743bc7768ea5f62d6ce84a0bdbdeab305c45dd181291169e69bcb06a1f276c

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 25f892bd3d3b0840c6a393a2506566747f1f9d38a8969c87cb6629b38b3130ab
MD5 3a8361cdcc129577c68fed7c9ea97214
BLAKE2b-256 7b4168a5200214be67aa44b44f79a66bea95c7ecc0900443410542f2fd9bc8f3

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 12fd2ad259c998c57638a6210c67852973ec0f2bb4b7088ab8424bbf87b2f056
MD5 891492f8016b7e0e8d4e8dd6fc04646d
BLAKE2b-256 444e5503f2be10eaec742c85c25e29453fe63ad8d1660195914fc852a36275ee

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 6ec0b9c9213a07cfeafb7e80d1ac91ca49e2ce45628bd65daefe92bf5181579b
MD5 f7a73b91e617dbb8f734fa5764859b88
BLAKE2b-256 6793f09713715eb2c765829c5200cb58d60b3991865fdccccb27410e1614e88d

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 58926aed4bd3e6745fdb3ba5326a7ca42bb27b55ef542f3c845d03f37c90ac4c
MD5 38aa29cfa1f1c64385c920863b4516cd
BLAKE2b-256 d8b65e7b9200cc450f6a807aed866e29c22b4a402b4608e71d5e1282488f5cca

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp27-cp27m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp27-cp27m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 fbefce3515f52c91a554334554220fb23ae449261e2847e4d709ae140fdfa172
MD5 f2aafb332e74e9eaf520a58edb787782
BLAKE2b-256 ee2210104bec81b3b2ea1c05acbceed8a79c9dd7039e3b52b4668f73ddc62a6f

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp26-cp26mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp26-cp26mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 97928077f5a80337ffc20c9ee49d1e421d562bde67d5e78de880eadf9ea27a96
MD5 c7ab2c752f6709ce0a2322a51f48cba6
BLAKE2b-256 0ba6d8da7f794eb3cbc2c62a1feac5c2694267b55ae01a1bd96dca28e157f15e

See more details on using hashes here.

File details

Details for the file parallel_ssh-1.2.0b1-cp26-cp26m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for parallel_ssh-1.2.0b1-cp26-cp26m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 95761a4be241946e67a6f4e17c23dc4d628cf91f37d4f3a1892f898b98bdfc6b
MD5 6eec93e18e6000ede31105e0235f1464
BLAKE2b-256 5588ebeab45d22a2dad740edb58a80fecf9b80338e86bf6b663b81598600a27e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page