You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+73-84Lines changed: 73 additions & 84 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,102 +22,126 @@ Run SSH commands over many - hundreds/hundreds of thousands - number of servers
22
22
23
23
.. _`read the docs`: http://parallel-ssh.readthedocs.org/en/latest/
24
24
25
-
.. contents::Table of Contents
25
+
.. contents::
26
26
27
27
************
28
28
Installation
29
29
************
30
30
31
-
::
31
+
.. code-block:: shell
32
32
33
33
pip install parallel-ssh
34
34
35
-
As of version ``0.93.0`` ``pip`` version >= ``6.0.0`` is required for Python 2.6 compatibility with latest versions of gevent which have dropped 2.6 support. This limitation will be removed post ``1.0.0`` releases which will deprecate ``2.6`` support.
36
-
37
-
To upgrade ``pip`` run the following - use of ``virtualenv`` is recommended so as not to override system provided packages::
38
-
39
-
pip install -U pip
40
-
pip install parallel-ssh
41
-
42
35
*************
43
36
Usage Example
44
37
*************
45
38
46
39
See documentation on `read the docs`_ for more complete examples.
47
40
41
+
48
42
Run ``ls`` on two remote hosts in parallel with ``sudo``.
Standard output buffers are available in output object. Iterating on them can be used to get output as it becomes available. Iteration ends *only when command has finished*, though it may be interrupted and resumed at any point.
72
72
73
-
`Host output <http://parallel-ssh.readthedocs.io/en/latest/output.html>`_ attributes are available in per-host output dictionary, for example ``output['myhost1'].stdout``.
73
+
`Host output <http://parallel-ssh.readthedocs.io/en/latest/output.html>`_ attributes are available in host output object, for example ``output['myhost1'].stdout``.
Exit codes become available once output is iterated on to completion *or* ``client.join(output)`` is called.
86
91
87
-
::
92
+
.. code-block:: python
88
93
89
94
for host in output:
90
95
print(output[host].exit_code)
91
-
0
92
-
0
93
96
94
-
The client's ``join`` function can be used to block and wait for all parallel commands to finish::
97
+
:Output:
98
+
.. code-block:: python
99
+
100
+
0
101
+
0
102
+
103
+
The client's ``join`` function can be used to block and wait for all parallel commands to finish:
104
+
105
+
.. code-block:: python
95
106
96
107
client.join(output)
97
108
98
-
Similarly, output and exit codes are available after ``client.join`` is called::
109
+
Similarly, output and exit codes are available after ``client.join`` is called:
110
+
111
+
.. code-block:: python
99
112
100
113
output = client.run_command('exit 0')
114
+
101
115
# Block and gather exit codes. Output is updated in-place
102
116
client.join(output)
103
117
pprint(output.values()[0].exit_code)
104
-
0
118
+
105
119
# Output is available
106
120
for line in output.values()[0].stdout:
107
121
pprint(line)
108
-
<..stdout..>
122
+
123
+
:Output:
124
+
.. code-block:: python
125
+
126
+
0
127
+
<..stdout..>
109
128
110
129
.. note::
111
130
112
131
In versions prior to ``1.0.0`` only, ``client.join`` would consume standard output.
113
132
114
-
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, for example ::
133
+
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, for example:
134
+
135
+
.. code-block:: python
115
136
116
137
import pssh.utils
117
138
pssh.utils.enable_host_logger()
118
139
client.join(client.run_command('uname'))
119
-
120
-
[localhost] Linux
140
+
141
+
:Output:
142
+
.. code-block:: shell
143
+
144
+
[localhost] Linux
121
145
122
146
*****************
123
147
Design And Goals
@@ -154,9 +178,11 @@ Output *generation* is done remotely and has no effect on the event loop until o
154
178
SFTP/SCP
155
179
********
156
180
157
-
SFTP is supported (SCP version 2) natively, no ``scp`` command required.
181
+
SFTP is supported (SCP version 2) natively, no ``scp`` binary required.
158
182
159
-
For example to copy a local file to remote hosts in parallel::
183
+
For example to copy a local file to remote hosts in parallel:
184
+
185
+
.. code-block:: python
160
186
161
187
from pssh import ParallelSSHClient, utils
162
188
from gevent import joinall
@@ -166,15 +192,18 @@ For example to copy a local file to remote hosts in parallel::
Copied local file ../test to remote destination myhost1:test_dir/test
171
-
Copied local file ../test to remote destination myhost2:test_dir/test
195
+
196
+
:Output:
197
+
.. code-block:: python
198
+
199
+
Copied local file ../test to remote destination myhost1:test_dir/test
200
+
Copied local file ../test to remote destination myhost2:test_dir/test
172
201
173
202
There is similar capability to copy remote files to local ones suffixed with the host's name with the ``copy_remote_file`` function.
174
203
175
204
Directory recursion is supported in both cases via the ``recurse`` parameter - defaults to off.
176
205
177
-
See `copy_file <http://parallel-ssh.readthedocs.io/en/latest/pssh_client.html#pssh.pssh_client.ParallelSSHClient.copy_file>`_ and `copy_remote_file <http://parallel-ssh.readthedocs.io/en/latest/pssh_client.html#pssh.pssh_client.ParallelSSHClient.copy_remote_file>`_ documentation for more examples.
206
+
See `SFTP documentation <http://parallel-ssh.readthedocs.io/en/latest/advanced.html#sftp>`_ for more examples.
178
207
179
208
**************************
180
209
Frequently asked questions
@@ -186,7 +215,7 @@ Frequently asked questions
186
215
:A:
187
216
In short, the tools are intended for different use cases.
188
217
189
-
``ParallelSSH`` satisfies uses cases for a parallel SSH client library that scales well over hundreds to hundreds of thousands of hosts - per `Design And Goals`_ - a use case that is very common on cloud platforms and virtual machine automation. It would be best used where it is a good fit for the use case at hand.
218
+
``ParallelSSH`` is a parallel SSH client library that scales well over hundreds to hundreds of thousands of hosts - per `Design And Goals`_ - a use case that is very common on cloud platforms and virtual machine automation. It would be best used where it is a good fit for the use case at hand.
190
219
191
220
Fabric and tools like it on the other hand are not well suited to such use cases, for many reasons, performance and differing design goals in particular. The similarity is only that these tools also make use of SSH to run commands.
192
221
@@ -212,48 +241,8 @@ Frequently asked questions
212
241
213
242
Though ``ParallelSSH`` is pure python code and will run on any platform that has a working Python interpreter, its ``gevent`` dependency and certain dependencies of ``paramiko`` contain native code which either needs a binary package to be provided for the platform or to be built from source. Binary packages for ``gevent`` are provided for OSX, Linux and Windows platforms as of this time of writing.
214
243
215
-
:Q:
216
-
Are SSH agents used?
217
-
218
-
:A:
219
-
All available keys in a system configured SSH agent in addition to SSH keys in the user's home directory, `~/.ssh/id_dsa`, `~/.ssh/id_rsa` et al are automatically used by ParallelSSH.
220
-
221
-
Use of SSH agent can be disabled by creating a client as ``ParallelSSHClient(allow_agent=False)``. `See documentation <http://parallel-ssh.readthedocs.org/en/latest/>`_ for more information.
222
-
223
-
:Q:
224
-
Can ParallelSSH forward my SSH agent?
225
-
226
-
:A:
227
-
SSH agent forwarding, what ``ssh -A`` does on the command line, is supported and enabled by default. Creating an object as ``ParallelSSHClient(forward_ssh_agent=False)`` will disable this behaviour.
228
-
229
-
:Q:
230
-
Is tunneling/proxying supported?
231
-
232
-
:A:
233
-
Yes, `ParallelSSH` natively supports tunelling - also known as proxying - through an intermediate SSH server. Connecting to a remote host is accomplished via an SSH tunnel using the SSH's protocol direct TCP tunneling feature, using local port forwarding. This is done natively in python and tunnel connections are asynchronous like all other connections in the `ParallelSSH` library. For example, client -> proxy SSH server -> remote SSH destination.
234
-
235
-
Use the ``proxy_host`` and ``proxy_port`` parameters to configure your proxy::
Note that while connections from the ParallelSSH `client` to the tunnel host are asynchronous, connections from the tunnel host to the remote destination(s) may not be, depending on the SSH server implementation. If the SSH server uses threading to implement its tunelling and that server is used to tunnel to a large number of remote destinations system load on the tunnel server will increase linearly with number of threads used.
240
-
241
-
:Q:
242
-
Is there a way to programmatically provide an SSH key?
243
-
244
-
:A:
245
-
Yes, use the ``pkey`` parameter of the `ParallelSSHClient class`_. There is also a ``load_private_key`` helper function in ``pssh.utils`` that can be used to load any supported key type. See `ParallelSSHClient class`_ documentation for examples.
246
-
247
-
:Q:
248
-
Is there a way to programmatically provide an SSH agent?
249
-
250
-
:A:
251
-
Yes, with the ``SSHAgent`` class that can be provided via the ``agent`` class parameter of `ParallelSSHClient class`_. Supplying an agent object in this way overrides use of the system's SSH agent, if any. See `SSHAgent documentation <http://parallel-ssh.readthedocs.io/en/latest/agent.html>`_ for an example.
252
-
253
244
:Q:
254
245
Is there a user's group for feedback and discussion about ParallelSSH?
255
246
256
247
:A:
257
248
There is a public `ParallelSSH Google group <https://groups.google.com/forum/#!forum/parallelssh>`_ setup for this purpose - both posting and viewing are open to the public.
0 commit comments