Esempio n. 1
0
def servers_runner(**kwargs):
    with db_session() as db:
        servers = get_servers(db)
    init_md5 = get_md5_for_file("ansible/project/server.yml")
    for server in servers:
        if "init" not in server.config or server.config["init"] != init_md5:
            server_runner.delay(server.id, **kwargs)
Esempio n. 2
0
async def servers_list(
    response: Response,
    db=Depends(get_db),
    user=Depends(get_current_active_user),
):
    """
    Get all servers
    """
    return paginate(get_servers(db, user))
Esempio n. 3
0
def traffic_runner():
    servers = get_servers(SessionLocal())
    for server in servers:
        priv_data_dir = prepare_priv_dir(server)
        ansible_runner.run_async(
            private_data_dir=priv_data_dir,
            project_dir="ansible/project",
            playbook="traffic.yml",
            extravars={"host": server.ansible_name},
            finished_callback=iptables_finished_handler(server),
        )
Esempio n. 4
0
async def servers_list(
        response: Response,
        offset: int = 0,
        limit: int = 100,
        db=Depends(get_db),
        user=Depends(get_current_active_user),
):
    """
    Get all servers
    """
    servers = get_servers(db, user)
    return servers
Esempio n. 5
0
async def servers_list(
    response: Response,
    offset: int = 0,
    limit: int = 100,
    db=Depends(get_db),
    user=Depends(get_current_active_user),
):
    """
    Get all servers
    """
    servers = jsonable_encoder(get_servers(db, user, offset, limit))
    # This is necessary for react-admin to work
    response.headers["Content-Range"] = f"0-9/{len(servers)}"
    if user.is_ops or user.is_superuser:
        return [ServerOpsOut(**server) for server in servers]
    return [ServerOut(**server) for server in servers]
Esempio n. 6
0
def traffic_runner():
    with db_session() as db:
        servers = get_servers(db)
    for server in servers:
        traffic_server_runner(server.id)
    clear_cache()
Esempio n. 7
0
def traffic_runner():
    with db_session() as db:
        servers = get_servers(db)
    for server in servers:
        traffic_server_runner.delay(server.id)