Show More
@@ -88,11 +88,12 b' aliases = dict(ipkernel_aliases)' | |||
|
88 | 88 | |
|
89 | 89 | # also scrub aliases from the frontend |
|
90 | 90 | app_aliases = dict( |
|
91 | ip = 'KernelManager.ip', | |
|
92 | transport = 'KernelManager.transport', | |
|
91 | 93 | hb = 'IPythonConsoleApp.hb_port', |
|
92 | 94 | shell = 'IPythonConsoleApp.shell_port', |
|
93 | 95 | iopub = 'IPythonConsoleApp.iopub_port', |
|
94 | 96 | stdin = 'IPythonConsoleApp.stdin_port', |
|
95 | ip = 'IPythonConsoleApp.ip', | |
|
96 | 97 | existing = 'IPythonConsoleApp.existing', |
|
97 | 98 | f = 'IPythonConsoleApp.connection_file', |
|
98 | 99 | |
@@ -153,27 +154,6 b' class IPythonConsoleApp(Configurable):' | |||
|
153 | 154 | auto_create = CBool(True) |
|
154 | 155 | # connection info: |
|
155 | 156 | |
|
156 | transport = CaselessStrEnum(['tcp', 'ipc'], default_value='tcp', config=True) | |
|
157 | ||
|
158 | ip = Unicode(config=True, | |
|
159 | help="""Set the kernel\'s IP address [default localhost]. | |
|
160 | If the IP address is something other than localhost, then | |
|
161 | Consoles on other machines will be able to connect | |
|
162 | to the Kernel, so be careful!""" | |
|
163 | ) | |
|
164 | def _ip_default(self): | |
|
165 | if self.transport == 'tcp': | |
|
166 | return LOCALHOST | |
|
167 | else: | |
|
168 | # this can fire early if ip is given, | |
|
169 | # in which case our return value is meaningless | |
|
170 | if not hasattr(self, 'profile_dir'): | |
|
171 | return '' | |
|
172 | ipcdir = os.path.join(self.profile_dir.security_dir, 'kernel-%s' % os.getpid()) | |
|
173 | os.makedirs(ipcdir) | |
|
174 | atexit.register(lambda : shutil.rmtree(ipcdir)) | |
|
175 | return os.path.join(ipcdir, 'ipc') | |
|
176 | ||
|
177 | 157 | sshserver = Unicode('', config=True, |
|
178 | 158 | help="""The SSH server to use to connect to the kernel.""") |
|
179 | 159 | sshkey = Unicode('', config=True, |
@@ -274,9 +254,9 b' class IPythonConsoleApp(Configurable):' | |||
|
274 | 254 | with open(fname) as f: |
|
275 | 255 | cfg = json.load(f) |
|
276 | 256 | |
|
277 | self.transport = cfg.get('transport', 'tcp') | |
|
278 | if 'ip' in cfg: | |
|
279 | self.ip = cfg['ip'] | |
|
257 | self.config.KernelManager.transport = cfg.get('transport', 'tcp') | |
|
258 | self.config.KernelManager.ip = cfg.get('ip', LOCALHOST) | |
|
259 | ||
|
280 | 260 | for channel in ('hb', 'shell', 'iopub', 'stdin'): |
|
281 | 261 | name = channel + '_port' |
|
282 | 262 | if getattr(self, name) == 0 and name in cfg: |
@@ -285,33 +265,37 b' class IPythonConsoleApp(Configurable):' | |||
|
285 | 265 | if 'key' in cfg: |
|
286 | 266 | self.config.Session.key = str_to_bytes(cfg['key']) |
|
287 | 267 |
|
|
288 | ||
|
289 | 268 | def init_ssh(self): |
|
290 | 269 | """set up ssh tunnels, if needed.""" |
|
291 | if not self.sshserver and not self.sshkey: | |
|
270 | if not self.existing or (not self.sshserver and not self.sshkey): | |
|
292 | 271 | return |
|
293 | 272 | |
|
294 | if self.transport != 'tcp': | |
|
295 | self.log.error("Can only use ssh tunnels with TCP sockets, not %s", self.transport) | |
|
296 | return | |
|
273 | self.load_connection_file() | |
|
274 | ||
|
275 | transport = self.config.KernelManager.transport | |
|
276 | ip = self.config.KernelManager.ip | |
|
277 | ||
|
278 | if transport != 'tcp': | |
|
279 | self.log.error("Can only use ssh tunnels with TCP sockets, not %s", transport) | |
|
280 | sys.exit(-1) | |
|
297 | 281 | |
|
298 | 282 | if self.sshkey and not self.sshserver: |
|
299 | 283 | # specifying just the key implies that we are connecting directly |
|
300 |
self.sshserver = |
|
|
301 |
|
|
|
284 | self.sshserver = ip | |
|
285 | ip = LOCALHOST | |
|
302 | 286 | |
|
303 | 287 | # build connection dict for tunnels: |
|
304 |
info = dict(ip= |
|
|
288 | info = dict(ip=ip, | |
|
305 | 289 | shell_port=self.shell_port, |
|
306 | 290 | iopub_port=self.iopub_port, |
|
307 | 291 | stdin_port=self.stdin_port, |
|
308 | 292 | hb_port=self.hb_port |
|
309 | 293 | ) |
|
310 | 294 | |
|
311 |
self.log.info("Forwarding connections to %s via %s"%( |
|
|
295 | self.log.info("Forwarding connections to %s via %s"%(ip, self.sshserver)) | |
|
312 | 296 | |
|
313 | 297 | # tunnels return a new set of ports, which will be on localhost: |
|
314 | self.ip = LOCALHOST | |
|
298 | self.config.KernelManager.ip = LOCALHOST | |
|
315 | 299 | try: |
|
316 | 300 | newports = tunnel_to_kernel(info, self.sshserver, self.sshkey) |
|
317 | 301 | except: |
@@ -347,8 +331,6 b' class IPythonConsoleApp(Configurable):' | |||
|
347 | 331 | |
|
348 | 332 | # Create a KernelManager and start a kernel. |
|
349 | 333 | self.kernel_manager = self.kernel_manager_class( |
|
350 | transport=self.transport, | |
|
351 | ip=self.ip, | |
|
352 | 334 | shell_port=self.shell_port, |
|
353 | 335 | iopub_port=self.iopub_port, |
|
354 | 336 | stdin_port=self.stdin_port, |
@@ -359,6 +341,7 b' class IPythonConsoleApp(Configurable):' | |||
|
359 | 341 | # start the kernel |
|
360 | 342 | if not self.existing: |
|
361 | 343 | self.kernel_manager.start_kernel(extra_arguments=self.kernel_argv) |
|
344 | atexit.register(self.kernel_manager.cleanup_ipc_files) | |
|
362 | 345 | elif self.sshserver: |
|
363 | 346 | # ssh, write new connection file |
|
364 | 347 | self.kernel_manager.write_connection_file() |
@@ -242,6 +242,7 b' aliases.update({' | |||
|
242 | 242 | 'ip': 'NotebookApp.ip', |
|
243 | 243 | 'port': 'NotebookApp.port', |
|
244 | 244 | 'port-retries': 'NotebookApp.port_retries', |
|
245 | 'transport': 'KernelManager.transport', | |
|
245 | 246 | 'keyfile': 'NotebookApp.keyfile', |
|
246 | 247 | 'certfile': 'NotebookApp.certfile', |
|
247 | 248 | 'notebook-dir': 'NotebookManager.notebook_dir', |
@@ -193,9 +193,7 b' class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):' | |||
|
193 | 193 | def new_frontend_master(self): |
|
194 | 194 | """ Create and return new frontend attached to new kernel, launched on localhost. |
|
195 | 195 | """ |
|
196 | ip = self.ip if self.ip in LOCAL_IPS else LOCALHOST | |
|
197 | 196 | kernel_manager = self.kernel_manager_class( |
|
198 | ip=ip, | |
|
199 | 197 | connection_file=self._new_connection_file(), |
|
200 | 198 | config=self.config, |
|
201 | 199 | ) |
@@ -245,7 +243,11 b' class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):' | |||
|
245 | 243 | self.app.icon = QtGui.QIcon(icon_path) |
|
246 | 244 | QtGui.QApplication.setWindowIcon(self.app.icon) |
|
247 | 245 | |
|
248 | local_kernel = (not self.existing) or self.ip in LOCAL_IPS | |
|
246 | try: | |
|
247 | ip = self.config.KernelManager.ip | |
|
248 | except AttributeError: | |
|
249 | ip = LOCALHOST | |
|
250 | local_kernel = (not self.existing) or ip in LOCAL_IPS | |
|
249 | 251 | self.widget = self.widget_factory(config=self.config, |
|
250 | 252 | local_kernel=local_kernel) |
|
251 | 253 | self.init_colors(self.widget) |
General Comments 0
You need to be logged in to leave comments.
Login now