def connect(address, port, authkey='PublicKey', pubkey=None):
    """
    Connects to the :class:`ObjServerFactory` at `address` and `port`
    using `key` and returns a (shared) proxy for it.

    address: string
        IP address for server, or pipe filename.

    port: int
        Server port.  If < 0, `address` is a pipe filename.

    authkey:
        Server authorization key.

    pubkey:
        Server public key, required if `authkey` is 'PublicKey'.
    """
    if port < 0:
        location = address
    else:
        location = (address, port)
    try:
        return _PROXIES[location]
    except KeyError:
        if not OpenMDAO_Proxy.manager_is_alive(location):
            raise RuntimeError("can't connect to %s" % (location,))
        mgr = _FactoryManager(location, authkey, pubkey=pubkey)
        mgr.connect()
        proxy = mgr.openmdao_main_objserverfactory_ObjServerFactory()
        _PROXIES[location] = proxy
        return proxy
def connect(address, port, tunnel=False, authkey='PublicKey', pubkey=None,
            logfile=None):
    """
    Connects to the server at `address` and `port` using `key` and returns
    a (shared) proxy for the associated :class:`ObjServerFactory`.

    address: string
        IP address for server or pipe filename.

    port: int
        Server port.  If < 0, `address` is a pipe filename.

    tunnel: bool
        Connect via SSH tunnel.

    authkey:
        Server authorization key.

    pubkey:
        Server public key; required if `authkey` is 'PublicKey'.

    logfile:
        Location of server's log file, if known.
    """
    if port < 0:
        key = address
    else:
        key = (address, port)
    try:
        return _PROXIES[key]
    except KeyError:
        # Requires ssh setup.
        if tunnel:  # pragma no cover
            location, cleanup = setup_tunnel(address, port)
            atexit.register(*cleanup)
        else:
            location = key
        via = ' (via tunnel)' if tunnel else ''
        log = ' at %s' % logfile if logfile else ''
        if not OpenMDAO_Proxy.manager_is_alive(location):
            raise RuntimeError("Can't connect to server at %s:%s%s. It appears"
                               " to be offline. Please check the server log%s."
                               % (address, port, via, log))

        mgr = _FactoryManager(location, authkey, pubkey=pubkey)
        try:
            mgr.connect()
        except EOFError:
            raise RuntimeError("Can't connect to server at %s:%s%s. It appears"
                               " to be rejecting the connection. Please check"
                               " the server log%s." % (address, port, via, log))

        proxy = mgr.openmdao_main_objserverfactory_ObjServerFactory()
        if proxy.version != __version__:
            logging.warning('Server version %r different than local version %r',
                            proxy.version, __version__)
        _PROXIES[key] = proxy
        return proxy
 def _finalize_host(address, authkey, fcleanup, rcleanup):
     """ Sends a shutdown message and cleans up tunnels. """
     mgr_ok = OpenMDAO_Proxy.manager_is_alive(address)
     if mgr_ok:
         conn = connection.Client(address, authkey=authkey)
         try:
             managers.dispatch(conn, None, 'shutdown')
         except EOFError:
             pass
         finally:
             conn.close()
     if fcleanup is not None:
         fcleanup[0](*fcleanup[1:], **dict(keep_log=not mgr_ok))
     if rcleanup is not None:
         rcleanup[0](*rcleanup[1:], **dict(keep_log=not mgr_ok))
예제 #4
0
 def _finalize_host(address, authkey, fcleanup, rcleanup):
     """ Sends a shutdown message and cleans up tunnels. """
     mgr_ok = OpenMDAO_Proxy.manager_is_alive(address)
     if mgr_ok:
         conn = connection.Client(address, authkey=authkey)
         try:
             managers.dispatch(conn, None, 'shutdown')
         except EOFError:
             pass
         finally:
             conn.close()
     if fcleanup is not None:
         fcleanup[0](*fcleanup[1:], **dict(keep_log=not mgr_ok))
     if rcleanup is not None:
         rcleanup[0](*rcleanup[1:], **dict(keep_log=not mgr_ok))