From 984e9d72bad4da6f7494a345b17f1f25f83c645b Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 29 Nov 2023 11:59:10 -0800 Subject: [PATCH] Adding additional netbox files --- bonus2/collateral/netbox/defaults.yaml | 3 ++ bonus2/collateral/netbox/nbox_test.py | 45 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 bonus2/collateral/netbox/defaults.yaml create mode 100644 bonus2/collateral/netbox/nbox_test.py diff --git a/bonus2/collateral/netbox/defaults.yaml b/bonus2/collateral/netbox/defaults.yaml new file mode 100644 index 0000000..a144ff1 --- /dev/null +++ b/bonus2/collateral/netbox/defaults.yaml @@ -0,0 +1,3 @@ +--- +username: pyclass +password: bogus123 diff --git a/bonus2/collateral/netbox/nbox_test.py b/bonus2/collateral/netbox/nbox_test.py new file mode 100644 index 0000000..d68b811 --- /dev/null +++ b/bonus2/collateral/netbox/nbox_test.py @@ -0,0 +1,45 @@ +import os +import pdbr + +from nornir import InitNornir +from nornir.core.filter import F + + +NBOX_TOKEN = os.environ.get("NETBOX_TOKEN", "sad, no token") + + +def nbox_task(task): + print(task.host["site"]["name"]) + + +def main(): + nr = InitNornir( + config_file="config.yaml", + inventory={ + "plugin": "NetBoxInventory2", + "options": { + "nb_token": NBOX_TOKEN, + "nb_url": "https://netbox.lasthop.io", + "ssl_verify": False, + # "filter_parameters": {"site": "aws-us-west1"}, + # "filter_parameters": {"site": "fremont-dc"}, + # "use_platform_slug": True, + # + # Newer Netbox (roughly NetBox 3.5) doesn't support this directly + # "use_platform_napalm_driver": True, + }, + }, + ) + pdbr.set_trace() + + cisco1 = nr.inventory.hosts["cisco1"] + + # Filter after loaded + fremont = nr.filter(F(groups__contains="site__fremont-dc")) + cisco = nr.filter(F(groups__contains="manufacturer__cisco")) + + nr.run(task=nbox_task) + + +if __name__ == "__main__": + main()