为什么在TypeError 'num_workers'中得到一个意外的关键字参数:__init__()?


from nornir import InitNornir
from nornir_napalm.plugins.tasks import napalm_get
from nornir_utils.plugins.functions import print_result
import json
def prettyPrintDictionary(dict):
print(json.dumps(dict, indent=2))

nr = InitNornir(config_file="/home/python/nornir-scripts/config.yaml")
print(nr.inventory.hosts)

prettyPrintDictionary(nr.inventory.get_hosts_dict())
# config.yaml
inventory:
plugin: SimpleInventory
options:
host_file: '/home/python/nornir-scripts/inventory/hosts.yaml'
group_file: '/home/python/nornir-scripts/inventory/groups.yaml'
defaults_file: '/home/python/nornir-scripts/inventory/defaults.yaml'
runner:
plugin: threaded
options:
num_workers: 100

请帮忙我不明白如何初始化nornir我试着在导游的指导下做这件事,但也有错误。现在我犯了这个错误。。。

根据文档,num_workers密钥应该在runner.options密钥内。将其添加到options密钥并重试:

inventory:
plugin: nornir.plugins.inventory.simple.SimpleInventory
options:
host_file: 'inventory/hosts.yaml'
group_file: 'inventory/groups.yaml'
defaults_file: 'inventory/defaults.yaml'
runner:
plugin: threaded
options:
num_workers: 100

相关内容

  • 没有找到相关文章

最新更新