util

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSlash

func AddSlash(path string) string

AddSlash adds a slash to the end of paths if they don't already have one. This can be useful for rsyncing things, since rsync has behavior present on the presence or absence of a trailing slash.

func CachePath

func CachePath(path ...string) string

CachePath returns the directory that Incus should its cache under. If INCUS_DIR is set, this path is $INCUS_DIR/cache, otherwise it is /var/cache/incus.

func CanonicalNetworkAddress

func CanonicalNetworkAddress(address string, defaultPort int) string

CanonicalNetworkAddress parses the given network address and returns a string of the form "host:port", possibly filling it with the default port if it's missing. It will also wrap a bare IPv6 address with square brackets if needed.

func CanonicalNetworkAddressFromAddressAndPort

func CanonicalNetworkAddressFromAddressAndPort(address string, port int, defaultPort int) string

CanonicalNetworkAddressFromAddressAndPort returns a network address from separate address and port values. The address accepts values such as "[::]", "::" and "localhost".

func DirCopy

func DirCopy(source string, dest string) error

DirCopy copies a directory recursively, overwriting the target if it exists.

func FileCopy

func FileCopy(source string, dest string) error

FileCopy copies a file, overwriting the target if it exists.

func FileMove

func FileMove(oldPath string, newPath string) error

FileMove tries to move a file by using os.Rename, if that fails it tries to copy the file and remove the source.

func IsAddressCovered

func IsAddressCovered(address1, address2 string) bool

IsAddressCovered detects if network address1 is actually covered by address2, in the sense that they are either the same address or address2 is specified using a wildcard with the same port of address1.

func IsDir

func IsDir(name string) bool

IsDir returns true if the given path is a directory.

func IsUnixSocket

func IsUnixSocket(path string) bool

IsUnixSocket returns true if the given path is either a Unix socket or a symbolic link pointing at a Unix socket.

func IsWildCardAddress

func IsWildCardAddress(address string) bool

IsWildCardAddress returns whether the given address is a wildcard.

func JoinTokenDecode

func JoinTokenDecode(input string) (*api.ClusterMemberJoinToken, error)

JoinTokenDecode decodes a base64 and JSON encoded join token.

func LoadCert

func LoadCert(dir string) (*localtls.CertInfo, error)

LoadCert reads the server certificate from the given var dir.

If a cluster certificate is found it will be loaded instead. If neither a server or cluster certfificate exists, a new server certificate will be generated.

func LoadClusterCert

func LoadClusterCert(dir string) (*localtls.CertInfo, error)

LoadClusterCert reads the cluster certificate from the given var dir.

If a cluster certificate doesn't exist, a new one is generated.

func LoadServerCert

func LoadServerCert(dir string) (*localtls.CertInfo, error)

LoadServerCert reads the server certificate from the given var dir.

func LogPath

func LogPath(path ...string) string

LogPath returns the directory that Incus should put logs under. If INCUS_DIR is set, this path is $INCUS_DIR/logs, otherwise it is /var/log/incus.

func MkdirAllOwner

func MkdirAllOwner(path string, perm os.FileMode, uid int, gid int) error

func NetworkInterfaceAddress

func NetworkInterfaceAddress() string

NetworkInterfaceAddress returns the first global unicast address of any of the system network interfaces. Return the empty string if none is found.

func PathIsEmpty

func PathIsEmpty(path string) (bool, error)

PathIsEmpty checks if the given path is empty.

func RandomHexString

func RandomHexString(length int) (string, error)

RandomHexString returns a random string of hexadecimal characters.

func RenderTemplate

func RenderTemplate(template string, ctx pongo2.Context) (string, error)

RenderTemplate renders a pongo2 template.

func RunPath added in v0.5.0

func RunPath(path ...string) string

RunPath returns the directory that Incus should put runtime data under. If INCUS_DIR is set, this path is $INCUS_DIR/run, otherwise it is /run/incus.

func VarPath

func VarPath(path ...string) string

VarPath returns the provided path elements joined by a slash and appended to the end of $INCUS_DIR, which defaults to /var/lib/incus.

func WriteCert

func WriteCert(dir, prefix string, cert, key, ca []byte) error

WriteCert writes the given material to the appropriate certificate files in the given directory.

Types

type PoolType

type PoolType string

PoolType represents a type of storage pool (local, remote or any).

const PoolTypeAny PoolType = ""

PoolTypeAny represents any storage pool (local or remote).

const PoolTypeLocal PoolType = "local"

PoolTypeLocal represents local storage pools.

const PoolTypeRemote PoolType = "remote"

PoolTypeRemote represents remote storage pools.

Jump to

Keyboard shortcuts

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