core

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: BSD-3-Clause Imports: 108 Imported by: 2

Documentation

Index

Constants

View Source
const (

	// DefaultVethLinkMTU is the veth link mtu.
	DefaultVethLinkMTU = 9500
)

Variables

View Source
var ErrNodeNotFound = errors.New("node not found")

Functions

func FindTopoFileByPath

func FindTopoFileByPath(path string) (string, error)

FindTopoFileByPath takes a topology path, which might be the path to a directory and returns the topology file name if found.

func RetrieveSSHAgentKeys

func RetrieveSSHAgentKeys(ctx context.Context) ([]ssh.PublicKey, error)

RetrieveSSHAgentKeys retrieves public keys registered with the ssh-agent.

func RetrieveSSHPubKeysFromFiles

func RetrieveSSHPubKeysFromFiles() ([]ssh.PublicKey, error)

RetrieveSSHPubKeysFromFiles retrieves public keys from the ~/.ssh/*.authorized_keys and ~/.ssh/*.pub files.

func RuntimeInitializer

func RuntimeInitializer(name string) (string, clabruntime.Initializer, error)

RuntimeInitializer returns a runtime initializer function for a provided runtime name. Order of preference: cli flag -> env var -> default value of docker.

Types

type AnsibleInventory

type AnsibleInventory struct {
	// clab node kinds
	Kinds map[string]*AnsibleKindProps
	// clab nodes aggregated by their kind
	Nodes map[string][]*AnsibleInventoryNode
	// clab nodes aggregated by user-defined groups
	Groups map[string][]*AnsibleInventoryNode
}

AnsibleInventory represents the data structure used to generate the ansible inventory file.

type AnsibleInventoryNode

type AnsibleInventoryNode struct {
	*clabtypes.NodeConfig
}

AnsibleInventoryNode represents the data structure used to generate the ansible inventory file. It embeds the NodeConfig struct and adds the Username and Password fields extracted from the node registry.

type AnsibleKindProps

type AnsibleKindProps struct {
	Username    string
	Password    string
	NetworkOS   string
	AnsibleConn string
}

AnsibleKindProps is the kind properties structure used to generate the ansible inventory file.

type CLab

type CLab struct {
	Config    *Config `json:"config,omitempty"`
	TopoPaths *clabtypes.TopoPaths
	Nodes     map[string]clabnodes.Node `json:"nodes,omitempty"`
	Links     map[int]clablinks.Link    `json:"links,omitempty"`
	Endpoints []clablinks.Endpoint
	Runtimes  map[string]clabruntime.ContainerRuntime `json:"runtimes,omitempty"`
	// reg is a registry of node kinds
	Reg  *clabnodes.NodeRegistry
	Cert *clabcert.Cert
	// List of SSH public keys extracted from the ~/.ssh/authorized_keys file
	// and ~/.ssh/*.pub files.
	// The keys are used to enable key-based SSH access for the nodes.
	SSHPubKeys []ssh.PublicKey
	// contains filtered or unexported fields
}

func NewContainerLab

func NewContainerLab(opts ...ClabOption) (*CLab, error)

NewContainerLab function defines a new container lab.

func (*CLab) BuildGraphFromDeployedLab

func (c *CLab) BuildGraphFromDeployedLab(g *GraphTopo, containers []clabruntime.GenericContainer)

func (*CLab) BuildGraphFromTopo

func (c *CLab) BuildGraphFromTopo(g *GraphTopo)

func (*CLab) CheckConnectivity

func (c *CLab) CheckConnectivity(ctx context.Context) error

CheckConnectivity checks the connectivity to all container runtimes, returns an error if it encounters any, otherwise nil.

func (*CLab) CreateNetwork

func (c *CLab) CreateNetwork(ctx context.Context) error

func (*CLab) DeleteEntriesFromHostsFile

func (c *CLab) DeleteEntriesFromHostsFile() error

func (*CLab) Deploy

func (c *CLab) Deploy(
	ctx context.Context,
	options *DeployOptions,
) ([]clabruntime.GenericContainer, error)

Deploy the given topology. skipcq: GO-R1005

func (*CLab) Destroy

func (c *CLab) Destroy(ctx context.Context, options ...DestroyOption) (err error)

func (*CLab) Exec

func (c *CLab) Exec(
	ctx context.Context,
	cmds []string,
	listOptions ...ListOption,
) (*clabexec.ExecCollection, error)

Exec execute commands on running topology nodes.

func (*CLab) GenerateDotGraph

func (c *CLab) GenerateDotGraph(ctx context.Context) error

GenerateDotGraph generates a graph of the lab topology.

func (*CLab) GenerateDrawioDiagram

func (c *CLab) GenerateDrawioDiagram(version string, userArgs []string) error

GenerateDrawioDiagram pulls (if needed) and runs the "clab-io-draw" container in interactive TTY mode. The container is removed automatically when the TUI session ends.

func (*CLab) GenerateExports

func (c *CLab) GenerateExports(ctx context.Context, f io.Writer, p string) error

GenerateExports generates various export files and writes it to a file in the lab directory. `p` is the path to the template. `f` is the file to write the exported data to.

func (*CLab) GenerateInventories

func (c *CLab) GenerateInventories() error

GenerateInventories generate various inventory files and writes it to a lab location.

func (*CLab) GenerateMermaidGraph

func (c *CLab) GenerateMermaidGraph(direction string) error

func (*CLab) GetNode

func (c *CLab) GetNode(name string) (clabnodes.Node, error)

GetNode retrieve a node from the clab instance.

func (*CLab) HasKind

func (c *CLab) HasKind(k string) bool

HasKind returns true if kind k is found in the list of nodes.

func (*CLab) ListContainerInterfaces

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

ListContainerInterfaces list interfaces of the given container.

func (*CLab) ListContainers

func (c *CLab) ListContainers(
	ctx context.Context,
	options ...ListOption,
) ([]clabruntime.GenericContainer, error)

ListContainers lists all containers using provided filter.

func (*CLab) ListContainersInterfaces

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

ListContainersInterfaces list interfaces of all given containers.

func (*CLab) ListNodesContainers

func (c *CLab) ListNodesContainers(
	ctx context.Context,
) ([]clabruntime.GenericContainer, error)

ListNodesContainers lists all containers based on the nodes stored in clab instance.

func (*CLab) ListNodesContainersIgnoreNotFound

func (c *CLab) ListNodesContainersIgnoreNotFound(
	ctx context.Context,
) ([]clabruntime.GenericContainer, error)

ListNodesContainersIgnoreNotFound lists all containers based on the nodes stored in clab instance, ignoring errors for non found containers.

func (*CLab) LoadOrGenerateCA

func (c *CLab) LoadOrGenerateCA(caCertInput *clabcert.CACSRInput) error

LoadOrGenerateCA loads the CA certificate from the storage, or generates a new one if it does not exist.

func (*CLab) LoadTopologyFromFile

func (c *CLab) LoadTopologyFromFile(topo, varsFile string) error

LoadTopologyFromFile loads a topology by the topo file path parses the topology file into c.Conf structure as well as populates the TopoFile structure with the topology file related information.

func (*CLab) NewNode

func (c *CLab) NewNode(
	nodeName,
	nodeRuntime string,
	nodeDef *clabtypes.NodeDefinition,
	idx int,
) error

NewNode initializes a new node object.

func (*CLab) ProcessTopoPath

func (c *CLab) ProcessTopoPath(path string) (string, error)

ProcessTopoPath takes a topology path, which might be the path to a directory or a file or stdin or a URL (HTTP/HTTPS/S3) and returns the topology file name if found.

func (*CLab) RegisterNodes

func (c *CLab) RegisterNodes()

RegisterNodes registers all the nodes/kinds supported by containerlab.

func (*CLab) RemoveSSHConfig

func (c *CLab) RemoveSSHConfig(topoPaths *clabtypes.TopoPaths) error

RemoveSSHConfig removes the lab specific ssh config file.

func (c *CLab) ResolveLinks() error

ResolveLinks resolves raw links to the actual link types and stores them in the CLab.Links map.

func (*CLab) RetrieveSSHPubKeys

func (c *CLab) RetrieveSSHPubKeys(ctx context.Context) ([]ssh.PublicKey, error)

RetrieveSSHPubKeys retrieves the PubKeys from the different sources SSHAgent as well as all home dir based /.ssh/*.pub files.

func (*CLab) Save added in v0.70.0

func (c *CLab) Save(
	ctx context.Context,
) error

func (*CLab) ServeTopoGraph

func (c *CLab) ServeTopoGraph(tmpl, staticDir, srv string, topoD TopoData) error

type ClabOption

type ClabOption func(c *CLab) error

func WithDebug

func WithDebug(debug bool) ClabOption

WithDebug sets debug mode.

func WithDependencyManager

WithDependencyManager adds Dependency Manager.

func WithKeepMgmtNet

func WithKeepMgmtNet() ClabOption

func WithLabOwner

func WithLabOwner(owner string) ClabOption

WithLabOwner sets the owner label for all nodes in the lab. Only users in the clab_admins group can set a custom owner.

func WithManagementIpv4Subnet

func WithManagementIpv4Subnet(s string) ClabOption

WithManagementIpv4Subnet defined the IPv4 subnet that will be used for the mgmt network.

func WithManagementIpv6Subnet

func WithManagementIpv6Subnet(s string) ClabOption

WithManagementIpv6Subnet defined the IPv6 subnet that will be used for the mgmt network.

func WithManagementNetworkName

func WithManagementNetworkName(n string) ClabOption

WithManagementNetworkName sets the name of the management network that is to be used.

func WithNodeFilter

func WithNodeFilter(nodeFilter []string) ClabOption

WithNodeFilter option sets a filter for nodes to be deployed. A filter is a list of node names to be deployed, names are provided exactly as they are listed in the topology file. Since this is altering the clab.config.Topology.[Nodes,Links] it must only be called after WithTopoFile.

func WithRuntime

func WithRuntime(name string, rtconfig *clabruntime.RuntimeConfig) ClabOption

WithRuntime option sets a container runtime to be used by containerlab.

func WithSkippedBindsPathsCheck

func WithSkippedBindsPathsCheck() ClabOption

WithSkippedBindsPathsCheck skips the binds paths checks.

func WithTimeout

func WithTimeout(dur time.Duration) ClabOption

func WithTopoBackup

func WithTopoBackup(path string) ClabOption

WithTopoBackup creates a backup of the topology file.

func WithTopoPath

func WithTopoPath(path, varsFile string) ClabOption

func WithTopologyFromLab added in v0.71.0

func WithTopologyFromLab(labName string) ClabOption

WithTopologyFromLab loads the topology file path based on a running lab name. The lab name is used to look up the container labels of a running lab and derive the topology file location. It falls back to WithTopoPath once the topology path is discovered.

func WithTopologyName added in v0.70.0

func WithTopologyName(n string) ClabOption

WithTopologyName sets the name of the lab/topology to the provided string.

type Config

type Config struct {
	Name     string              `json:"name,omitempty"`
	Prefix   *string             `json:"prefix,omitempty"`
	Mgmt     *clabtypes.MgmtNet  `json:"mgmt,omitempty"`
	Settings *clabtypes.Settings `json:"settings,omitempty"`
	Topology *clabtypes.Topology `json:"topology,omitempty"`
	// the debug flag value as passed via cli
	// may be used by other packages to enable debug logging
	Debug bool `json:"debug"`
}

Config defines lab configuration as it is provided in the YAML file.

type DeployOptions

type DeployOptions struct {
	// contains filtered or unexported fields
}

DeployOptions represents the options for deploying a lab.

func NewDeployOptions

func NewDeployOptions(maxWorkers uint) (*DeployOptions, error)

NewDeployOptions creates a new DeployOptions instance with the specified maxWorkers value.

func (*DeployOptions) ExportTemplate

func (d *DeployOptions) ExportTemplate() string

ExportTemplate returns the exportTemplate option value.

func (*DeployOptions) Graph

func (d *DeployOptions) Graph() bool

Graph returns the graph option value.

func (*DeployOptions) MaxWorkers

func (d *DeployOptions) MaxWorkers() uint

MaxWorkers returns the maxWorkers option value.

func (*DeployOptions) Reconfigure

func (d *DeployOptions) Reconfigure() bool

Reconfigure returns the reconfigure option value.

func (*DeployOptions) RestoreAll added in v0.72.0

func (d *DeployOptions) RestoreAll() string

RestoreAll returns the restoreAll option value.

func (*DeployOptions) RestoreNodeSnapshots added in v0.72.0

func (d *DeployOptions) RestoreNodeSnapshots() []string

RestoreNodeSnapshots returns the restoreNodeSnapshots option value.

func (*DeployOptions) SetExportTemplate

func (d *DeployOptions) SetExportTemplate(templatePath string) *DeployOptions

SetExportTemplate sets the exportTemplate option and returns the updated DeployOptions instance.

func (*DeployOptions) SetGraph

func (d *DeployOptions) SetGraph(b bool) *DeployOptions

SetGraph sets the graph option and returns the updated DeployOptions instance.

func (*DeployOptions) SetMaxWorkers

func (d *DeployOptions) SetMaxWorkers(i uint) *DeployOptions

SetMaxWorkers sets the maxWorkers option and returns the updated DeployOptions instance.

func (*DeployOptions) SetReconfigure

func (d *DeployOptions) SetReconfigure(b bool) *DeployOptions

SetReconfigure sets the reconfigure option and returns the updated DeployOptions instance.

func (*DeployOptions) SetRestoreAll added in v0.72.0

func (d *DeployOptions) SetRestoreAll(path string) *DeployOptions

SetRestoreAll sets the restoreAll option and returns the updated DeployOptions instance.

func (*DeployOptions) SetRestoreNodeSnapshots added in v0.72.0

func (d *DeployOptions) SetRestoreNodeSnapshots(snapshots []string) *DeployOptions

SetRestoreNodeSnapshots sets the restoreNodeSnapshots option and returns the updated DeployOptions instance.

func (*DeployOptions) SetSkipLabDirFileACLs

func (d *DeployOptions) SetSkipLabDirFileACLs(b bool) *DeployOptions

SetSkipLabDirFileACLs sets the skipLabDirFileACLs deployment option.

func (*DeployOptions) SetSkipPostDeploy

func (d *DeployOptions) SetSkipPostDeploy(b bool) *DeployOptions

SetSkipPostDeploy sets the skipPostDeploy option and returns the updated DeployOptions instance.

func (*DeployOptions) SkipPostDeploy

func (d *DeployOptions) SkipPostDeploy() bool

SkipPostDeploy returns the skipPostDeploy option value.

type DestroyOption added in v0.70.0

type DestroyOption func(o *DestroyOptions)

DestroyOption is a type used for functional options for the Clab Destroy method.

func WithDestroyAll added in v0.70.0

func WithDestroyAll() DestroyOption

WithDestroyAll informs the destroy method to destroy all labs.

func WithDestroyCleanup added in v0.70.0

func WithDestroyCleanup() DestroyOption

WithDestroyCleanup informs the destroy method to also try to cleanup directories.

func WithDestroyGraceful added in v0.70.0

func WithDestroyGraceful() DestroyOption

WithDestroyGraceful attempts to stop containers before destroying them.

func WithDestroyKeepMgmtNet added in v0.70.0

func WithDestroyKeepMgmtNet() DestroyOption

WithDestroyKeepMgmtNet retains the mgmt network on destroy.

func WithDestroyMaxWorkers added in v0.70.0

func WithDestroyMaxWorkers(
	i uint,
) DestroyOption

WithDestroyMaxWorkers sets max workers for destroy events.

func WithDestroyNodeFilter added in v0.70.0

func WithDestroyNodeFilter(ss []string) DestroyOption

WithDestroyNodeFilter accepts a normal node-filter to be used with the Destroy operation.

func WithDestroyTerminalPrompt added in v0.70.0

func WithDestroyTerminalPrompt() DestroyOption

WithDestroyTerminalPrompt asks the destroy method to prompt for deletion when using the all option.

type DestroyOptions added in v0.70.0

type DestroyOptions struct {
	// contains filtered or unexported fields
}

DestroyOptions represents the options for destroying lab(s).

func NewDestroyOptions added in v0.70.0

func NewDestroyOptions() *DestroyOptions

NewDestroyOptions returns a new destroy options object.

type GraphTopo

type GraphTopo struct {
	Nodes []clabtypes.ContainerDetails `json:"nodes,omitempty"`
	Links []Link                       `json:"links,omitempty"`
}
type Link struct {
	Source         string `json:"source,omitempty"`
	SourceEndpoint string `json:"source_endpoint,omitempty"`
	Target         string `json:"target,omitempty"`
	TargetEndpoint string `json:"target_endpoint,omitempty"`
}

type ListOption added in v0.70.0

type ListOption func(o *ListOptions)

ListOption is a type used for functional options for the Clab List method.

func WithListContainerName added in v0.71.0

func WithListContainerName(
	s string,
) ListOption

WithListContainerName filters the list operation to the given container name.

func WithListFilter added in v0.71.0

func WithListFilter(fs []*clabtypes.GenericFilter) ListOption

WithListFilter adds user created normal filters to the filter set.

func WithListFromCliArgs added in v0.70.0

func WithListFromCliArgs(ss []string) ListOption

WithListFromCliArgs filters the list based on a string slice of cli args, transforming those args into proper filters in the ToFilters method.

func WithListLabName added in v0.70.0

func WithListLabName(
	s string,
) ListOption

WithListLabName filters the list operation to the given lab name.

func WithListNodeName added in v0.70.0

func WithListNodeName(
	s string,
) ListOption

WithListNodeName filters the list operation to the given node name.

func WithListToolType added in v0.70.0

func WithListToolType(
	s string,
) ListOption

WithListToolType filters the list operation to the tool type name.

func WithListclabLabelExists added in v0.70.0

func WithListclabLabelExists() ListOption

WithListclabLabelExists filters the list to any containers that include a containerlab label.

type ListOptions added in v0.70.0

type ListOptions struct {
	// contains filtered or unexported fields
}

ListOptions represents the options for listing containers.

func NewListOptions added in v0.70.0

func NewListOptions() *ListOptions

NewListOptions returns a new list options object.

func (*ListOptions) ToFilters added in v0.70.0

func (o *ListOptions) ToFilters() []*clabtypes.GenericFilter

ToFilters converts the list options to a slice of generic filters.

type NornirSimpleInventory

type NornirSimpleInventory struct {
	// clab node kinds
	Kinds map[string]*NornirSimpleInventoryKindProps
	// clab nodes aggregated by their kind
	Nodes map[string][]*NornirSimpleInventoryNode
	// clab nodes aggregated by user-defined groups
	Groups map[string][]*NornirSimpleInventoryNode
}

NornirSimpleInventory represents the data structure used to generate the nornir simple inventory file.

type NornirSimpleInventoryKindProps

type NornirSimpleInventoryKindProps struct {
	Username string
	Password string
	Platform string
}

NornirSimpleInventoryKindProps is the kind properties structure used to generate the nornir simple inventory file.

type NornirSimpleInventoryNode

type NornirSimpleInventoryNode struct {
	*clabtypes.NodeConfig
	NornirGroups []string
}

NornirSimpleInventoryNode represents the data structure used to generate the nornir simple inventory file. It embeds the NodeConfig struct and adds the Username and Password fields extracted from the node registry.

type SSHConfigNodeTmpl

type SSHConfigNodeTmpl struct {
	Name      string
	Username  string
	SSHConfig *clabtypes.SSHConfig
}

SSHConfigNodeTmpl represents values for a single node in the sshconfig template.

type SSHConfigTmpl

type SSHConfigTmpl struct {
	Nodes        []SSHConfigNodeTmpl
	TopologyName string
}

SSHConfigTmpl is the top-level data structure for the sshconfig template.

type TopoData

type TopoData struct {
	Name string
	Data template.JS
}

type TopologyExport

type TopologyExport struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Clab *CLab  `json:"clab,omitempty"`
	// SSHPubKeys is a list of string representations of SSH public keys.
	SSHPubKeys  []string                         `json:"SSHPubKeys,omitempty"`
	NodeConfigs map[string]*clabtypes.NodeConfig `json:"nodeconfigs,omitempty"`
}

TopologyExport holds a combination of CLab structure and map of NodeConfig types, which expands Node definitions with dynamically created values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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