Example #1
0
    def _recv_loop(self):
        while True:
            try:
                msg = self.parser.send(self.mode)
            except Exception as e:
                logger.info("Stopping recv thread due to exception %s", e)
                return

            ele = etree.fromstring(msg)
            if ele.xpath("/nc:rpc-reply", namespaces=NAMESPACES):
                try:
                    f = self.rpc_reply_futures.get(block=False)

                    if ele.xpath("/nc:rpc-reply/nc:rpc-error",
                                 namespaces=NAMESPACES):
                        f.set_exception(RpcError(msg, ele))
                    else:
                        f.set_result((msg, ele))
                    self.rpc_reply_futures.task_done()
                    msg = None
                except Empty:
                    logger.warning(
                        "An <rpc-reply> was received "
                        "with no corresponding handler: %s",
                        msg,
                    )
            elif ele.xpath("/notif:notification", namespaces=NAMESPACES):
                self.notifications.put((msg, ele))
                msg = None

            if msg is not None:
                self.unknown_recvq.put((msg, ele))
Example #2
0
    def accept_one(self, timeout=120):
        """Accept a single TCP client and returns it

        :param int timeout: Seconds to wait for an incoming connection

        """
        self.server_socket.settimeout(timeout)
        (sock, remote_host) = self.server_socket.accept()
        self.server_socket.settimeout(None)
        logger.info("Callhome connection initiated from remote host %s",
                    remote_host)
        return sock