Nornir 获取cisco设备接口信息-LAB
拓扑:
创建、进入、退出虚拟环境:
创建:python3 -m venv test
进入: source /root/test/bin/activate
退出: deactivate
依赖库:
nornir==3.1.1
nornir-napalm==0.1.2
nornir-netmiko==0.1.1
nornir-utils==0.1.2
napalm==3.3.1
netmiko==3.4.0
nornir-jinja2==0.2.0
scrapli==2021.7.30
ipdb==0.13.9
ncclient==0.6.9
文件配置:
nornir.py |
from nornir import InitNornir from nornir_napalm.plugins.tasks import napalm_get from nornir_utils.plugins.functions import print_result nr = InitNornir(config_file="config.yaml") results = nr.run(task=napalm_get, getters=["facts", "interfaces"]) print_result(results) |
config.yaml |
--- inventory: plugin: SimpleInventory options: host_file: "inventory/hosts.yaml" group_file: "inventory/groups.yaml" defaults_file: "inventory/defaults.yaml" runner: plugin: threaded options: num_workers: 100 |
Directory:
|
运行结果:
引用:
Nornir官方文档
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步