hypervisor

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hypervisor finds local VMs and their current SSH address through each hypervisor's own CLI, so a devbox's Host block need not carry an IP that changes on every boot.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("not supported by this hypervisor's CLI")

ErrNotSupported means the hypervisor's CLI cannot do this without more than authama has (VMware runs guest commands only with guest credentials).

View Source
var ErrOwnKeys = errors.New("this hypervisor manages its own SSH access and keys")

ErrOwnKeys means the hypervisor runs its own SSH access and keys (OrbStack, Podman): authama lists the machine and can point a Docker context at it, but does not take its keys over.

Functions

func Available

func Available(d Driver) bool

Available reports whether d's CLI was found.

func CanExec added in v0.1.3

func CanExec(d Driver) bool

CanExec reports whether d can run a command in a guest without SSH (and so re-install a key). A driver may say so itself with a CanExec() bool method.

func Describe added in v0.1.3

func Describe(d Driver) string

Describe is a one-line description of d for listings.

func EnabledNames added in v0.1.3

func EnabledNames(get func(string) string) []string

EnabledNames parses $AUTHAMA_VM_HYPERVISORS (authama.json vm.hypervisors): the hypervisors the user has and uses, comma- or space-separated. nil means the setting is unset, so every driver is enabled.

func IsCustom added in v0.1.3

func IsCustom(d Driver) bool

IsCustom reports whether d is a command driver from authama.json.

func IsEnabled added in v0.1.3

func IsEnabled(name string) bool

IsEnabled reports whether the hypervisor called name is enabled.

func Register added in v0.1.3

func Register(specs map[string]CommandSpec)

Register replaces the command drivers with specs (authama.json's "hypervisors" section) and tells the manifest validator their names. Invalid specs are skipped; settings validation reports them.

func UnknownEnabled added in v0.1.3

func UnknownEnabled() []string

UnknownEnabled lists names in the enabled setting that match no driver.

Types

type CommandSpec added in v0.1.3

type CommandSpec struct {
	Description string   `json:"description,omitempty"`
	List        []string `json:"list"`
	Address     []string `json:"address"`
	Start       []string `json:"start,omitempty"`
	Exec        []string `json:"exec,omitempty"`
}

CommandSpec declares a hypervisor authama has no built-in driver for: the commands that list its VMs and resolve one's address. It is the value of one entry in authama.json's "hypervisors" section. Every element is one argv element - nothing runs through a shell - and "{vm}" in any element is replaced with the VM's name.

list prints the VMs: a JSON array of {"name", "state"} objects (an optional boolean "running" overrides state), or one VM per line as name<TAB>state. A VM is running when its state is "running", "started" or "up".

address prints where the VM's SSH server answers: host, or host:port.

func (CommandSpec) Validate added in v0.1.3

func (s CommandSpec) Validate(name string) []string

Validate reports what is wrong with a spec named name.

type Driver

type Driver interface {
	Name() string
	// CLI is the command the driver runs, "" when it cannot be found.
	CLI() string
	List() ([]VM, error)
	Address(vm string) (Endpoint, error)
	Start(vm string) error
	// Exec runs argv inside the VM (for installing a key without SSH); ErrNotSupported or ErrOwnKeys
	// when the CLI cannot.
	Exec(vm string, argv ...string) ([]byte, error)
}

Driver is one hypervisor.

func All

func All() []Driver

All returns every driver: the built-in ones, then the registered command drivers in name order.

func Builtin added in v0.1.3

func Builtin() []Driver

Builtin returns the built-in drivers, in the documented order.

func Enabled added in v0.1.3

func Enabled() []Driver

Enabled returns the drivers the user enabled, in All's order; every driver when the setting is unset.

func For

func For(name string) (Driver, error)

For returns the driver for a manifest hypervisor name: a built-in one, or a command driver authama.json declares. It ignores the enabled list, so a host on a hypervisor the user later turned off still resolves when ssh connects.

type Endpoint

type Endpoint struct {
	Host string
	Port int
}

Endpoint is where a VM's SSH server answers right now.

func ParseAddress added in v0.1.3

func ParseAddress(out []byte) (Endpoint, error)

ParseAddress reads "host" or "host:port" (the first non-empty line).

func (Endpoint) HostPort

func (e Endpoint) HostPort() string

HostPort renders an endpoint for ssh -W style use.

type Exister added in v0.1.3

type Exister interface {
	Exists(vm string) (bool, error)
}

Exister is a driver that can say a VM it does not list still exists (VMware lists running VMs only).

type VM

type VM struct {
	Name    string
	State   string
	Running bool
	// ID is the hypervisor's own identifier, when it has one besides the name.
	ID string
	// Guest is the guest OS family when the hypervisor reports it ("windows", "linux").
	Guest string
}

VM is one machine a hypervisor reports.

func ParseCommandList added in v0.1.3

func ParseCommandList(out []byte) ([]VM, error)

ParseCommandList reads a command driver's list output (exported for tests and for `vm list` diagnostics).

func (VM) Matches added in v0.1.3

func (v VM) Matches(name string) bool

Matches reports whether v is the VM a manifest names as name.

Jump to

Keyboard shortcuts

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