Skip to content

Commit

Permalink
Adding additional netbox files
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Nov 29, 2023
1 parent 73e354b commit 984e9d7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bonus2/collateral/netbox/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
username: pyclass
password: bogus123
45 changes: 45 additions & 0 deletions bonus2/collateral/netbox/nbox_test.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 984e9d7

Please sign in to comment.