Netbox and Python for network merge

When two large companies merge, they may be required to merge their respective networks as well, including address spaces.

A few years ago I found myself supporting a client in this very situation.

The client had started to create a large Excel file with the prefixes in use, to be used for analysis.

I proposed to the client to approach the problem in a different way.

Enter Netbox

First, I installed an instance of NetBox and loaded all known prefixes, importing them from in CSV file.

Then I wrote several scripts to import the prefixes from the routing tables of some significant routers and switches, so that I have a complete view of the prefixes of both VRFs.

Merge

The next step was to write a script that would do the daily merge of the two VRFs, thus giving evidence of the overlaps.

The script each day deletes all the prefixes of the merge target VRF, and then imports all the prefixes of the two source VRFs.

The Operations team was responsible for changing the addressing of all overlap sites.

At the end of the activity, the Service Provider put the two VRFs in communication.

Wrap-up

The project was longer and more complex than what I describe here. The script was first run in June 2021, today I decommissioned1 it because the project was completed.

The code runs in NetBox 2.6.8 but I share it anyway as a reminder of a success.

Netbox VRF merger on GitHub


  1. Decommissionig means I commented the line in crontab. ↩︎