vm

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 38 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

Copied from third_party/lima/cmd/limactl: the drivers limactl has.

Package vm is what agent-vm asks of what runs its VMs. Lima does it (lima.go); the interface keeps the rest of agent-vm apart from it, so tests use a fake, and another backend could take Lima's place.

Index

Constants

View Source
const ReverseSSHFS = "reverse-sshfs"

ReverseSSHFS is the mount type whose shares the host serves over SFTP, which is where readonlyNames are enforced.

Variables

View Source
var ErrLimaOverrides = errors.New("agent-vm does not use Lima's default.yaml or override.yaml; move it out of the way")

ErrLimaOverrides is returned while the backend's own config would add to what agent-vm sets for every VM (Lima's _config/default.yaml and override.yaml).

View Source
var ErrNameTooLong = errors.New("VM name too long")

ErrNameTooLong is returned for a VM name the backend cannot have here: the paths of its sockets would be too long.

View Source
var ErrNetworkOpen = errors.New("agent-vm starts no VM with a network besides its own")

ErrNetworkOpen is returned by Start for a VM with a network besides its own isolated one: the network policy (netguard) applies to the connections of the VM's own netstack only.

View Source
var ErrNotFound = errors.New("no such VM")

ErrNotFound is returned for a VM that does not exist.

View Source
var ErrUnconfined = errors.New("agent-vm starts no VM with a share not confined to its folder")

ErrUnconfined is returned by Start for a VM with a share the VM could reach the rest of the host through (see Confined).

View Source
var ErrUnmountable = errors.New("a share the backend cannot take as written")

ErrUnmountable is returned by Edit for a share the backend would read as another path than the one given.

Functions

func Confined

func Confined(inst *Instance) error

Confined fails unless every share of inst is served by the builtin SFTP server, over reverse-sshfs: the one server confined to its folder. No other way into the host is started.

func LimaOverrides

func LimaOverrides(home string) []string

LimaOverrides are the default.yaml and override.yaml found in the Lima home's _config: shown Host-spelled, as user-facing host paths are.

func MaxName

func MaxName(home string) int

MaxName is the longest VM name whose sockets fit under the Lima home home (UNIX_PATH_MAX: 104 bytes on macOS), and Lima's 76 at most. Lima resolves the home's symlinks: so does this, as far as it exists.

func MoveOld

func MoveOld(ctx context.Context, old, now, name, to string) error

MoveOld moves the VM name from the Lima home old to the Lima home now, as to: stopped first, through its hostagent, whichever Lima started it; then its folder moved as Lima's rename moves one (no lock, pid, socket or temporary file; vz's identifier emptied). Its shares and the rest of its config go with it. Lima's own config in old (_config) does not.

func NetworkConfined

func NetworkConfined(cfg *limatype.LimaYAML) error

NetworkConfined fails when cfg gives the guest a network of Lima's `networks` (a shared usernet, a socket, vzNAT, a vmnet one): its traffic does not go through the netstack that the policy is applied to.

func UserLimaHome

func UserLimaHome() string

UserLimaHome is the user's own LIMA_HOME, "" when unset. It is only known once NewLima has run, which replaces it for Lima's packages.

Types

type Backend

type Backend interface {
	// List is every VM, in name order.
	List(ctx context.Context) ([]*Instance, error)
	// Get is one VM, or ErrNotFound.
	Get(ctx context.Context, name string) (*Instance, error)
	// Create makes a VM from a template, with settings, and does not start it.
	// log gets the backend's progress.
	Create(ctx context.Context, name, template string, s Settings, log io.Writer) error
	// Clone copies the stopped VM from as to, stopped.
	Clone(ctx context.Context, from, to string) error
	// Edit changes the stopped VM name.
	Edit(ctx context.Context, name string, s Settings) error
	// Start boots the stopped VM name, and returns once it is ready. log
	// gets the backend's progress. It refuses a VM whose shares are not
	// confined to their folders (see Confined).
	Start(ctx context.Context, name string, log io.Writer) error
	// Stop shuts down the running VM name, and kills an orphaned one. Any
	// other VM is left as it is.
	Stop(ctx context.Context, name string) error
	// Delete removes the VM name, running or not.
	Delete(ctx context.Context, name string) error
	// Shell runs a command in the running VM name, and returns its exit
	// status.
	Shell(ctx context.Context, name string, o ShellOpts) (int, error)
}

Backend runs VMs.

type Instance

