Example #1
0
    def run(self):
        if conf.station_api_port is not None:
            self.station_api_server = xmlrpcutil.SimpleThreadedXmlRpcServer(
                (conf.station_api_bind_address, int(conf.station_api_port)),
                allow_none=True,
                logRequests=logging.getLogger().level <= logging.DEBUG)
            self.station_api_server.register_instance(STATION_API)

            # Discovery is useless if station_api is disabled, so we don't ever start
            # a MulticastListener if station_api_port isn't set, even if
            # enable_station_discovery is set.
            if conf.enable_station_discovery:
                self.multicast_listener = multicast.MulticastListener(
                    self.multicast_response, **MULTICAST_KWARGS())
                _LOG.debug('Listening for multicast discovery at %s:%s',
                           self.multicast_listener.address,
                           self.multicast_listener.port)
                self.multicast_listener.start()

            # server_forever() doesn't return until we call stop()
            self.station_api_server.serve_forever()
            _LOG.debug(
                'Station API returned from serve_forever(), done serving.')
        else:
            _LOG.debug(
                'Started Station API, but station_api_port disabled, bailing.')
Example #2
0
    def __init__(self, executor, http_port, multicast_info=None):
        super(Server, self).__init__()

        def multicast_response(message):
            """Formulate a response to a station discovery ping."""
            if message == PING_STRING:
                return json.dumps({PING_RESPONSE_KEY: http_port})
            else:
                _LOG.debug(
                    'Received non-openhtf traffic on multicast socket: %s' %
                    message)

        self.servers = [
            HTTPServer(executor, http_port),
            multicast.MulticastListener(multicast_response,
                                        **(multicast_info or {}))
        ]