clab

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

internal/clab/converters.go

internal/clab/service.go

internal/clab/utils.go

Index

Constants

This section is empty.

Variables

View Source
var ErrNetemInterfaceNotFound = errors.New("netem interface not found")

Functions

func ApplyResultToResponse added in v0.5.0

func ApplyResultToResponse(result *clabcore.ApplyResult) models.ApplyLabResponse

ApplyResultToResponse converts a containerlab apply result to the API response model.

func ContainerInterfacesToNodeInterfaceInfo added in v0.2.0

func ContainerInterfacesToNodeInterfaceInfo(ci *clabtypes.ContainerInterfaces) models.NodeInterfaceInfo

ContainerInterfacesToNodeInterfaceInfo converts containerlab interfaces to API format.

func ContainerToClabContainerInfo added in v0.2.0

func ContainerToClabContainerInfo(c clabruntime.GenericContainer) models.ClabContainerInfo

ContainerToClabContainerInfo converts a containerlab GenericContainer to API ClabContainerInfo.

func ContainersInterfacesToInspectOutput added in v0.2.0

func ContainersInterfacesToInspectOutput(cis []*clabtypes.ContainerInterfaces) models.ClabInspectInterfacesOutput

ContainersInterfacesToInspectOutput converts a slice of container interfaces to API format.

func ContainersToClabInspectOutput added in v0.2.0

func ContainersToClabInspectOutput(containers []clabruntime.GenericContainer) models.ClabInspectOutput

ContainersToClabInspectOutput converts a slice of containers to the API inspect output format.

func ExecCollectionToExecResponse added in v0.2.0

func ExecCollectionToExecResponse(ec *clabexec.ExecCollection) models.ExecResponse

ExecCollectionToExecResponse converts containerlab exec results to API format.

func FilterContainersByLab added in v0.2.0

func FilterContainersByLab(containers []clabruntime.GenericContainer, labName string) []clabruntime.GenericContainer

FilterContainersByLab filters containers by lab name.

func FilterContainersByOwner added in v0.2.0

func FilterContainersByOwner(containers []clabruntime.GenericContainer, owner string) []clabruntime.GenericContainer

FilterContainersByOwner filters containers by owner.

func FindContainerByName added in v0.2.0

func FindContainerByName(containers []clabruntime.GenericContainer, name string) *clabruntime.GenericContainer

FindContainerByName finds a container by its name in a slice.

func GetContainerLabName added in v0.2.0

func GetContainerLabName(c *clabruntime.GenericContainer) string

GetContainerLabName extracts the lab name from a container's labels.

func GetContainerName added in v0.2.0

func GetContainerName(c *clabruntime.GenericContainer) string

GetContainerName safely extracts the container name from a GenericContainer.

func GetContainerNodeName added in v0.3.0

func GetContainerNodeName(c *clabruntime.GenericContainer) string

GetContainerNodeName extracts the topology node name from a container's labels.

func GetContainerOwner added in v0.2.0

func GetContainerOwner(c *clabruntime.GenericContainer) string

GetContainerOwner extracts the owner from a container's labels.

func GetContainerTopoPath added in v0.2.0

func GetContainerTopoPath(c *clabruntime.GenericContainer) string

GetContainerTopoPath extracts the topology path from a container's labels.

func GroupContainersByLab added in v0.2.0

func GroupContainersByLab(containers []clabruntime.GenericContainer) map[string][]clabruntime.GenericContainer

GroupContainersByLab groups containers by their lab name.

func SanitizePath

func SanitizePath(relativePath string) (string, error)

SanitizePath prevents path traversal. Returns the cleaned path if valid, otherwise an error.

Types

type ApplyOptions added in v0.5.0

type ApplyOptions struct {
	TopoPath       string
	Username       string
	DryRun         bool
	MaxWorkers     uint
	ExportTemplate string
	SkipPostDeploy bool
}

ApplyOptions contains options for applying topology changes to a lab.

type CACreateOptions added in v0.2.0

