nodes

package
v0.0.0-0.60.0-beta3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: BSD-3-Clause Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// default connection mode for vrnetlab based containers.
	VrDefConnMode = "tc"
	// keys for the map returned by GetImages.
	ImageKey   = "image"
	KernelKey  = "kernel"
	SandboxKey = "sandbox"
)

Variables

View Source
var (
	// a map of node kinds overriding the default global runtime.
	NonDefaultRuntimes = map[string]string{}

	// ErrCommandExecError is an error returned when a command is failed to execute on a given node.
	ErrCommandExecError = errors.New("command execution error")
	// ErrContainersNotFound indicated that for a given node no containers where found in the runtime.
	ErrContainersNotFound = errors.New("containers not found")
)
View Source
var VMInterfaceRegexp = regexp.MustCompile(`eth[1-9][0-9]*$`) // skipcq: GO-C4007

Functions

func GenericVMInterfaceCheck added in v0.38.0

func GenericVMInterfaceCheck(nodeName string, eps []links.Endpoint) error

GenericVMInterfaceCheck checks interface names for generic VM-based nodes. These nodes could only have interfaces named ethX, where X is >0.

func LoadStartupConfigFileVr added in v0.34.0

func LoadStartupConfigFileVr(node Node, configDirName, startupCfgFName string) error

LoadStartupConfigFileVr templates a startup-config using the file specified for VM-based nodes in the topo and puts the resulting config file by the LabDir/configDirName/startupCfgFName path.

func SetNonDefaultRuntimePerKind added in v0.27.0

func SetNonDefaultRuntimePerKind(kindnames []string, runtime string) error

SetNonDefaultRuntimePerKind sets a non default runtime for kinds that requires that (see cvx).

Types

type Credentials added in v0.35.0

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

Credentials defines NOS SSH credentials.

func NewCredentials added in v0.35.0

func NewCredentials(username, password string) *Credentials

NewCredentials constructor for the Credentials struct.

func (*Credentials) GetPassword added in v0.35.0

func (c *Credentials) GetPassword() string

func (*Credentials) GetUsername added in v0.35.0

func (c *Credentials) GetUsername() string

func (*Credentials) Slice added in v0.35.2

func (c *Credentials) Slice() []string

Slice returns credentials as a slice.

type DefaultNode added in v0.33.0

type DefaultNode struct {
	Cfg              *types.NodeConfig
	Mgmt             *types.MgmtNet
	Runtime          runtime.ContainerRuntime
	HostRequirements *types.HostRequirements
	// SSHConfig is the SSH client configuration that a clab node requires.
	SSHConfig *types.SSHConfig
	// Indicates that the node should not start without no license file defined
	LicensePolicy types.LicensePolicy
	// OverwriteNode stores the interface used to overwrite methods defined
	// for DefaultNode, so that particular nodes can provide custom implementations.
	OverwriteNode NodeOverwrites
	// List of link endpoints that are connected to the node.
	Endpoints []links.Endpoint
	// Interface aliasing-related variables
	InterfaceRegexp       *regexp.Regexp
	InterfaceMappedPrefix string
	InterfaceOffset       int
	InterfaceHelp         string
	FirstDataIfIndex      int
	// contains filtered or unexported fields
}

DefaultNode implements the Node interface and is embedded to the structs of all other nodes. It has common fields and methods that every node should typically have. Nodes can override methods if needed.

func NewDefaultNode added in v0.34.0

func NewDefaultNode(n NodeOverwrites) *DefaultNode

NewDefaultNode initializes the DefaultNode structure and receives a NodeOverwrites interface which is implemented by the node struct of a particular kind. This allows DefaultNode to access fields of the specific node struct in the methods defined for DefaultNode.

func (*DefaultNode) AddEndpoint added in v0.44.0

func (d *DefaultNode) AddEndpoint(e links.Endpoint) error

AddEndpoint maps the endpoint name to before adding it to the node endpoints if it matches the interface alias regexp. Returns an error if the mapping goes wrong.

func (*DefaultNode) AddLinkToContainer added in v0.44.0

func (d *DefaultNode) AddLinkToContainer(ctx context.Context, link netlink.Link, f func(ns.NetNS) error) error

func (*DefaultNode) CalculateInterfaceIndex added in v0.56.0

func (d *DefaultNode) CalculateInterfaceIndex(ifName string) (int, error)

CalculateInterfaceIndex parses the supplied interface name with the InterfaceRegexp. Using the the port offset, it calculates the mapped interface index based on the InterfaceOffset and the first data interface index.

