EVPN-VXLAN Automation with NetBox and Python

Self-service L2 segments for a data center that sells VMs, containers and bare metal

Customer Story

This EVPN-VXLAN automation case study shows how a data center operator that sells VMs, containers and bare-metal servers turned Layer 2 connectivity between customer instances into a button in their portal. We built it with NetBox as the source of truth and Python doing the work, including the part most designs skip: deciding whether each tunnel ends on a leaf or on the hypervisor.

OperatorData center and hosting provider selling VMs, containers and bare-metal servers
FabricEVPN-VXLAN leaf-spine, one leaf pair per rack, FRR VTEPs on hypervisors
StackPython (pynetbox, Jinja2, Netmiko), NetBox as the source of truth
ResultA new L2 segment in under a minute in the recorded run, with no hand-written switch configuration

Engineering

Client: Confidential

Industry: Data Center and Hosting

Services: Professional DevOps Services, Network Automation

Technologies: EVPN-VXLAN, BGP EVPN, FRR, NetBox, Python, pynetbox, Jinja2, Netmiko

EVPN-VXLAN automation flow: the portal or an engineer calls the Python automation, NetBox is read first and updated at the end, and the segment ends on a leaf, a hypervisor or another switch
From portal click to fabric config: the portal or an engineer calls the Python automation, NetBox is read first and updated at the end.

The request

One of our customers runs their own data center and sells virtual machines, containers and bare-metal servers. A recurring ask kept landing on their team: give me Layer 2 connectivity between my instances and my servers. A customer running a database cluster wanted the nodes on one broadcast domain. Another wanted a private segment that behaved like a single switch, with workloads spread across racks and across different types of compute.

Every one of those requests became a manual job. A network engineer opened a ticket, picked a VLAN, checked that it did not clash with anything already deployed, logged into the switches and applied the configuration by hand. It worked, but it was slow, easy to get wrong, and it depended on whoever knew the fabric best being available.

The customer wanted it to become a button in their portal. We built the automation behind that button.

What is EVPN-VXLAN, and why use it for multi-tenant L2?

EVPN-VXLAN lets a routed leaf-spine fabric carry isolated Layer 2 segments between any two racks. VXLAN is the data plane: it wraps Layer 2 frames in UDP and carries them across the routed underlay, and each segment gets its own 24-bit VXLAN Network Identifier (VNI). EVPN is the control plane: instead of flooding to learn where every MAC address lives, the fabric advertises MAC and IP reachability as BGP EVPN Type-2 routes and coordinates broadcast and unknown-unicast handling with Type-3 routes. The design is standardised in RFC 8365.

For an operator that sells L2 connectivity, the useful part is the separation of local and global identifiers. In this fabric a VLAN ID only has to be unique inside one rack, on the ports of that rack’s leaf pair, while the VNI identifies the segment across the whole fabric. The 4094 VLAN limit stops being a fabric-wide planning problem, and tenant segments stay separated from each other on the same physical network.

The technology choice was the easy part. The real work in EVPN-VXLAN automation is turning a request into the right configuration on the right devices, every time, with a record of what was done.

EVPN-VXLAN automation architecture

How the automation is built and deployed: request, Python automation host, NetBox, and one rack of the EVPN-VXLAN fabric.
How the automation is built and deployed: request, Python automation host, NetBox, and one rack of the EVPN-VXLAN fabric.

The portal owns intent. When a customer requests L2 connectivity, the portal calls the automation with three inputs: the customer, the server and the type of service. The portal never talks to a network device and holds no network state. When a request arrives outside the portal, an engineer runs the same automation with the same inputs and gets the same result.

NetBox is the source of truth. It models the devices and the rack each one sits in, the leaf pair that serves each rack, a pool of VLANs for every rack, and the L2VPN objects with the VNI and the endpoints of each segment. The automation reads NetBox to decide what to build and writes back what it deployed, so NetBox stays the record of what exists and where.

The execution layer is our own Python code: pynetbox for the NetBox API, Jinja2 for the configuration templates and Netmiko for device access. It runs on an automation host in the management network, talks to NetBox over its HTTPS API and to the switches and hypervisors over SSH.

Where the tunnel ends

Switch side and host side: the automation reads from NetBox where each endpoint lives and configures that side.
Switch side and host side: the automation reads from NetBox where each endpoint lives and configures that side.

The most interesting part of the build was that the two ends of a segment are not always the same kind of thing.

When the workload is a bare-metal server cabled into a leaf, the leaf pair is the VXLAN tunnel endpoint (VTEP). The automation maps the customer’s segment to its VNI on both leaves and binds the server’s port into it.

