From 49d331b3cd3e4c96331e585b80b33be7447d6386 Mon Sep 17 00:00:00 2001 From: FloSch62 Date: Fri, 13 Nov 2026 11:14:46 +0100 Subject: [PATCH] fix(labs): report the root node of sub-containers in lab inspect A distributed SR-SIM node runs as several containers (CPM, cards), each with its own clab-node-name such as sr1-a or sr1-1. Clients that capture through the API took that name as the topology node, and the capture failed with "node sr1-1 is not part of lab". Lab inspect now also reports rootNodeName from the clab-root-node-name label, the topology node the container belongs to. --- docs/docs.go | 5 ++++ docs/swagger.json | 5 ++++ docs/swagger.yaml | 6 +++++ internal/clab/containerlab_compat_test.go | 20 ++++++++++++++ internal/clab/converters.go | 33 ++++++++++++----------- internal/models/models.go | 11 +++++--- 6 files changed, 60 insertions(+), 20 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index cf795c7..edb6aaf 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -8361,6 +8361,11 @@ const docTemplate = `{ "$ref": "#/definitions/models.ClabPortBinding" } }, + "rootNodeName": { + "description": "RootNodeName is the topology node a sub-container belongs to, e.g. the\nnode of a distributed SR-SIM's CPM and card containers. Empty otherwise.", + "type": "string", + "example": "sr1" + }, "state": { "description": "e.g., \"running\"", "type": "string" diff --git a/docs/swagger.json b/docs/swagger.json index 5b6efba..eb877aa 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -8357,6 +8357,11 @@ "$ref": "#/definitions/models.ClabPortBinding" } }, + "rootNodeName": { + "description": "RootNodeName is the topology node a sub-container belongs to, e.g. the\nnode of a distributed SR-SIM's CPM and card containers. Empty otherwise.", + "type": "string", + "example": "sr1" + }, "state": { "description": "e.g., \"running\"", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e0e889d..6007efd 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -453,6 +453,12 @@ definitions: items: $ref: '#/definitions/models.ClabPortBinding' type: array + rootNodeName: + description: |- + RootNodeName is the topology node a sub-container belongs to, e.g. the + node of a distributed SR-SIM's CPM and card containers. Empty otherwise. + example: sr1 + type: string state: description: e.g., "running" type: string diff --git a/internal/clab/containerlab_compat_test.go b/internal/clab/containerlab_compat_test.go index 4d4911d..67c5274 100644 --- a/internal/clab/containerlab_compat_test.go +++ b/internal/clab/containerlab_compat_test.go @@ -150,6 +150,26 @@ func TestContainerToClabContainerInfoReportsMgmtNetworkAndPorts(t *testing.T) { } } +func TestContainerToClabContainerInfoReportsRootNodeName(t *testing.T) { + info := ContainerToClabContainerInfo(clabruntime.GenericContainer{ + Names: []string{"clab-demo-sr1-1"}, + Labels: map[string]string{ + clabconst.Containerlab: "demo", + clabconst.NodeName: "sr1-1", + clabconst.RootNodeName: "sr1", + }, + }) + if info.NodeName != "sr1-1" || info.RootNodeName != "sr1" { + t.Fatalf("node = %q, root node = %q, want sr1-1 and sr1", info.NodeName, info.RootNodeName) + } + + if info := ContainerToClabContainerInfo(clabruntime.GenericContainer{ + Labels: map[string]string{clabconst.NodeName: "n1"}, + }); info.RootNodeName != "" { + t.Fatalf("root node of a plain node = %q, want none", info.RootNodeName) + } +} + func TestTailscaleDeviceClassification(t *testing.T) { tests := []struct { name string diff --git a/internal/clab/converters.go b/internal/clab/converters.go index 77bb230..1520415 100644 --- a/internal/clab/converters.go +++ b/internal/clab/converters.go @@ -95,22 +95,23 @@ func ContainerToClabContainerInfo(c clabruntime.GenericContainer) models.ClabCon name = c.Names[0] } info := models.ClabContainerInfo{ - Name: name, - ContainerID: c.ShortID, - Image: c.Image, - Kind: c.Labels[clabconst.NodeKind], - State: c.State, - Status: c.Status, - IPv4Address: c.GetContainerIPv4(), - IPv6Address: c.GetContainerIPv6(), - LabName: c.Labels[clabconst.Containerlab], - NodeName: c.Labels[clabconst.NodeName], - LabPath: c.Labels[clabconst.TopoFile], - AbsLabPath: c.Labels[clabconst.TopoFile], - Group: c.Labels[clabconst.NodeGroup], - Owner: c.Labels[clabconst.Owner], - MgmtNetwork: containerMgmtNetwork(c), - Ports: containerPorts(c), + Name: name, + ContainerID: c.ShortID, + Image: c.Image, + Kind: c.Labels[clabconst.NodeKind], + State: c.State, + Status: c.Status, + IPv4Address: c.GetContainerIPv4(), + IPv6Address: c.GetContainerIPv6(), + LabName: c.Labels[clabconst.Containerlab], + NodeName: c.Labels[clabconst.NodeName], + RootNodeName: c.Labels[clabconst.RootNodeName], + LabPath: c.Labels[clabconst.TopoFile], + AbsLabPath: c.Labels[clabconst.TopoFile], + Group: c.Labels[clabconst.NodeGroup], + Owner: c.Labels[clabconst.Owner], + MgmtNetwork: containerMgmtNetwork(c), + Ports: containerPorts(c), } if workload := c.Workload; workload != nil { info.Namespace = workload.Namespace diff --git a/internal/models/models.go b/internal/models/models.go index ac79041..24cdbc2 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -172,10 +172,13 @@ type ClabContainerInfo struct { IPv6Address string `json:"ipv6_address"` // Management IPv6 Address/Mask LabName string `json:"lab_name"` // Name of the lab this node belongs to (redundant with map key but present) NodeName string `json:"nodeName"` // Topology node name from containerlab labels - LabPath string `json:"labPath"` // Path to the topology file used (relative) - AbsLabPath string `json:"absLabPath"` // Absolute path to topology file - Group string `json:"group"` // Group assigned in topology (Might not always be present) - Owner string `json:"owner"` // OS user from clab inspect output (Used for authorization) + // RootNodeName is the topology node a sub-container belongs to, e.g. the + // node of a distributed SR-SIM's CPM and card containers. Empty otherwise. + RootNodeName string `json:"rootNodeName,omitempty" example:"sr1"` + LabPath string `json:"labPath"` // Path to the topology file used (relative) + AbsLabPath string `json:"absLabPath"` // Absolute path to topology file + Group string `json:"group"` // Group assigned in topology (Might not always be present) + Owner string `json:"owner"` // OS user from clab inspect output (Used for authorization) // MgmtNetwork is the management network the node is attached to; with // several management networks (mgmt list in the topology) it tells them apart. MgmtNetwork string `json:"mgmt_network,omitempty" example:"clab"`