Skip to content

Commit ad9fea4

Browse files
author
Dan
committed
Cleanup - updated docstrings.
1 parent 1f330b6 commit ad9fea4

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

pssh.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ class AuthenticationException(Exception):
6262
pass
6363

6464

65-
class ProxyCommandException(Exception):
66-
"""Raised on ProxyCommand error - ProxyCommand configured exited with error"""
67-
pass
68-
69-
7065
class SSHException(Exception):
7166
"""Raised on SSHException error - error authenticating with SSH server"""
7267
pass
@@ -113,16 +108,18 @@ def __init__(self, host,
113108
connecting to local SSH agent to lookup keys with our own SSH agent. \
114109
Only really useful for testing, hence the internal variable prefix.
115110
:type _agent: :mod:`paramiko.agent.Agent`
116-
:raises: :mod:`pssh.AuthenticationException` on authentication error
117-
:raises: :mod:`pssh.UnknownHostException` on DNS resolution error
118-
:raises: :mod:`pssh.ConnectionErrorException` on error connecting
119-
:raises: :mod:`pssh.ProxyCommandException` on error with ProxyCommand configured
111+
:param proxy_host: (Optional) SSH host to tunnel connection through
112+
so that SSH clients connects to self.host via client -> proxy_host -> host
113+
:type proxy_host: str
114+
:param proxy_port: (Optional) SSH port to use to login to proxy host if set.
115+
Defaults to 22.
116+
:type proxy_port: int
120117
"""
121118
ssh_config = paramiko.SSHConfig()
122119
_ssh_config_file = os.path.sep.join([os.path.expanduser('~'),
123120
'.ssh',
124121
'config'])
125-
# Load ~/.ssh/config if it exists to pick up username, ProxyCommand
122+
# Load ~/.ssh/config if it exists to pick up username
126123
# and host address if set
127124
if os.path.isfile(_ssh_config_file):
128125
ssh_config.parse(open(_ssh_config_file))
@@ -146,6 +143,7 @@ def __init__(self, host,
146143
self.num_retries = num_retries
147144
self.timeout = timeout
148145
self.proxy_host, self.proxy_port = proxy_host, proxy_port
146+
self.proxy_client = None
149147
if self.proxy_host and self.proxy_port:
150148
logger.debug("Proxy configured for destination host %s - Proxy host: %s:%s",
151149
self.host, self.proxy_host, self.proxy_port,)
@@ -199,9 +197,6 @@ def _connect(self, client, host, port, sock=None, retries=1):
199197
retries, self.num_retries,)
200198
except paramiko.AuthenticationException, e:
201199
raise AuthenticationException(e)
202-
except paramiko.ProxyCommandFailure, e:
203-
logger.error("Error executing ProxyCommand - %s", e.message,)
204-
raise ProxyCommandException(e.message)
205200
# SSHException is more general so should be below other types
206201
# of SSH failure
207202
except paramiko.SSHException, e:
@@ -349,8 +344,13 @@ def __init__(self, hosts,
349344
whichever is lower. Pool size will be *equal to* number of hosts if number\
350345
of hosts is lower than the pool size specified as that would only \
351346
increase overhead with no benefits.
352-
353347
:type pool_size: int
348+
:param proxy_host: (Optional) SSH host to tunnel connection through
349+
so that SSH clients connects to self.host via client -> proxy_host -> host
350+
:type proxy_host: str
351+
:param proxy_port: (Optional) SSH port to use to login to proxy host if set.
352+
Defaults to 22.
353+
:type proxy_port: int
354354
355355
**Example**
356356
@@ -425,17 +425,24 @@ def __init__(self, hosts,
425425

426426
def run_command(self, *args, **kwargs):
427427
"""Run command on all hosts in parallel, honoring self.pool_size,
428-
and return output buffers. This function will block until all commands
429-
have **started** and then return immediately. Any connection and/or
430-
authentication exceptions will be raised here and need catching.
428+
and return output buffers.
429+
430+
This function will block until all commands have **started** and
431+
then return immediately. Any connection and/or authentication exceptions
432+
will be raised here and need catching.
431433
432434
:param args: Positional arguments for command
433435
:type args: tuple
434436
:param kwargs: Keyword arguments for command
435437
:type kwargs: dict
436438
437439
:rtype: Dictionary with host as key as per :mod:`ParallelSSH.get_output`:
438-
440+
441+
:raises: :mod:`pssh.AuthenticationException` on authentication error
442+
:raises: :mod:`pssh.UnknownHostException` on DNS resolution error
443+
:raises: :mod:`pssh.ConnectionErrorException` on error connecting
444+
:raises: :mod:`pssh.SSHException` on other undefined SSH errors
445+
439446
::
440447
441448
{'myhost1': {'exit_code': exit code if ready else None,
@@ -616,9 +623,9 @@ def get_stdout(self, greenlet, return_buffers=False):
616623
return_buffers = True
617624
# Channel must be closed or reading stdout/stderr will block forever
618625
if not return_buffers and channel.closed:
619-
for line in stdout:
626+
for _ in stdout:
620627
pass
621-
for line in stderr:
628+
for _ in stderr:
622629
pass
623630
return {host: {'exit_code': channel.recv_exit_status(),}}
624631
gevent.sleep(.2)

0 commit comments

Comments
 (0)