Ejemplo n.º 1
0
def connect_stream(stream, service=VoidService, config={}):
    """creates a connection over a given stream

    :param stream: the stream to use
    :param service: the local service to expose (defaults to Void)
    :param config: configuration dict

    :returns: an RPyC connection
    """
    return connect_channel(Channel(stream), service=service, config=config)
Ejemplo n.º 2
0
def ssh_connect(remote_machine, remote_port, service=VoidService, config={}):
    """
    Connects to an RPyC server over an SSH tunnel (created by plumbum).
    See `Plumbum tunneling <http://plumbum.readthedocs.org/en/latest/remote.html#tunneling>`_
    for further details.

    .. note::
       This function attempts to allocate a free TCP port for the underlying tunnel, but doing
       so is inherently prone to a race condition with other processes who might bind the
       same port before sshd does. Albeit unlikely, there is no sure way around it.

    :param remote_machine: an :class:`plumbum.remote.RemoteMachine` instance
    :param remote_port: the port of the remote server
    :param service: the local service to expose (defaults to Void)
    :param config: configuration dict

    :returns: an RPyC connection
    """
    with _ssh_connect_lock:
        loc_port = _get_free_port()
        tun = remote_machine.tunnel(loc_port, remote_port)
        stream = TunneledSocketStream.connect("localhost", loc_port)
        stream.tun = tun
    return service._connect(Channel(stream), config=config)