How to use the nornir.plugins.tasks.networking.napalm_get 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 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"]
github ctopher78 / network-automation-course / Homework2 / render_bgp_topology.py View on Github external
def main():

    devices = InitNornir(
    core={"num_workers": 100},
    inventory={
        "plugin": "nornir.plugins.inventory.simple.SimpleInventory",
        "options": {
            "host_file": "inventory/hosts.yaml",
            "group_file": "inventory/groups.yaml"
            }
        }
    )

    results = devices.run(task=networking.napalm_get, getters=["get_bgp_neighbors_detail"])

    bgp = dict()
    for k, v in results.items():
        bgp[k] = v.result["get_bgp_neighbors_detail"]["global"]

    env = Environment(
        loader=PackageLoader('render_bgp_topology', 'templates'),
        autoescape=select_autoescape(['html'])
    )

    template = env.get_template('js.jinja')

    rendered = template.render(netdev_bgp=bgp)

    with open("bgp_topology.html", "w+") as fh:
        fh.write(rendered)
github twin-bridges / nornir_course / class3 / exercises / exercise6 / exercise6a.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    nr = nr.filter(F(groups__contains="nxos"))
    agg_result = nr.run(task=napalm_get, getters=["config"])
    print_result(agg_result)
github twin-bridges / nornir_course / class2 / collateral / nornir_napalm_plugins / napalm_example / napalm_lldp.py View on Github external
from pprint import pprint
from nornir import InitNornir
from nornir.plugins.tasks.networking import napalm_get

nr = InitNornir(config_file="nornir.yaml")
results = nr.run(task=napalm_get, getters=["lldp_neighbors"])

print()
for k, v in results.items():
    print("-" * 50)
    print(k)
    pprint(v[0].result)
    print("-" * 50)
print()
github twin-bridges / nornir_course / class4 / exercises / exercise5 / exercise5b.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    nr = nr.filter(name="arista4")

    # Current running config
    agg_result = nr.run(
        task=networking.napalm_get, getters=["config"], retrieve="running"
    )
    arista4_result = agg_result["arista4"][0].result
    arista4_running_config = arista4_result["config"]["running"]  # noqa

    # New config
    config = """
interface loopback123
  description verycoolloopback
    """
    agg_result = nr.run(task=networking.napalm_configure, configuration=config)
    print_result(agg_result)
github twin-bridges / nornir_course / class2 / collateral / nornir_napalm_plugins / enable / napalm_config.py View on Github external
from nornir import InitNornir
from nornir.plugins.tasks.networking import napalm_get
from pprint import pprint

nr = InitNornir(config_file="nornir.yaml")
results = nr.run(task=napalm_get, getters=["config"])

print()
for k, v in results.items():
    print("-" * 50)
    print(k)
    pprint(v[0].result)
    print("-" * 50)
print()
github twin-bridges / nornir_course / bonus1 / exercises / exercise2 / exercise2b.py View on Github external
def main():
    nr = InitNornir(config_file="config_b.yaml")
    nr = nr.filter(F(groups__contains="nxos"))
    agg_result = nr.run(task=networking.napalm_get, getters=["facts"])
    print_result(agg_result)
github writememe / day-one-net-toolkit / day-one-toolkit.py View on Github external
# Assign facts directory to variable
    fact_dir = "facts"
    # Assign hostname directory to a variable
    host_dir = task.host.name
    # Assign the destination directory to a variable. i.e facts/hostname/
    entry_dir = fact_dir + "/" + host_dir
    # If Else to handle creating directories. Default is to create them
    if dir is False:
        # Create facts directory
        pathlib.Path(fact_dir).mkdir(exist_ok=True)
        # Create entry directory
        pathlib.Path(entry_dir).mkdir(exist_ok=True)
    # Try/except block to catch exceptions, such as NotImplementedError
    try:
        # Gather facts using napalm_get and assign to a variable
        facts_result = task.run(task=napalm_get, getters=[getter])
        # Write the results to a JSON, using the convention .json
        task.run(
            task=write_file,
            content=json.dumps(facts_result[0].result[getter], indent=2),
            filename=f"" + str(entry_dir) + "/" + str(getter) + ".json",
        )
    # Handle NAPALM Not Implemented Error exceptions
    except NotImplementedError:
        return "Getter Not Implemented"
    except AttributeError:
        return "AttributeError: Driver has no attribute"
github twin-bridges / nornir_course / class4 / exercises / exercise5 / exercise5a.py View on Github external
def main():
    nr = InitNornir(config_file="config.yaml")
    nr = nr.filter(name="arista4")
    agg_result = nr.run(
        task=networking.napalm_get, getters=["config"], retrieve="running"
    )
    arista4_result = agg_result["arista4"][0].result
    arista4_running_config = arista4_result["config"]["running"]

    file_name = "arista4-running.txt"
    with open(file_name, "w") as f:
        f.write(arista4_running_config)
    print()
    print("#" * 40)
    print(arista4_running_config)
    print("#" * 40)
    print()