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
- Variables
- func Confined(inst *Instance) error
- func LimaOverrides(home string) []string
- func MaxName(home string) int
- func MoveOld(ctx context.Context, old, now, name, to string) error
- func NetworkConfined(cfg *limatype.LimaYAML) error
- func UserLimaHome() string
- type Backend
- type Instance
- type Lima
- func (l *Lima) Clone(ctx context.Context, from, to string) error
- func (l *Lima) Create(ctx context.Context, name, template string, s Settings, log io.Writer) error
- func (l *Lima) Delete(ctx context.Context, name string) error
- func (l *Lima) Edit(ctx context.Context, name string, s Settings) error
- func (l *Lima) Get(ctx context.Context, name string) (*Instance, error)
- func (l *Lima) List(ctx context.Context) ([]*Instance, error)
- func (l *Lima) Shell(ctx context.Context, name string, o ShellOpts) (int, error)
- func (l *Lima) Start(ctx context.Context, name string, log io.Writer) error
- func (l *Lima) Stop(ctx context.Context, name string) error
- type Mount
- type OldVM
- type SSHFS
- type Settings
- type ShellOpts
- type Status
Constants ¶
const ReverseSSHFS = "reverse-sshfs"
ReverseSSHFS is the mount type whose shares the host serves over SFTP, which is where readonlyNames are enforced.
Variables ¶
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).
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.
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.
var ErrNotFound = errors.New("no such VM")
ErrNotFound is returned for a VM that does not exist.
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).
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
NewLima keeps its VMs in home (LIMA_HOME), and writes Lima's guest agent and templates under stateDir.
func (*Lima) Edit ¶
Edit applies s as `limactl edit` does: the same checks, and nothing is written when one fails.
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 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.