How to use the nornir.plugins.tasks.networking.netmiko_send_command function in nornir

To help you get started, we’ve selected a few nornir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twin-bridges / nornir_course / class6 / collateral / troubleshooting / test_netmiko_slog1.py View on Github external
def uptime(task):
    cmd_mapper = {
        "ios": "show version | inc uptime",
        "eos": "show version | inc Uptime",
        "nxos": "show version | inc uptime",
        "junos": "show system uptime | match System",
    }

    host = task.host
    platform = host.platform
    cmd = cmd_mapper[platform]

    multi_result = task.run(task=networking.netmiko_send_command, command_string=cmd)
    print(multi_result)
github twr14152 / Network-Automation-Scripts_Python3 / Nornir / using_netmiko_plugin / show_cmds_example.py View on Github external
from nornir.core import InitNornir
from nornir.plugins.tasks.networking import netmiko_send_command
from nornir.plugins.functions.text import print_result

commands = input("Enter commands: ")
cmds = commands.split(",")

for cmd in cmds:
    nr = InitNornir()

    result = nr.run(
        task=netmiko_send_command,
        command_string=cmd
     )

    print_result(result)
github twin-bridges / nornir_course / class2 / exercises / exercise5 / exercise5a.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    ios_filt = F(groups__contains="ios")
    nr = nr.filter(ios_filt)
    my_results = nr.run(task=netmiko_send_command, command_string="show ip int brief")
    print_result(my_results)
github twin-bridges / nornir_course / class6 / exercises / exercise1 / exercise1a.py View on Github external
def send_command(task):
    task.run(
        task=networking.netmiko_send_command,
        command_string="set cli complete-on-space off",
    )
    task.run(task=networking.netmiko_send_command, command_string="show ip interface")
github twin-bridges / nornir_course / class2 / exercises / exercise5 / exercise5c.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    ios_filt = F(groups__contains="ios")
    nr = nr.filter(ios_filt)

    # Set one of the devices to an invalid password
    nr.inventory.hosts["cisco3"].password = "bogus"
    my_results = nr.run(task=netmiko_send_command, command_string="show ip int brief")
    print()
    print_result(my_results)
    print()
    print(f"Task failed hosts: {my_results.failed_hosts}")
    print(f"Global failed hosts: {nr.data.failed_hosts}")
    print()

    # Re-set password back to valid value
    nr.inventory.hosts["cisco3"].password = os.environ["NORNIR_PASSWORD"]

    # Nornir doesnt reset connection for failed hosts causing issues
    print(nr.inventory.hosts["cisco3"].connections)
    try:
        nr.inventory.hosts["cisco3"].close_connections()
    except ValueError:
        pass
github twin-bridges / nornir_course / class6 / exercises / exercise4 / exercise4b.py View on Github external
def log_send_command(task):
    log_file = f"{task.host}_session.log"
    # Obtain the group object using the "refs" attribute
    group = task.host.groups.refs[0]
    group.connection_options["netmiko"].extras["session_log"] = log_file
    task.run(
        task=networking.netmiko_send_command, command_string="show mac address-table"
    )
github twin-bridges / nornir_course / class6 / collateral / enable_secret / enable_secret.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    nr = nr.filter(name="arista1")
    agg_result = nr.run(
        task=networking.netmiko_send_command,
        command_string="show run | i hostname",
        enable=True,
    )
    print(agg_result["arista1"].result)
github twin-bridges / nornir_course / class2 / exercises / exercise2 / exercise2c.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    filt = F(groups__contains="ios")
    nr = nr.filter(filt)
    my_results = nr.run(
        task=netmiko_send_command, command_string="show run | i hostname"
    )
    host_results = my_results["cisco3"]

    print()
    print(type(host_results))
    print(repr(host_results[0]))
    print(host_results.__iter__)
    print()
github twin-bridges / nornir_course / class2 / exercises / exercise2 / exercise2d.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    filt = F(groups__contains="ios")
    nr = nr.filter(filt)
    my_results = nr.run(
        task=netmiko_send_command, command_string="show run | i hostname"
    )
    host_results = my_results["cisco3"]
    task_result = host_results[0]

    print()
    print(type(task_result))
    print(
        f"Host: {task_result.host}\n"
        f"Task Name: {task_result.name}\n"
        f"Failed: {task_result.failed}\n"
        f"Result: {task_result.result}"
    )
    print()
github ktbyers / pynet / nornir / os_upgrade / part2 / netmiko_file_transfer_3.py View on Github external
std_print(result)

    # Reload
    continue_func(msg="Do you want to reload the device (y/n)? ")
    result = brg_ios.run(
        netmiko_send_command,
        use_timing=True,
        command_string="reload",
        num_workers=1,
    )

    # Confirm the reload (if 'confirm' is in the output)
    for device_name, multi_result in result.items():
        if 'confirm' in multi_result[0].result:
            result = brg_ios.run(
                netmiko_send_command,
                use_timing=True,
                command_string="y",
            )

    print("Devices reloaded")