##// END OF EJS Templates
Merge pull request #1627 from minrk/msgspec...
Merge pull request #1627 from minrk/msgspec Test the Message Spec and add our zmq subpackage to the test suite. It uses Traitlets to perform validation of keys. Checks right now are not very strict, as (almost) any key is allowed to be None, as long as it is defined. This is because I simply do not know which keys are allowed to be None, and this is not discussed in the specification. If no keys are allowed to be None, we violate that all over the place. Parametric tests are used, so every key validation counts as a test (147!). Message spec doc was found to misrepresent code in a few points, and some changes were made: * spec had error keys as `exc_name/value`, but we are actually using `ename/value` (docs updated to match code) * payloads were inaccurate - list of dicts, rather than single dict, and transformed_output is a payload, not top-level in exec-reply (docs update to match code). * in oinfo_request, detail_level was in message spec, but not actually implemented (code updated to match docs). History messages are not yet tested, but I think I get at least elementary coverage of everything else in the doc.

File last commit:

r4574:a8c54759
r6567:232fa81a merge
Show More
forward.py
88 lines | 3.4 KiB | text/x-python | PythonLexer
MinRK
added basic tunneling with ssh or paramiko
r3571 #
Min RK
added preliminary ssh tunneling support for clients
r3572 # This file is adapted from a paramiko demo, and thus licensed under LGPL 2.1.
MinRK
added basic tunneling with ssh or paramiko
r3571 # Original Copyright (C) 2003-2007 Robey Pointer <robeypointer@gmail.com>
# Edits Copyright (C) 2010 The IPython Team
#
# Paramiko is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
Thomas Spura
Fix rpmlint: incorrect-fsf-address...
r4456 # 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA.
MinRK
added basic tunneling with ssh or paramiko
r3571
"""
Sample script showing how to do local port forwarding over paramiko.
This script connects to the requested SSH server and sets up local port
forwarding (the openssh -L option) from a local port through a tunneled
connection to a destination reachable from the SSH server machine.
"""
from __future__ import print_function
MinRK
ssh tunneling utils into IPython.external.ssh
r3619 import logging
MinRK
added basic tunneling with ssh or paramiko
r3571 import select
import SocketServer
MinRK
ssh tunneling utils into IPython.external.ssh
r3619 logger = logging.getLogger('ssh')
MinRK
added basic tunneling with ssh or paramiko
r3571
class ForwardServer (SocketServer.ThreadingTCPServer):
daemon_threads = True
allow_reuse_address = True
class Handler (SocketServer.BaseRequestHandler):
def handle(self):
try:
chan = self.ssh_transport.open_channel('direct-tcpip',
(self.chain_host, self.chain_port),
self.request.getpeername())
except Exception, e:
MinRK
ssh tunneling utils into IPython.external.ssh
r3619 logger.debug('Incoming request to %s:%d failed: %s' % (self.chain_host,
MinRK
added basic tunneling with ssh or paramiko
r3571 self.chain_port,
repr(e)))
return
if chan is None:
MinRK
ssh tunneling utils into IPython.external.ssh
r3619 logger.debug('Incoming request to %s:%d was rejected by the SSH server.' %
MinRK
added basic tunneling with ssh or paramiko
r3571 (self.chain_host, self.chain_port))
return
MinRK
ssh tunneling utils into IPython.external.ssh
r3619 logger.debug('Connected! Tunnel open %r -> %r -> %r' % (self.request.getpeername(),
MinRK
added basic tunneling with ssh or paramiko
r3571 chan.getpeername(), (self.chain_host, self.chain_port)))
while True:
r, w, x = select.select([self.request, chan], [], [])
if self.request in r:
data = self.request.recv(1024)
if len(data) == 0:
break
chan.send(data)
if chan in r:
data = chan.recv(1024)
if len(data) == 0:
break
self.request.send(data)
chan.close()
self.request.close()
MinRK
ssh tunneling utils into IPython.external.ssh
r3619 logger.debug('Tunnel closed ')
MinRK
added basic tunneling with ssh or paramiko
r3571
def forward_tunnel(local_port, remote_host, remote_port, transport):
# this is a little convoluted, but lets me configure things for the Handler
# object. (SocketServer doesn't give Handlers any way to access the outer
# server normally.)
class SubHander (Handler):
chain_host = remote_host
chain_port = remote_port
ssh_transport = transport
Min RK
added preliminary ssh tunneling support for clients
r3572 ForwardServer(('127.0.0.1', local_port), SubHander).serve_forever()
MinRK
added basic tunneling with ssh or paramiko
r3571
Thomas Spura
Fix rpmlint: incorrect-fsf-address...
r4456 __all__ = ['forward_tunnel']