type CACreateOptions struct {
	Name         string
	Expiry       time.Duration
	CommonName   string
	Country      string
	Locality     string
	Organization string
	OrgUnit      string
	KeySize      int
	OutputPath   string
}

CACreateOptions contains options for creating a CA.

type CertSignOptions added in v0.2.0

type CertSignOptions struct {
	Name         string
	Hosts        []string
	CommonName   string
	Country      string
	Locality     string
	Organization string
	OrgUnit      string
	KeySize      int
	CACertPath   string
	CAKeyPath    string
	OutputPath   string
}

CertSignOptions contains options for signing a certificate.

type CloneTopologySourceOptions added in v0.3.0

type CloneTopologySourceOptions struct {
	SourceURL string
	Username  string
}

type CloneTopologySourceResult added in v0.3.0

type CloneTopologySourceResult struct {
	RepoDir      string
	RepoName     string
	TopologyPath string
}

type ContainerlabToolRunOptions added in v0.3.0

type ContainerlabToolRunOptions struct {
	Args []string
}

type DeployOptions added in v0.2.0

type DeployOptions struct {
	TopoPath string
	// LabName is the API-authorized lab name. It is required and overrides the
	// name from the topology so deployment cannot switch to an unchecked lab.
	LabName        string
	Username       string
	Reconfigure    bool
	MaxWorkers     uint
	ExportTemplate string
	NodeFilter     []string
	SkipPostDeploy bool
	SkipLabDirACLs bool
}

DeployOptions contains options for deploying a lab.

type DestroyOptions added in v0.2.0

type DestroyOptions struct {
	LabName         string
	TopoPath        string
	Username        string
	Graceful        bool
	GracefulTimeout time.Duration
	Cleanup         bool
	KeepMgmtNet     bool
	NodeFilter      []string
	MaxWorkers      uint
}

DestroyOptions contains options for destroying a lab.

type DisableTxOffloadOptions added in v0.2.0

type DisableTxOffloadOptions struct {
	ContainerName string
	InterfaceName string
}

DisableTxOffloadOptions contains options for disabling TX offload.

type DrawioGenerateOptions added in v0.3.0

type DrawioGenerateOptions struct {
	TopoPath      string
	Runtime       string
	Layout        string
	Theme         string
	Interactive   bool
	DrawioVersion string
}

type DrawioGenerateResult added in v0.3.0

type DrawioGenerateResult struct {
	Path   string
	Output string
}

type ExecOptions added in v0.2.0

type ExecOptions struct {
	TopoPath      string
	LabName       string
	ContainerName string
	NodeName      string
	Commands      []string
	Username      string
}

ExecOptions contains options for executing commands.

type FcliRunOptions added in v0.3.0

type FcliRunOptions struct {
	Runtime      string
	Network      string
	TopologyPath string
	CommandArgs  []string
}

type GenerateTopologyOptions added in v0.2.0

type GenerateTopologyOptions struct {
	Name              string
	Tiers             []TierDefinition
	DefaultKind       string
	Images            map[string]string
	Licenses          map[string]string
	NodePrefix        string
	GroupPrefix       string
	ManagementNetwork string
	IPv4Subnet        string
	IPv6Subnet        string
}

GenerateTopologyOptions contains options for generating a topology.

type InspectOptions added in v0.2.0

type InspectOptions struct {
	LabName  string
	Username string
	Details  bool
}

InspectOptions contains options for inspecting labs.

type InterfacesOptions added in v0.2.0

type InterfacesOptions struct {
	LabName    string
	Username   string
	NodeFilter string
}

InterfacesOptions contains options for listing interfaces.

type ListOptions added in v0.2.0

type ListOptions struct {
	LabName       string
	ContainerName string
	NodeName      string
}

ListOptions contains options for listing labs/containers.

type NetemSetOptions added in v0.2.0

type NetemSetOptions struct {
	ContainerName string
	Interface     string
	Delay         time.Duration
	Jitter        time.Duration
	Loss          float64
	Rate          uint64 // kbit/s
	Corruption    float64
}

