Exemple #1
0
def getConnection(host=C.MANAGER_HOST, port=None, name="Python Client",
                  password=None, tls_mode=C.MANAGER_TLS):
    """Connect to LabRAD and return a deferred that fires the protocol object."""
    p = yield protocol.connect(host, port, tls_mode)
    yield p.authenticate(password)
    yield p.loginClient(name)
    returnValue(p)
Exemple #2
0
    def run(self):
        """Run the node in a loop, reconnecting after connection loss."""
        log = logging.getLogger('labrad.node')
        while True:
            print('Connecting to {}:{}...'.format(self.host, self.port))
            try:
                p = yield protocol.connect(self.host, self.port, self.tls_mode,
                                           self.username, self.password)
                node = NodeServer(self.nodename, self.host, self.port,
                                  p.credential)
                yield node.startup(p)
            except Exception:
                log.error('Node failed to start', exc_info=True)
            else:
                try:
                    yield node.onShutdown()
                except Exception:
                    log.error('Error during node shutdown', exc_info=True)

            ## hack: manually clear the internal message dispatcher
            dispatcher.connections.clear()
            dispatcher.senders.clear()
            dispatcher._boundMethods.clear()

            yield util.wakeupCall(0)
            print('Will try to reconnect in {} seconds...'.format(self.reconnectDelay))
            yield util.wakeupCall(self.reconnectDelay)
Exemple #3
0
    def run(self):
        """Run the node in a loop, reconnecting after connection loss."""
        log = logging.getLogger('labrad.node')
        while True:
            print 'Connecting to {}:{}...'.format(self.host, self.port)
            try:
                p = yield protocol.connect(self.host, self.port, self.tls_mode)
                yield p.authenticate(self.password)
                node = NodeServer(self.nodename, self.host, self.port,
                                  self.password)
                yield node.startup(p)
            except Exception:
                log.error('Node failed to start', exc_info=True)
            else:
                try:
                    yield node.onShutdown()
                except Exception:
                    log.error('Error during node shutdown', exc_info=True)

            ## hack: manually clear the internal message dispatcher
            dispatcher.connections.clear()
            dispatcher.senders.clear()
            dispatcher._boundMethods.clear()

            yield util.wakeupCall(0)
            print 'Will try to reconnect in {} seconds...'.format(self.reconnectDelay)
            yield util.wakeupCall(self.reconnectDelay)
Exemple #4
0
def getConnection(host=C.MANAGER_HOST, port=None, name=None,
                  password=None, tls_mode=C.MANAGER_TLS, username=None,
                  headless=False):
    """Connect to LabRAD and return a deferred that fires the protocol object."""
    name = name or 'Python Client ({})'.format(support.getNodeName())
    p = yield protocol.connect(host, port, tls_mode, username, password,
                               headless)
    yield p.loginClient(name)
    returnValue(p)
Exemple #5
0
 def run(srv):
     host = config['host']
     port = int(config['port'])
     tls_mode = config['tls']
     try:
         p = yield protocol.connect(host, port, tls_mode)
         yield p.authenticate(config['password'])
         yield srv.startup(p)
         yield srv.onShutdown()
         log.msg('Disconnected cleanly.')
     except Exception as e:
         log.msg('There was an error: {}'.format(e))
     if stop_reactor:
         try:
             reactor.stop()
         except Exception:
             pass
Exemple #6
0
 def run(srv):
     host = config["host"]
     port = int(config["port"])
     tls_mode = config["tls"]
     try:
         p = yield protocol.connect(host, port, tls_mode)
         yield p.authenticate(config["password"])
         yield srv.startup(p)
         yield srv.onShutdown()
         log.msg("Disconnected cleanly.")
     except Exception as e:
         log.msg("There was an error: {}".format(e))
     if stop_reactor:
         try:
             reactor.stop()
         except Exception:
             pass