func (*DefaultNode) CheckDeploymentConditions added in v0.34.0

func (d *DefaultNode) CheckDeploymentConditions(ctx context.Context) error

CheckDeploymentConditions wraps individual functions that check if a node satisfies deployment requirements.

func (*DefaultNode) CheckInterfaceName added in v0.34.0

func (d *DefaultNode) CheckInterfaceName() error

CheckInterfaceName checks if a name of the interface referenced in the topology file is in the expected range of name values. A no-op for the default node, specific nodes should implement this method.

func (*DefaultNode) CheckInterfaceOverlap added in v0.56.0

func (d *DefaultNode) CheckInterfaceOverlap() error

func (*DefaultNode) Config added in v0.33.0

func (d *DefaultNode) Config() *types.NodeConfig

func (*DefaultNode) Delete added in v0.33.0

func (d *DefaultNode) Delete(ctx context.Context) error
func (d *DefaultNode) DeleteNetnsSymlink() error

DeleteNetnsSymlink deletes the symlink file created for the container netns.

func (*DefaultNode) Deploy added in v0.33.0

func (d *DefaultNode) Deploy(ctx context.Context, _ *DeployParams) error

func (*DefaultNode) DeployEndpoints added in v0.52.0

func (d *DefaultNode) DeployEndpoints(ctx context.Context) error

DeployEndpoints deploys endpoints associated with the node. The deployment of endpoints is done by deploying a link with the endpoint triggering it.

func (*DefaultNode) ExecFunction added in v0.44.0

func (d *DefaultNode) ExecFunction(ctx context.Context, f func(ns.NetNS) error) error

ExecFunction executes the given function in the nodes network namespace.

func (*DefaultNode) GenerateConfig added in v0.34.0

func (d *DefaultNode) GenerateConfig(dst, templ string) error

GenerateConfig generates configuration for the nodes out of the template based on the node configuration and saves the result to dst.

func (*DefaultNode) GetContainerName added in v0.35.0

func (d *DefaultNode) GetContainerName() string

GetContainerName returns the name used by the runtime to identify the container e.g. ext-container nodes use the name as defined in the topo file, while most other containers use long (prefixed) name.

func (*DefaultNode) GetContainerStatus added in v0.51.0

func (d *DefaultNode) GetContainerStatus(ctx context.Context) runtime.ContainerStatus

func (*DefaultNode) GetContainers added in v0.34.0

func (d *DefaultNode) GetContainers(ctx context.Context) ([]runtime.GenericContainer, error)

func (*DefaultNode) GetEndpoints added in v0.44.0

func (d *DefaultNode) GetEndpoints() []links.Endpoint

func (*DefaultNode) GetImages added in v0.33.0

func (d *DefaultNode) GetImages(_ context.Context) map[string]string

func (*DefaultNode) GetLinkEndpointType added in v0.44.0

func (*DefaultNode) GetLinkEndpointType() links.LinkEndpointType

GetLinkEndpointType returns a veth link endpoint type for default nodes. The LinkEndpointTypeVeth indicates a veth endpoint which doesn't require special handling.

func (*DefaultNode) GetMappedInterfaceName added in v0.56.0

func (d *DefaultNode) GetMappedInterfaceName(ifName string) (string, error)

GetMappedInterfaceName returns with a mapped interface name based on the mapped interface prefix and calculated mapped interface index.

func (*DefaultNode) GetRuntime added in v0.33.0

func (d *DefaultNode) GetRuntime() runtime.ContainerRuntime

func (*DefaultNode) GetSSHConfig added in v0.48.0

func (d *DefaultNode) GetSSHConfig() *types.SSHConfig

func (*DefaultNode) GetShortName added in v0.44.0

func (d *DefaultNode) GetShortName() string

func (*DefaultNode) GetState added in v0.44.0

func (d *DefaultNode) GetState() state.NodeState

func (*DefaultNode) IsHealthy added in v0.51.0

func (d *DefaultNode) IsHealthy(ctx context.Context) (bool, error)

func (*DefaultNode) LoadOrGenerateCertificate added in v0.39.0

func (d *DefaultNode) LoadOrGenerateCertificate(certInfra *cert.Cert, topoName string) (nodeCert *cert.Certificate, err error)

LoadOrGenerateCertificate loads a certificate using a certificate storage provider provided in certInfra or generates a new one if it does not exist.

func (*DefaultNode) PostDeploy added in v0.33.0

func (*DefaultNode) PostDeploy(_ context.Context, _ *PostDeployParams) error

func (*DefaultNode) PreDeploy added in v0.33.0

