clab

package
v0.0.0-arista-mac Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: BSD-3-Clause Imports: 45 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SIOCETHTOOL     = 0x8946     // linux/sockios.h
	ETHTOOL_GTXCSUM = 0x00000016 // linux/ethtool.h
	ETHTOOL_STXCSUM = 0x00000017 // linux/ethtool.h
	IFNAMSIZ        = 16         // linux/if.h
)

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 CreateDirectory

func CreateDirectory(path string, perm os.FileMode)

CreateDirectory creates a directory by a path with a mode/permission specified by perm. If directory exists, the function does not do anything.

func EthtoolTXOff

func EthtoolTXOff(name string) error

EthtoolTXOff disables TX checksum offload on specified interface

func GetLiknsByNamePrefix

func GetLiknsByNamePrefix(prefix string) ([]netlink.Link, error)

GetLiknsByNamePrefix 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]*Node
	Links        map[int]*Link
	DockerClient *docker.Client
	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 (*CLab) CreateContainer

func (c *CLab) CreateContainer(ctx context.Context, node *Node) (err error)

CreateContainer creates a docker container

func (*CLab) CreateDockerNet

func (c *CLab) CreateDockerNet(ctx context.Context) (err error)

CreateDockerNet creates a docker network or reusing if it exists

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 *Node, certs *Certificates) error

func (*CLab) CreateNodeDirStructure

func (c *CLab) CreateNodeDirStructure(node *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 *Link) (err error)

CreateVirtualWiring creates the virtual topology between the containers

func (*CLab) DeleteBridge

func (c *CLab) DeleteBridge(ctx context.Context) (err error)

DeleteBridge deletes a docker bridge

func (*CLab) DeleteContainer

func (c *CLab) DeleteContainer(ctx context.Context, name string) error

DeleteContainer tries to stop a container then remove it

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

DeleteNetnsSymlinks deletes the symlink file created for each container netns

func (*CLab) Exec

func (c *CLab) Exec(ctx context.Context, id string, cmd []string) ([]byte, []byte, error)

Exec executes cmd on container identified with id and returns stdout, stderr bytes and an error

func (*CLab) ExecNotWait

func (c *CLab) ExecNotWait(ctx context.Context, id string, cmd []string) error

ExecNotWait executes cmd on container identified with id but doesn't wait for output nor attaches stodout/err

func (*CLab) ExecPostDeployTasks

func (c *CLab) ExecPostDeployTasks(ctx context.Context, node *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) GetNSPath

func (c *CLab) GetNSPath(ctx context.Context, containerId string) (string, error)

GetNSPath inspects a container by its name/id and returns an netns path using the pid of a container

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

func (c *CLab) ListContainers(ctx context.Context, labels []string) ([]types.Container, error)

ListContainers lists all containers with labels []string

func (*CLab) NewEndpoint

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

NewEndpoint initializes a new endpoint object

func (c *CLab) NewLink(l LinkConfig) *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) PullImageIfRequired

func (c *CLab) PullImageIfRequired(ctx context.Context, imageName string) error

func (*CLab) RetrieveNodeCertData

func (c *CLab) RetrieveNodeCertData(n *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) StartContainer

func (c *CLab) StartContainer(ctx context.Context, id string) error

StartContainer starts a docker container

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

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 WithEnvDockerClient

func WithEnvDockerClient() ClabOption

func WithGracefulShutdown

func WithGracefulShutdown(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       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 Endpoint

type Endpoint struct {
	Node *Node
	// e1-x, eth, etc
	EndpointName string
}

Endpoint is a struct that contains information of a link endpoint

type EthtoolValue

type EthtoolValue struct {
	Cmd  uint32
	Data uint32
}

linux/ethtool.h 'struct ethtool_value'

type IFReqData

type IFReqData struct {
	Name [IFNAMSIZ]byte
	Data uintptr
}

linux/if.h 'struct ifreq'

type Link struct {
	A      *Endpoint
	B      *Endpoint
	MTU    int
	Labels map[string]string
}

Link is a struct that contains the information of a link between 2 containers

type LinkConfig

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

type Node

type Node struct {
	ShortName string
	LongName  string
	Fqdn      string
	LabDir    string // LabDir is a directory related to the node, it contains config items and/or other persistent state
	Index     int
	Group     string
	Kind      string
	// path to config template file that is used for config generation
	Config       string
	ResConfig    string // path to config file that is actually mounted to the container and is a result of templation
	NodeType     string
	Position     string
	License      string
	Image        string
	Topology     string
	Sysctls      map[string]string
	User         string
	Entrypoint   string
	Cmd          string
	Env          map[string]string
	Binds        []string    // Bind mounts strings (src:dest:options)
	PortBindings nat.PortMap // PortBindings define the bindings between the container ports and host ports
	PortSet      nat.PortSet // PortSet define the ports that should be exposed on a container
	// container networking mode. if set to `host` the host networking will be used for this node, else bridged network
	NetworkMode          string
	MgmtNet              string // name of the docker network this node is connected to with its first interface
	MgmtIPv4Address      string
	MgmtIPv4PrefixLength int
	MgmtIPv6Address      string
	MgmtIPv6PrefixLength int
	ContainerID          string
	TLSCert              string
	TLSKey               string
	TLSAnchor            string
	NSPath               string   // network namespace path for this node
	Publish              []string //list of ports to publish with mysocketctl
	// container labels
	Labels map[string]string
}

Node is a struct that contains the information of a container element

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