utils

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersDir  = ".vers"
	HeadFile = "HEAD"
)

Variables

View Source
var (
	ErrHeadNotFound = errors.New("head not found")
	ErrHeadEmpty    = errors.New("head empty")
)

Functions

func CheckVMImpactsHead

func CheckVMImpactsHead(vmID string) bool

CheckVMImpactsHead checks if a specific VM deletion will affect HEAD

func CleanupAfterDeletion

func CleanupAfterDeletion(deletedVMIDs []string) bool

CleanupAfterDeletion clears HEAD if any of the deleted VM IDs match current HEAD

func ClearHead

func ClearHead() error

ClearHead clears the HEAD file

func GetAliasByVMID added in v0.5.4

func GetAliasByVMID(vmID string) string

GetAliasByVMID performs a reverse lookup to find an alias for a VM ID Returns empty string if no alias exists

func GetAliasesPath added in v0.5.4

func GetAliasesPath() (string, error)

GetAliasesPath returns the path to the aliases file (~/.vers/aliases.json)

func GetCurrentHeadVM

func GetCurrentHeadVM() (string, error)

GetCurrentHeadVM returns the VM ID from the current HEAD

func GetVmAndNodeIP

func GetVmAndNodeIP(ctx context.Context, client *vers.Client, vmID string) (*vers.Vm, string, error)

GetVmAndNodeIP retrieves VM information and the node IP from headers in a single request. We use the lower-level client.Get() instead of client.Vm.List() because we need response headers.

func IsHostLocal

func IsHostLocal(hostName string) bool

func LoadAliases added in v0.5.4

func LoadAliases() (map[string]string, error)

LoadAliases loads the alias map from ~/.vers/aliases.json Returns an empty map if the file doesn't exist

func RemoveAlias added in v0.5.4

func RemoveAlias(alias string) error

RemoveAlias removes an alias mapping

func ResolveAlias added in v0.5.4

func ResolveAlias(identifier string) string

ResolveAlias checks if the identifier is an alias and returns the VM ID If not an alias, returns the identifier unchanged

func SaveAliases added in v0.5.4

func SaveAliases(aliases map[string]string) error

SaveAliases saves the alias map to ~/.vers/aliases.json

func SetAlias added in v0.5.4

func SetAlias(alias, vmID string) error

SetAlias adds or updates an alias mapping

func SetHead

func SetHead(vmID string) error

SetHead sets the HEAD to point to a specific VM ID (always stores ID, never alias)

Types

type VMInfo

type VMInfo struct {
	ID          string
	DisplayName string
}

VMInfo contains both ID and display name for a VM

func CreateVMInfoFromVM added in v0.5.0

func CreateVMInfoFromVM(vm vers.Vm) *VMInfo

CreateVMInfoFromVM creates VMInfo from a Vm struct

func GetCurrentHeadVMInfo

func GetCurrentHeadVMInfo(ctx context.Context, client *vers.Client) (*VMInfo, error)

GetCurrentHeadVMInfo returns both the HEAD VM ID and its display information

func ResolveVMIdentifier

func ResolveVMIdentifier(ctx context.Context, client *vers.Client, identifier string) (*VMInfo, error)

ResolveVMIdentifier takes a VM ID or alias and returns the VM info Aliases are resolved locally from ~/.vers/aliases.json

func SetHeadFromIdentifier

func SetHeadFromIdentifier(ctx context.Context, client *vers.Client, identifier string) (*VMInfo, error)

SetHeadFromIdentifier resolves a VM identifier to an ID and sets HEAD

Jump to

Keyboard shortcuts

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