clab

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: BSD-3-Clause Imports: 40 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCredentials = map[string][]string{
	"vr-sros":  {"admin", "admin"},
	"vr-vmx":   {"admin", "admin@123"},
	"vr-xrv9k": {"clab", "clab@123"},
}

DefaultCredentials holds default username and password per each kind

Functions

func AddVxLanInterface

func AddVxLanInterface(vxlan VxLAN) (err error)

AddVxLanInterface creates VxLan interface by given vxlan object

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 SetIngressMirror

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

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

func StringInSlice

func StringInSlice(slice []string, val string) (int, bool)

Types

type CLab

type CLab struct {
	Config   *Config
	TopoFile *TopoFile

	Nodes   map[string]*types.Node
	Links   map[int]*types.Link
	Runtime runtime.ContainerRuntime
	Dir     *Directory
	// contains filtered or unexported fields
}

func NewContainerLab

func NewContainerLab(opts ...ClabOption) *CLab

NewContainerLab function defines a new container lab

func (*CLab) CheckResources

func (c *CLab) CheckResources() error

CheckResources runs container host resources check

func (*CLab) CheckTopologyDefinition

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

CheckTopologyDefinition runs topology checks and returns any errors found

func (c *CLab) CreateLinks(ctx context.Context, workers uint, postdeploy bool)

CreateLinks creates links using the specified number of workers `postdeploy` indicates the stage of links creation. `postdeploy=true` means the links routine is called after nodes postdeploy tasks

func (*CLab) CreateNode

func (c *CLab) CreateNode(ctx context.Context, node *types.Node, certs *Certificates) error

func (*CLab) CreateNodeDirStructure

func (c *CLab) CreateNodeDirStructure(node *types.Node) (err error)

CreateNodeDirStructure create the directory structure and files for the lab nodes

func (*CLab) CreateNodes

func (c *CLab) CreateNodes(ctx context.Context, workers uint)

func (*CLab) CreateRootCA

func (c *CLab) CreateRootCA() error

CreateRootCA creates RootCA key/certificate if it is needed by the topology

func (*CLab) CreateVirtualWiring

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

CreateVirtualWiring creates the virtual topology between the containers

func (c *CLab) DeleteNetnsSymlinks() (err error)

DeleteNetnsSymlinks deletes the symlink file created for each container netns

func (*CLab) ExecPostDeployTasks

func (c *CLab) ExecPostDeployTasks(ctx context.Context, node *types.Node, lworkers uint) error

ExecPostDeployTasks executes tasks that some nodes might require to boot properly after start

func (*CLab) GenerateCert

func (c *CLab) GenerateCert(ca string, caKey string, csrJSONTpl *template.Template, input CertInput, targetPath string) (*Certificates, error)

GenerateCert generates and signs a certificate passed as input and saves the certificate and generated private key by path CA used to sign the cert is passed as ca and caKey file paths

func (*CLab) GenerateGraph

func (c *CLab) GenerateGraph(topo string) error

GenerateGraph generates a graph of the lab topology

func (*CLab) GenerateInventories

func (c *CLab) GenerateInventories() error

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

func (*CLab) GenerateRootCa

func (c *CLab) GenerateRootCa(csrRootJsonTpl *template.Template, input CaRootInput) (*Certificates, error)

GenerateRootCa function

func (*CLab) GetTopology

func (c *CLab) GetTopology(topo 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) NewEndpoint

func (c *CLab) NewEndpoint(e string) *types.Endpoint

NewEndpoint initializes a new endpoint object

func (c *CLab) NewLink(l LinkConfig) *types.Link

NewLink initializes a new link object

func (*CLab) NewNode

func (c *CLab) NewNode(nodeName string, nodeCfg NodeConfig, idx int) error

NewNode initializes a new node object

func (*CLab) ParseTopology

func (c *CLab) ParseTopology() error

ParseTopology parses the lab topology

func (*CLab) RetrieveNodeCertData

func (c *CLab) RetrieveNodeCertData(n *types.Node) (*Certificates, error)

