clab

package
v0.51.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: BSD-3-Clause Imports: 83 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// veth link mtu.
	DefaultVethLinkMTU = 9500
)

Variables

This section is empty.

Functions

func AddVxLanInterface

func AddVxLanInterface(vxlan VxLAN) (err error)

AddVxLanInterface creates VxLan interface by given vxlan object.

func AppendHostsFileEntries added in v0.16.2

func AppendHostsFileEntries(containers []runtime.GenericContainer, labname string) error

func DeleteEntriesFromHostsFile added in v0.16.2

func DeleteEntriesFromHostsFile(labname string) error

func FindTopoFileByPath added in v0.48.5

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 GetLinksByNamePrefix added in v0.14.0

func GetLinksByNamePrefix(prefix string) ([]netlink.Link, error)

GetLinksByNamePrefix returns a list of links whose name matches a prefix.

func RetrieveSSHAgentKeys added in v0.44.0

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

RetrieveSSHAgentKeys retrieves public keys registered with the ssh-agent.

func RetrieveSSHPubKeysFromFiles added in v0.44.0

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

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

func RuntimeInitializer added in v0.44.0

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

RuntimeInitializer returns a runtime initializer function for a provided runtime name.

func SetIngressMirror

func SetIngressMirror(src, dst string) (err error)

SetIngressMirror sets TC to mirror ingress from given port as MirrorIngress.

Types

type AnsibleInventory added in v0.50.0

type AnsibleInventory struct {
	// clab node kinds
	Kinds map[string]*KindProps
	// 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 added in v0.50.0

type AnsibleInventoryNode struct {
	*types.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 CLab

type CLab struct {
	Config    *Config `json:"config,omitempty"`
	TopoPaths *types.TopoPaths
	Nodes     map[string]nodes.Node `json:"nodes,omitempty"`
	Links     map[int]links.Link    `json:"links,omitempty"`
	Endpoints []links.Endpoint
	Runtimes  map[string]runtime.ContainerRuntime `json:"runtimes,omitempty"`
	// reg is a registry of node kinds
	Reg  *nodes.NodeRegistry
	Cert *cert.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) AddSSHConfig added in v0.47.0

func (c *CLab) AddSSHConfig() error

AddSSHConfig adds the lab specific ssh config file.

func (*CLab) BuildGraphFromDeployedLab added in v0.25.0

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

func (*CLab) BuildGraphFromTopo added in v0.25.0

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

func (*CLab) CheckTopologyDefinition

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

CheckTopologyDefinition runs topology checks and returns any errors found. This function runs after topology file is parsed and all nodes/links are initialized.

func (*CLab) CreateAuthzKeysFile added in v0.22.0

func (c *CLab) CreateAuthzKeysFile() error

CreateAuthzKeysFile creates the authorized_keys file in the lab directory using the public ssh keys retrieved from agent and local files.

func (*CLab) CreateNetwork added in v0.24.0

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

func (*CLab) CreateNodes

func (c *CLab) CreateNodes(ctx context.Context, maxWorkers uint, skipPostDeploy bool) (*sync.WaitGroup, *exec.ExecCollection, error)

CreateNodes schedules nodes creation and returns a waitgroup for all nodes with the exec collection created from the exec config of each node. The exec collection is returned to the caller to ensure that the execution log is printed after the nodes are created. Nodes interdependencies are created in this function.

func (*CLab) DeleteNodes added in v0.15.0

func (c *CLab) DeleteNodes(ctx context.Context, workers uint, serialNodes map[string]struct{})

func (*CLab) ExtractDNSServers added in v0.47.0

func (c *CLab) ExtractDNSServers(filesys fs.FS) error

ExtractDNSServers extracts DNS servers from the resolv.conf files and populates the Nodes DNS Config with these if not specifically provided.

func (*CLab) GenerateDotGraph added in v0.43.0

func (c *CLab) GenerateDotGraph() error

GenerateDotGraph generates a graph of the lab topology.

func (*CLab) GenerateExports added in v0.26.0

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

GenerateExports generates various export files and writes it to a lab location.

func (*CLab) GenerateInventories

func (c *CLab) GenerateInventories() error

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

func (*CLab) GenerateMermaidGraph added in v0.43.0

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

func (*CLab) GetLinkNodes added in v0.46.0

func (c *CLab) GetLinkNodes() map[string]links.Node

GetLinkNodes returns all CLab.Nodes nodes as links.Nodes enriched with the special nodes - host and mgmt-net. The CLab nodes are copied to a new map and thus clab.Node interface is converted to link.Node.

func (*CLab) GetNodeRuntime added in v0.15.0

func (c *CLab) GetNodeRuntime(contName string) (runtime.ContainerRuntime, error)

func (*CLab) GetSpecialLinkNodes added in v0.46.0

func (c *CLab) GetSpecialLinkNodes() map[string]links.Node

GetSpecialLinkNodes returns a map of special nodes that are used to resolve links. Special nodes are host and mgmt-bridge nodes that are not typically present in the topology file but are required to resolve links.

func (*CLab) GetTopology

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

GetTopology parses the topology file into c.Conf structure as well as populates the TopoFile structure with the topology file related information.

func (*CLab) GlobalRuntime added in v0.15.0

func (c *CLab) GlobalRuntime() runtime.ContainerRuntime

func (*CLab) HasKind added in v0.25.0

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

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

func (*CLab) ListContainers

func (c *CLab) ListContainers(ctx context.Context, filter []*types.GenericFilter) ([]runtime.GenericContainer, error)

ListContainers lists all containers using provided filter.

func (*CLab) ListNodesContainers added in v0.34.0

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

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

func (*CLab) ListNodesContainersIgnoreNotFound added in v0.44.0

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

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

func (*CLab) LoadKernelModules added in v0.41.0

func (c *CLab) LoadKernelModules() error

LoadKernelModules loads containerlab-required kernel modules.

func (*CLab) LoadOrGenerateCA added in v0.37.0

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

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

func (*CLab) NewNode

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

NewNode initializes a new node object.

func (*CLab) ProcessTopoPath added in v0.48.5

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 and returns the topology file name if found.

func (*CLab) RegisterNodes added in v0.35.0

func (c *CLab) RegisterNodes()

RegisterNodes registers all the nodes/kinds supported by containerlab.

func (*CLab) RemoveHostOrBridgeVeth added in v0.32.4

func (c *CLab) RemoveHostOrBridgeVeth(l *types.Link) (err error)

RemoveHostOrBridgeVeth tries to remove veths connected to the host network namespace or a linux bridge and does nothing in case they are not found.

func (*CLab) RemoveSSHConfig added in v0.47.0

func (c *CLab) RemoveSSHConfig(topoPaths *types.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 added in v0.44.0

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

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

func (*CLab) ServeTopoGraph added in v0.25.0

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

func (*CLab) SetClabIntfsEnvVar added in v0.44.3

func (c *CLab) SetClabIntfsEnvVar()

SetClabIntfsEnvVar sets CLAB_INTFS env var for each node which holds the number of interfaces a node expects to have (without mgmt interfaces).

func (*CLab) VerifyContainersUniqueness

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

VerifyContainersUniqueness ensures that nodes defined in the topology do not have names of the existing containers additionally it checks that the lab name is unique and no containers are currently running with the same lab name label.

func (*CLab) WaitForExternalNodeDependencies added in v0.32.0

func (c *CLab) WaitForExternalNodeDependencies(ctx context.Context, nodeName string)

WaitForExternalNodeDependencies makes nodes that have a reference to an external container network-namespace (network-mode: container:<NAME>) to wait until the referenced container is in started status. The wait time is 15 minutes by default.

type ClabOption

type ClabOption func(c *CLab) error

func WithDebug

func WithDebug(debug bool) ClabOption

WithDebug sets debug mode.

func WithDependencyManager added in v0.51.0

func WithDependencyManager(dm depMgr.DependencyManager) ClabOption

WithDependencyManager adds Dependency Manager.

func WithKeepMgmtNet added in v0.15.0

func WithKeepMgmtNet() ClabOption

func WithNodeFilter added in v0.39.0

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 added in v0.14.0

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

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

func WithTimeout

func WithTimeout(dur time.Duration) ClabOption

func WithTopoPath added in v0.45.0

func WithTopoPath(path, varsFile string) ClabOption

type Config

type Config struct {
	Name     string          `json:"name,omitempty"`
	Prefix   *string         `json:"prefix,omitempty"`
	Mgmt     *types.MgmtNet  `json:"mgmt,omitempty"`
	Settings *types.Settings `json:"settings,omitempty"`
	Topology *types.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 GraphTopo added in v0.25.0

type GraphTopo struct {
	Nodes []types.ContainerDetails `json:"nodes,omitempty"`
	Links []Link                   `json:"links,omitempty"`
}

type KindProps added in v0.50.0

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

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

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 SSHConfigNodeTmpl added in v0.47.0

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

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

type SSHConfigTmpl added in v0.47.0

type SSHConfigTmpl struct {
	Nodes        []SSHConfigNodeTmpl
	TopologyName string
}

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

type TopoData added in v0.25.0

type TopoData struct {
	Name string
	Data template.JS
}

type TopologyExport added in v0.26.0

type TopologyExport struct {
	Name        string                       `json:"name"`
	Type        string                       `json:"type"`
	Clab        *CLab                        `json:"clab,omitempty"`
	NodeConfigs map[string]*types.NodeConfig `json:"nodeconfigs,omitempty"`
}

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

type VxLAN

type VxLAN struct {
	Name     string // interface name
	ParentIf string // parent interface name
	ID       int    // VxLan ID
	Remote   net.IP // VxLan destination address
	MTU      int    // VxLan Interface MTU (with VxLan encap), used mirroring
	UDPPort  int    // VxLan UDP port (src/dest, no range, single value)
}

VxLAN is a structure to describe vxlan endpoint adopted from https://github.com/redhat-nfvpe/koko/blob/bd156c82bf25837545fb109c69c7b91c3457b318/api/koko_api.go#L46

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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