NetBox Shell Examples with Jupyter Notebook

When I started working with the hardware team at eBay I was shocked to learn that they were tracking ALL of their assets with Wiki and spreadsheets. Everything was static, all of the IP addresses, the hardware locations, serial numbers, etc and let me tell you it was a nightmare to try and manage that infrastructure or even use the lab for that matter.

One of the things I was most proud of during my time at eBay was how I was able to transform the entire lab with the help of NetBox and a whole lot of Python. In the end I was using NetBox to build real time ZTP configurations for SONiC switches using the data in NetBox along with Jinja2 templates for true Infrastructure as Code deployments.

Infrastructure as Code example using NetBox and Jinja2 to build ZTP SONiC configs

I brought that lab into the 21st century and transformed it in such a manner that we could offer Lab as a Service to other teams. If you have not used NetBox you would be AMAZED at what is possible with free and open source software.

I’ve posted this example on github in case you have Jupyter Notebook and want to download. I’m not going to cover the process of getting these tools working together in this post but it’s not too difficult. In this blog post I will just be using screenshots taken from the notebook I created.

List all of the NetBox Models that are available

Examine Shell Help for the IP Address Model

Import all the NetBox Models so we can start chaining results later

We will use the IP address to find out all kinds of other things using different models

We can use the IP address to get all the info about the interface it’s assigned to

We can also look at what device that IP is assigned to

Using the IP address we can see all of the details of the device it’s assigned to

Using the IP we can see all of the details of the device type by chaining the models

Next we can dig into the help for the Device Type Model

You can work from the other direction and find IP from Device Name

You can define config contexts that the devices inherit based off user criteria

Digging into the Interface model various ways

Sync Data from Git to NetBox

Jinja 2 Examples using NetBox data to render configs (Infrastructure as Code)

This entry was posted in Uncategorized. Bookmark the permalink.