예제 #1
0
파일: receiver.py 프로젝트: notner/Medusa
def main():
    control = Control()

    communicate.listen()

    while True:
        control.action, control.option = communicate.accept()

        log.write("Received action '%s' and option '%s'." % (control.action,
                                                             control.option))

        control.get_state()

        if control.state == "Ended":
            control.stop()

            api.action("stop")

        log.write("Performing action '%s'." % (control.action))

        if control.action == "restart":
            break

        try:
            action_result = getattr(control, control.action)()

            if action_result:
                communicate.reply(action_result)

        except Exception as error:
            log.error("Failed to perform action '%s': %s." % (control.action,
                                                              error))

            continue
예제 #2
0
파일: webmote.py 프로젝트: notner/Medusa
def check_alive_receivers(receivers):
    """Check to make sure that all Receivers passed through will respond to
    a socket communication request. If the request fails, clear the database
    entry.

    Return a list of all alive (responding) Receivers.

    """
    if not receivers:
        return []

    alive_receivers = []

    for rcv in receivers:
        try:
            communicate.receiver_hostname = rcv["host"]

            with communicate:
                communicate.send("get_status")

                # The content of the status check is not important.
                communicate.receive()

            alive_receivers.append(rcv)

        except IOError as error:
            log.error("Clearing dead Receiver '%s': %s." % (rcv["host"],
                                                            error))

            # This removes the Receiver database entry entirely.
            api("delete", rcv["host"])

    return alive_receivers