예제 #1
0
파일: task_execute.py 프로젝트: Chanran/app
def get_a_api_url():
    """
    获取一个API服务器地址
    :return:
    """

    objs = ContainerServerModel.select().where(ContainerServerModel.status == 0).order_by(ContainerServerModel.sort.desc())
    d = [999999, 999999, None, None]
    for obj in objs:
        url = "http://%s:%d/container/" % (obj.server_host, obj.server_port)
        r = request_api(url+"analy", {})
        if r.status_code != 200:
            continue

        response_data_obj = json.loads(r.text)
        if response_data_obj['code'] != 0:
            continue
        if response_data_obj['result']['count'] < d[0] and response_data_obj['result']['totalMemory'] < d[1]:
            d[2] = obj
            d[0] = response_data_obj['result']['count']
            d[1] = response_data_obj['result']['totalMemory']
            d[3] = {"url": url, "server_host": obj.server_host}
    if d[2] is None:
        return None
    login_log("containerAPI", "获取到的API服务器为:%s:%d,当前容器数:%d,容器内存:%dM" %(d[2].server_host, d[2].server_port, d[0], d[1]))
    return d[3]['url'], d[3]['server_host']
예제 #2
0
def get_a_api_url():
    """
    获取一个API服务器地址
    :return:
    """

    objs = ContainerServerModel.select().where(
        ContainerServerModel.status == 0).order_by(
            ContainerServerModel.sort.desc())
    d = [999999, 999999, None, None]
    for obj in objs:
        url = "http://%s:%d/container/" % (obj.server_host, obj.server_port)
        r = request_api(url + "analy", {})
        if r.status_code != 200:
            continue

        response_data_obj = json.loads(r.text)
        if response_data_obj['code'] != 0:
            continue
        if response_data_obj['result']['count'] < d[0] and response_data_obj[
                'result']['totalMemory'] < d[1]:
            d[2] = obj
            d[0] = response_data_obj['result']['count']
            d[1] = response_data_obj['result']['totalMemory']
            d[3] = {"url": url, "server_host": obj.server_host}
    if d[2] is None:
        return None
    login_log(
        "containerAPI", "获取到的API服务器为:%s:%d,当前容器数:%d,容器内存:%dM" %
        (d[2].server_host, d[2].server_port, d[0], d[1]))
    return d[3]['url'], d[3]['server_host']
예제 #3
0
파일: admin.py 프로젝트: Chanran/app
def get_servers():
    """
    获取所有的容器服务器
    :return:
    """
    lists = ContainerServerModel.select().where(ContainerServerModel.status != 2).order_by(ContainerServerModel.sort.desc(), ContainerServerModel.id.desc())
    objs = list(map(ContainerServerModel.get_dict_from_obj, lists))

    return json.dumps(objs)
예제 #4
0
파일: admin.py 프로젝트: mumulizi/app
def get_servers():
    """
    获取所有的容器服务器
    :return:
    """
    lists = ContainerServerModel.select().where(
        ContainerServerModel.status != 2).order_by(
            ContainerServerModel.sort.desc(), ContainerServerModel.id.desc())
    objs = list(map(ContainerServerModel.get_dict_from_obj, lists))

    return json.dumps(objs)