Skip to content

Commit

Permalink
update example and few cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkala committed Feb 5, 2025
1 parent 061ecf0 commit 1351a26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions examples/basic_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
from netutils.lib_mapper import NAPALM_LIB_MAPPER_REVERSE
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from nornir_nautobot.plugins.tasks.dispatcher import dispatcher
Expand All @@ -24,8 +25,8 @@
my_nornir.inventory.defaults.password = os.getenv("NORNIR_PASSWORD")

for nr_host, nr_obj in my_nornir.inventory.hosts.items():
network_driver = my_nornir.inventory.hosts[nr_host].platform
my_nornir.inventory.hosts[nr_host].platform = "ios"
network_driver = my_nornir.inventory.hosts[nr_host].data["pynautobot_object"].platform.network_driver
my_nornir.inventory.hosts[nr_host].platform = NAPALM_LIB_MAPPER_REVERSE.get(network_driver)
result = my_nornir.run(
task=dispatcher,
logger=LOGGER,
Expand All @@ -37,14 +38,13 @@
print_result(result)

for nr_host, nr_obj in my_nornir.inventory.hosts.items():
network_driver = my_nornir.inventory.hosts[nr_host].platform
my_nornir.inventory.hosts[nr_host].platform = "ios"
result = my_nornir.run(
task=dispatcher,
logger=LOGGER,
method="get_command",
obj=nr_host,
framework="netmiko",
command="show version",
use_textfsm=True,
)
print_result(result)
print_result(result)
4 changes: 3 additions & 1 deletion nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def get_command(cls, task: Task, logger, obj, command, **kwargs):

if result[0].failed:
return result
return Result(host=task.host, result={"output": result[0].result})

@classmethod
def replace_config(
Expand Down Expand Up @@ -386,7 +387,7 @@ def replace_config(
)

@classmethod
def merge_config(
def merge_config( # pylint: disable=too-many-positional-arguments
cls,
task: Task,
logger,
Expand Down Expand Up @@ -603,6 +604,7 @@ def merge_config(
@classmethod
def get_command(cls, task: Task, logger, obj, command, **kwargs):
"""A tasks to get the commands from a device.
Args:
task (Task): Nornir Task.
logger (logging.Logger): Logger that may be a Nautobot Jobs or Python logger.
Expand Down

0 comments on commit 1351a26

Please sign in to comment.