Version: v0.41.2 Latest Latest

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

Go to latest
Published: May 18, 2023 License: BSD-3-Clause Imports: 19 Imported by: 0




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"


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


func GenericVMInterfaceCheck added in v0.38.0

func GenericVMInterfaceCheck(nodeName string, eps []types.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).


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

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) 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 (*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) 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) 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) GetContainers added in v0.34.0

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

func (*DefaultNode) GetImages added in v0.33.0

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

func (*DefaultNode) GetRuntime added in v0.33.0

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

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

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

NodeOverwrites is an interface that every node implementation 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

Jump to

Keyboard shortcuts

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