NetemSetOptions contains options for setting link impairments using netem.

type NodeLifecycleAction added in v0.3.0

type NodeLifecycleAction string
const (
	NodeLifecycleActionStart   NodeLifecycleAction = "start"
	NodeLifecycleActionStop    NodeLifecycleAction = "stop"
	NodeLifecycleActionRestart NodeLifecycleAction = "restart"
	NodeLifecycleActionPause   NodeLifecycleAction = "pause"
	NodeLifecycleActionUnpause NodeLifecycleAction = "unpause"
)

type NodeLifecycleOptions added in v0.3.0

type NodeLifecycleOptions struct {
	ContainerName string
	LabName       string
	TopoPath      string
	Username      string
	NodeNames     []string
	Action        NodeLifecycleAction
}

type ResolveTopologySourceOptions added in v0.6.0

type ResolveTopologySourceOptions struct {
	SourcePath string
	Username   string
}

type ResolveTopologySourceResult added in v0.6.0

type ResolveTopologySourceResult struct {
	TopologyPath string
	LabName      string
}

type RuntimeImageSummary added in v0.3.0

type RuntimeImageSummary struct {
	ID          string
	ShortID     string
	RepoTags    []string
	RepoDigests []string
	CreatedAt   string
	Size        string
	VirtualSize string
}

type SaveOptions added in v0.2.0

type SaveOptions struct {
	TopoPath   string
	Username   string
	NodeFilter []string
}

SaveOptions contains options for saving lab configuration.

type Service added in v0.2.0

type Service struct{}

Service provides an interface to containerlab operations using the library directly.

func NewService added in v0.2.0

func NewService() *Service

NewService creates a new containerlab service.

func (*Service) Apply added in v0.5.0

func (s *Service) Apply(ctx context.Context, opts ApplyOptions) (*clabcore.ApplyResult, error)

Apply applies topology changes to a lab using the containerlab library.

func (*Service) CloneTopologySource added in v0.3.0

func (s *Service) CloneTopologySource(opts CloneTopologySourceOptions) (*CloneTopologySourceResult, error)

CloneTopologySource clones a supported topology source URL and resolves the topology file path.

func (*Service) CreateCA added in v0.2.0

func (s *Service) CreateCA(ctx context.Context, opts CACreateOptions) (*clabcert.Certificate, error)

CreateCA creates a new Certificate Authority.

func (*Service) CreateVeth added in v0.2.0

func (s *Service) CreateVeth(ctx context.Context, opts VethCreateOptions) error

CreateVeth creates a veth pair between two endpoints.

func (*Service) CreateVxlan added in v0.2.0

func (s *Service) CreateVxlan(ctx context.Context, opts VxlanCreateOptions) error

CreateVxlan creates a VxLAN tunnel.

func (*Service) DeleteVxlan added in v0.2.0

func (s *Service) DeleteVxlan(ctx context.Context, prefix string) ([]string, error)

DeleteVxlan deletes VxLAN tunnels matching a prefix.

func (*Service) Deploy added in v0.2.0

Deploy deploys a lab using the containerlab library.

func (*Service) Destroy added in v0.2.0

func (s *Service) Destroy(ctx context.Context, opts DestroyOptions) error

Destroy destroys a lab using the containerlab library.

func (*Service) DisableTxOffload added in v0.2.0

func (s *Service) DisableTxOffload(ctx context.Context, opts DisableTxOffloadOptions) error

DisableTxOffload disables TX checksum offload on a container's interface.

func (*Service) Exec added in v0.2.0

Exec executes commands on containers.

func (*Service) GenerateDrawioFile added in v0.3.0

func (s *Service) GenerateDrawioFile(ctx context.Context, opts DrawioGenerateOptions) (DrawioGenerateResult, error)

func (*Service) GenerateTopology added in v0.2.0

func (s *Service) GenerateTopology(ctx context.Context, opts GenerateTopologyOptions) ([]byte, error)

