Skip to content

Commit 1515270

Browse files
author
Pan
committed
New native client tunneling implementation - resolves #123.
Added greenlet timeout setting to native clients. Native clients raise specific exceptions on errors. Fixed timeout setting not being applied to native client sockets. Fixed native client raising incorrect exception on timeouts connecting to host. Updated documentation. Increased test coverage.
1 parent b7f5a55 commit 1515270

22 files changed

+992
-508
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ script:
2626
- export LD_LIBRARY_PATH=/usr/local/lib/x86_64-linux-gnu
2727
# For testing SSH agent related functionality
2828
- eval `ssh-agent -s`
29-
- nosetests --with-coverage --cover-package=pssh
29+
- nosetests --with-coverage --cover-package=pssh tests/test_native_tunnel.py
30+
- nosetests --with-coverage --cover-package=pssh tests/test_native_*_client.py
31+
- nosetests --with-coverage --cover-package=pssh tests/test_paramiko*.py
3032
- flake8 pssh
3133
- cd doc; make html; cd ..
3234
# Test building from source distribution

Changelog.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
Change Log
22
============
33

4+
1.7.0
5+
++++++
6+
7+
Changes
8+
--------
9+
10+
* Better tunneling implementation for native clients that supports multiple tunnels over single SSH connection for connecting multiple hosts through single proxy.
11+
* Added ``greenlet_timeout`` setting to native client ``run_command`` to pass on to getting greenlet result to allow for greenlets to timeout.
12+
* Native client raises specific exceptions on non-authentication errors connecting to host instead of generic ``SessionError``.
13+
14+
15+
Fixes
16+
------
17+
18+
* Native client tunneling would not work correctly - #123.
19+
* ``timeout`` setting was not applied to native client sockets.
20+
* Native client would have ``SessionError`` instead of ``Timeout`` exceptions on timeout errors connecting to hosts.
21+
422
1.6.3
523
++++++
624

doc/advanced.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ To make use of this new client, ``ParallelSSHClient`` can be imported from ``pss
111111

112112
`Feature comparison <ssh2.html>`_ for how the client features compare.
113113

114-
API documentation for `parallel <pssh2_client.html>`_ and `single <ssh2_client.html>`_ native clients.
114+
API documentation for `parallel <native_parallel.html>`_ and `single <native_single.html>`_ native clients.
115115

116116
Tunneling
117117
**********

doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ API Documentation
1111
base_pssh
1212
output
1313
agent
14+
tunnel
1415
utils
1516
exceptions

doc/index.rst

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ It uses non-blocking asynchronous SSH sessions and is to date the only publicly
3232
quickstart
3333
ssh2
3434
advanced
35-
Changelog
3635
api
36+
Changelog
3737

3838
In a nutshell
3939
**************
4040

41+
Client will attempt to use all available keys under ``~/.ssh`` as well as any keys in an SSH agent, if one is available.
42+
4143
.. code-block:: python
4244
4345
from __future__ import print_function
4446
45-
from pssh.pssh_client import ParallelSSHClient
47+
from pssh.clients import ParallelSSHClient
4648
4749
client = ParallelSSHClient(['localhost'])
4850
output = client.run_command('whoami')
@@ -54,31 +56,11 @@ In a nutshell
5456
5557
<your username here>
5658
57-
`ssh2-python` (`libssh2`) based clients
58-
******************************************
59-
60-
As of version ``1.2.0``, new single host and parallel clients are available based on the ``libssh2`` C library via its ``ssh2-python`` wrapper.
61-
62-
They offer significantly enhanced performance and stability, at much less overhead, with a native non-blocking mode meaning *no monkey patching of the Python standard library* when using them.
63-
64-
To use them, import from ``pssh2_client`` or ``ssh2_client`` for the parallel and single clients respectively.
65-
66-
.. code-block:: python
67-
68-
from __future__ import print_function
69-
70-
from pssh.pssh2_client import ParallelSSHClient
71-
72-
client = ParallelSSHClient(['localhost'])
73-
output = client.run_command('whoami')
74-
for line in output['localhost'].stdout:
75-
print(line)
76-
77-
The API is mostly identical to the current clients, though some features are not yet supported. See `client feature comparison <ssh2.html>`_ section for how feature support differs between the two clients.
78-
7959
.. note::
8060

81-
From version ``2.x.x`` onwards, the ``ssh2-python`` based clients will *become the default*, replacing the current ``pssh_client.ParallelSSHClient``, with the current clients renamed.
61+
There is also a now deprecated paramiko based client available under ``pssh.clients.miko`` that has much the same API. It supports some features not currently supported by the native client - see `feature comparison <ssh2.html>`_.
62+
63+
From version ``2.x.x`` onwards, the clients under ``pssh.clients.miko`` will be an optional ``extras`` install.
8264

8365

8466
Indices and tables

doc/ssh2.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Below is a comparison of feature support for the two client types.
88
=============================== ============== ======================
99
Feature paramiko ssh2-python (libssh2)
1010
=============================== ============== ======================
11-
Agent forwarding Yes Not supported (*PR Pending*)
11+
Agent forwarding Yes Yes (binary wheels or from source builds only)
1212
Proxying/tunnelling Yes Yes
1313
Kerberos (GSS) authentication Yes Not supported
1414
Private key file authentication Yes Yes
@@ -20,8 +20,8 @@ Session timeout setting Yes Yes
2020
Per-channel timeout setting Yes Yes
2121
Programmatic SSH agent Yes Not supported
2222
OpenSSH config parsing Yes Not yet implemented
23-
ECSA keys support Yes Not supported (*PR Pending*)
24-
SCP functionality Not supported Not yet implemented
23+
ECSA keys support Yes Yes
24+
SCP functionality Not supported Yes
2525
=============================== ============== ======================
2626

2727
If any of missing features are required for a use case, then the paramiko based clients should be used instead.

doc/tunnel.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Native Tunnel
2+
==============
3+
4+
.. automodule:: pssh.clients.native.tunnel
5+
:member-order: groupwise

pssh/clients/base_pssh.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def run_command(self, command, user=None, stop_on_errors=True,
6767
host_args=None, use_pty=False, shell=None,
6868
encoding='utf-8',
6969
*args, **kwargs):
70+
greenlet_timeout = kwargs.pop('greenlet_timeout', None)
7071
output = {}
7172
if host_args:
7273
try:
@@ -88,7 +89,7 @@ def run_command(self, command, user=None, stop_on_errors=True,
8889
for host in self.hosts]
8990
for cmd in cmds:
9091
try:
91-
self.get_output(cmd, output)
92+
self.get_output(cmd, output, timeout=greenlet_timeout)
9293
except Exception:
9394
if stop_on_errors:
9495
raise
@@ -122,7 +123,7 @@ def _get_host_config_values(self, host):
122123
def _run_command(self, host, command, *args, **kwargs):
123124
raise NotImplementedError
124125

125-
def get_output(self, cmd, output):
126+
def get_output(self, cmd, output, timeout=None):
126127
"""Get output from command.
127128
128129
:param cmd: Command to get output from
@@ -133,7 +134,7 @@ def get_output(self, cmd, output):
133134
:type output: dict
134135
:rtype: None"""
135136
try:
136-
(channel, host, stdout, stderr, stdin) = cmd.get()
137+
(channel, host, stdout, stderr, stdin) = cmd.get(timeout=timeout)
137138
except Exception as ex:
138139
host = ex.host
139140
self._update_host_output(

pssh/clients/miko/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
# License along with this library; if not, write to the Free Software
1616
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717

18-
# flake8: noqa: F401
19-
from .parallel import ParallelSSHClient
20-
from .single import SSHClient, logger
18+
from .parallel import ParallelSSHClient # noqa: F401
19+
from .single import SSHClient, logger # noqa: F401

0 commit comments

Comments
 (0)