示例#1
0
def check(_dict, check_exist=True):
    """ 检查 name, vip 或 lb 是否已经存在.

    _dict 格式如下:
        {
            "name": name,
            "vips": vips,
            "lbs": lbs
        }

    当 check_exist 为 True 时, _dict 中的信息即使有一个不存在, 返回 False;
    当 check_exist 为 False 时, _dict 中的信息即使有一个存在, 返回 False;

    """
    for key in _dict:
        if key == "name":
            name = _dict[key]
            if check_exist and not client.keys("cluster:" + name):
                return False
            if not check_exist and client.keys("cluster:" + name):
                return False
        else:
            if key == "vips":
                for v in _dict[key]:
                    if check_exist and v not in info.vips():
                        return False
                    if not check_exist and v in info.vips():
                        return False
            elif key == "lbs":
                for v in _dict[key]:
                    if check_exist and v not in info.lbs():
                        return False
                    if not check_exist and v in info.lbs():
                        return False
    return True
示例#2
0
    def get(self):
        """ 查看 lb 列表.

        """
        self.write(json.dumps(info.lbs()))
示例#3
0
    def get(self):
        """ 查看 lb 列表.

        """
        self.write(json.dumps(info.lbs()))