示例#1
0
    def _spawn_ssh_tunnel(self,
                          kernel_channel,
                          local_port,
                          remote_port,
                          remote_ip,
                          server,
                          port=ssh_port,
                          key=None):
        """ This method spawns a child process to create a SSH tunnel and returns the spawned process.
            ZMQ's implementation returns a pid on UNIX based platforms and a process handle/reference on
            Win32. By consistently returning a process handle/reference on both UNIX and Win32 platforms,
            this method enables the caller to deal with the same currency regardless of the platform. For
            example, on both UNIX and Win32 platforms, the developer will have the option to stash the
            child process reference and manage it's lifecycle consistently.

            On UNIX based platforms, ZMQ's implementation is more generic to be able to handle various
            use-cases. ZMQ's implementation also requests the spawned process to go to background using
            '-f' command-line option. As a result, the spawned process becomes an orphan and any references
            to the process obtained using it's pid become stale. On the other hand, this implementation is
            specifically for password-less SSH login WITHOUT the '-f' command-line option thereby allowing
            the spawned process to be owned by the parent process. This allows the parent process to control
            the lifecycle of it's child processes and do appropriate cleanup during termination.
        """
        if sys.platform == 'win32':
            ssh_server = server + ":" + str(port)
            return tunnel.paramiko_tunnel(local_port, remote_port, ssh_server,
                                          remote_ip, key)
        else:
            ssh = "ssh -p %s -o ServerAliveInterval=%i" % \
                  (port, self._get_keep_alive_interval(kernel_channel))
            cmd = "%s -S none -L 127.0.0.1:%i:%s:%i %s" % (
                ssh, local_port, remote_ip, remote_port, server)
            return pexpect.spawn(cmd,
                                 env=os.environ.copy().pop(
                                     'SSH_ASKPASS', None))
    def _spawn_ssh_tunnel(self, kernel_channel, local_port, remote_port, remote_ip, server, port=ssh_port, key=None):
        """ This method spawns a child process to create a SSH tunnel and returns the spawned process.
            ZMQ's implementation returns a pid on UNIX based platforms and a process handle/reference on
            Win32. By consistently returning a process handle/reference on both UNIX and Win32 platforms,
            this method enables the caller to deal with the same currency regardless of the platform. For
            example, on both UNIX and Win32 platforms, the developer will have the option to stash the
            child process reference and manage it's lifecycle consistently.

            On UNIX based platforms, ZMQ's implementation is more generic to be able to handle various
            use-cases. ZMQ's implementation also requests the spawned process to go to background using
            '-f' command-line option. As a result, the spawned process becomes an orphan and any references
            to the process obtained using it's pid become stale. On the other hand, this implementation is
            specifically for password-less SSH login WITHOUT the '-f' command-line option thereby allowing
            the spawned process to be owned by the parent process. This allows the parent process to control
            the lifecycle of it's child processes and do appropriate cleanup during termination.
        """
        if sys.platform == 'win32':
            ssh_server = server + ":" + str(port)
            return tunnel.paramiko_tunnel(local_port, remote_port, ssh_server, remote_ip, key)
        else:
            ssh = "ssh -p %s -o ServerAliveInterval=%i" % \
                  (port, self._get_keep_alive_interval(kernel_channel))
            cmd = "%s -S none -L 127.0.0.1:%i:%s:%i %s" % (
                ssh, local_port, remote_ip, remote_port, server)
            return pexpect.spawn(cmd, env=os.environ.copy().pop('SSH_ASKPASS', None))
示例#3
0
 def ssh_tunnel(self, *args, **kwargs):
     if os.name == 'nt':
         return zmqtunnel.paramiko_tunnel(*args, **kwargs)
     else:
         return openssh_tunnel(None, *args, **kwargs)