Skip to content

Node filtering#

With the node filtering feature containerlab enables users to perform operations on a subset of nodes defined in the topology file. A typical use case is to deploy only a subset of nodes in a lab to save deployment time and host resources.

Consider the following topology file that defines 4 interconnected nodes:

name: filter

topology:
  defaults:
    image: alpine:3
  nodes:
    node1:
    node2:
    node3:
    node4:

  links:
    - endpoints: ["node1:eth1", "node2:eth1"]
    - endpoints: ["node1:eth2", "node3:eth2"]
    - endpoints: ["node1:eth3", "node4:eth3"]
    - endpoints: ["node2:eth2", "node4:eth2"]
    - endpoints: ["node3:eth1", "node4:eth1"]

A graphical representation of the topology forms a ring with 4 nodes and 5 links between them:

Deploying a subset of nodes#

By default, all nodes and their links are deployed when the deploy command is executed. But what if each node is a massive VM that consumes a lot of RAM and you want to launch just a few of them? This use case becomes even more relevant when you have a large lab with many nodes and isolated domains.

For the sake of this example, let's assume that we want to deploy only nodes node1, node2, and node4, representing a subring. To do that, we can use the --node-filter flag and provide a comma-separated list of nodes names to deploy:

clab deploy --node-filter node1,node2,node4

As a result of this command, only nodes node1, node2, and node4 will be deployed, and the links between them will be created. The remaining nodes and links will be ignored.

When filtering the nodes to node1 and node2 the topology becomes a linear chain:

Destroying a subset of nodes#

The destroy command can also be scoped to a subset of nodes. The same --node-filter flag can be used to specify the nodes to destroy. For example, to destroy only nodes node1 and node2 from the previous example, we can run:

clab destroy --node-filter node1,node2

And only these two nodes will be destroyed (with all links connected to them), leaving the rest of the lab intact.

Other commands#

The following commands have support for --node-filter flag:

  • graph
  • save
  • config