コード例 #1
0
ファイル: haproxy.py プロジェクト: munjalpatel/haproxy
def main():
    logging.basicConfig(stream=sys.stdout)
    logging.getLogger("tutum_haproxy").setLevel(
        logging.DEBUG if DEBUG else logging.INFO)

    # Tell the user the mode of autoupdate we are using, if any
    if TUTUM_SERVICE_API_URI and TUTUM_CONTAINER_API_URI:
        if TUTUM_AUTH:
            logger.info(
                "HAProxy has access to Tutum API - will reload list of backends in real-time"
            )
        else:
            logger.warning(
                "HAProxy doesn't have access to Tutum API and it's running in Tutum - you might want to give "
                "an API role to this service for automatic backend reconfiguration"
            )
    else:
        logger.info("HAProxy is not running in Tutum")

    if TUTUM_SERVICE_API_URI and TUTUM_CONTAINER_API_URI and TUTUM_AUTH:
        init_tutum_settings()
        events = tutum.TutumEvents()
        events.on_open(run_tutum)
        events.on_message(tutum_event_handler)
        events.run_forever()
    else:
        while True:
            run()
            time.sleep(1)
コード例 #2
0
def main():
    logging.basicConfig(stream=sys.stdout)
    logging.getLogger("haproxy").setLevel(
        logging.DEBUG if DEBUG else logging.INFO)

    if Haproxy.cls_container_uri and Haproxy.cls_service_uri:
        if Haproxy.cls_tutum_auth:
            logger.info(
                "HAProxy has access to Tutum API - will reload list of backends in real-time"
            )
        else:
            logger.warning(
                "HAProxy doesn't have access to Tutum API and it's running in Tutum - you might want to give "
                "an API role to this service for automatic backend reconfiguration"
            )
    else:
        logger.info("HAProxy is not running in Tutum")

    if Haproxy.cls_container_uri and Haproxy.cls_service_uri and Haproxy.cls_tutum_auth:
        events = tutum.TutumEvents()
        events.on_open(run_haproxy)
        events.on_message(tutum_event_handler)
        events.run_forever()
    else:
        run_haproxy()
コード例 #3
0
ファイル: main.py プロジェクト: versus/haproxy
def main():
    logging.basicConfig(stream=sys.stdout)
    logging.getLogger("haproxy").setLevel(logging.DEBUG if DEBUG else logging.INFO)

    pid = create_pid_file()
    signal.signal(signal.SIGUSR1, user_reload_haproxy)
    signal.signal(signal.SIGTERM, sys.exit)

    if Haproxy.cls_container_uri and Haproxy.cls_service_uri:
        if Haproxy.cls_tutum_auth:
            logger.info(
                    "Tutum-haproxy %s (PID: %s) has access to Tutum API - will reload list of backends in real-time" % (
                        __version__, pid))
        else:
            logger.warning(
                    "Tutum-haproxy %s (PID: %s) doesn't have access to Tutum API and it's running in Tutum - you might want to"
                    " give an API role to this service for automatic backend reconfiguration" % (__version__, pid))
    else:
        logger.info("Tutum-haproxy %s (PID: %s) is not running in Tutum" % (__version__, pid))

    if Haproxy.cls_container_uri and Haproxy.cls_service_uri and Haproxy.cls_tutum_auth:
        def _websocket_open():
            Haproxy.cls_linked_container_object_cache.clear()
            run_haproxy("Websocket open")

        events = tutum.TutumEvents()
        events.on_open(_websocket_open)
        events.on_close(lambda: logger.info("Websocket close"))
        events.on_message(tutum_event_handler)
        events.run_forever()
    else:
        run_haproxy("Initial start")
コード例 #4
0
ファイル: client.py プロジェクト: WebTales/tutum-stream
import os
import tutum


def on_message(event):
    if event.get("state", "") not in [
            "In progress", "Pending", "Terminating", "Starting", "Scaling",
            "Stopping"
    ] and event.get("type", "").lower() in ["container", "service"]:
        msg = "Tutum event: %s %s is %s" % (
            event["type"], str(event.get(
                "resource_uri", "")).split('/')[-2], event["state"].lower())
        print(msg)


if __name__ == "__main__":
    events = tutum.TutumEvents()
    events.on_message(on_message)
    events.run_forever()