##// END OF EJS Templates
add ssh tunnel support to qtconsole
MinRK -
Show More
@@ -20,11 +20,13 b' Authors:'
20 20 import os
21 21 import signal
22 22 import sys
23 from getpass import getpass
23 24
24 25 # System library imports
25 26 from IPython.external.qt import QtGui
26 27 from pygments.styles import get_all_styles
27 28
29 # from IPython.external.ssh import tunnel
28 30 # Local imports
29 31 from IPython.config.application import boolean_flag
30 32 from IPython.core.application import BaseIPythonApplication
@@ -34,6 +36,7 b' from IPython.frontend.qt.console.ipython_widget import IPythonWidget'
34 36 from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
35 37 from IPython.frontend.qt.console import styles
36 38 from IPython.frontend.qt.kernelmanager import QtKernelManager
39 from IPython.parallel.util import select_random_ports
37 40 from IPython.utils.traitlets import (
38 41 Dict, List, Unicode, Int, CaselessStrEnum, CBool, Any
39 42 )
@@ -219,6 +222,7 b' qt_aliases = dict('
219 222
220 223 editor = 'IPythonWidget.editor',
221 224 paging = 'ConsoleWidget.paging',
225 ssh = 'IPythonQtConsoleApp.sshserver',
222 226 )
223 227 aliases.update(qt_aliases)
224 228 # also scrub aliases from the frontend
@@ -266,6 +270,12 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
266 270 Consoles on other machines will be able to connect
267 271 to the Kernel, so be careful!"""
268 272 )
273
274 sshserver = Unicode('', config=True,
275 help="""The SSH server to use to connect to the kernel.""")
276 sshkey = Unicode('', config=True,
277 help="""Path to the ssh key to use for logging in to the ssh server.""")
278
269 279 hb_port = Int(0, config=True,
270 280 help="set the heartbeat port [default: random]")
271 281 shell_port = Int(0, config=True,
@@ -322,7 +332,33 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
322 332 key = a.lstrip('-').split('=')[0]
323 333 if key in qt_flags:
324 334 self.kernel_argv.remove(a)
325
335
336 def init_ssh(self):
337 # import here, to prevent circular import
338 from IPython.external.ssh import tunnel
339 if not self.sshserver and not self.sshkey:
340 return
341
342 if self.sshkey and not self.sshserver:
343 self.sshserver = self.ip
344 self.ip=LOCALHOST
345
346 lports = select_random_ports(4)
347 rports = self.shell_port, self.iopub_port, self.stdin_port, self.hb_port
348 self.shell_port, self.iopub_port, self.stdin_port, self.hb_port = lports
349
350 remote_ip = self.ip
351 self.ip = LOCALHOST
352 self.log.info("Forwarding connections to %s via %s"%(remote_ip, self.sshserver))
353
354 if tunnel.try_passwordless_ssh(self.sshserver, self.sshkey):
355 password=False
356 else:
357 password = getpass("SSH Password for %s: "%self.sshserver)
358
359 for lp,rp in zip(lports, rports):
360 tunnel.ssh_tunnel(lp, rp, self.sshserver, remote_ip, self.sshkey, password)
361
326 362 def init_kernel_manager(self):
327 363 # Don't let Qt or ZMQ swallow KeyboardInterupts.
328 364 signal.signal(signal.SIGINT, signal.SIG_DFL)
@@ -420,6 +456,7 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
420 456
421 457 def initialize(self, argv=None):
422 458 super(IPythonQtConsoleApp, self).initialize(argv)
459 self.init_ssh()
423 460 self.init_kernel_manager()
424 461 self.init_qt_elements()
425 462 self.init_colors()
General Comments 0
You need to be logged in to leave comments. Login now