Introduction
A network change is less risky when you know its result before you make it. Many teams do not test a change, or they test it on a small lab that looks a little like production. Then they make the change in a maintenance window and see the result for the first time in production.
Nautobot already knows your network. It holds the devices, the cables, the IP addresses, and often the configs. containerlab builds labs of container network devices, such as Arista cEOS, from one YAML file. Containerlab Orchestrator is a Nautobot app that connects the two. It reads your devices and cables in Nautobot and builds a containerlab topology from them. Then it deploys that topology to a containerlab host.
The result is a copy of your network, or of a part of it, that runs real network operating systems. The lab is a copy of the data in Nautobot. If Nautobot or Golden Config does not match production, the lab does not match production either. You can log in to each node, make your change, and watch what happens.
This post shows how to set up a containerlab API server and add the Arista cEOS image. Then it installs the app and deploys a lab from the demo data of the app. The last part tests a real change on the lab. You do not need to write code for any of these steps.
What you need
- Nautobot 3.2.8 or later.
- A Linux machine with Docker. This machine is the containerlab host.
- The clab-api-server on that host. The app talks to the host only through this API. It needs no SSH access.
- A container image for each network operating system in the lab. This post uses Arista cEOS.
Set up the containerlab API server
The clab-api-server gives containerlab a REST API. It has containerlab built in, so the host needs only Docker and the API server. By default, the API server listens on port 8090 with HTTPS and a self-signed certificate.
The API server uses local Linux accounts
The API server signs in each user with a local Linux account on the host and its Linux password. After a correct login, the API server gives the user a token for the next API calls.
A Linux account can use the API only when it is in one of two groups:
clab_api: a normal API user. The user sees and changes only the labs that the user owns.clab_admins: an API superuser. The user sees and changes all the labs on the host.
Make one account for Nautobot, and put it in clab_api. The installer makes the two groups.
sudo useradd -m -G clab_api nautobot
sudo passwd nautobot
To give an account that exists access to the API, add the account to the group:
sudo usermod -aG clab_api <username>
WARNING: A member of clab_admins can destroy the labs of all users on the host. Do not put the Nautobot account in clab_admins.
Install the API server as a service
The tested version of the app is clab-api-server v0.10.0. Run the installer as root:
curl -fsSL https://raw.githubusercontent.com/srl-labs/clab-api-server/v0.10.0/install.sh \
| sudo bash -s -- install --version v0.10.0
The installer writes the API server, the file /etc/clab-api-server/clab-api-server.env, and a systemd service. It also writes a random secret for the tokens.
Open the env file. Set API_SERVER_HOST to the host name or the IP address that Nautobot uses for the API server.
sudoedit /etc/clab-api-server/clab-api-server.env
Start the service:
sudo systemctl enable --now clab-api-server
sudo systemctl status clab-api-server
Make sure that the login works from the machine that runs Nautobot. The -k option accepts the self-signed certificate. The result has a token key.
curl -k -X POST https://clab01.example.com:8090/login \
-H "Content-Type: application/json" \
-d '{"username": "nautobot", "password": "<password>"}'
The API server also shows its API documentation at https://<server>:8090/swagger/index.html.
Local API server or external API server
The app repository has a Docker Compose file, development/docker-compose.clab.yml. It runs the API server as a container next to a local Nautobot. This is a fast way to try the app on a laptop.
The resources of your computer limit the local API server. On Docker Desktop, Nautobot, its database, and every lab node share the memory of one VM. Each cEOS node runs a full EOS, so a small lab can use all the memory of the VM. The development guide of the app tells you to run one lab at a time. It also tells you to deploy only when 2 GB or more is free. The local container also runs privileged with host networking, so use it only on a network that you trust.
An external host is better. My host for this post is a small Linux machine with 4 CPUs and 32 GB of memory. It has enough memory for the six cEOS nodes and four Linux hosts of the demo lab. A lab on an external host also stays up when you close your laptop.
Add the Arista cEOS image
Arista does not publish cEOS to a public registry. You download the image and import it into Docker on the containerlab host. See the containerlab cEOS page for the details.
- Log in to the software download page at arista.com.
- Download the cEOS64 lab image, for example
cEOS64-lab-4.37.0F.tar.xz. - Copy the file to the containerlab host.
- Import the file into Docker. Give the image the name
ceosand the EOS version as the tag.
docker import cEOS64-lab-4.37.0F.tar.xz ceos:4.37.0F
docker images ceos
Remember the name ceos:4.37.0F. In Nautobot, the node mapping of each Arista model uses this exact image name. If the host does not have an image that the lab needs, the Deploy Lab job stops and lists the missing images.
The containerlab kind for cEOS is arista_ceos. containerlab also accepts the short name ceos, and the demo data uses that name. With the default config of containerlab, a cEOS node has the user admin with the password admin. A startup config from your own network sets your own accounts.
Install the app
The app is on PyPI as nautobot-containerlab-orchestrator. Install it on each machine that runs Nautobot or a Nautobot worker:
pip install nautobot-containerlab-orchestrator
To use the intended configs or the backup configs from Golden Config as the startup configs of the lab nodes, install the golden-config extra:
pip install "nautobot-containerlab-orchestrator[golden-config]"
In nautobot_config.py, add "containerlab_orchestrator" to the PLUGINS list. Then run the post-upgrade command and restart the Nautobot services:
nautobot-server post_upgrade
sudo systemctl restart nautobot nautobot-worker nautobot-scheduler
The app adds a Containerlab menu with three pages: Labs, Containerlab Hosts, and Node Mappings. The app also adds six jobs, and it turns on all six when you install it. The installation guide gives each setting.
Tell Nautobot about the host
Nautobot keeps the password of the host account in a Secrets Group. Do these steps one time for each containerlab host:
- Make two Secrets, one for the username and one for the password of the Linux account.
- Make a Secrets Group. Add the username Secret with the access type HTTP(S) and the secret type Username.
- Add the password Secret with the access type HTTP(S) and the secret type Password.
- Open Containerlab > Containerlab Hosts, and add a host. Give the URL of the API server, with port 8090, and the Secrets Group.
- If the API server uses its self-signed certificate, turn off “Verify SSL”.
Map device models to containerlab nodes
A node mapping tells the app how to make a containerlab node from a Nautobot device. It gives the containerlab kind, the image, and the startup config source. Its interface table also gives the container name of each physical interface, for example Ethernet49 to eth49.
The app finds the mapping of a device in this order:
- The mapping of the Device Type of the device.
- The mapping of the Platform of the device.
- The default mapping of the app settings, which is a Linux node.
The startup config of a node can come from Golden Config intended, Golden Config backup, or a Jinja2 template. It can also be the default config of the containerlab kind.
The demo data
The app includes demo data, so you can see a full lab before you map your own network. In the development environment of the app, the command invoke generate-test-data loads it. The demo data makes:
- Two Arista spines,
dc1-spine1anddc1-spine2. - Four Arista leafs,
dc1-leaf1todc1-leaf4, with one cable to each spine. - Four Linux hosts,
dc1-host1todc1-host4, with one cable each to a leaf. - Node mappings for the two Arista models to
ceos:4.37.0F, and for the Linux model toalpine:latest. - Backup configs from Golden Config for the Arista devices, from a public demo repository. The configs build an EVPN fabric with one tenant VRF,
TENANT_A. - The lab
demo-spine-leaf, which selects all the devices of the location “Demo DC1”.
Make a lab of all your network, or of a part of it
A lab selects its devices in three ways. You can use one, two, or all three:
- Pick each device.
- Select a Dynamic Group of devices.
- Give a device filter, for example
{"role": ["leaf"]}or{"location": ["Demo DC1"]}.
The app reads the Dynamic Group and the device filter again at each build. So a device that you add to Nautobot is in the next build of the lab.
A lab can also hold only a part of the network, such as the devices of one site, one pair of core routers, or the devices that a change touches. A selected device can have a cable to a device outside the lab. In that case, the app adds a small Linux “stub” node in place of the far device. The cable and the interface of your device stay in the lab. Because of this, the interface numbers of the lab match production.
The management network of the lab uses a subnet that you give. The demo lab uses 10.20.20.0/24, which is also the management prefix of the demo devices in Nautobot.
Build the lab
The lab page has a button for each lab job. Each button opens the form of its job with the lab selected. Click Build, and then click Run Job Now. The Build Lab Topology job reads Nautobot and stores the containerlab topology on the lab. It changes nothing on the host.
For the demo lab, the job log shows this result:
Built lab demo-spine-leaf: 10 nodes, 12 links, 0 warnings. Status: Built.
The lab is now in the Built status. The Nodes table shows each node with its kind, its image, and its management address. The Devices panel lists only the devices that you picked one by one. This lab uses a device filter, so that panel is empty.
The Topology YAML tab shows the containerlab file that the app made. Each Arista node has its startup config inside the file, from Golden Config. The Download YAML button saves the file, so you can also use it with the containerlab command.
Deploy the lab
Click Deploy, and then click Run Job Now. The Deploy Lab job sends the stored topology to the API server, waits for containerlab, and records the state of each node. On my host, the deploy of the demo lab took about three minutes.
The lab is now in the Deployed status, and each node shows the state running. The Redeploy and Destroy buttons are now active.
The Topology tab draws the lab from the stored node states. Green is running, red is not running, and grey is not inspected. A stub node shows as a square.
Look at the lab on the host
On the containerlab host, each node is a Docker container. Its name is clab-<lab>-<node>:
$ docker ps --filter label=containerlab=demo-spine-leaf --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
NAMES IMAGE STATUS
clab-demo-spine-leaf-dc1-host3 alpine:latest Up 3 minutes
clab-demo-spine-leaf-dc1-host1 alpine:latest Up 3 minutes
clab-demo-spine-leaf-dc1-leaf2 ceos:4.37.0F Up 3 minutes
clab-demo-spine-leaf-dc1-spine2 ceos:4.37.0F Up 3 minutes
clab-demo-spine-leaf-dc1-leaf3 ceos:4.37.0F Up 4 minutes
clab-demo-spine-leaf-dc1-leaf4 ceos:4.37.0F Up 4 minutes
clab-demo-spine-leaf-dc1-spine1 ceos:4.37.0F Up 4 minutes
clab-demo-spine-leaf-dc1-leaf1 ceos:4.37.0F Up 4 minutes
clab-demo-spine-leaf-dc1-host2 alpine:latest Up 4 minutes
clab-demo-spine-leaf-dc1-host4 alpine:latest Up 4 minutes
You can open the EOS CLI of a node with docker exec. From the containerlab host, you can also use SSH to the management address of the node, for example ssh [email protected] for dc1-leaf1. The leaf starts with its config from Golden Config. With this config, the BGP sessions to both spines are up:
$ docker exec -it clab-demo-spine-leaf-dc1-leaf1 Cli
dc1-leaf1>show bgp summary
BGP summary information for VRF default
Router identifier 10.255.0.11, local AS number 65101
Neighbor AS Session State AFI/SAFI AFI/SAFI State NLRI Rcd NLRI Acc NLRI Adv
---------- ----------- ------------- ----------------------- -------------- ---------- ---------- ----------
10.1.0.0 65100 Established IPv4 Unicast Negotiated 7 7 5
10.1.0.8 65100 Established IPv4 Unicast Negotiated 7 7 7
10.255.0.1 65100 Established L2VPN EVPN Negotiated 3 3 2
10.255.0.2 65100 Established L2VPN EVPN Negotiated 3 3 3
The tenant VRF has a route to the subnet of the Linux host behind each other leaf, through VXLAN:
dc1-leaf1>show ip route vrf TENANT_A
VRF: TENANT_A
C 10.1.1.0/31
directly connected, Ethernet1
B E 10.1.1.2/31 [20/0]
via VTEP 10.255.1.12 VNI 50001 router-mac 00:1c:73:ec:54:a4 local-interface Vxlan1
B E 10.1.1.4/31 [20/0]
via VTEP 10.255.1.13 VNI 50001 router-mac 00:1c:73:00:d5:33 local-interface Vxlan1
B E 10.1.1.6/31 [20/0]
via VTEP 10.255.1.14 VNI 50001 router-mac 00:1c:73:ec:e4:4b local-interface Vxlan1
The Linux hosts of the demo data get no startup config. Give each Linux host its address on eth1 and a route to the other Linux hosts. The leaf has the even address of each /31, and the Linux host has the odd address. For dc1-host1 and dc1-host4:
docker exec clab-demo-spine-leaf-dc1-host1 ip addr add 10.1.1.1/31 dev eth1
docker exec clab-demo-spine-leaf-dc1-host1 ip route add 10.1.1.0/24 via 10.1.1.0
docker exec clab-demo-spine-leaf-dc1-host4 ip addr add 10.1.1.7/31 dev eth1
docker exec clab-demo-spine-leaf-dc1-host4 ip route add 10.1.1.0/24 via 10.1.1.6
Now traffic from dc1-host1 goes through dc1-leaf1, across the fabric, and out of dc1-leaf4 to dc1-host4:
$ docker exec clab-demo-spine-leaf-dc1-host1 traceroute -n 10.1.1.7
traceroute to 10.1.1.7 (10.1.1.7), 30 hops max, 46 byte packets
1 10.1.1.0 0.006 ms 0.005 ms 0.004 ms
2 10.1.1.6 3.335 ms 1.548 ms 2.760 ms
3 10.1.1.7 1.992 ms 3.504 ms 1.745 ms
Test a change before production
Suppose that you must take the uplink from dc1-leaf1 to dc1-spine1 out of service. You want to know that the tenant traffic of dc1-leaf1 moves to dc1-spine2. On the lab, shut down the uplink from dc1-leaf1 to dc1-spine1:
dc1-leaf1#configure
dc1-leaf1(config)#interface Ethernet49
dc1-leaf1(config-if-Et49)#shutdown
dc1-leaf1(config-if-Et49)#end
The sessions to dc1-spine1 go down, and the sessions to dc1-spine2 stay up:
dc1-leaf1#show bgp summary
Neighbor AS Session State AFI/SAFI AFI/SAFI State NLRI Rcd NLRI Acc NLRI Adv
---------- ----------- ------------- ----------------------- -------------- ---------- ---------- ----------
10.1.0.0 65100 Idle IPv4 Unicast Configured 0 0 0
10.1.0.8 65100 Established IPv4 Unicast Negotiated 7 7 2
10.255.0.1 65100 Connect L2VPN EVPN Configured 0 0 0
10.255.0.2 65100 Established L2VPN EVPN Negotiated 3 3 1
Five seconds after the shutdown, a ping from dc1-host1 to dc1-host4 gets each reply:
$ docker exec clab-demo-spine-leaf-dc1-host1 ping -c 3 10.1.1.7
3 packets transmitted, 3 packets received, 0% packet loss
This ping shows the path after BGP converges. To measure the loss during the change, run a continuous ping while you shut down the interface.
Twenty seconds after no shutdown, all four sessions are Established again. So before the maintenance window starts, you know the steps and the show output to expect at each step.
The same method works for other changes. Examples are a new route policy, new BGP timers, a new VRF, or a new config template. Make the change on the lab and check the result. If the lab breaks, click Redeploy, and the app gives you a new lab from Nautobot in a few minutes.
Keep the lab status current
Two more jobs keep Nautobot and the host in agreement:
- Inspect Lab reads the containers of one lab on its host. It updates the state of each node and the status of the lab. It changes nothing on the host.
- Sync Labs inspects each Deployed or Failed lab. Schedule this job to keep the status of all labs current.
When you finish the test, click Destroy. The job removes the containers and the lab directory on the host. The lab keeps its stored topology, so you can deploy it again later.
The limits of a container lab
A container lab runs the control plane of the real network operating system. So routing protocols, VRFs, EVPN, route policy, and most of the CLI work as they do in production. A container lab cannot show features that depend on the switch hardware. Examples are optics, hardware queues and QoS, forwarding table scale, and line-rate performance.
Some software features are also missing from a container image. The cEOS version of the lab can be different from the EOS version in production. Read the release notes of your vendor before you trust a lab result for a feature. Convergence time depends on the hardware and the timers. Because of this, a time from the lab is not a production time.
For hardware features and for convergence time, you still need a hardware lab. For a change to the config or the control plane, test it on the container lab first. If a change passes on the lab and fails in production, record the difference. Then add a check for it to your test steps.
Get the app and report issues
- Install the app from PyPI: nautobot-containerlab-orchestrator.
- Read the documentation: nautobot-app-containerlab-orchestrator.readthedocs.io. It has a getting started tutorial, node mapping examples for other vendors, and a FAQ.
- Read the source on GitHub: jtdub/nautobot-app-containerlab-orchestrator.
If you find a bug, or if you want a new feature, open an issue on GitHub. For a bug, give the version of the app and of Nautobot, the steps to reproduce the problem, and the job log. For a feature request, tell me about the change that you want to test and what the lab needs to do for it.