RetrieveNodeCertData reads the node private key and certificate by the well known paths if either of those files doesn't exist, an error is returned

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

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

VerifyImages will check if image referred in the node config either pullable or present or is available in the local registry if it is not available it will emit an error

type CaRootInput

type CaRootInput struct {
	CommonName       string
	Country          string
	Locality         string
	Organization     string
	OrganizationUnit string
	Expiry           string

	Prefix string
	Names  map[string]string // Not used right now
	// prefix for certificate/key file name
	NamePrefix string
}

CaRootInput struct

type CertInput

type CertInput struct {
	Hosts            []string
	CommonName       string
	Country          string
	Locality         string
	Organization     string
	OrganizationUnit string
	Expiry           string

	Name     string
	LongName string
	Fqdn     string
	Prefix   string
}

CertInput struct

type Certificates

type Certificates struct {
	Key  []byte
	Csr  []byte
	Cert []byte
}

type ClabOption

type ClabOption func(c *CLab)

func WithDebug

func WithDebug(d bool) ClabOption

func WithGracefulShutdown

func WithGracefulShutdown(gracefulShutdown bool) ClabOption

func WithRuntime added in v0.14.0

func WithRuntime(name string, d bool, dur time.Duration, gracefulShutdown bool) ClabOption

func WithTimeout

func WithTimeout(dur time.Duration) ClabOption

func WithTopoFile

func WithTopoFile(file string) ClabOption

type Config

type Config struct {
	Name       string         `json:"name,omitempty"`
	Mgmt       *types.MgmtNet `json:"mgmt,omitempty"`
	Topology   Topology       `json:"topology,omitempty"`
	ConfigPath string         `yaml:"config_path,omitempty"`
}

Config defines lab configuration as it is provided in the YAML file

type Directory

type Directory struct {
	Lab       string
	LabCA     string
	LabCARoot string
	LabGraph  string
}

type LinkConfig

type LinkConfig struct {
	Endpoints []string
	Labels    map[string]string `yaml:"labels,omitempty"`
}

type NodeConfig

type NodeConfig struct {
	Kind     string `yaml:"kind,omitempty"`
	Group    string `yaml:"group,omitempty"`
	Type     string `yaml:"type,omitempty"`
	Config   string `yaml:"config,omitempty"`
	Image    string `yaml:"image,omitempty"`
	License  string `yaml:"license,omitempty"`
	Position string `yaml:"position,omitempty"`
	Cmd      string `yaml:"cmd,omitempty"`
	// list of bind mount compatible strings
	Binds []string `yaml:"binds,omitempty"`
	// list of port bindings
	Ports []string `yaml:"ports,omitempty"`
	// user-defined IPv4 address in the management network
	MgmtIPv4 string `yaml:"mgmt_ipv4,omitempty"`
	// user-defined IPv6 address in the management network
	MgmtIPv6 string `yaml:"mgmt_ipv6,omitempty"`
	// list of ports to publish with mysocketctl
	Publish []string `yaml:"publish,omitempty"`
	// environment variables
	Env map[string]string `yaml:"env,omitempty"`
	// linux user used in a container
	User string `yaml:"user,omitempty"`
	// container labels
	Labels map[string]string `yaml:"labels,omitempty"`
	// container networking mode. if set to `host` the host networking will be used for this node, else bridged network
	NetworkMode string `yaml:"network-mode,omitempty"`
}

NodeConfig represents a configuration a given node can have in the lab definition file

type TopoFile

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

TopoFile type is a struct which defines parameters of the topology file

type Topology

type Topology struct {
	Defaults NodeConfig            `yaml:"defaults,omitempty"`
	Kinds    map[string]NodeConfig `yaml:"kinds,omitempty"`
	Nodes    map[string]NodeConfig `yaml:"nodes,omitempty"`
	Links    []LinkConfig          `yaml:"links,omitempty"`
}

Topology represents a lab topology

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

Jump to

Keyboard shortcuts

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