首页 > 其他 > 详细

test

时间:2021-09-12 13:31:18      阅读:28      评论:0      收藏:0      [点我收藏+]
b1 = {"id": 1,"env":"PROD", "db_type":"mysql", "ip":"10.0.66.107"}
b2 = {"id": 2,"env":"PROD", "db_type":"mysql", "ip":"10.0.66.117"}
a = []
a.append(b1)
a.append(b2)
b3 = {"id": 3,"env":"TEST", "db_type":"mongodb", "ip":"10.0.66.127"}
b4 = {"id": 4,"env":"TEST", "db_type":"mysql", "ip":"10.0.66.137"}

a.append(b3)
a.append(b4)

b5 = {"id": 5,"env":"UAT", "db_type":"mysql", "ip":"10.0.66.147"}
b6 = {"id": 6,"env":"UAT", "db_type":"mysql", "ip":"10.0.66.157"}
a.append(b5)
a.append(b6)

b7 = {"id": 7,"env":"TEST", "db_type":"mysql", "ip":"10.0.66.117"}
b8 = {"id": 8,"env":"TEST", "db_type":"mysql", "ip":"10.0.66.117"}

a.append(b7)
a.append(b8)


def get_cmdblist(*cmdb_all_list, env=None, db_type=None, ip=None):
    # 根据 env, db_type, ip 的条件搜索返回值。如果三个参数都为空,则返回全部数据
    resdict = {}
    if env:
        resdict[env] = env
    if db_type:
        resdict[db_type] = db_type
    if ip:
        resdict[ip] = ip
    res = []
    if env == None and db_type == None and ip == None:
        return cmdb_all_list
    for item in cmdb_all_list:
        for i in item:
            #res.append(i)
            for k in resdict:
                if resdict[k] == i[k]:
                    print(resdict[k])
    #return res


get_cmdblist(a, env="UAT", ip="10.0.66.147")

 

test

原文:https://www.cnblogs.com/l10n/p/15252895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!