##// END OF EJS Templates
add ssh tunnel support to qtconsole
MinRK -
Show More
@@ -20,11 +20,13 b' Authors:'
20 import os
20 import os
21 import signal
21 import signal
22 import sys
22 import sys
23 from getpass import getpass
23
24
24 # System library imports
25 # System library imports
25 from IPython.external.qt import QtGui
26 from IPython.external.qt import QtGui
26 from pygments.styles import get_all_styles
27 from pygments.styles import get_all_styles
27
28
29 # from IPython.external.ssh import tunnel
28 # Local imports
30 # Local imports
29 from IPython.config.application import boolean_flag
31 from IPython.config.application import boolean_flag
30 from IPython.core.application import BaseIPythonApplication
32 from IPython.core.application import BaseIPythonApplication
@@ -34,6 +36,7 b' from IPython.frontend.qt.console.ipython_widget import IPythonWidget'
34 from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
36 from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
35 from IPython.frontend.qt.console import styles
37 from IPython.frontend.qt.console import styles
36 from IPython.frontend.qt.kernelmanager import QtKernelManager
38 from IPython.frontend.qt.kernelmanager import QtKernelManager
39 from IPython.parallel.util import select_random_ports
37 from IPython.utils.traitlets import (
40 from IPython.utils.traitlets import (
38 Dict, List, Unicode, Int, CaselessStrEnum, CBool, Any
41 Dict, List, Unicode, Int, CaselessStrEnum, CBool, Any
39 )
42 )
@@ -219,6 +222,7 b' qt_aliases = dict('
219
222
220 editor = 'IPythonWidget.editor',
223 editor = 'IPythonWidget.editor',
221 paging = 'ConsoleWidget.paging',
224 paging = 'ConsoleWidget.paging',
225 ssh = 'IPythonQtConsoleApp.sshserver',
222 )
226 )
223 aliases.update(qt_aliases)
227 aliases.update(qt_aliases)
224 # also scrub aliases from the frontend
228 # also scrub aliases from the frontend
@@ -266,6 +270,12 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
266 Consoles on other machines will be able to connect
270 Consoles on other machines will be able to connect
267 to the Kernel, so be careful!"""
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 hb_port = Int(0, config=True,
279 hb_port = Int(0, config=True,
270 help="set the heartbeat port [default: random]")
280 help="set the heartbeat port [default: random]")
271 shell_port = Int(0, config=True,
281 shell_port = Int(0, config=True,
@@ -322,7 +332,33 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
322 key = a.lstrip('-').split('=')[0]
332 key = a.lstrip('-').split('=')[0]
323 if key in qt_flags:
333 if key in qt_flags:
324 self.kernel_argv.remove(a)
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 def init_kernel_manager(self):
362 def init_kernel_manager(self):
327 # Don't let Qt or ZMQ swallow KeyboardInterupts.
363 # Don't let Qt or ZMQ swallow KeyboardInterupts.
328 signal.signal(signal.SIGINT, signal.SIG_DFL)
364 signal.signal(signal.SIGINT, signal.SIG_DFL)
@@ -420,6 +456,7 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
420
456
421 def initialize(self, argv=None):
457 def initialize(self, argv=None):
422 super(IPythonQtConsoleApp, self).initialize(argv)
458 super(IPythonQtConsoleApp, self).initialize(argv)
459 self.init_ssh()
423 self.init_kernel_manager()
460 self.init_kernel_manager()
424 self.init_qt_elements()
461 self.init_qt_elements()
425 self.init_colors()
462 self.init_colors()
General Comments 0
You need to be logged in to leave comments. Login now