Esempio n. 1
0
def list_threebot_solutions(owner):
    result = []
    owner = text.removesuffix(owner, ".3bot")
    cursor, _, threebots = USER_THREEBOT_FACTORY.find_many(owner_tname=owner)
    threebots = list(threebots)
    while cursor:
        cursor, _, result = USER_THREEBOT_FACTORY.find_many(cursor, owner_tname=owner)
        threebots += list(result)
    for threebot in threebots:
        zos = get_threebot_zos(threebot)
        grouped_identity_workloads = group_threebot_workloads_by_uuid(threebot, zos)
        workloads = grouped_identity_workloads.get(threebot.solution_uuid)
        if not workloads:
            continue
        solution_info = build_solution_info(workloads, threebot)
        if "ipv4" not in solution_info or "domain" not in solution_info:
            continue
        solution_info["solution_uuid"] = threebot.solution_uuid
        solution_info["farm"] = threebot.farm_name
        solution_info["state"] = threebot.state.value
        solution_info["continent"] = threebot.continent
        compute_pool = zos.pools.get(solution_info["compute_pool"])
        solution_info["expiration"] = compute_pool.empty_at
        if not compute_pool:
            continue
        if threebot.state == ThreebotState.RUNNING and compute_pool.empty_at == 9223372036854775807:
            solution_info["state"] = ThreebotState.STOPPED.value
            threebot.state = ThreebotState.STOPPED
            threebot.save()
        result.append(solution_info)
    return result
Esempio n. 2
0
def list_threebot_solutions(owner):
    result = []
    owner = text.removesuffix(owner, ".3bot")
    cursor, _, threebots = USER_THREEBOT_FACTORY.find_many(owner_tname=owner)
    threebots = list(threebots)
    while cursor:
        cursor, _, result = USER_THREEBOT_FACTORY.find_many(cursor,
                                                            owner_tname=owner)
        threebots += list(result)

    def get_threebot_info(threebot):
        zos = get_threebot_zos(threebot)
        grouped_identity_workloads = group_threebot_workloads_by_uuid(
            threebot, zos)
        workloads = grouped_identity_workloads.get(threebot.solution_uuid)
        if not workloads:
            return
        solution_info = build_solution_info(workloads, threebot)
        if "ipv4" not in solution_info or "domain" not in solution_info:
            return
        solution_info["solution_uuid"] = threebot.solution_uuid
        solution_info["farm"] = threebot.farm_name
        solution_info["state"] = threebot.state.value
        solution_info["continent"] = threebot.continent
        compute_pool = zos.pools.get(solution_info["compute_pool"])
        solution_info["expiration"] = compute_pool.empty_at
        if not compute_pool:
            return

        domain = f"https://{zos.workloads.get(threebot.subdomain_wid).domain}/admin"
        reachable = j.sals.reservation_chatflow.check_url_reachable(
            domain, timeout=10, verify=not j.config.get("TEST_CERT"))
        if (threebot.state in [
                ThreebotState.RUNNING, ThreebotState.ERROR,
                ThreebotState.STOPPED
        ] and compute_pool.empty_at == 9223372036854775807):
            solution_info["state"] = ThreebotState.STOPPED.value
            threebot.state = ThreebotState.STOPPED
            threebot.save()
        # check it the 3bot is reachable
        elif threebot.state == ThreebotState.RUNNING and not reachable:
            solution_info["state"] = ThreebotState.ERROR.value
            threebot.state = ThreebotState.ERROR
            threebot.save()
        elif threebot.state == ThreebotState.ERROR and reachable:
            solution_info["state"] = ThreebotState.RUNNING.value
            threebot.state = ThreebotState.RUNNING
            threebot.save()
        elif reachable:
            solution_info["state"] = ThreebotState.RUNNING.value
            threebot.state = ThreebotState.RUNNING
            threebot.save()

        result.append(solution_info)

    threads = []
    for threebot in threebots:
        thread = gevent.spawn(get_threebot_info, threebot)
        threads.append(thread)
    gevent.joinall(threads)
    return result