util

package
v0.0.0-pre.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableFormatCSV     = "csv"
	TableFormatJSON    = "json"
	TableFormatTable   = "table"
	TableFormatYAML    = "yaml"
	TableFormatCompact = "compact"
)

Table list format.

View Source
const (
	// TableOptionNoHeader hides the table header when possible.
	TableOptionNoHeader = "noheader"

	// TableOptionHeader adds header to csv.
	TableOptionHeader = "header"
)

Variables

This section is empty.

Functions

func CachePath

func CachePath(path ...string) string

CachePath returns the directory that migration manager should use for caching assets. If MIGRATION_MANAGER_DIR is set, this path is $MIGRATION_MANAGER_DIR/cache, otherwise it is /var/cache/migration-manager.

func CreateTarball

func CreateTarball(target string, contentPath string) error

CreateTarball creates a tarball from a given path. If the path is a directory, the tarball will include the directory.

func DoBasicConnectivityCheck

func DoBasicConnectivityCheck(endpoint string, trustedCertFingerprint string) (api.ExternalConnectivityStatus, *x509.Certificate)

func FileCopy

func FileCopy(source string, dest string) error

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

func GetOwnerMode

func GetOwnerMode(fInfo os.FileInfo) (os.FileMode, int, int)

func GetProjectRepo

func GetProjectRepo(ctx context.Context, latest bool) (*githubRepo, error)

GetProjectRepo returns a GitHub repository client for the project at the current tag, and populates release assets. If latest is true, release assets will be populated from the latest release instead of the tag.

func GetTOFUServerConfig

func GetTOFUServerConfig(serverCert *x509.Certificate) *tls.Config

func InTestingMode

func InTestingMode() bool

InTestingMode returns whether migration manager is running in testing mode.

func IsDebianOrDerivative

func IsDebianOrDerivative(osString string) bool

func IsDir

func IsDir(name string) bool

IsDir returns true if the given path is a directory.

func IsRHELOrDerivative

func IsRHELOrDerivative(osString string) bool

func IsSUSEOrDerivative

func IsSUSEOrDerivative(osString string) bool

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 LogPath

func LogPath(path ...string) string

LogPath returns the directory that migration manager should put logs under. If MIGRATION_MANAGER_DIR is set, this path is $MIGRATION_MANAGER_DIR/logs, otherwise it is /var/log.

func RawWorkerImage

func RawWorkerImage() string

RawWorkerImage represents the raw worker image supplied to an Incus target.

func RenderTable

func RenderTable(w io.Writer, format string, header []string, data [][]string, raw any) error

RenderTable renders tabular data in various formats.

func RunConcurrentList

func RunConcurrentList[T any](entities []T, f func(T) error) error

RunConcurrentList runs the given function concurrently for each entity in the given list. Any encountered errors will be logged, and when the run finishes, the last encountered error is returned.

func RunConcurrentMap

func RunConcurrentMap[K comparable, V any](entities map[K]V, f func(K, V) error) error

RunConcurrentMap runs the given function concurrently for each entity in the given map. Any encountered errors will be logged, and when the run finishes, the last encountered error is returned.

func RunPath

func RunPath(path ...string) string

RunPath returns the directory that migration manager should put runtime data under. If MIGRATION_MANAGER_DIR is set, this path is $MIGRATION_MANAGER_DIR/run, otherwise it is /run/migration-manager.

func UnixHTTPClient

func UnixHTTPClient(socketPath string) *http.Client

UnixHTTPClient returns an HTTP client suitable for a unix socket connection.

func VarPath

func VarPath(path ...string) string

VarPath returns the provided path elements joined by a slash and appended to the end of $MIGRATION_MANAGER_DIR, which defaults to /var/lib/migration-manager.

func WorkerVolume

func WorkerVolume() string

WorkerVolume represents the name of the storage volume containing the migration worker.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[K comparable, V any]() *Cache[K, V]

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key K)

func (*Cache[K, V]) Read

func (c *Cache[K, V]) Read(key K) (V, bool)

func (*Cache[K, V]) Replace

func (c *Cache[K, V]) Replace(cache map[K]V) error

func (*Cache[K, V]) Write

func (c *Cache[K, V]) Write(key K, val V, f func(existingVal V, newVal V) V)

type Column

type Column struct {
	Header string

	// DataFunc is a method to retrieve data for this column. The argument to this function will be an element of the
	// "data" slice that is passed into RenderSlice.
	DataFunc func(any) (string, error)
}

Column represents a single column in a table.

type IDLock

type IDLock[T comparable] struct {
	// contains filtered or unexported fields
}

func NewIDLock

func NewIDLock[T comparable]() IDLock[T]

NewIDLock creates a thread-safe map of sync.Mutexes keyed by ID.

func (*IDLock[T]) Lock

func (l *IDLock[T]) Lock(key T)

Lock fetches the existing lock, or creates a new lock for the given ID, and locks it.

func (*IDLock[T]) Unlock

func (l *IDLock[T]) Unlock(key T)

Unlock fetches the existing lock and deletes it from the map, before unlocking it.

type SortColumnsNaturally

type SortColumnsNaturally [][]string

SortColumnsNaturally represents the type for sorting columns in a natural order from left to right.

func (SortColumnsNaturally) Len

func (a SortColumnsNaturally) Len() int

func (SortColumnsNaturally) Less

func (a SortColumnsNaturally) Less(i, j int) bool

func (SortColumnsNaturally) Swap

func (a SortColumnsNaturally) Swap(i, j int)

Jump to

Keyboard shortcuts

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