Show More
@@ -88,11 +88,12 b' aliases = dict(ipkernel_aliases)' | |||||
88 |
|
88 | |||
89 | # also scrub aliases from the frontend |
|
89 | # also scrub aliases from the frontend | |
90 | app_aliases = dict( |
|
90 | app_aliases = dict( | |
|
91 | ip = 'KernelManager.ip', | |||
|
92 | transport = 'KernelManager.transport', | |||
91 | hb = 'IPythonConsoleApp.hb_port', |
|
93 | hb = 'IPythonConsoleApp.hb_port', | |
92 | shell = 'IPythonConsoleApp.shell_port', |
|
94 | shell = 'IPythonConsoleApp.shell_port', | |
93 | iopub = 'IPythonConsoleApp.iopub_port', |
|
95 | iopub = 'IPythonConsoleApp.iopub_port', | |
94 | stdin = 'IPythonConsoleApp.stdin_port', |
|
96 | stdin = 'IPythonConsoleApp.stdin_port', | |
95 | ip = 'IPythonConsoleApp.ip', |
|
|||
96 | existing = 'IPythonConsoleApp.existing', |
|
97 | existing = 'IPythonConsoleApp.existing', | |
97 | f = 'IPythonConsoleApp.connection_file', |
|
98 | f = 'IPythonConsoleApp.connection_file', | |
98 |
|
99 | |||
@@ -153,27 +154,6 b' class IPythonConsoleApp(Configurable):' | |||||
153 | auto_create = CBool(True) |
|
154 | auto_create = CBool(True) | |
154 | # connection info: |
|
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 | sshserver = Unicode('', config=True, |
|
157 | sshserver = Unicode('', config=True, | |
178 | help="""The SSH server to use to connect to the kernel.""") |
|
158 | help="""The SSH server to use to connect to the kernel.""") | |
179 | sshkey = Unicode('', config=True, |
|
159 | sshkey = Unicode('', config=True, | |
@@ -274,9 +254,9 b' class IPythonConsoleApp(Configurable):' | |||||
274 | with open(fname) as f: |
|
254 | with open(fname) as f: | |
275 | cfg = json.load(f) |
|
255 | cfg = json.load(f) | |
276 |
|
256 | |||
277 | self.transport = cfg.get('transport', 'tcp') |
|
257 | self.config.KernelManager.transport = cfg.get('transport', 'tcp') | |
278 | if 'ip' in cfg: |
|
258 | self.config.KernelManager.ip = cfg.get('ip', LOCALHOST) | |
279 | self.ip = cfg['ip'] |
|
259 | ||
280 | for channel in ('hb', 'shell', 'iopub', 'stdin'): |
|
260 | for channel in ('hb', 'shell', 'iopub', 'stdin'): | |
281 | name = channel + '_port' |
|
261 | name = channel + '_port' | |
282 | if getattr(self, name) == 0 and name in cfg: |
|
262 | if getattr(self, name) == 0 and name in cfg: | |
@@ -284,34 +264,38 b' class IPythonConsoleApp(Configurable):' | |||||
284 | setattr(self, name, cfg[name]) |
|
264 | setattr(self, name, cfg[name]) | |
285 | if 'key' in cfg: |
|
265 | if 'key' in cfg: | |
286 | self.config.Session.key = str_to_bytes(cfg['key']) |
|
266 | self.config.Session.key = str_to_bytes(cfg['key']) | |
287 |
|
||||
288 |
|
267 | |||
289 | def init_ssh(self): |
|
268 | def init_ssh(self): | |
290 | """set up ssh tunnels, if needed.""" |
|
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 | return |
|
271 | return | |
293 |
|
272 | |||
294 | if self.transport != 'tcp': |
|
273 | self.load_connection_file() | |
295 | self.log.error("Can only use ssh tunnels with TCP sockets, not %s", self.transport) |
|
274 | ||
296 | return |
|
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 | if self.sshkey and not self.sshserver: |
|
282 | if self.sshkey and not self.sshserver: | |
299 | # specifying just the key implies that we are connecting directly |
|
283 | # specifying just the key implies that we are connecting directly | |
300 |
self.sshserver = |
|
284 | self.sshserver = ip | |
301 |
|
|
285 | ip = LOCALHOST | |
302 |
|
286 | |||
303 | # build connection dict for tunnels: |
|
287 | # build connection dict for tunnels: | |
304 |
info = dict(ip= |
|
288 | info = dict(ip=ip, | |
305 | shell_port=self.shell_port, |
|
289 | shell_port=self.shell_port, | |
306 | iopub_port=self.iopub_port, |
|
290 | iopub_port=self.iopub_port, | |
307 | stdin_port=self.stdin_port, |
|
291 | stdin_port=self.stdin_port, | |
308 | hb_port=self.hb_port |
|
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 | # 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: | |
314 | self.ip = LOCALHOST |
|
298 | self.config.KernelManager.ip = LOCALHOST | |
315 | try: |
|
299 | try: | |
316 | newports = tunnel_to_kernel(info, self.sshserver, self.sshkey) |
|
300 | newports = tunnel_to_kernel(info, self.sshserver, self.sshkey) | |
317 | except: |
|
301 | except: | |
@@ -347,8 +331,6 b' class IPythonConsoleApp(Configurable):' | |||||
347 |
|
331 | |||
348 | # Create a KernelManager and start a kernel. |
|
332 | # Create a KernelManager and start a kernel. | |
349 | self.kernel_manager = self.kernel_manager_class( |
|
333 | self.kernel_manager = self.kernel_manager_class( | |
350 | transport=self.transport, |
|
|||
351 | ip=self.ip, |
|
|||
352 | shell_port=self.shell_port, |
|
334 | shell_port=self.shell_port, | |
353 | iopub_port=self.iopub_port, |
|
335 | iopub_port=self.iopub_port, | |
354 | stdin_port=self.stdin_port, |
|
336 | stdin_port=self.stdin_port, | |
@@ -359,6 +341,7 b' class IPythonConsoleApp(Configurable):' | |||||
359 | # start the kernel |
|
341 | # start the kernel | |
360 | if not self.existing: |
|
342 | if not self.existing: | |
361 | self.kernel_manager.start_kernel(extra_arguments=self.kernel_argv) |
|
343 | self.kernel_manager.start_kernel(extra_arguments=self.kernel_argv) | |
|
344 | atexit.register(self.kernel_manager.cleanup_ipc_files) | |||
362 | elif self.sshserver: |
|
345 | elif self.sshserver: | |
363 | # ssh, write new connection file |
|
346 | # ssh, write new connection file | |
364 | self.kernel_manager.write_connection_file() |
|
347 | self.kernel_manager.write_connection_file() |
@@ -242,6 +242,7 b' aliases.update({' | |||||
242 | 'ip': 'NotebookApp.ip', |
|
242 | 'ip': 'NotebookApp.ip', | |
243 | 'port': 'NotebookApp.port', |
|
243 | 'port': 'NotebookApp.port', | |
244 | 'port-retries': 'NotebookApp.port_retries', |
|
244 | 'port-retries': 'NotebookApp.port_retries', | |
|
245 | 'transport': 'KernelManager.transport', | |||
245 | 'keyfile': 'NotebookApp.keyfile', |
|
246 | 'keyfile': 'NotebookApp.keyfile', | |
246 | 'certfile': 'NotebookApp.certfile', |
|
247 | 'certfile': 'NotebookApp.certfile', | |
247 | 'notebook-dir': 'NotebookManager.notebook_dir', |
|
248 | 'notebook-dir': 'NotebookManager.notebook_dir', |
@@ -193,9 +193,7 b' class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):' | |||||
193 | def new_frontend_master(self): |
|
193 | def new_frontend_master(self): | |
194 | """ Create and return new frontend attached to new kernel, launched on localhost. |
|
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 | kernel_manager = self.kernel_manager_class( |
|
196 | kernel_manager = self.kernel_manager_class( | |
198 | ip=ip, |
|
|||
199 | connection_file=self._new_connection_file(), |
|
197 | connection_file=self._new_connection_file(), | |
200 | config=self.config, |
|
198 | config=self.config, | |
201 | ) |
|
199 | ) | |
@@ -245,7 +243,11 b' class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):' | |||||
245 | self.app.icon = QtGui.QIcon(icon_path) |
|
243 | self.app.icon = QtGui.QIcon(icon_path) | |
246 | QtGui.QApplication.setWindowIcon(self.app.icon) |
|
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 | self.widget = self.widget_factory(config=self.config, |
|
251 | self.widget = self.widget_factory(config=self.config, | |
250 | local_kernel=local_kernel) |
|
252 | local_kernel=local_kernel) | |
251 | self.init_colors(self.widget) |
|
253 | self.init_colors(self.widget) |
General Comments 0
You need to be logged in to leave comments.
Login now