When the workload is a virtual machine or a container on a hypervisor, the tunnel can end on the host itself. The hypervisor runs FRR as a VTEP and takes part in BGP EVPN like any leaf, and the same automation configures it. In other deployment types the far end is another switch. A single segment can mix these, with bare metal behind a leaf on one side and instances on a hypervisor on the other.

The EVPN-VXLAN automation decides which side to configure from what NetBox says about each endpoint. That decision used to depend on an engineer knowing the topology by heart. Now it comes from the source of truth.

One request, step by step

What the automation does for one new L2 segment.
What the EVPN-VXLAN automation does for one new L2 segment.
  1. Input. Customer name, server and service type (new service, extend or deploy).
  2. Find the rack. The rack is read from the server’s name, which follows the naming convention, and NetBox gives the leaf pair that serves that rack.
  3. Allocate. The next free VLAN is taken from that rack’s VLAN pool in NetBox. The VNI is generated at random and checked against NetBox, so no two segments ever share one.
  4. Render. The configuration for each device is generated from Jinja2 templates.
  5. Check. The automation confirms the VLAN is not already configured on either leaf. If it is, it stops.
  6. Push. The configuration is applied over SSH, to both leaves and, for host-side endpoints, to the hypervisor.
  7. Record. The new VLAN, the VNI and the L2VPN are registered in NetBox.
  8. Verify. The two endpoints reach each other across the new segment.

Here is what that looks like in a recorded run, on test servers, with names and addresses anonymised.

The run: VLAN 2001 is taken from the rack pool, checked on both leaves, pushed, and recorded in NetBox.
The run: VLAN 2001 is taken from the rack pool, checked on both leaves, pushed, and recorded in NetBox.
show vlan brief on the leaf, before and after: VLAN 2001 appears on the port-channel and the VXLAN interface.
show vlan brief on the leaf, before and after: VLAN 2001 appears on the port-channel and the VXLAN interface.
The two test servers go from Destination Host Unreachable to replies once the segment exists.
The two test servers go from Destination Host Unreachable to replies once the segment exists.
NetBox after the run: the rack's VLAN pool goes from 2000 free to 1999, with the new segment named and recorded.
NetBox after the run: the rack's VLAN pool goes from 2000 free to 1999, with the new segment named and recorded.

From the moment the script started to the moment NetBox was updated, the recorded EVPN-VXLAN automation run took under a minute.

Checks built into every run

  • The VLAN is always taken from NetBox, from the pool of the rack the server sits in, and the rack comes from the server’s name.
  • A randomly generated VNI is used only after NetBox confirms no other segment has it.
  • Before anything is pushed, both leaves are checked for an existing configuration with that VLAN. A clash stops the run.
  • NetBox is updated only after the configuration has been applied, so the record reflects what is really on the devices.
  • The same inputs produce the same result, whether the portal or an engineer starts the run.

Results of the EVPN-VXLAN automation

  • Provisioning time: from a ticket handled by an engineer to under a minute in the recorded run (measured on test servers).
  • Manual configuration: no hand-written switch configuration for new L2 segments.
  • Record keeping: every segment exists in NetBox with its VLAN, VNI and endpoints.
  • Scale: adding a tenant segment means another VNI and another NetBox entry, with VLAN IDs reused per rack.

Talk to the engineers who built it

If you run a data center, an ISP or a hosting and cloud platform, some version of this is probably sitting in your queue: connectivity requests that still run on tickets, VLANs tracked in spreadsheets, and provisioning that waits for the one engineer who knows the fabric. Our network automation and DevOps team, a NetBox Labs partner, designs the source of truth, builds the automation around it and connects it to the portals and systems your customers already use. If you are planning EVPN-VXLAN automation on your own fabric and want to compare notes, get in touch with the ITcare engineering team.

FAQ

Yes. On host-side endpoints the hypervisor runs FRR as a VTEP and peers in BGP EVPN like any leaf. The same automation configures it, so the switch side and the host side are built from the same request.

The script generates the VNI at random, checks in NetBox that no other segment uses it, and registers it in NetBox once the deploy has succeeded.

The run stops before anything is pushed. Both leaves are checked for an existing configuration with that VLAN ID first.

A VLAN ID only needs to be unique on the ports of one rack’s leaf pair, while the VNI identifies the segment across the fabric. That keeps the 4094 VLAN limit a local concern for each rack.

Yes. An engineer can start the same automation with the same inputs, customer, server and service type, and gets the same result.

be our next success story!

Drop us a line! We care for your Business and are here to answer your questions 24/7