type Instance struct {
	Name         string
	Status       Status
	Dir          string // the backend's folder for it
	CPUs         int
	Memory, Disk int64 // bytes
	SSHLocalPort int   // the port in use
	// SSHPortConfig is the port the config fixes, 0 when the backend
	// picks one on each start.
	SSHPortConfig int
	SSHAddress    string
	// SSHConfig is the ssh_config file the backend rewrites on each start,
	// for tools that connect to the VM.
	SSHConfig    string
	VMType, Arch string
	// MountType is the backend's name for how the shares reach the guest,
	// empty for its default.
	MountType string
	Mounts    []Mount
	// ConfigErr is why the backend cannot read the VM's config (Broken).
	ConfigErr error
	// Orphaned: Broken, the VM still running without the backend's process
	// that serves it (Lima's hostagent). Nothing reaches it; Stop ends it by
	// force.
	Orphaned bool
}

Instance is a VM as the backend has it.

type Lima

type Lima struct {
	// contains filtered or unexported fields
}

Lima runs VMs with the Lima built into agent-vm, as limactl's commands do, in this process; its hostagent is this executable again (see limaembed.Run).

func NewLima

func NewLima(home, stateDir string) (*Lima, error)

NewLima keeps its VMs in home (LIMA_HOME), and writes Lima's guest agent and templates under stateDir.

func (*Lima) Clone

func (l *Lima) Clone(ctx context.Context, from, to string) error

func (*Lima) Create

func (l *Lima) Create(ctx context.Context, name, template string, s Settings, log io.Writer) error

func (*Lima) Delete

func (l *Lima) Delete(ctx context.Context, name string) error

func (*Lima) Edit

func (l *Lima) Edit(ctx context.Context, name string, s Settings) error

Edit applies s as `limactl edit` does: the same checks, and nothing is written when one fails.

func (*Lima) Get

func (l *Lima) Get(ctx context.Context, name string) (*Instance, error)

func (*Lima) List

func (l *Lima) List(ctx context.Context) ([]*Instance, error)

func (*Lima) Shell

func (l *Lima) Shell(ctx context.Context, name string, o ShellOpts) (int, error)

Shell runs o as `limactl shell` does: over ssh, by the user's login shell, from o.Workdir (or fails), with a terminal when stdout is one.

func (*Lima) Start

func (l *Lima) Start(ctx context.Context, name string, log io.Writer) error

func (*Lima) Stop

func (l *Lima) Stop(ctx context.Context, name string) error

type Mount

type Mount struct {
	Location   string `json:"location"`             // on the host
	MountPoint string `json:"mountPoint,omitempty"` // in the guest; Location's spelling when empty
	Writable   bool   `json:"writable"`
	SSHFS      *SSHFS `json:"sshfs,omitempty"`
}

Mount is a host folder shared with the guest.

type OldVM

type OldVM struct {
	Name    string
	Running bool
}

OldVM is a VM agent-vm 0.2 left in another Lima home.

func FindOld

func FindOld(old, prefix string) ([]OldVM, error)

FindOld lists the VMs named prefix* in the Lima home old, that a move would take: those with a lima.yaml.

type SSHFS

type SSHFS struct {
	SFTPDriver string `json:"sftpDriver,omitempty"`
	// Cache is sshfs's own; nil for the backend's default.
	Cache *bool `json:"cache,omitempty"`
	// ReadonlyNames are read-only at any depth under the share, whatever
	// the guest does: .git and the like.
	ReadonlyNames []string `json:"readonlyNames,omitempty"`
}

SSHFS options of a reverse-sshfs share.

type Settings

type Settings struct {
	CPUs         int
	MemoryGiB    int
	DiskGiB      int
	SSHLocalPort *int // 0 gives the port back to the backend
	Mounts       *[]Mount
	MountType    *string // "" goes back to the backend's default
	// NoContainerd leaves out the backend's own containerd: Docker, when
	// installed, ships its own.
	NoContainerd bool
	// contains filtered or unexported fields
}

Settings change a VM. A zero field is left as it is.

type ShellOpts

type ShellOpts struct {
	// Workdir is where the command runs; it fails when it cannot cd there.
	Workdir string
	// Args is the command, run by the user's login shell; empty for the
	// shell itself.
	Args           []string
	Stdin          io.Reader
	Stdout, Stderr io.Writer
	// Interactive asks for a terminal in the guest, as a full-screen
	// program needs, when stdin is one. Stdout on a terminal gets one
	// anyway.
	Interactive bool
}

ShellOpts is a command run in a running VM.

type Status

type Status string

Status of a VM.

const (
	Running Status = "Running"
	Stopped Status = "Stopped"
	// Broken: the backend cannot tell, or the VM is half there.
	Broken Status = "Broken"
)

Directories

Path Synopsis
Package vmtest is a vm.Backend for tests: VMs in memory, every call recorded.
Package vmtest is a vm.Backend for tests: VMs in memory, every call recorded.

Jump to

Keyboard shortcuts

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