utils

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: BSD-3-Clause Imports: 20 Imported by: 0

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 (
	// map of commands per platform which start a CLI app
	NetworkOSCLICmd = map[string]string{
		"arista_eos":    "Cli",
		"nokia_srlinux": "sr_cli",
	}

	// map of the cli exec command and its argument per runtime
	// which is used to spawn CLI session
	CLIExecCommand = map[string]map[string]string{
		"docker": {
			"exec": "docker",
			"open": "exec -it",
		},
		"containerd": {
			"exec": "ctr",
			"open": "-n clab task exec -t --exec-id clab",
		},
	}
)

Functions

func BridgeByName

func BridgeByName(name string) (*netlink.Bridge, error)

BridgeByName returns a *netlink.Bridge referenced by its name

func CheckBrInUse added in v0.15.0

func CheckBrInUse(brname string) (bool, error)

func ConvertEnvs

func ConvertEnvs(m map[string]string) []string

convertEnvs convert env variables passed as a map to a list of them

func CopyFile

func CopyFile(src, dst string, mode os.FileMode) (err error)

CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return success. Otherwise, copy the file contents from src to dst. mode is the desired target file permissions, e.g. "0644".

func CopyFileContents

func CopyFileContents(src, dst string, mode os.FileMode) (err error)

CopyFileContents copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. src can be an http(s) URL as well.

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 CreateFile

func CreateFile(file, content string) (err error)

CreateFile writes content to a file by path `file`.

func DefaultNetMTU

func DefaultNetMTU() (string, error)

getDefaultDockerMTU gets the MTU of a docker0 bridge interface if fails to get the MTU of docker0, returns "1500"

func DeleteLinkByName added in v0.15.0

func DeleteLinkByName(name string) error
func DeleteNetnsSymlink(n string) error

deleteNetnsSymlink deletes a network namespace and removes the symlink created by linkContainerNS func

func EthtoolTXOff

func EthtoolTXOff(name string) error

EthtoolTXOff disables TX checksum offload on specified interface

func FileExists

func FileExists(filename string) bool

FileExists returns true if a file referenced by filename exists

func FirstLinkIPs added in v0.23.0

func FirstLinkIPs(ln string) (v4, v6 string, err error)

FirstLinkIPs returns string representation of the first IPv4/v6 address found for a link referenced by name

func GenMac added in v0.15.0

func GenMac(oui string) string

GenMac generates a random MAC address for a given OUI

func GetCNIBinaryPath added in v0.15.0

func GetCNIBinaryPath() string

func GetCanonicalImageName added in v0.15.0

func GetCanonicalImageName(imageName string) string

produces a canonical image name. returns the canonical image name including the tag if the input name did not specify a tag, the implicit "latest" tag is returned.

func LinkContainerNS

func LinkContainerNS(nspath, containerName string) error

linkContainerNS creates a symlink for containers network namespace so that it can be managed by iproute2 utility

func LinkIPs added in v0.23.0

func LinkIPs(ln string) (v4addrs, v6addrs []netlink.Addr, err error)

LinkIPs returns IPv4/IPv6 addresses assigned to a link referred by its name

func MergeMaps added in v0.15.0

func MergeMaps(dicts ...map[string]interface{}) map[string]interface{}

merge all dictionaries and return a new dictionary recursively if matching keys are both dictionaries

func MergeStringMaps added in v0.15.0

func MergeStringMaps(maps ...map[string]string) map[string]string

merge all string maps and return a new map maps that are passed for merging will not be changed

func MergeStringSlices added in v0.24.0

func MergeStringSlices(ss ...[]string) []string

MergeStringSlices merges string slices with duplicates removed

func ReadFileContent

func ReadFileContent(file string) ([]byte, error)

func SaveCfgViaNetconf added in v0.15.0

func SaveCfgViaNetconf(addr, username, password, _ string) error

SaveCfgViaNetconf saves the running config to the startup by means of invoking a netconf rpc <copy-config> this method is used on the network elements that can't perform a save of config via other means

func SpawnCLIviaExec added in v0.17.0

func SpawnCLIviaExec(platform, contName, runtime string) (*network.Driver, error)

SpawnCLIviaExec spawns a CLI session over container runtime exec function end ensures the CLI is available to be used for sending commands over

func StringInSlice added in v0.15.0

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

does a slice contain a string

Types

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'

Jump to

Keyboard shortcuts

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