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 ¶
- Variables
- func Available(d Driver) bool
- func CanExec(d Driver) bool
- func Describe(d Driver) string
- func EnabledNames(get func(string) string) []string
- func IsCustom(d Driver) bool
- func IsEnabled(name string) bool
- func Register(specs map[string]CommandSpec)
- func UnknownEnabled() []string
- type CommandSpec
- type Driver
- type Endpoint
- type Exister
- type VM
Constants ¶
This section is empty.
Variables ¶
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).
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 CanExec ¶ added in v0.1.3
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 EnabledNames ¶ added in v0.1.3
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 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.
type Endpoint ¶
Endpoint is where a VM's SSH server answers right now.
func ParseAddress ¶ added in v0.1.3
ParseAddress reads "host" or "host:port" (the first non-empty line).
type Exister ¶ added in v0.1.3
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
ParseCommandList reads a command driver's list output (exported for tests and for `vm list` diagnostics).