class_docstr: The base Jupyter console application.
class_docstr_tok: ["The","base","Jupyter","console","application","."]
docstr: set up ssh tunnels, if needed.
docstr_tok: ["set","up","ssh","tunnels",",","if","needed","."]
code: def init_ssh(self) -> None:
      """set up ssh tunnels, if needed."""
      if not self.existing or (not self.sshserver and not self.sshkey):
          return
      self.load_connection_file()
  
      transport = self.transport
      ip = self.ip
  
      if transport != "tcp":
          self.log.error(
              "Can only use ssh tunnels with TCP sockets, not %s",
              transport,
          )
          sys.exit(-1)
  
      if self.sshkey and not self.sshserver:
          # specifying just the key implies that we are connecting directly
          self.sshserver = ip
          ip = localhost()
  
      # build connection dict for tunnels:
      info: KernelConnectionInfo = {
          "ip": ip,
          "shell_port": self.shell_port,
          "iopub_port": self.iopub_port,
          "stdin_port": self.stdin_port,
          "hb_port": self.hb_port,
          "control_port": self.control_port,
      }
  
      self.log.info(
          "Forwarding connections to %s via %s", ip, self.sshserver
      )
  
      # tunnels return a new set of ports, which will be on localhost:
      self.ip = localhost()
      try:
          newports = tunnel_to_kernel(info, self.sshserver, self.sshkey)
      except:  # noqa
          # even catch KeyboardInterrupt
          self.log.error("Could not setup tunnels", exc_info=True)
          self.exit(1)  # type:ignore[attr-defined]
  
      (
          self.shell_port,
          self.iopub_port,
          self.stdin_port,
          self.hb_port,
          self.control_port,
      ) = newports
  
      cf = self.connection_file
      root, ext = os.path.splitext(cf)
      self.connection_file = root + "-ssh" + ext
      self.write_connection_file()  # write the new connection file
      self.log.info("To connect another client via this tunnel, use:")
      self.log.info(
          "--existing %s", os.path.basename(self.connection_file)
      )
  
imports: import atexit
  import os
  import signal
  import sys
  import typing
  import uuid
  import warnings
  from jupyter_core.application import base_aliases, base_flags
  from traitlets import CBool, CUnicode, Dict, List, Type, Unicode
  from traitlets.config.application import boolean_flag
  from .None import KernelManager, connect, find_connection_file, tunnel_to_kernel
  from .blocking import BlockingKernelClient
  from .connect import KernelConnectionInfo
  from .kernelspec import NoSuchKernel
  from .localinterfaces import localhost
  from .restarter import KernelRestarter
  from .session import Session
  from .utils import _filefind
label_desc: Use image node_id 4 for calling the JupyterConsoleApp obj's underlying member method code with example usage: obj.init_ssh() without return types