Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions internal/clab/containerlab_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 17 additions & 16 deletions internal/clab/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down