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'
评论列表
文章目录