GenerateTopology generates a topology YAML.

func (*Service) ListContainerInterfaces added in v0.2.0

func (s *Service) ListContainerInterfaces(ctx context.Context, container *clabruntime.GenericContainer) (*clabtypes.ContainerInterfaces, error)

ListContainerInterfaces lists interfaces for a specific container.

func (*Service) ListContainers added in v0.2.0

func (s *Service) ListContainers(ctx context.Context, opts ListOptions) ([]clabruntime.GenericContainer, error)

ListContainers lists containers matching the given options.

func (*Service) ListContainersInterfaces added in v0.2.0

func (s *Service) ListContainersInterfaces(ctx context.Context, containers []clabruntime.GenericContainer) ([]*clabtypes.ContainerInterfaces, error)

ListContainersInterfaces lists interfaces for multiple containers.

func (*Service) ListRuntimeImages added in v0.3.0

func (s *Service) ListRuntimeImages(ctx context.Context) ([]RuntimeImageSummary, error)

func (*Service) PullRuntimeImage added in v0.3.0

func (s *Service) PullRuntimeImage(ctx context.Context, image string) (string, error)

func (*Service) RemoveRuntimeImage added in v0.3.0

func (s *Service) RemoveRuntimeImage(ctx context.Context, reference string, force bool) (string, error)

func (*Service) ResetNetem added in v0.2.0

func (s *Service) ResetNetem(ctx context.Context, containerName, iface string) error

ResetNetem removes netem impairments from a specific interface in a container's network namespace.

func (*Service) ResolveTopologySource added in v0.6.0

func (s *Service) ResolveTopologySource(
	opts ResolveTopologySourceOptions,
) (*ResolveTopologySourceResult, error)

ResolveTopologySource materializes a topology source and returns its effective lab name after template, environment, and git-variable expansion.

func (*Service) RunContainerlabTool added in v0.3.0

func (s *Service) RunContainerlabTool(ctx context.Context, opts ContainerlabToolRunOptions) (string, error)

func (*Service) RunFcliCommand added in v0.3.0

func (s *Service) RunFcliCommand(ctx context.Context, opts FcliRunOptions) (string, error)

func (*Service) RunLabLifecycleAction added in v0.3.0

func (s *Service) RunLabLifecycleAction(ctx context.Context, opts NodeLifecycleOptions) error

func (*Service) RunNodeLifecycleAction added in v0.3.0

func (s *Service) RunNodeLifecycleAction(ctx context.Context, opts NodeLifecycleOptions) error

func (*Service) SaveConfig added in v0.2.0

func (s *Service) SaveConfig(ctx context.Context, opts SaveOptions) error

SaveConfig saves the configuration of lab nodes.

func (*Service) SetNetem added in v0.2.0

func (s *Service) SetNetem(ctx context.Context, opts NetemSetOptions) error

SetNetem applies netem impairments to a specific interface in a container's network namespace.

func (*Service) ShowNetem added in v0.2.0

func (s *Service) ShowNetem(ctx context.Context, containerName string) ([]clabtypes.ImpairmentData, error)

ShowNetem returns the current netem impairments for interfaces that have netem qdisc set.

func (*Service) SignCert added in v0.2.0

func (s *Service) SignCert(ctx context.Context, opts CertSignOptions) (*clabcert.Certificate, error)

SignCert signs a certificate with a CA.

type TierDefinition added in v0.2.0

type TierDefinition struct {
	Count int
	Kind  string
	Type  string
}

TierDefinition defines a tier in the topology.

type VethCreateOptions added in v0.2.0

type VethCreateOptions struct {
	AEndpoint string
	BEndpoint string
	MTU       int
}

VethCreateOptions contains options for creating a veth pair.

type VxlanCreateOptions added in v0.2.0

type VxlanCreateOptions struct {
	Remote       string
	Link         string
	ID           int
	DstPort      int
	SrcPort      int
	ParentDevice string
	MTU          int
}

VxlanCreateOptions contains options for creating a VxLAN tunnel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL