clab

package
v0.57.5 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: BSD-3-Clause Imports: 89 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// veth link mtu.
	DefaultVethLinkMTU = 9500
)

Variables

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

Functions

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 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.

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) 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) CreateNetwork added in v0.24.0

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

func (*CLab) DeleteEntriesFromHostsFile added in v0.53.0

func (c *CLab) DeleteEntriesFromHostsFile() error

func (*CLab) Deploy added in v0.53.0

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

Deploy the given topology. skipcq: GO-R1005

func (*CLab) Destroy added in v0.53.0

func (c *CLab) Destroy(ctx context.Context, maxWorkers uint, keepMgmtNet bool) error

Destroy the given topology.

func (*CLab) Exec

func (c *CLab) Exec(ctx context.Context, cmds []string, options *ExecOptions) (*exec.ExecCollection, error)

Exec execute commands on running topology nodes.

func (*CLab) GenerateDotGraph added in v0.43.0

func (c *CLab) GenerateDotGraph() error

GenerateDotGraph generates a graph of the lab topology.

func (*CLab) GenerateDrawioDiagram added in v0.53.0

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

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) GetNode added in v0.53.0

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

GetNode retrieve a node from the clab instance.

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) 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) LoadTopologyFromFile added in v0.53.0

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 *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) 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

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

func WithLabName(n string) ClabOption

WithLabName sets the name of the lab to the provided string.

func WithManagementIpv4Subnet added in v0.53.0

func WithManagementIpv4Subnet(s string) ClabOption

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

func WithManagementIpv6Subnet added in v0.53.0

func WithManagementIpv6Subnet(s string) ClabOption

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

func WithManagementNetworkName added in v0.53.0

func WithManagementNetworkName(n string) ClabOption

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

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

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

DeployOptions represents the options for deploying a lab.

func NewDeployOptions added in v0.53.0

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

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

func (*DeployOptions) ExportTemplate added in v0.53.0

func (d *DeployOptions) ExportTemplate() string

ExportTemplate returns the exportTemplate option value.

func (*DeployOptions) Graph added in v0.53.0

func (d *DeployOptions) Graph() bool

Graph returns the graph option value.

func (*DeployOptions) MaxWorkers added in v0.53.0

func (d *DeployOptions) MaxWorkers() uint

MaxWorkers returns the maxWorkers option value.

func (*DeployOptions) Reconfigure added in v0.53.0

func (d *DeployOptions) Reconfigure() bool

Reconfigure returns the reconfigure option value.

func (*DeployOptions) SetExportTemplate added in v0.53.0

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

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

func (*DeployOptions) SetGraph added in v0.53.0

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

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

func (*DeployOptions) SetMaxWorkers added in v0.53.0

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

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

func (*DeployOptions) SetReconfigure added in v0.53.0

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

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

func (*DeployOptions) SetSkipLabDirFileACLs added in v0.55.0

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

SetSkipLabDirFileACLs sets the skipLabDirFileACLs deployment option.

func (*DeployOptions) SetSkipPostDeploy added in v0.53.0

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

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

func (*DeployOptions) SkipPostDeploy added in v0.53.0

func (d *DeployOptions) SkipPostDeploy() bool

SkipPostDeploy returns the skipPostDeploy option value.

type ExecOptions added in v0.53.0

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

func NewExecOptions added in v0.53.0

func NewExecOptions(filters []*types.GenericFilter) *ExecOptions

func (*ExecOptions) AddFilters added in v0.53.0

func (e *ExecOptions) AddFilters(f ...*types.GenericFilter)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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