Пример #1
0
def remove_some_container(task, number):
    """
    删除若干个容器
    :param task:
    :param number:
    :return:
    """

    containers = AppContainModel.select().where(AppContainModel.app_id == task.app_id).limit(number)
    for obj in containers:
        api_url = obj.api_url + "remove"
        data = {
            "containerId": obj.container_id
        }
        r = request_api(api_url, data)
        if r.status_code == 200:
            d = json.loads(r.text)
            if d['code'] == 0:
                # 删除容器成功
                dao = AppContainModel.delete().where(AppContainModel.id == obj.id)
                dao.execute()
                login_log("common", "删除容器成功,触发应用id:%d,容器id:%s,容器服务器域名:%s" % (task.app_id, obj.container_id, obj.host))
                continue
        # 删除出错处理
        login_log("error", "删除容器失败,触发应用id:%d,容器id:%s,容器服务器域名:%s" % (task.app_id, obj.container_id, obj.host))

    return None
Пример #2
0
def remove_some_container(task, number):
    """
    删除若干个容器
    :param task:
    :param number:
    :return:
    """

    containers = AppContainModel.select().where(
        AppContainModel.app_id == task.app_id).limit(number)
    for obj in containers:
        api_url = obj.api_url + "remove"
        data = {"containerId": obj.container_id}
        r = request_api(api_url, data)
        if r.status_code == 200:
            d = json.loads(r.text)
            if d['code'] == 0:
                # 删除容器成功
                dao = AppContainModel.delete().where(
                    AppContainModel.id == obj.id)
                dao.execute()
                login_log(
                    "common", "删除容器成功,触发应用id:%d,容器id:%s,容器服务器域名:%s" %
                    (task.app_id, obj.container_id, obj.host))
                continue
        # 删除出错处理
        login_log(
            "error", "删除容器失败,触发应用id:%d,容器id:%s,容器服务器域名:%s" %
            (task.app_id, obj.container_id, obj.host))

    return None
Пример #3
0
for t in objs:
    obj['id'] = t[0]
    obj['api_url'] = t[1]
    obj['container_id'] = t[2]
    obj['app_id'] = t[3]
    obj['host'] = t[4]
    obj['port'] = t[5]
    login_log("maintain", "发现孤儿容器,所属应用id:%d,容器id:%s,容器域名:%s,容器端口:%d" % (obj['app_id'],
                                                                        obj['container_id'], obj['host'], obj['port']))
    api_url = obj['api_url'] + "remove"
    data = {
        "containerId": obj['container_id']
    }
    r = request_api(api_url, data)
    if r.status_code == 200:
        d = json.loads(r.text)
        if d['code'] == 0:
            # 删除容器成功
            dao = AppContainModel.delete().where(AppContainModel.id == obj['id'])
            dao.execute()
            login_log("maintain", "删除孤儿容器成功,所属应用id:%d,容器id:%s,容器域名:%s,容器端口:%d" % (obj['app_id'],
                                                                                  obj['container_id'], obj['host'],
                                                                                  obj['port']))
            continue
    login_log("maintain_error", "删除孤儿容器失败,所属应用id:%d,容器id:%s,容器域名:%s,容器端口:%d" % (obj['app_id'],
                                                                                obj['container_id'], obj['host'],
                                                                                obj['port']))

close_connect(sqlite_db_use=False)
print("清除孤儿容器结束")