func (d *DefaultNode) PreDeploy(_ context.Context, params *PreDeployParams) error

PreDeploy is a common method for all nodes that is called before the node is deployed.

func (*DefaultNode) PullImage added in v0.34.0

func (d *DefaultNode) PullImage(ctx context.Context) error

func (*DefaultNode) RunExec added in v0.34.0

func (d *DefaultNode) RunExec(ctx context.Context, execCmd *exec.ExecCmd) (*exec.ExecResult, error)

RunExec executes a single command for a node.

func (*DefaultNode) RunExecFromConfig added in v0.51.0

func (d *DefaultNode) RunExecFromConfig(ctx context.Context, ec *exec.ExecCollection) error

func (*DefaultNode) RunExecNotWait added in v0.35.0

func (d *DefaultNode) RunExecNotWait(ctx context.Context, execCmd *exec.ExecCmd) error

RunExecNotWait executes a command for a node, and doesn't block waiting for the output. Should be overriden if the nodes implementation differs.

func (*DefaultNode) SaveConfig added in v0.33.0

func (d *DefaultNode) SaveConfig(_ context.Context) error

func (*DefaultNode) SetState added in v0.44.0

func (d *DefaultNode) SetState(s state.NodeState)

func (*DefaultNode) UpdateConfigWithRuntimeInfo added in v0.34.0

func (d *DefaultNode) UpdateConfigWithRuntimeInfo(ctx context.Context) error

func (*DefaultNode) VerifyHostRequirements added in v0.34.0

func (d *DefaultNode) VerifyHostRequirements() error

func (*DefaultNode) VerifyLicenseFileExists added in v0.36.0

func (d *DefaultNode) VerifyLicenseFileExists(_ context.Context) error

VerifyLicenseFileExists checks if a license file with a provided path exists.

func (*DefaultNode) VerifyStartupConfig added in v0.34.0

func (d *DefaultNode) VerifyStartupConfig(topoDir string) error

VerifyStartupConfig verifies that startup config files exists on disks.

func (*DefaultNode) WithMgmtNet added in v0.33.0

func (d *DefaultNode) WithMgmtNet(mgmt *types.MgmtNet)

func (*DefaultNode) WithRuntime added in v0.33.0

func (d *DefaultNode) WithRuntime(r runtime.ContainerRuntime)

type DeployParams added in v0.39.0

type DeployParams struct{}

DeployParams contains parameters for the Deploy function.

type Initializer

type Initializer func() Node

type Node

type Node interface {
	Init(*types.NodeConfig, ...NodeOption) error
	// GetContainers returns a pointer to GenericContainer that the node uses.
	GetContainers(ctx context.Context) ([]runtime.GenericContainer, error)
	DeleteNetnsSymlink() (err error)
	Config() *types.NodeConfig // Config returns the nodes configuration
	// CheckDeploymentConditions checks if node-scoped deployment conditions are met.
	CheckDeploymentConditions(context.Context) error
	PreDeploy(ctx context.Context, params *PreDeployParams) error
	Deploy(context.Context, *DeployParams) error // Deploy triggers the deployment of this node
	PostDeploy(ctx context.Context, params *PostDeployParams) error
	WithMgmtNet(*types.MgmtNet)           // WithMgmtNet provides the management network for the node
	WithRuntime(runtime.ContainerRuntime) // WithRuntime provides the runtime for the node
	// CalculateInterfaceIndex returns with the interface index offset from the first valid dataplane interface based on the interface name. Errors otherwise.
	CalculateInterfaceIndex(ifName string) (int, error)
	// CheckInterfaceName checks if a name of the interface referenced in the topology file is correct for this node
	CheckInterfaceName() error
	// VerifyStartupConfig checks for existence of the referenced file and maybe performs additional config checks
	VerifyStartupConfig(topoDir string) error
	SaveConfig(context.Context) error            // SaveConfig saves the nodes configuration to an external file
	Delete(context.Context) error                // Delete triggers the deletion of this node
	GetImages(context.Context) map[string]string // GetImages returns the images used for this kind
	GetRuntime() runtime.ContainerRuntime        // GetRuntime returns the nodes assigned runtime
	GenerateConfig(dst, templ string) error      // Generate the nodes configuration
	// UpdateConfigWithRuntimeInfo updates node config with runtime info like IP addresses assigned by runtime
	UpdateConfigWithRuntimeInfo(context.Context) error
	// RunExec execute a single command for a given node.
	RunExec(ctx context.Context, execCmd *exec.ExecCmd) (*exec.ExecResult, error)
	// Adds the given link to the Node (container). After adding the Link to the node,
	// the given function f is called within the Nodes namespace to setup the link.
	AddLinkToContainer(ctx context.Context, link netlink.Link, f func(ns.NetNS) error) error
	AddEndpoint(e links.Endpoint) error
	GetEndpoints() []links.Endpoint
	GetLinkEndpointType() links.LinkEndpointType
	GetShortName() string
	// DeployEndpoints deploys the links for the node.
	DeployEndpoints(ctx context.Context) error
	// ExecFunction executes the given function within the nodes network namespace
	ExecFunction(context.Context, func(ns.NetNS) error) error
	GetState() state.NodeState
	SetState(state.NodeState)
	GetSSHConfig() *types.SSHConfig
	// RunExecFromConfig executes the topologyfile defined exec commands
	RunExecFromConfig(context.Context, *exec.ExecCollection) error
	IsHealthy(ctx context.Context) (bool, error)
	GetContainerStatus(ctx context.Context) runtime.ContainerStatus
}

