Documentation
¶
Index ¶
- Constants
- Variables
- func AdjustFileACLs(fsPath string) error
- func BridgeByName(name string) (*netlink.Bridge, error)
- func CIDRToDDN(length int) string
- func CheckAndGetRootPrivs() error
- func ContainerNSToPID(cID string) (int, error)
- func ContainerNameFromNetworkMode(s string) (string, error)
- func ConvertEnvs(m map[string]string) []string
- func CopyFile(ctx context.Context, src, dst string, mode os.FileMode) (err error)
- func CopyFileContents(ctx context.Context, src string, dst *os.File) (err error)
- func CreateConvFuncs() map[string]any
- func CreateDirectory(path string, perm os.FileMode)
- func CreateFile(file, content string) (err error)
- func CreateFileWithPermissions(filePath string, mode os.FileMode) (*os.File, func(), error)
- func CreateFuncs() template.FuncMap
- func CreateNetFuncs() map[string]any
- func CreateStringFuncs() map[string]any
- func DeleteNetnsSymlink(n string) error
- func DestinationBindMountExists(binds []string, dest string) bool
- func DirExists(filename string) bool
- func DisableTxOffloadByIndex(index int) error
- func DropRootPrivs() error
- func EthtoolTXOff(name string) error
- func ExpandEnvVarsInStrSlice(s []string)
- func ExpandHome(p string) string
- func ExtractDNSServersFromResolvConf(filesys fs.FS, filenames []string) ([]string, error)
- func FileExists(filename string) bool
- func FileLines(path, commentStr string) ([]string, error)
- func FileOrDirExists(filename string) bool
- func FilenameForURL(ctx context.Context, rawUrl string) string
- func FirstLinkIPs(ln string) (v4, v6 string, err error)
- func GenMac(oui string) (net.HardwareAddr, error)
- func GenerateIPv6ULASubnet() (string, error)
- func GetCanonicalImageName(imageName string) string
- func GetLinksByNamePrefix(prefix string) ([]netlink.Link, error)
- func GetOSRelease() string
- func GetOwner() string
- func GetRealUserIDs() (userUID, userGID int, err error)
- func GetRegexpCaptureGroups(r *regexp.Regexp, search string) (map[string]string, error)
- func GetRoutableAddresses() ([]string, error)
- func GetRouteForIP(ip net.IP) (*rtnl.Route, error)
- func GetSSHVersion() string
- func HostBig(base netip.Prefix, num *big.Int) (netip.Addr, error)
- func InterfaceSlice(slice any) ([]any, error)
- func IsHttpURL(s string, allowSchemaless bool) bool
- func IsKernelModuleLoaded(name string) (bool, error)
- func IsPartialConfigFile(configPath string) bool
- func IsS3URL(s string) bool
- func LinkContainerNS(nspath, containerName string) error
- func LinkIPs(ln string) (v4addrs, v6addrs []netlink.Addr, err error)
- func LoadEnvVarFiles(basefolder string, files []string) (map[string]string, error)
- func LoadSSHPubKeysFromFiles(paths []string) ([]ssh.PublicKey, error)
- func MarshalAndCatenateSSHPubKeys(in []ssh.PublicKey) string
- func MarshalSSHPubKeys(in []ssh.PublicKey) []string
- func MergeMaps(dicts ...map[string]any) map[string]any
- func MergeStringMaps(maps ...map[string]string) map[string]string
- func MergeStringSlices(ss ...[]string) []string
- func ModInitFunc(path, params string, _ int) error
- func NSEthtoolTXOff(cntName, ifaceName string) func(ns.NetNS) error
- func NewHTTPClient() *http.Client
- func NormalizeMapForJSON(i any) any
- func ParseS3URL(s3URL string) (bucket, key string, err error)
- func PauseProcessGroup(pgid int) error
- func Pointer[T any](v T) *T
- func ReadFileContent(file string) ([]byte, error)
- func ReadPasswordFromTerminal() (string, error)
- func ResolvePath(p, base string) string
- func SetUIDAndGID(fsPath string) error
- func ShortID(id string) string
- func SpawnCLIviaExec(platformName, contName, runtime string) (*network.Driver, error)
- func StringInSlice(slice []string, val string) (int, bool)
- func StripNonPrintChars(s string) string
- func SubstituteEnvsAndTemplate(r io.Reader, data any) (*bytes.Buffer, error)
- func ToEnvKey(s string) string
- func ToFloat64(v any) (float64, error)
- func ToInt64(v any) (int64, error)
- func ToString(in any) string
- func UnixGroupExists(groupName string) (bool, error)
- func UnpauseProcessGroup(pgid int) error
- func UserInUnixGroup(username, groupName string) (bool, error)
- func VethPeerIndex(ifaceName string, peerIndex *int) func(ns.NetNS) error
- type ConvFuncs
- type DockerEventData
- type EthtoolValue
- type IFReqData
- type KernelVersion
- type NetFuncs
- type StringFuncs
Constants ¶
const ( SIOCETHTOOL = 0x8946 // linux/sockios.h ETHTOOL_GTXCSUM = 0x00000016 // linux/ethtool.h ETHTOOL_STXCSUM = 0x00000017 // linux/ethtool.h IFNAMSIZ = 16 // linux/if.h )
const ( CLAB_AUTHORIZED_GROUP = "clab_admins" ROOT_UID = 0 NOMODIFY = -1 )
const (
UndefinedFileName = "undefined"
)
Variables ¶
var ( // map of commands per platform which start a CLI app. NetworkOSCLICmd = map[string][]string{ "arista_eos": {"Cli"}, "nokia_srlinux": {"sr_cli"}, "vyatta_vyos": {"su", "-", "admin"}, } // 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", }, "podman": { "exec": "podman", "open": "exec -it", }, } )
var IfWaitScript string
IfWaitScript is used in ENTRYPOINT/CMD of the nodes that need to ensure that all of the clab links/interfaces are available in the container before calling the main process.
Functions ¶
func AdjustFileACLs ¶ added in v0.48.0
AdjustFileACLs takes the given fs path, tries to load the access file acl of that path and adds ACL rules: rwx for the real UID user and r-x for the real GID group.
func BridgeByName ¶
BridgeByName returns a *netlink.Bridge referenced by its name.
func CIDRToDDN ¶ added in v0.58.0
CIDRToDDN converts CIDR mask to a Dotted Decimal Notation ie CIDR: 24 -> DDN: 255.255.255.0 The result is a string.
func CheckAndGetRootPrivs ¶ added in v0.70.0
func CheckAndGetRootPrivs() error
func ContainerNSToPID ¶ added in v0.26.0
ContainerNSToPID resolves the name of a container via the "/run/netns/<CONTAINERNAME>" to its PID.
func ContainerNameFromNetworkMode ¶ added in v0.69.0
ContainerNameFromNetworkMode takes the NetworkMode config string and returns the container name from it.
func ConvertEnvs ¶
ConvertEnvs converts env variables passed as a map to a list of them.
func CopyFile ¶
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 ¶
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 or an S3 URL.
func CreateConvFuncs ¶ added in v0.68.0
CreateConvFuncs returns a new mapping of template ConvFuncs.
func CreateDirectory ¶
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 ¶
CreateFile writes content to a file by path `file`.
func CreateFileWithPermissions ¶ added in v0.71.0
CreateFileWithPermissions creates a file with proper directory structure, ownership, and permissions. It returns the file handle and a cleanup function. The caller is responsible for calling the cleanup function to close the file.
func CreateFuncs ¶ added in v0.68.0
func CreateNetFuncs ¶ added in v0.72.0
CreateNetFuncs returns a new mapping of template NetFuncs.
func CreateStringFuncs ¶ added in v0.68.0
CreateStringFuncs returns a new mapping of template StringFuncs.
func DeleteNetnsSymlink ¶ added in v0.15.0
DeleteNetnsSymlink deletes a network namespace and removes the symlink created by LinkContainerNS func.
func DestinationBindMountExists ¶ added in v0.66.0
DestinationBindMountExists checks if a bind mount destination exists in a list of bind mounts. The bind options are not matched, only the destination is matched. The binds are expected to be in the format of "source:destination[:options]".
func DirExists ¶ added in v0.48.4
DirExists returns true if a dir referenced by path exists & accessible.
func DisableTxOffloadByIndex ¶ added in v0.72.0
DisableTxOffloadByIndex disables TX checksum offload on an interface by its index.
func DropRootPrivs ¶ added in v0.70.0
func DropRootPrivs() error
func EthtoolTXOff ¶
EthtoolTXOff disables TX checksum offload on specified interface.
func ExpandEnvVarsInStrSlice ¶ added in v0.25.0
func ExpandEnvVarsInStrSlice(s []string)
ExpandEnvVarsInStrSlice makes an in-place expansion of env vars in a slice of strings.
func ExpandHome ¶ added in v0.25.0
ExpandHome expands `~` char in the path to home path of a current user in provided path p. When sudo is used, it expands to home dir of a sudo user.
func ExtractDNSServersFromResolvConf ¶ added in v0.47.0
ExtractDNSServersFromResolvConf extracts IP addresses of the DNS servers from the resolv.conf-formatted files passed in filenames list. Returns a list of IP addresses of the DNS servers.
func FileExists ¶
FileExists returns true if a file referenced by filename exists & accessible.
func FileLines ¶ added in v0.44.0
FileLines opens a file by the `path` and returns a slice of strings for each line excluding lines that start with `commentStr` or are empty.
func FileOrDirExists ¶ added in v0.48.0
FileOrDirExists returns true if a file or dir referenced by path exists & accessible.
func FilenameForURL ¶ added in v0.38.0
FilenameForURL extracts a filename from a given url returns "undefined" when unsuccessful.
func FirstLinkIPs ¶ added in v0.23.0
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) (net.HardwareAddr, error)
GenMac generates a random MAC address for a given OUI.
func GenerateIPv6ULASubnet ¶ added in v0.55.0
GenerateIPv6ULASubnet creates a random /64 ULA (Unique Local Address) IPv6 subnet in the fd00::/8 range.
func GetCanonicalImageName ¶ added in v0.15.0
GetCanonicalImageName produces a canonical image name. if the input name did not specify a tag, the implicit "latest" tag is returned.
func GetLinksByNamePrefix ¶ added in v0.46.0
GetLinksByNamePrefix returns a list of links whose name matches a prefix.
func GetOSRelease ¶ added in v0.59.0
func GetOSRelease() string
GetOSRelease returns the OS release of the host by inspecting /etc/*-release files.
func GetOwner ¶ added in v0.69.0
func GetOwner() string
GetOwner determines the lab owner by first checking the SUDO_USER environment variable, and then if that is not set the USER environment variable.
func GetRealUserIDs ¶ added in v0.68.0
func GetRegexpCaptureGroups ¶ added in v0.56.0
func GetRoutableAddresses ¶ added in v0.71.0
GetRoutableAddresses returns a list of routable IPv4 and IPv6 addresses on the system. It excludes loopback, link-local, and other special-use addresses.
func GetSSHVersion ¶ added in v0.48.1
func GetSSHVersion() string
GetSSHVersion returns the version of the ssh client that is installed on the host.
func HostBig ¶ added in v0.72.0
HostBig takes a parent CIDR range and turns it into a host IP address with the given host number.
For example, 10.3.0.0/16 with a host number of 2 gives 10.3.0.2.
Copied from github.com/hairyhenderson/gomplate internal/cidr package.
func InterfaceSlice ¶ added in v0.68.0
InterfaceSlice converts an array or slice of any type into an []any for use in functions that expect this.
func IsHttpURL ¶ added in v0.48.0
IsHttpURL checks if the url is a downloadable HTTP URL. The allowSchemaless toggle when set to true will allow URLs without a schema such as "srlinux.dev/clab-srl". This is shortened notion that is used with "deploy -t <url>" only. Other callers of IsHttpURL should set the toggle to false.
func IsKernelModuleLoaded ¶ added in v0.41.0
IsKernelModuleLoaded checks if a kernel module is loaded by parsing /proc/modules file.
func IsPartialConfigFile ¶ added in v0.72.0
IsPartialConfigFile returns true if the config file name contains .partial substring (case insensitive).
func LinkContainerNS ¶
LinkContainerNS creates a symlink for containers network namespace so that it can be managed by iproute2 utility.
func LinkIPs ¶ added in v0.23.0
LinkIPs returns IPv4/IPv6 addresses assigned to a link referred by its name.
func LoadEnvVarFiles ¶ added in v0.26.0
LoadEnvVarFiles load EnvVars from the given files, resolving relative paths.
func LoadSSHPubKeysFromFiles ¶ added in v0.44.0
LoadSSHPubKeysFromFiles parses openssh keys from the files referenced by the paths and returns a slice of ssh.PublicKey pointers. The files may contain multiple keys each on a separate line.
func MarshalAndCatenateSSHPubKeys ¶ added in v0.62.0
MarshalAndCatenateSSHPubKeys catenates the ssh public keys and produces a string that can be used in the cli config command to set the ssh public keys for users. Each key value in the catenated string will be double quoted.
func MarshalSSHPubKeys ¶ added in v0.62.0
MarshalSSHPubKeys marshals the ssh public keys and a string slice that contains string representations of the keys.
func MergeMaps ¶ added in v0.15.0
MergeMaps merges all dictionaries and return a new dictionary recursively if matching keys are both dictionaries.
func MergeStringMaps ¶ added in v0.15.0
MergeStringMaps merges all string maps and return a new map maps that are passed for merging will not be changed merging to empty maps return an empty map merging nils return nil.
func MergeStringSlices ¶ added in v0.24.0
MergeStringSlices merges string slices with duplicates removed.
func ModInitFunc ¶ added in v0.59.0
ModInitFunc supports uncompressed files and gzip and xz compressed files.
func NSEthtoolTXOff ¶ added in v0.53.0
NSEthtoolTXOff EthtoolTXOff wrapper that can be handed straight to Node.ExecFunc().
func NewHTTPClient ¶ added in v0.48.0
NewHTTPClient creates a new HTTP client with insecure skip verify set to true and min TLS version set to 1.2.
func NormalizeMapForJSON ¶ added in v0.71.0
NormalizeMapForJSON recursively converts map[any]any to map[string]any and []any elements to ensure JSON serialization compatibility. This is needed because yaml.v2 unmarshals nested maps as map[any]any which cannot be serialized to JSON.
func ParseS3URL ¶ added in v0.69.0
ParseS3URL parses an S3 URL and returns the bucket and key.
func PauseProcessGroup ¶ added in v0.26.0
PauseProcessGroup sends the SIGSTOP signal to a process group, causing all the processes within the group to be Paused e.g. SRL runs multilpe processes, if the container is meant to be stopped, all the related processes must be paused. To me it seams like the ProcessGroupID is set correctly so we can count on that field. The syscall.Kill interpretes negative ints as a PGID and not as a common PID.
func Pointer ¶ added in v0.54.1
func Pointer[T any](v T) *T
Pointer returns a pointer to a value of any type.
func ReadFileContent ¶
func ReadPasswordFromTerminal ¶ added in v0.39.0
func ResolvePath ¶ added in v0.25.0
ResolvePath resolves a string path by expanding `~` to home dir or resolving a relative path by joining it with the base path. When resolving `~` the function uses the home dir of a sudo user, so that -E sudo flag can be omitted.
func SetUIDAndGID ¶ added in v0.48.2
SetUIDAndGID changes the UID and GID of the given path recursively to the values taken from getRealUserIDs, which should reflect the non-root user's UID and GID.
func ShortID ¶ added in v0.72.0
ShortID trims the supplied identifier to the first 12 characters, matching Docker's short ID format.
func SpawnCLIviaExec ¶ added in v0.17.0
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
StringInSlice checks if a slice contains `val` string and returns slice index if true.
func StripNonPrintChars ¶ added in v0.71.0
StripNonPrintChars removes non-printable characters from the string.
func SubstituteEnvsAndTemplate ¶ added in v0.65.0
SubstituteEnvsAndTemplate substitutes environment variables and template the reader `r` with the `data` template data.
func ToEnvKey ¶ added in v0.26.0
ToEnvKey capitalizes and removes special chars from a string to is used as an environment variable key.
func UnixGroupExists ¶ added in v0.66.0
UnixGroupExists checks if the group, given as a group name, exists on the system. `getent group` is used to retrieve domain-joined group information, as `os/user`'s pure Go implementation only checks against /etc/groups.
func UnpauseProcessGroup ¶ added in v0.26.0
UnpauseProcessGroup send the SIGCONT to the given ProcessGroup identified by its ID.
func UserInUnixGroup ¶ added in v0.66.0
UserInUnixGroup returns whether the given user (via username) is part of the Unix group given in the second argument.
Types ¶
type ConvFuncs ¶ added in v0.68.0
type ConvFuncs struct{}
ConvFuncs holds conversion related functions for templates.
func (ConvFuncs) Join ¶ added in v0.68.0
Join concatenates the elements of a to create a single string. The separator string sep is placed between elements in the resulting string. This is functionally identical to strings.Join, except that each element is coerced to a string first.
func (ConvFuncs) ToInt ¶ added in v0.68.0
ToInt converts the input to an int (signed integer, 32- or 64-bit depending on platform). This is similar to conv.ToInt64 on 64-bit platforms, but is useful when input to another function must be provided as an int. Unconvertible inputs will result in errors. On 32-bit systems, given a number that is too large to fit in an int, the result is -1. This is done to protect against CWE-190 and CWE-681.
type DockerEventData ¶ added in v0.72.0
type DockerEventData struct {
Timestamp time.Time
Type string
Action string
ActorID string
ActorName string
ActorFullID string
Attributes map[string]string
}
DockerEventData captures container-related information from a Docker event message.
func DockerMessageToEventData ¶ added in v0.72.0
func DockerMessageToEventData(msg dockerEvents.Message) DockerEventData
DockerMessageToEventData normalizes a Docker event message into DockerEventData.
type EthtoolValue ¶
EthtoolValue linux/ethtool.h 'struct ethtool_value'.
type KernelVersion ¶ added in v0.42.0
type KernelVersion struct {
Major int
Minor int
Revision int
Remainder string // the rest of the version string, e.g. "-amd64"
}
KernelVersion holds the parsed OS kernel version.
func GetKernelVersion ¶ added in v0.42.0
func GetKernelVersion() (*KernelVersion, error)
GetKernelVersion returns the parsed OS kernel version.
func (*KernelVersion) GreaterOrEqual ¶ added in v0.42.0
func (kv *KernelVersion) GreaterOrEqual(cmpKv *KernelVersion) bool
GreaterOrEqual returns true if the Kernel version is greater or equal to the compared Kernel version.
func (*KernelVersion) String ¶ added in v0.42.0
func (kv *KernelVersion) String() string
String returns the Kernel version as string.
type NetFuncs ¶ added in v0.72.0
type NetFuncs struct{}
NetFuncs holds network related functions for templates.
type StringFuncs ¶ added in v0.68.0
type StringFuncs struct{}
StringFuncs holds string related functions for templates.
func (*StringFuncs) ReplaceAll ¶ added in v0.68.0
func (sf *StringFuncs) ReplaceAll(old, replacement string, s any) string
ReplaceAll replaces all occurrences of a given string with another.
func (*StringFuncs) Split ¶ added in v0.68.0
func (sf *StringFuncs) Split(sep string, s any) []string
Split slices input into the substrings separated by separator, returning a slice of the substrings between those separators. If input does not contain separator and separator is not empty, returns a single-element slice whose only element is input. If separator is empty, it will split after each UTF-8 sequence. If both inputs are empty (i.e. strings.Split "" ""), it will return an empty slice. This is equivalent to strings.SplitN with a count of -1. Note that the delimiter is not included in the resulting elements.