python-3.x - (Python) Netmiko : 将路由器的配置与模板进行比较
问题描述
我想使用 netmiko 库在 txt 文件中的路由器配置和模板之间进行比较。
使用“show run”命令显示所有路由器配置,必须逐块进行比较,例如:命令输出中的“access-list snmp”块与模板中的“access-list snmp”块等等,因为某些 permet xxxx 在 3 个 ACL 中重复,我必须检查它们是否在这 3 个 ACL 中。
我不知道如何进行此比较,如果您有任何想法,请帮助我。
我试图用这段代码来做,但这里的比较是逐行完成的:
cisco = {
'device_type': 'cisco_ios',
'host': 'router',
'username': 'admin',
'password': 'cisco123',
}
try
ssh = ConnectHandler(**cisco)
ssh.send_command('terminal length 0')
output = ssh.send_command("show run")
except Exception as e:
# exceptions
try:
template_file = open("template.txt", "r")
for l in file:
line = l.strip()
if line not in output:
f = open("ligne_not_in_config.txt", "a")
f.write(l, "is not in config\n")
except FileNotFoundError as e:
# exceptions
解决方案
推荐阅读
- cmake - 看不懂cmake中set(var val ${var})的用法
- python - 选择输入字段时如何修复“不允许复合类名”异常
- mysql - MySQL max date 生成不正确的输出
- git - 撤消所有本地已提交但未在 git 中推送的文件
- java - 为什么带有 list.add 的嵌套循环会给出 O(n^4) 时间复杂度?
- javascript - 如何动态创建 Javascript/Jquery 事件?
- javascript - MUI 数据表服务器端渲染
- python - Flask,Bcrypt - ImportError:没有名为 ext.bcrypt 的模块
- bash - 将手册复制到剪贴板
- swift - Firebase Xcode Swift - 卡在 downloadURL