Documentation
¶
Index ¶
- Constants
- Variables
- func FindTopoFileByPath(path string) (string, error)
- func RetrieveSSHAgentKeys() ([]ssh.PublicKey, error)
- func RetrieveSSHPubKeysFromFiles() ([]ssh.PublicKey, error)
- func RuntimeInitializer(name string) (string, runtime.Initializer, error)
- type AnsibleInventory
- type AnsibleInventoryNode
- type AnsibleKindProps
- type CLab
- func (c *CLab) BuildGraphFromDeployedLab(g *GraphTopo, containers []runtime.GenericContainer)
- func (c *CLab) BuildGraphFromTopo(g *GraphTopo)
- func (c *CLab) CheckConnectivity(ctx context.Context) error
- func (c *CLab) CreateNetwork(ctx context.Context) error
- func (c *CLab) DeleteEntriesFromHostsFile() error
- func (c *CLab) Deploy(ctx context.Context, options *DeployOptions) ([]runtime.GenericContainer, error)
- func (c *CLab) Destroy(ctx context.Context, maxWorkers uint, keepMgmtNet bool) error
- func (c *CLab) Exec(ctx context.Context, cmds []string, options *ExecOptions) (*exec.ExecCollection, error)
- func (c *CLab) GenerateDotGraph() error
- func (c *CLab) GenerateDrawioDiagram(version string, userArgs []string) error
- func (c *CLab) GenerateExports(ctx context.Context, f io.Writer, p string) error
- func (c *CLab) GenerateInventories() error
- func (c *CLab) GenerateMermaidGraph(direction string) error
- func (c *CLab) GetNode(name string) (nodes.Node, error)
- func (c *CLab) HasKind(k string) bool
- func (c *CLab) ListContainerInterfaces(ctx context.Context, container runtime.GenericContainer) (*types.ContainerInterfaces, error)
- func (c *CLab) ListContainers(ctx context.Context, filter []*types.GenericFilter) ([]runtime.GenericContainer, error)
- func (c *CLab) ListContainersInterfaces(ctx context.Context, containers []runtime.GenericContainer) ([]*types.ContainerInterfaces, error)
- func (c *CLab) ListNodesContainers(ctx context.Context) ([]runtime.GenericContainer, error)
- func (c *CLab) ListNodesContainersIgnoreNotFound(ctx context.Context) ([]runtime.GenericContainer, error)
- func (c *CLab) LoadOrGenerateCA(caCertInput *cert.CACSRInput) error
- func (c *CLab) LoadTopologyFromFile(topo, varsFile string) error
- func (c *CLab) NewNode(nodeName, nodeRuntime string, nodeDef *types.NodeDefinition, idx int) error
- func (c *CLab) ProcessTopoPath(path string) (string, error)
- func (c *CLab) RegisterNodes()
- func (c *CLab) RemoveSSHConfig(topoPaths *types.TopoPaths) error
- func (c *CLab) ResolveLinks() error
- func (c *CLab) RetrieveSSHPubKeys() ([]ssh.PublicKey, error)
- func (c *CLab) ServeTopoGraph(tmpl, staticDir, srv string, topoD TopoData) error
- type ClabOption
- func WithDebug(debug bool) ClabOption
- func WithDependencyManager(dm depMgr.DependencyManager) ClabOption
- func WithKeepMgmtNet() ClabOption
- func WithLabName(n string) ClabOption
- func WithLabOwner(owner string) ClabOption
- func WithManagementIpv4Subnet(s string) ClabOption
- func WithManagementIpv6Subnet(s string) ClabOption
- func WithManagementNetworkName(n string) ClabOption
- func WithNodeFilter(nodeFilter []string) ClabOption
- func WithRuntime(name string, rtconfig *runtime.RuntimeConfig) ClabOption
- func WithSkippedBindsPathsCheck() ClabOption
- func WithTimeout(dur time.Duration) ClabOption
- func WithTopoBackup(path string) ClabOption
- func WithTopoFromLab(labName string) ClabOption
- func WithTopoPath(path, varsFile string) ClabOption
- type Config
- type DeployOptions
- func (d *DeployOptions) ExportTemplate() string
- func (d *DeployOptions) Graph() bool
- func (d *DeployOptions) MaxWorkers() uint
- func (d *DeployOptions) Reconfigure() bool
- func (d *DeployOptions) SetExportTemplate(templatePath string) *DeployOptions
- func (d *DeployOptions) SetGraph(b bool) *DeployOptions
- func (d *DeployOptions) SetMaxWorkers(i uint) *DeployOptions
- func (d *DeployOptions) SetReconfigure(b bool) *DeployOptions
- func (d *DeployOptions) SetSkipLabDirFileACLs(b bool) *DeployOptions
- func (d *DeployOptions) SetSkipPostDeploy(b bool) *DeployOptions
- func (d *DeployOptions) SkipPostDeploy() bool
- type ExecOptions
- type GraphTopo
- type Link
- type NornirSimpleInventory
- type NornirSimpleInventoryKindProps
- type NornirSimpleInventoryNode
- type SSHConfigNodeTmpl
- type SSHConfigTmpl
- type TopoData
- type TopologyExport
Constants ¶
const (
// veth link mtu.
DefaultVethLinkMTU = 9500
)
const NornirPlatformNameSchemaEnvVar = "CLAB_NORNIR_PLATFORM_NAME_SCHEMA"
Variables ¶
var ErrNodeNotFound = errors.New("node not found")
Functions ¶
func FindTopoFileByPath ¶
FindTopoFileByPath takes a topology path, which might be the path to a directory and returns the topology file name if found.
func RetrieveSSHAgentKeys ¶
RetrieveSSHAgentKeys retrieves public keys registered with the ssh-agent.
func RetrieveSSHPubKeysFromFiles ¶
RetrieveSSHPubKeysFromFiles retrieves public keys from the ~/.ssh/*.authorized_keys and ~/.ssh/*.pub files.
func RuntimeInitializer ¶
func RuntimeInitializer(name string) (string, runtime.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 {
*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 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 *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 NewContainerlabFromTopologyFileOrLabName ¶
func NewContainerlabFromTopologyFileOrLabName(ctx context.Context, topoPath, labName, varsFile, runtimeName string, debug bool, timeout time.Duration, graceful bool, ) (*CLab, error)
NewContainerlabFromTopologyFileOrLabName creates a containerlab instance using either a topology file path or a lab name. It returns the initialized CLab structure with the topology loaded.
func (*CLab) BuildGraphFromDeployedLab ¶
func (c *CLab) BuildGraphFromDeployedLab(g *GraphTopo, containers []runtime.GenericContainer)
func (*CLab) BuildGraphFromTopo ¶
func (*CLab) CheckConnectivity ¶
CheckConnectivity checks the connectivity to all container runtimes, returns an error if it encounters any, otherwise nil.
func (*CLab) DeleteEntriesFromHostsFile ¶
func (*CLab) Deploy ¶
func (c *CLab) Deploy(ctx context.Context, options *DeployOptions) ([]runtime.GenericContainer, error)
Deploy the given topology. skipcq: GO-R1005
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 ¶
GenerateDotGraph generates a graph of the lab topology.
func (*CLab) GenerateDrawioDiagram ¶
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 ¶
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 ¶
GenerateInventories generate various inventory files and writes it to a lab location.
func (*CLab) GenerateMermaidGraph ¶
func (*CLab) ListContainerInterfaces ¶
func (c *CLab) ListContainerInterfaces( ctx context.Context, container runtime.GenericContainer, ) (*types.ContainerInterfaces, error)
ListContainerInterfaces list interfaces of the given container.
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) ListContainersInterfaces ¶
func (c *CLab) ListContainersInterfaces( ctx context.Context, containers []runtime.GenericContainer, ) ([]*types.ContainerInterfaces, error)
ListContainersInterfaces list interfaces of all given containers.
func (*CLab) ListNodesContainers ¶
ListNodesContainers lists all containers based on the nodes stored in clab instance.
func (*CLab) ListNodesContainersIgnoreNotFound ¶
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 ¶
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 ¶
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) ProcessTopoPath ¶
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 ¶
RemoveSSHConfig removes the lab specific ssh config file.
func (*CLab) ResolveLinks ¶
ResolveLinks resolves raw links to the actual link types and stores them in the CLab.Links map.
func (*CLab) RetrieveSSHPubKeys ¶
RetrieveSSHPubKeys retrieves the PubKeys from the different sources SSHAgent as well as all home dir based /.ssh/*.pub files.
type ClabOption ¶
func WithDependencyManager ¶
func WithDependencyManager(dm depMgr.DependencyManager) ClabOption
WithDependencyManager adds Dependency Manager.
func WithKeepMgmtNet ¶
func WithKeepMgmtNet() ClabOption
func WithLabName ¶
func WithLabName(n string) ClabOption
WithLabName sets the name of the lab to the provided string.
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 *runtime.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 WithTopoFromLab ¶
func WithTopoFromLab(labName string) ClabOption
WithTopoFromLab 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 WithTopoPath ¶
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 ¶
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) 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) 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 ExecOptions ¶
type ExecOptions struct {
// contains filtered or unexported fields
}
func NewExecOptions ¶
func NewExecOptions(filters []*types.GenericFilter) *ExecOptions
func (*ExecOptions) AddFilters ¶
func (e *ExecOptions) AddFilters(f ...*types.GenericFilter)
type GraphTopo ¶
type GraphTopo struct {
Nodes []types.ContainerDetails `json:"nodes,omitempty"`
Links []Link `json:"links,omitempty"`
}
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 ¶
NornirSimpleInventoryKindProps is the kind properties structure used to generate the nornir simple inventory file.
type NornirSimpleInventoryNode ¶
type NornirSimpleInventoryNode struct {
*types.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 ¶
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 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]*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.