Documentation
¶
Overview ¶
Package vm is the backend-agnostic VM layer: the VM and VMBackend interfaces, install/run configuration, and disk-format types. Implementations live in vm/qemu and vm/vz.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultBackendName ¶
func DefaultBackendName() string
DefaultBackendName returns the platform default backend name.
Types ¶
type DiskFormat ¶
type DiskFormat int
DiskFormat selects the virtual disk image format.
const ( // DiskFormatDefault lets the backend choose (qcow2 for QEMU, raw for vz). DiskFormatDefault DiskFormat = iota DiskFormatQcow2 DiskFormatRaw )
func (DiskFormat) String ¶
func (f DiskFormat) String() string
type PortForward ¶
VMRunConfig is the backend-agnostic configuration for booting an already- installed disk (continue/finalize mode). PortForward is one host→guest TCP forward on the user-mode network.
type VM ¶
type VM interface {
Stop() error
Wait() error
SSHAddr() string
OutputDir() string
PID() int
// Done returns a channel that is closed when the VM stops or enters an
// error state. Callers can select on this to detect unexpected exits.
Done() <-chan struct{}
}
VM is a handle to a running virtual machine.
type VMBackend ¶
type VMBackend interface {
StartInstall(ctx context.Context, cfg VMInstallConfig) (VM, error)
StartRun(ctx context.Context, cfg VMRunConfig) (VM, error)
CreateDisk(path string, sizeGB int, format DiskFormat) error
// CreateOverlay creates a copy-on-write layer over base at path.
// QEMU: qcow2 backing file. vz/raw: full copy of base (APFS sparse).
CreateOverlay(path, base string) error
// Flatten merges an overlay into a standalone image at dst.
// QEMU: qemu-img convert. vz/raw: no-op (already standalone).
Flatten(src, dst string) error
// DefaultDiskFormat returns the backend's preferred disk format.
DefaultDiskFormat() DiskFormat
}
VMBackend abstracts the VM lifecycle so callers are backend-agnostic. Implementations live in vm/qemu (QEMU) and vm/vz (macOS Virtualization.framework). QMP, screendump, stall detection, and send-key are QEMU-specific and intentionally excluded.
func ResolveBackend ¶
ResolveBackend returns a VMBackend by name using the provided registry. An empty name checks WINKIT_VM_BACKEND env, then falls back to the platform default (vz on darwin, qemu elsewhere).
type VMInstallConfig ¶
type VMInstallConfig struct {
WindowsISO string
VirtIOISO string
AnswerISO string
ScratchVolume string
DiskPath string
DiskSizeGB int
DiskFormat DiskFormat
CPUs uint
MemoryGB uint64
OutputDir string
SSHPort uint16
SSHGuestPort uint16
OpenSSHHostPort uint16
RDPPort uint16
Accel string
// BackendExtra holds backend-specific configuration. Each backend
// type-asserts to its own options type and ignores unrecognized values.
BackendExtra any
}
VMInstallConfig is the backend-agnostic configuration for a fresh Windows install VM. Backend-specific options (QEMU's BootVolume, Secure, CDBus, etc.) are passed via BackendExtra: each backend type-asserts to its own options type.
type VMRunConfig ¶
type VMRunConfig struct {
DiskPath string
DiskFormat DiskFormat
OutputDir string
VMName string
VirtIOISO string
CPUs uint
MemoryGB uint64
SSHPort uint16
SSHGuestPort uint16
OpenSSHHostPort uint16
RDPPort uint16
SSHHost string
// Forwards are extra host→guest TCP forwards beyond the SSH, OpenSSH
// and RDP ones above (e.g. a VNC server running inside the guest).
Forwards []PortForward
Accel string
// SMBIOSSerial, when non-empty, passes the value as the SMBIOS serial
// number so the guest's boot-time hostname task can read and apply it.
SMBIOSSerial string
// BackendExtra holds backend-specific configuration.
BackendExtra any
}