##// END OF EJS Templates
Backport PR #3978: fix `--existing` with non-localhost IP...
Paul Ivanov -
Show More
@@ -24,7 +24,6 b' Authors:'
24 import atexit
24 import atexit
25 import json
25 import json
26 import os
26 import os
27 import shutil
28 import signal
27 import signal
29 import sys
28 import sys
30 import uuid
29 import uuid
@@ -32,7 +31,6 b' import uuid'
32
31
33 # Local imports
32 # Local imports
34 from IPython.config.application import boolean_flag
33 from IPython.config.application import boolean_flag
35 from IPython.config.configurable import Configurable
36 from IPython.core.profiledir import ProfileDir
34 from IPython.core.profiledir import ProfileDir
37 from IPython.kernel.blocking import BlockingKernelClient
35 from IPython.kernel.blocking import BlockingKernelClient
38 from IPython.kernel import KernelManager
36 from IPython.kernel import KernelManager
@@ -40,7 +38,7 b' from IPython.kernel import tunnel_to_kernel, find_connection_file, swallow_argv'
40 from IPython.utils.path import filefind
38 from IPython.utils.path import filefind
41 from IPython.utils.py3compat import str_to_bytes
39 from IPython.utils.py3compat import str_to_bytes
42 from IPython.utils.traitlets import (
40 from IPython.utils.traitlets import (
43 Dict, List, Unicode, CUnicode, Int, CBool, Any, CaselessStrEnum
41 Dict, List, Unicode, CUnicode, Int, CBool, Any
44 )
42 )
45 from IPython.kernel.zmq.kernelapp import (
43 from IPython.kernel.zmq.kernelapp import (
46 kernel_flags,
44 kernel_flags,
@@ -49,12 +47,13 b' from IPython.kernel.zmq.kernelapp import ('
49 )
47 )
50 from IPython.kernel.zmq.session import Session, default_secure
48 from IPython.kernel.zmq.session import Session, default_secure
51 from IPython.kernel.zmq.zmqshell import ZMQInteractiveShell
49 from IPython.kernel.zmq.zmqshell import ZMQInteractiveShell
50 from IPython.kernel.connect import ConnectionFileMixin
52
51
53 #-----------------------------------------------------------------------------
52 #-----------------------------------------------------------------------------
54 # Network Constants
53 # Network Constants
55 #-----------------------------------------------------------------------------
54 #-----------------------------------------------------------------------------
56
55
57 from IPython.utils.localinterfaces import LOCALHOST, LOCAL_IPS
56 from IPython.utils.localinterfaces import LOCALHOST
58
57
59 #-----------------------------------------------------------------------------
58 #-----------------------------------------------------------------------------
60 # Globals
59 # Globals
@@ -89,8 +88,8 b' aliases = dict(kernel_aliases)'
89
88
90 # also scrub aliases from the frontend
89 # also scrub aliases from the frontend
91 app_aliases = dict(
90 app_aliases = dict(
92 ip = 'KernelManager.ip',
91 ip = 'IPythonConsoleApp.ip',
93 transport = 'KernelManager.transport',
92 transport = 'IPythonConsoleApp.transport',
94 hb = 'IPythonConsoleApp.hb_port',
93 hb = 'IPythonConsoleApp.hb_port',
95 shell = 'IPythonConsoleApp.shell_port',
94 shell = 'IPythonConsoleApp.shell_port',
96 iopub = 'IPythonConsoleApp.iopub_port',
95 iopub = 'IPythonConsoleApp.iopub_port',
@@ -120,7 +119,7 b' except ImportError:'
120 else:
119 else:
121 classes.append(InlineBackend)
120 classes.append(InlineBackend)
122
121
123 class IPythonConsoleApp(Configurable):
122 class IPythonConsoleApp(ConnectionFileMixin):
124 name = 'ipython-console-mixin'
123 name = 'ipython-console-mixin'
125
124
126 description = """
125 description = """
@@ -254,11 +253,10 b' class IPythonConsoleApp(Configurable):'
254 self.log.debug(u"Loading connection file %s", fname)
253 self.log.debug(u"Loading connection file %s", fname)
255 with open(fname) as f:
254 with open(fname) as f:
256 cfg = json.load(f)
255 cfg = json.load(f)
256 self.transport = cfg.get('transport', 'tcp')
257 self.ip = cfg.get('ip', LOCALHOST)
257
258
258 self.config.KernelManager.transport = cfg.get('transport', 'tcp')
259 for channel in ('hb', 'shell', 'iopub', 'stdin', 'control'):
259 self.config.KernelManager.ip = cfg.get('ip', LOCALHOST)
260
261 for channel in ('hb', 'shell', 'iopub', 'stdin'):
262 name = channel + '_port'
260 name = channel + '_port'
263 if getattr(self, name) == 0 and name in cfg:
261 if getattr(self, name) == 0 and name in cfg:
264 # not overridden by config or cl_args
262 # not overridden by config or cl_args
@@ -272,11 +270,10 b' class IPythonConsoleApp(Configurable):'
272 """set up ssh tunnels, if needed."""
270 """set up ssh tunnels, if needed."""
273 if not self.existing or (not self.sshserver and not self.sshkey):
271 if not self.existing or (not self.sshserver and not self.sshkey):
274 return
272 return
275
276 self.load_connection_file()
273 self.load_connection_file()
277
274
278 transport = self.config.KernelManager.transport
275 transport = self.transport
279 ip = self.config.KernelManager.ip
276 ip = self.ip
280
277
281 if transport != 'tcp':
278 if transport != 'tcp':
282 self.log.error("Can only use ssh tunnels with TCP sockets, not %s", transport)
279 self.log.error("Can only use ssh tunnels with TCP sockets, not %s", transport)
@@ -298,7 +295,7 b' class IPythonConsoleApp(Configurable):'
298 self.log.info("Forwarding connections to %s via %s"%(ip, self.sshserver))
295 self.log.info("Forwarding connections to %s via %s"%(ip, self.sshserver))
299
296
300 # tunnels return a new set of ports, which will be on localhost:
297 # tunnels return a new set of ports, which will be on localhost:
301 self.config.KernelManager.ip = LOCALHOST
298 self.ip = LOCALHOST
302 try:
299 try:
303 newports = tunnel_to_kernel(info, self.sshserver, self.sshkey)
300 newports = tunnel_to_kernel(info, self.sshserver, self.sshkey)
304 except:
301 except:
@@ -337,6 +334,8 b' class IPythonConsoleApp(Configurable):'
337
334
338 # Create a KernelManager and start a kernel.
335 # Create a KernelManager and start a kernel.
339 self.kernel_manager = self.kernel_manager_class(
336 self.kernel_manager = self.kernel_manager_class(
337 ip=self.ip,
338 transport=self.transport,
340 shell_port=self.shell_port,
339 shell_port=self.shell_port,
341 iopub_port=self.iopub_port,
340 iopub_port=self.iopub_port,
342 stdin_port=self.stdin_port,
341 stdin_port=self.stdin_port,
@@ -367,6 +366,8 b' class IPythonConsoleApp(Configurable):'
367 self.kernel_client = self.kernel_manager.client()
366 self.kernel_client = self.kernel_manager.client()
368 else:
367 else:
369 self.kernel_client = self.kernel_client_class(
368 self.kernel_client = self.kernel_client_class(
369 ip=self.ip,
370 transport=self.transport,
370 shell_port=self.shell_port,
371 shell_port=self.shell_port,
371 iopub_port=self.iopub_port,
372 iopub_port=self.iopub_port,
372 stdin_port=self.stdin_port,
373 stdin_port=self.stdin_port,
@@ -147,8 +147,10 b' class KernelClient(LoggingConfigurable, ConnectionFileMixin):'
147 def shell_channel(self):
147 def shell_channel(self):
148 """Get the shell channel object for this kernel."""
148 """Get the shell channel object for this kernel."""
149 if self._shell_channel is None:
149 if self._shell_channel is None:
150 url = self._make_url('shell')
151 self.log.debug("connecting shell channel to %s", url)
150 self._shell_channel = self.shell_channel_class(
152 self._shell_channel = self.shell_channel_class(
151 self.context, self.session, self._make_url('shell')
153 self.context, self.session, url
152 )
154 )
153 return self._shell_channel
155 return self._shell_channel
154
156
@@ -156,8 +158,10 b' class KernelClient(LoggingConfigurable, ConnectionFileMixin):'
156 def iopub_channel(self):
158 def iopub_channel(self):
157 """Get the iopub channel object for this kernel."""
159 """Get the iopub channel object for this kernel."""
158 if self._iopub_channel is None:
160 if self._iopub_channel is None:
161 url = self._make_url('iopub')
162 self.log.debug("connecting iopub channel to %s", url)
159 self._iopub_channel = self.iopub_channel_class(
163 self._iopub_channel = self.iopub_channel_class(
160 self.context, self.session, self._make_url('iopub')
164 self.context, self.session, url
161 )
165 )
162 return self._iopub_channel
166 return self._iopub_channel
163
167
@@ -165,8 +169,10 b' class KernelClient(LoggingConfigurable, ConnectionFileMixin):'
165 def stdin_channel(self):
169 def stdin_channel(self):
166 """Get the stdin channel object for this kernel."""
170 """Get the stdin channel object for this kernel."""
167 if self._stdin_channel is None:
171 if self._stdin_channel is None:
172 url = self._make_url('stdin')
173 self.log.debug("connecting stdin channel to %s", url)
168 self._stdin_channel = self.stdin_channel_class(
174 self._stdin_channel = self.stdin_channel_class(
169 self.context, self.session, self._make_url('stdin')
175 self.context, self.session, url
170 )
176 )
171 return self._stdin_channel
177 return self._stdin_channel
172
178
@@ -174,8 +180,10 b' class KernelClient(LoggingConfigurable, ConnectionFileMixin):'
174 def hb_channel(self):
180 def hb_channel(self):
175 """Get the hb channel object for this kernel."""
181 """Get the hb channel object for this kernel."""
176 if self._hb_channel is None:
182 if self._hb_channel is None:
183 url = self._make_url('hb')
184 self.log.debug("connecting heartbeat channel to %s", url)
177 self._hb_channel = self.hb_channel_class(
185 self._hb_channel = self.hb_channel_class(
178 self.context, self.session, self._make_url('hb')
186 self.context, self.session, url
179 )
187 )
180 return self._hb_channel
188 return self._hb_channel
181
189
@@ -249,10 +249,7 b' class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):'
249 self.app.icon = QtGui.QIcon(icon_path)
249 self.app.icon = QtGui.QIcon(icon_path)
250 QtGui.QApplication.setWindowIcon(self.app.icon)
250 QtGui.QApplication.setWindowIcon(self.app.icon)
251
251
252 try:
252 ip = self.ip
253 ip = self.config.KernelManager.ip
254 except AttributeError:
255 ip = LOCALHOST
256 local_kernel = (not self.existing) or ip in LOCAL_IPS
253 local_kernel = (not self.existing) or ip in LOCAL_IPS
257 self.widget = self.widget_factory(config=self.config,
254 self.widget = self.widget_factory(config=self.config,
258 local_kernel=local_kernel)
255 local_kernel=local_kernel)
General Comments 0
You need to be logged in to leave comments. Login now