|
18 | 18 |
|
19 | 19 | """Package containing ParallelSSHClient class.""" |
20 | 20 |
|
21 | | - |
| 21 | +import sys |
| 22 | +if 'threading' in sys.modules: |
| 23 | + del sys.modules['threading'] |
22 | 24 | from gevent import monkey |
23 | 25 | monkey.patch_all() |
24 | 26 | import logging |
25 | 27 | import gevent.pool |
26 | 28 | import gevent.hub |
27 | 29 | gevent.hub.Hub.NOT_ERROR = (Exception,) |
28 | 30 | import warnings |
29 | | -import hashlib |
| 31 | +import string |
| 32 | +import random |
30 | 33 | from .constants import DEFAULT_RETRIES |
31 | 34 | from .ssh_client import SSHClient |
32 | 35 |
|
@@ -137,7 +140,7 @@ def __init__(self, hosts, |
137 | 140 | ``exit_code`` in ``output`` will be ``None`` if command has not finished. |
138 | 141 | |
139 | 142 | ``get_exit_codes`` is not a blocking function and will not wait for commands |
140 | | - to finish. Use ``client.pool.join()`` to block until all commands have |
| 143 | + to finish. Use ``client.join(output)`` to block until all commands have |
141 | 144 | finished. |
142 | 145 | |
143 | 146 | ``output`` parameter is modified in-place. |
@@ -169,7 +172,7 @@ def __init__(self, hosts, |
169 | 172 | |
170 | 173 | >>> client = ParallelSSHClient(['localhost']) |
171 | 174 | >>> output = client.run_command('ls -ltrh /tmp/aasdfasdf') |
172 | | - >>> client.pool.join() |
| 175 | + >>> client.join(output) |
173 | 176 | |
174 | 177 | :netstat: ``tcp 0 0 127.0.0.1:53054 127.0.0.1:22 ESTABLISHED`` |
175 | 178 | |
@@ -239,9 +242,9 @@ def run_command(self, *args, **kwargs): |
239 | 242 | 0 |
240 | 243 | 0 |
241 | 244 | |
242 | | - *Wait for completion, no stdout* |
| 245 | + *Wait for completion, no stdout printing* |
243 | 246 | |
244 | | - >>> client.pool.join() |
| 247 | + >>> client.join(output) |
245 | 248 | |
246 | 249 | *Run with sudo* |
247 | 250 | |
@@ -269,7 +272,7 @@ def run_command(self, *args, **kwargs): |
269 | 272 | **Do not stop on errors, return per-host exceptions in output** |
270 | 273 | |
271 | 274 | >>> output = client.run_command('ls -ltrh', stop_on_errors=False) |
272 | | - >>> client.pool.join() |
| 275 | + >>> client.join(output) |
273 | 276 | >>> print output |
274 | 277 | |
275 | 278 | :: |
@@ -376,7 +379,10 @@ def _update_host_output(self, output, host, exit_code, channel, stdout, stderr, |
376 | 379 | exception=None): |
377 | 380 | """Update host output with given data""" |
378 | 381 | if host in output: |
379 | | - new_host = "_".join([host, hashlib.sha1().hexdigest()[:10]]) |
| 382 | + new_host = "_".join([host, |
| 383 | + ''.join(random.choice( |
| 384 | + string.ascii_lowercase + string.digits) |
| 385 | + for _ in xrange(8))]) |
380 | 386 | logger.warning("Already have output for host %s - changing host key for %s to %s", |
381 | 387 | host, host, new_host) |
382 | 388 | host = new_host |
|
0 commit comments