Exemplo n.º 1
0
def init_hostname_certname(): 
    hosts = {
        'linux2233.puppet.com':'template_1',
        'windows2233.puppet.com':'template_1',
        'linux22101.zjz.com':'template_1',
    }
    #主机名对应的模板添加到redis
    for key,value in hosts.items():
        rediscli.set(key, value)

def run(result):    
    
    while True:
        data = result.parse_response()
        get_info = json.loads(data[2])
        if get_info['level'] == 3:
            print '\033[31m %s \033[0m' %(get_info,)
        elif get_info['level'] == 2:
            print '\033[33m %s \033[0m' %(get_info,)
        elif get_info['level'] == 1:
            print '\033[32m %s \033[0m' %(get_info,)
        print '============================'
        
if __name__ == '__main__':
    rediscli = RedisHelper()
    result = rediscli.subscribe()
    templates = init_template()
    init_hostname_certname()
    push_config_to_redis(rediscli,templates)
    run(result)