Exemple #7
0
 def run(srv):
     host = config['host']
     port = int(config['port'])
     tls_mode = config['tls']
     try:
         p = yield protocol.connect(host, port, tls_mode,
                                    config['username'], config['password'])
         yield srv.startup(p)
         yield srv.onShutdown()
         log.msg('Disconnected cleanly.')
     except Exception as e:
         log.msg('There was an error: {}'.format(e))
     if stop_reactor:
         try:
             reactor.stop()
         except Exception:
             pass
    def start(self, dv):
        """Start the given DataVaultMultihead server.

        The server startup and shutdown logic changed in pylabrad 0.95, so we
        need separate logic to handle the old and new cases.

        Args:
            dv (DataVaultMultihead): The labrad server object that we want to
                start.

        Returns:
            A deferred that fires after the server has successfully started.
            This deferred contains a function that can be invoked to shutdown
            the server. That function itself returns a deferred that will fire
            when the shutdown is complete.
        """
        if hasattr(dv, 'startup'):
            # pylabrad 0.95+
            p = yield protocol.connect(self.host, self.port)
            yield p.authenticate(password=self.password)
            yield dv.startup(p)

            @inlineCallbacks
            def stop_func():
                dv.disconnect()
                yield dv.onShutdown()
        else:
            # pylabrad 0.94 and earlier
            try:
                dv.configure_tls(self.host, "starttls")
            except AttributeError:
                self.report("pylabrad doesn't support TLS")
            cxn = TCPClient(self.host, self.port, dv)
            cxn.startService()
            yield dv.onStartup()

            @inlineCallbacks
            def stop_func():
                yield cxn.stopService()

        returnValue(stop_func)
Exemple #9
0
    def start(self, dv):
        """Start the given DataVaultMultihead server.

        The server startup and shutdown logic changed in pylabrad 0.95, so we
        need separate logic to handle the old and new cases.

        Args:
            dv (DataVaultMultihead): The labrad server object that we want to
                start.

        Returns:
            A deferred that fires after the server has successfully started.
            This deferred contains a function that can be invoked to shutdown
            the server. That function itself returns a deferred that will fire
            when the shutdown is complete.
        """
        if hasattr(dv, 'startup'):
            # pylabrad 0.95+
            p = yield protocol.connect(self.host, self.port)
            yield p.authenticate(password=self.password)
            yield dv.startup(p)

            @inlineCallbacks
            def stop_func():
                dv.disconnect()
                yield dv.onShutdown()
        else:
            # pylabrad 0.94 and earlier
            try:
                dv.configure_tls(self.host, "starttls")
            except AttributeError:
                self.report("pylabrad doesn't support TLS")
            cxn = TCPClient(self.host, self.port, dv)
            cxn.startService()
            yield dv.onStartup()

            @inlineCallbacks
            def stop_func():
                yield cxn.stopService()

        returnValue(stop_func)
Exemple #10
0
    def run(self):
        """Run the node in a loop, reconnecting after connection loss."""
        log = logging.getLogger('labrad.node')
        while True:
            print('Connecting to {}:{}...'.format(self.host, self.port))
            try:
                p = yield protocol.connect(self.host, self.port, self.tls_mode,
                                           self.username, self.password)
                node = NodeServer(self.nodename, self.host, self.port,
                                  p.credential)
                yield node.startup(p)
            except Exception:
                log.error('Node failed to start', exc_info=True)
            else:
                try:
                    yield node.onShutdown()
                except Exception:
                    log.error('Error during node shutdown', exc_info=True)

            yield util.wakeupCall(0)
            print('Will try to reconnect in {} seconds...'.format(self.reconnectDelay))
            yield util.wakeupCall(self.reconnectDelay)
Exemple #11
0
 def start_server():
     p = yield protocol.connect(host, port, tls_mode)
     yield p.authenticate(password)
     yield srv.startup(p)
Exemple #12
0
 def start_server():
     p = yield protocol.connect(host, port, tls_mode, username, password)
     yield srv.startup(p)
Exemple #13
0
 def start_server():
     p = yield protocol.connect(host, port, tls_mode, username, password)
     yield srv.startup(p)