util

package
v0.0.0-pre.5 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: Apache-2.0 Imports: 34 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"
)
View Source
const IncusOSSocket = "/run/incus-os/unix.socket"

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. Calls tar -C dirname(contentPath) -czf target basename(contentPath).

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 IsIncusOS

func IsIncusOS() bool

IsIncusOS checks if the host system is running Incus OS.

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 MapWindowsVersionToAbbrev

func MapWindowsVersionToAbbrev(version string) (string, error)

MapWindowsVersionToAbbrev takes a full version string and returns the abbreviation used by distrobuilder logic. Versions supported are an intersection of what's supported by distrobuilder and vCenter.

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 SharePath

func SharePath(path ...string) string

SharePath returns the directory that migration manager should put static content under. If MIGRATION_MANAGER_DIR is set, this path is $MIGRATION_MANAGER_DIR/share, otherwise it is /usr/share/migration-manager.

func UnixHTTPClient

func UnixHTTPClient(socketPath string) *http.Client

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

func UnpackTarball

func UnpackTarball(target string, tarballPath string) error

UnpackTarball creates the target directory and calls tar -C <target> -xf <tarballPath>.

func UsrPath

func UsrPath(path ...string) string

UsrPath returns the directory that migration manager should put static library & binary content under. If MIGRATION_MANAGER_DIR is set, this path is $MIGRATION_MANAGER_DIR/lib, otherwise it is /usr/lib/migration-manager.

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 LSBLKOutput

type LSBLKOutput struct {
	BlockDevices []struct {
		Name     string `json:"name"`
		Serial   string `json:"serial"`
		Children []struct {
			Name         string `json:"name"`
			FSType       string `json:"fstype"`
			PartLabel    string `json:"partlabel"`
			PartTypeName string `json:"parttypename"`
		} `json:"children"`
	} `json:"blockdevices"`
}

func ScanPartitions

func ScanPartitions(device string) (LSBLKOutput, error)

type ProgressRenderer

type ProgressRenderer struct {
	Format string
	Quiet  bool
	// contains filtered or unexported fields
}

ProgressRenderer tracks the progress information.

func (*ProgressRenderer) Done

func (p *ProgressRenderer) Done(msg string)

Done prints the final status and prevents any update.

func (*ProgressRenderer) Update

func (p *ProgressRenderer) Update(status string)

Update changes the status message to the provided string.

func (*ProgressRenderer) UpdateOp

func (p *ProgressRenderer) UpdateOp(op api.Operation)

UpdateOp is a helper to update the status using a REST API operation.

func (*ProgressRenderer) UpdateProgress

func (p *ProgressRenderer) UpdateProgress(progress ioprogress.ProgressData)

UpdateProgress is a helper to update the status using an iopgress instance.

func (*ProgressRenderer) Warn

func (p *ProgressRenderer) Warn(status string, timeout time.Duration)

Warn shows a temporary message instead of the status.

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