为什么得到一个意外的关键字参数“num\u workers”,其类型为错误:\uuuu init\uuuu()?

2024-05-21 01:51:45 发布

您现在位置:Python中文网/ 问答频道 /正文

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 我试着用指南来做,但也有错误。 现在我犯了这个错误


Tags: fromimportconfigyamlhomescriptsnrdict
1条回答
网友
1楼 · 发布于 2024-05-21 01:51:45

根据documentationnum_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

相关问题 更多 >