How to use nornir - 10 common examples

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 nornir-automation / nornir / tests / plugins / tasks / networking / test_napalm_configure.py View on Github external
def test_napalm_configure_change_commit(self, nornir):
        opt = {"path": THIS_DIR + "/test_napalm_configure_change_commit/step1"}
        configuration = "hostname changed-hostname"
        d = nornir.filter(name="dev3.group_2")
        d.run(connections.napalm_connection, optional_args=opt)
        result = d.run(
            networking.napalm_configure, dry_run=False, configuration=configuration
        )
        assert result
        for h, r in result.items():
            assert "+hostname changed-hostname" in r.diff
            assert r.changed
        opt = {"path": THIS_DIR + "/test_napalm_configure_change_commit/step2"}
        d.run(connections.napalm_connection, optional_args=opt)
        result = d.run(
            networking.napalm_configure, dry_run=True, configuration=configuration
        )
        assert result
        for h, r in result.items():
            assert "+hostname changed-hostname" not in r.diff
            assert not r.changed
github twin-bridges / nornir_course / tests / test_class4.py View on Github external
def remove_ex2_flash_files():
    # prep to ensure test files do not exist on devices
    nornir_inventory = gen_inventory_dict("~/nornir_inventory/")
    nr = InitNornir(inventory=nornir_inventory, logging=NORNIR_LOGGING)
    eos = nr.filter(F(groups__contains="eos"))

    # remove test files from eos flash
    eos.run(task=networking.netmiko_send_command, command_string="terminal dont-ask")
    eos.run(
        task=networking.netmiko_send_command,
        command_string="delete flash:arista_zzzzz.txt",
    )
github nornir-automation / nornir / tests / core / test_filter.py View on Github external
def test_negate_or_both_negate(self, nornir):
        f = ~F(site="site1") | ~F(role="www")
        filtered = sorted(list((nornir.inventory.filter(f).hosts.keys())))

        assert filtered == [
            "dev2.group_1",
            "dev3.group_2",
            "dev4.group_2",
            "dev5.no_group",
        ]
github nornir-automation / nornir / tests / plugins / functions / text / test_print_result.py View on Github external
def test_print_failed_with_severity(self, nornir):
        nornir.config.logging.configure()
        result = nornir.run(read_data)
        print_result(result, vars=["exception", "output"], severity_level=logging.ERROR)
github twin-bridges / nornir_course / tests / test_class4.py View on Github external
def remove_ex2_flash_files():
    # prep to ensure test files do not exist on devices
    nornir_inventory = gen_inventory_dict("~/nornir_inventory/")
    nr = InitNornir(inventory=nornir_inventory, logging=NORNIR_LOGGING)
    eos = nr.filter(F(groups__contains="eos"))

    # remove test files from eos flash
    eos.run(task=networking.netmiko_send_command, command_string="terminal dont-ask")
    eos.run(
        task=networking.netmiko_send_command,
        command_string="delete flash:arista_zzzzz.txt",
    )
github twin-bridges / nornir_course / tests / test_class4.py View on Github external
def remove_vlan():
    nornir_inventory = gen_inventory_dict("~/nornir_inventory/")
    nr = InitNornir(inventory=nornir_inventory, logging=NORNIR_LOGGING)
    ex3_hosts = nr.filter(F(groups__contains="eos") | F(groups__contains="nxos"))

    ex3_hosts.run(task=networking.netmiko_send_config, config_commands=["no vlan 123"])
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 nornir-automation / nornir / tests / plugins / functions / text / test_print_result.py View on Github external
def echo_task(task, msg="Nornir"):
    return Result(
        host=task.host,
        result="Hello from {}".format(msg),
        output="Hello from {}".format(msg),
    )
github nornir-automation / nornir / tests / plugins / functions / text / test_print_result.py View on Github external
def load_data(task):
    data = {"os": "Linux", "services": ["http", "smtp", "dns"]}
    return Result(host=task.host, result=data)
github nornir-automation / nornir / tests / plugins / tasks / networking / test_napalm_get.py View on Github external
def test_napalm_getters(self, nornir):
        opt = {"path": THIS_DIR + "/test_napalm_getters"}
        d = nornir.filter(name="dev3.group_2")
        d.run(connections.napalm_connection, optional_args=opt)
        result = d.run(networking.napalm_get, getters=["facts", "interfaces"])
        assert result
        for h, r in result.items():
            assert r.result["facts"]
            assert r.result["interfaces"]