Documentation
¶
Index ¶
- Constants
- Variables
- func CheckVMImpactsHead(vmID string) bool
- func CleanupAfterDeletion(deletedVMIDs []string) bool
- func ClearHead() error
- func GetAliasByVMID(vmID string) string
- func GetAliasesPath() (string, error)
- func GetCurrentHeadVM() (string, error)
- func GetVmAndNodeIP(ctx context.Context, client *vers.Client, vmID string) (*vers.Vm, string, error)
- func IsHostLocal(hostName string) bool
- func LoadAliases() (map[string]string, error)
- func RemoveAlias(alias string) error
- func ResolveAlias(identifier string) string
- func SaveAliases(aliases map[string]string) error
- func SetAlias(alias, vmID string) error
- func SetHead(vmID string) error
- func ShellJoin(args []string) string
- func ShellQuote(s string) string
- func WaitForRunning(ctx context.Context, client *vers.Client, vmID string) error
- type ResolvedVM
- type TargetResult
- type VMInfo
- func CreateVMInfoFromVM(vm vers.Vm) *VMInfo
- func GetCurrentHeadVMInfo(ctx context.Context, client *vers.Client) (*VMInfo, error)
- func ResolveVMIdentifier(ctx context.Context, client *vers.Client, identifier string) (*VMInfo, error)
- func SetHeadFromIdentifier(ctx context.Context, client *vers.Client, identifier string) (*VMInfo, error)
Constants ¶
const ( VersDir = ".vers" HeadFile = "HEAD" )
Variables ¶
var ( ErrHeadNotFound = errors.New("head not found") ErrHeadEmpty = errors.New("head empty") )
Functions ¶
func CheckVMImpactsHead ¶
CheckVMImpactsHead checks if a specific VM deletion will affect HEAD
func CleanupAfterDeletion ¶
CleanupAfterDeletion clears HEAD if any of the deleted VM IDs match current HEAD
func GetAliasByVMID ¶ added in v0.5.4
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
GetAliasesPath returns the path to the aliases file (~/.vers/aliases.json)
func GetCurrentHeadVM ¶
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 LoadAliases ¶ added in v0.5.4
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
RemoveAlias removes an alias mapping
func ResolveAlias ¶ added in v0.5.4
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
SaveAliases saves the alias map to ~/.vers/aliases.json
func ShellJoin ¶ added in v0.6.0
ShellJoin quotes each argument and joins them with spaces, producing a command string safe for passing to a remote shell.
func ShellQuote ¶ added in v0.6.0
ShellQuote returns s quoted so it is treated as a single token by a POSIX shell. If s is already "safe" (only alphanumerics, hyphens, underscores, dots, forward-slashes, colons, equals, and commas) it is returned unchanged. Otherwise it is wrapped in single quotes with any embedded single quotes escaped.
func WaitForRunning ¶ added in v0.7.0
WaitForRunning polls the VM status until it reaches the "running" state. Returns the final VM state or an error if the context is cancelled or the VM enters an unexpected terminal state.
Types ¶
type ResolvedVM ¶ added in v0.7.0
type ResolvedVM struct {
ID string // Verified VM ID
UsedHEAD bool // Whether HEAD was used as fallback
}
ResolvedVM holds a verified VM identity.
func ResolveTargetVM ¶ added in v0.7.0
ResolveTargetVM resolves a target string to a verified VM ID. If target is empty, uses HEAD. Then verifies the VM exists via the API.
type TargetResult ¶ added in v0.6.0
type TargetResult struct {
Ident string // The resolved VM identifier (ID or alias)
UsedHEAD bool // Whether HEAD was used as fallback
HeadID string // The HEAD VM ID (only set if UsedHEAD is true)
}
TargetResult holds the result of resolving a VM target identifier.
func ResolveTarget ¶ added in v0.6.0
func ResolveTarget(target string) (TargetResult, error)
ResolveTarget resolves a VM target string. If target is empty, falls back to the current HEAD VM. This centralises the pattern used across handlers.
type VMInfo ¶
VMInfo contains both ID and display name for a VM
func CreateVMInfoFromVM ¶ added in v0.5.0
CreateVMInfoFromVM creates VMInfo from a Vm struct
func GetCurrentHeadVMInfo ¶
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. Uses the single-VM Status endpoint (O(1)) instead of listing all VMs. Aliases are resolved locally from ~/.vers/aliases.json.