util

package
v0.0.0-...-f4e8587 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2019 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilesystemSuperMagicTmpfs = 0x01021994
	FilesystemSuperMagicExt4  = 0xEF53
	FilesystemSuperMagicXfs   = 0x58465342
	FilesystemSuperMagicNfs   = 0x6969
	FilesystemSuperMagicZfs   = 0x2fc12fc1
)

Filesystem magic numbers

View Source
const (
	// FilesystemSuperMagicBtrfs is the 64bit magic for Btrfs
	FilesystemSuperMagicBtrfs = 0x9123683E
)
View Source
const SystemdListenFDsStart = 3

SystemdListenFDsStart is the number of the first file descriptor that might have been opened by systemd when socket activation is enabled. It's always 3 in real-world usage (i.e. the first file descriptor opened after stdin, stdout and stderr), so this constant should always be the value passed to GetListeners, except for unit tests.

Variables

This section is empty.

Functions

func AppArmorProfile

func AppArmorProfile() string

AppArmorProfile returns the current apparmor profile.

func CPUResource

func CPUResource() (*api.ResourcesCPU, error)

CPUResource returns the system CPU information

func CanonicalNetworkAddress

func CanonicalNetworkAddress(address string) 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.

func CheckTrustState

func CheckTrustState(cert x509.Certificate, trustedCerts map[string]x509.Certificate) (bool, string)

CheckTrustState checks whether the given client certificate is trusted (i.e. it has a valid time span and it belongs to the given list of trusted certificates).

func CompareConfigs

func CompareConfigs(config1, config2 map[string]string, exclude []string) error

CompareConfigs compares two config maps and returns an error if they differ.

func CompareVersions

func CompareVersions(version1, version2 [2]int) (int, error)

CompareVersions the versions of two LXD nodes.

A version consists of the version the node's schema and the number of API extensions it supports.

Return 0 if they equal, 1 if the first version is greater than the second and 2 if the second is greater than the first.

Return an error if inconsistent versions are detected, for example the first node's schema is greater than the second's, but the number of extensions is smaller.

func CopyConfig

func CopyConfig(config map[string]string) map[string]string

CopyConfig creates a new map with a copy of the given config.

func EtagCheck

func EtagCheck(r *http.Request, data interface{}) error

EtagCheck validates the hash of the current state with the hash provided by the client

func EtagHash

func EtagHash(data interface{}) (string, error)

EtagHash hashes the provided data and returns the sha256

func FilesystemDetect

func FilesystemDetect(path string) (string, error)

FilesystemDetect returns the filesystem on which the passed-in path sits.

func GetArchitectures

func GetArchitectures() ([]int, error)

GetArchitectures returns the list of supported architectures.

func GetExecPath

func GetExecPath() string

GetExecPath returns the path to the current binary

func GetIdmapSet

func GetIdmapSet() *idmap.IdmapSet

GetIdmapSet reads the uid/gid allocation.

func GetListeners

func GetListeners(start int) []net.Listener

GetListeners returns the socket-activated network listeners, if any.

The 'start' parameter must be SystemdListenFDsStart, except in unit tests, see the docstring of SystemdListenFDsStart below.

func HTTPClient

func HTTPClient(certificate string, proxy proxyFunc) (*http.Client, error)

HTTPClient returns an http.Client using the given certificate and proxy.

func InMemoryNetwork

func InMemoryNetwork() (net.Listener, func() net.Conn)

InMemoryNetwork creates a fully in-memory listener and dial function.

Each time the dial function is invoked a new pair of net.Conn objects will be created using net.Pipe: the listener's Accept method will unblock and return one end of the pipe and the other end will be returned by the dial function.

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 IsRecursionRequest

func IsRecursionRequest(r *http.Request) bool

IsRecursionRequest checks whether the given HTTP request is marked with the "recursion" flag in its form values.

func ListenAddresses

func ListenAddresses(value string) ([]string, error)

ListenAddresses returns a list of host:port combinations at which this machine can be reached

func LoadCert

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

LoadCert reads the LXD server certificate from the given var dir.

If a cluster certificate is found it will be loaded instead.

func LoadModule

func LoadModule(module string) error

LoadModule loads the kernel module with the given name, by invoking modprobe.

func MemoryResource

func MemoryResource() (*api.ResourcesMemory, error)

MemoryResource returns the system memory information

func NetworkInterfaceAddress

func NetworkInterfaceAddress() string

NetworkInterfaceAddress returns the first non-loopback address of any of the system network interfaces.

Return the empty string if none is found.

func PasswordCheck

func PasswordCheck(secret string, password string) error

PasswordCheck validates the provided password against the encoded secret

func RuntimeLiblxcVersionAtLeast

func RuntimeLiblxcVersionAtLeast(major int, minor int, micro int) bool

RuntimeLiblxcVersionAtLeast checks if the system's liblxc matches the provided version requirement

func ServerTLSConfig

func ServerTLSConfig(cert *shared.CertInfo) *tls.Config

ServerTLSConfig returns a new server-side tls.Config generated from the give certificate info.

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 LXD var directory.

func WriteJSON

func WriteJSON(w http.ResponseWriter, body interface{}, debug bool) error

WriteJSON encodes the body as JSON and sends it back to the client

Types

type ContextAwareRequest

type ContextAwareRequest interface {
	WithContext(ctx context.Context) *http.Request
}

ContextAwareRequest is an interface implemented by http.Request starting from Go 1.8. It supports graceful cancellation using a context.

Jump to

Keyboard shortcuts

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