device_group_mgmt.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:NetMgmt 作者: that1guy15 项目源码 文件源码
def device_add(device, mgmt, role, network, username, password):
    device_conf = device + '.yaml'
    print device_conf
    device_dir = inv_dir + device + '/'
    print device_dir
    directory = os.path.dirname(device_dir) + '/'
    print directory
    if not os.path.exists(directory):
        os.makedirs(directory)
    target_dict = defaultdict(dict)
    target_dict[device]['name'] = device
    target_dict[device]['mgmt_ip'] = mgmt_ip
    target_dict[device]['role'] = role
    target_dict[device]['network'] = network
    target_dict[device]['username'] = username
    target_dict[device]['password'] = password

    with open(directory + device_conf, 'w') as outfile:
        yaml.add_representer(defaultdict, Representer.represent_dict)
        yaml.dump(target_dict, outfile, default_flow_style=False)
        return device + ' config added to inventory'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号