Node is an interface that defines the behavior of a node.

type NodeOption

type NodeOption func(Node)

func WithMgmtNet

func WithMgmtNet(mgmt *types.MgmtNet) NodeOption

func WithRuntime

func WithRuntime(r runtime.ContainerRuntime) NodeOption

type NodeOverwrites added in v0.34.0

type NodeOverwrites interface {
	VerifyStartupConfig(topoDir string) error
	CheckInterfaceName() error
	CalculateInterfaceIndex(ifName string) (int, error)
	GetMappedInterfaceName(ifName string) (string, error)
	VerifyHostRequirements() error
	PullImage(ctx context.Context) error
	GetImages(ctx context.Context) map[string]string
	GetContainers(ctx context.Context) ([]runtime.GenericContainer, error)
	GetContainerName() string
	VerifyLicenseFileExists(context.Context) error
	RunExec(context.Context, *exec.ExecCmd) (*exec.ExecResult, error)
}

NodeOverwrites is an interface that every node implements. It is used to enable DefaultNode to get access to the particular node structs and is provided as an argument of the NewDefaultNode function. The methods defined for this interfaces are the methods that particular node has a custom implementation of.

type NodeRegistry added in v0.35.0

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

func NewNodeRegistry added in v0.35.0

func NewNodeRegistry() *NodeRegistry

NewNodeRegistry constructs a new Registry.

func (*NodeRegistry) GetRegisteredNodeKindNames added in v0.35.0

func (r *NodeRegistry) GetRegisteredNodeKindNames() []string

GetRegisteredNodeKindNames returns a sorted slice of all the registered node kind names in the registry.

func (*NodeRegistry) Kind added in v0.35.2

func (r *NodeRegistry) Kind(kind string) *NodeRegistryEntry

func (*NodeRegistry) NewNodeOfKind added in v0.35.0

func (r *NodeRegistry) NewNodeOfKind(nodeKindName string) (Node, error)

NewNodeOfKind return a new Node of the given Node Kind.

func (*NodeRegistry) Register added in v0.35.0

func (r *NodeRegistry) Register(names []string, initf Initializer, credentials *Credentials) error

Register registers the node' init function for all provided names.

type NodeRegistryEntry added in v0.35.2

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

func (*NodeRegistryEntry) Credentials added in v0.35.2

func (e *NodeRegistryEntry) Credentials() *Credentials

Credentials returns entry's credentials.

type PostDeployParams added in v0.39.0

type PostDeployParams struct {
	Nodes map[string]Node
}

PostDeployParams contains parameters for the PostDeploy function.

type PreDeployParams added in v0.39.0

type PreDeployParams struct {
	Cert         *cert.Cert
	TopologyName string
	TopoPaths    *types.TopoPaths
	SSHPubKeys   []ssh.PublicKey
}

type VRNode added in v0.56.0

type VRNode struct {
	DefaultNode
}

func NewVRNode added in v0.56.0

func NewVRNode(n NodeOverwrites) *VRNode

func (*VRNode) AddEndpoint added in v0.56.0

func (vr *VRNode) AddEndpoint(e links.Endpoint) error

AddEndpoint override version maps the endpoint name to an ethX-based name before adding it to the node endpoints. Returns an error if the mapping goes wrong.

func (*VRNode) CheckInterfaceName added in v0.56.0

func (vr *VRNode) CheckInterfaceName() error

CheckInterfaceName checks interface names for generic VM-based nodes. Displays InterfaceHelp if the check fails for the expected VM interface regexp.

Jump to

Keyboard shortcuts

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