Documentation
¶
Overview ¶
Package hypervisor provides an abstraction layer for virtual machine managers. This allows the instances package to work with different hypervisors (e.g., Cloud Hypervisor, QEMU) through a common interface.
Index ¶
- Variables
- func RegisterClientFactory(t Type, factory ClientFactory)
- func RegisterSocketName(t Type, name string)
- func RegisterVsockDialerFactory(t Type, factory VsockDialerFactory)
- func SocketNameForType(t Type) string
- type CPUTopology
- type Capabilities
- type ClientFactory
- type DiskConfig
- type Hypervisor
- type NetworkConfig
- type Type
- type VMConfig
- type VMInfo
- type VMStarter
- type VMState
- type VsockDialer
- type VsockDialerFactory
Constants ¶
This section is empty.
Variables ¶
var ( // ErrHypervisorNotRunning is returned when trying to connect to a hypervisor // that is not currently running or cannot be reconnected to. ErrHypervisorNotRunning = errors.New("hypervisor is not running") // ErrNotSupported is returned when an operation is not supported by the hypervisor. ErrNotSupported = errors.New("operation not supported by this hypervisor") )
Common errors
Functions ¶
func RegisterClientFactory ¶ added in v0.0.6
func RegisterClientFactory(t Type, factory ClientFactory)
RegisterClientFactory registers a Hypervisor client factory.
func RegisterSocketName ¶
RegisterSocketName registers the socket filename for a hypervisor type. Called by each hypervisor implementation's init() function.
func RegisterVsockDialerFactory ¶
func RegisterVsockDialerFactory(t Type, factory VsockDialerFactory)
RegisterVsockDialerFactory registers a VsockDialer factory for a hypervisor type. Called by each hypervisor implementation's init() function.
func SocketNameForType ¶
SocketNameForType returns the socket filename for a hypervisor type. Falls back to type + ".sock" if not registered.
Types ¶
type CPUTopology ¶
CPUTopology defines the virtual CPU topology
type Capabilities ¶
type Capabilities struct {
// SupportsSnapshot indicates if Snapshot/Restore are available
SupportsSnapshot bool
// SupportsHotplugMemory indicates if ResizeMemory is available
SupportsHotplugMemory bool
// SupportsPause indicates if Pause/Resume are available
SupportsPause bool
// SupportsVsock indicates if vsock communication is available
SupportsVsock bool
// SupportsGPUPassthrough indicates if PCI device passthrough is available
SupportsGPUPassthrough bool
// SupportsDiskIOLimit indicates if disk I/O rate limiting is available
SupportsDiskIOLimit bool
}
Capabilities indicates which optional features a hypervisor supports. Callers should check these before calling optional methods.
type ClientFactory ¶ added in v0.0.6
type ClientFactory func(socketPath string) (Hypervisor, error)
ClientFactory creates Hypervisor client instances for a hypervisor type.
type DiskConfig ¶
type DiskConfig struct {
Path string
Readonly bool
IOBps int64 // Sustained I/O rate limit in bytes/sec (0 = unlimited)
IOBurstBps int64 // Burst I/O rate in bytes/sec (0 = same as IOBps)
}
DiskConfig represents a disk attached to the VM
type Hypervisor ¶
type Hypervisor interface {
// DeleteVM sends a graceful shutdown signal to the guest.
DeleteVM(ctx context.Context) error
// Shutdown stops the VMM process gracefully.
Shutdown(ctx context.Context) error
// GetVMInfo returns current VM state information.
GetVMInfo(ctx context.Context) (*VMInfo, error)
// Pause suspends VM execution.
// Check Capabilities().SupportsPause before calling.
Pause(ctx context.Context) error
// Resume continues VM execution after pause.
// Check Capabilities().SupportsPause before calling.
Resume(ctx context.Context) error
// Snapshot creates a VM snapshot at the given path.
// Check Capabilities().SupportsSnapshot before calling.
Snapshot(ctx context.Context, destPath string) error
// ResizeMemory changes the VM's memory allocation.
// Check Capabilities().SupportsHotplugMemory before calling.
ResizeMemory(ctx context.Context, bytes int64) error
// ResizeMemoryAndWait changes the VM's memory allocation and waits for it to stabilize.
// This polls until the actual memory size matches the target or stabilizes.
// Check Capabilities().SupportsHotplugMemory before calling.
ResizeMemoryAndWait(ctx context.Context, bytes int64, timeout time.Duration) error
// Capabilities returns what features this hypervisor supports.
Capabilities() Capabilities
}
Hypervisor defines the interface for VM control operations. A Hypervisor client is returned by VMStarter.StartVM after the VM is running.
type NetworkConfig ¶
NetworkConfig represents a network interface attached to the VM
type VMConfig ¶
type VMConfig struct {
// Compute resources
VCPUs int
MemoryBytes int64
HotplugBytes int64
Topology *CPUTopology
// Storage
Disks []DiskConfig
// Network
Networks []NetworkConfig
// Console
SerialLogPath string
// Vsock
VsockCID int64
VsockSocket string
// PCI device passthrough (GPU, etc.)
PCIDevices []string
// Boot configuration
KernelPath string
InitrdPath string
KernelArgs string
}
VMConfig is the hypervisor-agnostic VM configuration. Each hypervisor implementation translates this to its native format.
type VMInfo ¶
type VMInfo struct {
State VMState
MemoryActualSize *int64 // Current actual memory size in bytes (if available)
}
VMInfo contains current VM state information
type VMStarter ¶
type VMStarter interface {
// SocketName returns the socket filename for this hypervisor.
// Uses short names to stay within Unix socket path length limits (SUN_LEN ~108 bytes).
SocketName() string
// GetBinaryPath returns the path to the hypervisor binary, extracting if needed.
GetBinaryPath(p *paths.Paths, version string) (string, error)
// GetVersion returns the version of the hypervisor binary.
// For embedded binaries (Cloud Hypervisor), returns the latest supported version.
// For system binaries (QEMU), queries the installed binary for its version.
GetVersion(p *paths.Paths) (string, error)
// StartVM launches the hypervisor process and boots the VM.
// Returns the process ID and a Hypervisor client for subsequent operations.
StartVM(ctx context.Context, p *paths.Paths, version string, socketPath string, config VMConfig) (pid int, hv Hypervisor, err error)
// RestoreVM starts the hypervisor and restores VM state from a snapshot.
// Each hypervisor implements its own restore flow:
// - Cloud Hypervisor: starts process, calls Restore API
// - QEMU: would start with -incoming or -loadvm flags (not yet implemented)
// Returns the process ID and a Hypervisor client. The VM is in paused state after restore.
RestoreVM(ctx context.Context, p *paths.Paths, version string, socketPath string, snapshotPath string) (pid int, hv Hypervisor, err error)
}
VMStarter handles the full VM startup sequence. Each hypervisor implements its own startup flow: - Cloud Hypervisor: starts process, configures via HTTP API, boots via HTTP API - QEMU: converts config to command-line args, starts process (VM runs immediately)
type VMState ¶
type VMState string
VMState represents the VM execution state
const ( // StateCreated means the VM is configured but not running StateCreated VMState = "created" // StateRunning means the VM is actively executing StateRunning VMState = "running" // StatePaused means the VM execution is suspended StatePaused VMState = "paused" // StateShutdown means the VM has stopped but VMM exists StateShutdown VMState = "shutdown" )
type VsockDialer ¶
type VsockDialer interface {
// DialVsock connects to the guest on the specified port.
// Returns a net.Conn that can be used for bidirectional communication.
DialVsock(ctx context.Context, port int) (net.Conn, error)
// Key returns a unique identifier for this dialer, used for connection pooling.
Key() string
}
VsockDialer provides vsock connectivity to a guest VM. Each hypervisor implements its own connection method: - Cloud Hypervisor: Unix socket file + text handshake protocol - QEMU: Kernel AF_VSOCK with CID-based addressing
func NewVsockDialer ¶
func NewVsockDialer(hvType Type, vsockSocket string, vsockCID int64) (VsockDialer, error)
NewVsockDialer creates a VsockDialer for the given hypervisor type. Returns an error if the hypervisor type doesn't have a registered factory.
type VsockDialerFactory ¶
type VsockDialerFactory func(vsockSocket string, vsockCID int64) VsockDialer
VsockDialerFactory creates VsockDialer instances for a hypervisor type.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cloudhypervisor implements the hypervisor.Hypervisor interface for Cloud Hypervisor VMM.
|
Package cloudhypervisor implements the hypervisor.Hypervisor interface for Cloud Hypervisor VMM. |
|
Package qemu implements the hypervisor.Hypervisor interface for QEMU.
|
Package qemu implements the hypervisor.Hypervisor interface for QEMU. |
|
Package vz implements the hypervisor.Hypervisor interface for Apple's Virtualization.framework on macOS via the vz-shim subprocess.
|
Package vz implements the hypervisor.Hypervisor interface for Apple's Virtualization.framework on macOS via the vz-shim subprocess. |
|
shimconfig
Package shimconfig defines the configuration types shared between the hypeman API server and the vz-shim subprocess.
|
Package shimconfig defines the configuration types shared between the hypeman API server and the vz-shim subprocess. |