拓扑:
创建、进入、退出虚拟环境:
创建: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官方文档