firecracker

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package firecracker implements the hypervisor interfaces with Firecracker. It embeds the supported VMM binaries and drives them over their API socket using the hand-written types in api.go. Unsupported operations return errors.ErrUnsupported, as Capabilities reports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Extract

func Extract(dstPath string, version Version) (string, error)

Extract atomically writes the embedded binary for version to dstPath, unless a file is already there, and returns dstPath.

Types

type Hypervisor

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

Hypervisor controls one Firecracker VMM over its API socket.

func NewHypervisor

func NewHypervisor(socketPath string) *Hypervisor

NewHypervisor returns a Hypervisor for the VMM serving its API on socketPath. It does not connect until the first request.

func (*Hypervisor) DestroyVM

func (h *Hypervisor) DestroyVM(context.Context) error

DestroyVM is unsupported: Firecracker has no way to discard a guest short of ending the VMM process.

func (*Hypervisor) PauseVM

func (h *Hypervisor) PauseVM(ctx context.Context) error

PauseVM halts the guest's vCPUs.

func (*Hypervisor) ResizeVMCPU

func (h *Hypervisor) ResizeVMCPU(context.Context, int) error

ResizeVMCPU is unsupported: Firecracker cannot hotplug vCPUs.

func (*Hypervisor) ResizeVMMemory

func (h *Hypervisor) ResizeVMMemory(ctx context.Context, bytes int64) error

ResizeVMMemory sets the guest's total memory to bytes by plugging or unplugging virtio-mem memory, and waits until the guest has, or ctx is done.

func (*Hypervisor) ResumeVM

func (h *Hypervisor) ResumeVM(ctx context.Context) error

ResumeVM continues a paused guest.

func (*Hypervisor) Shutdown

func (h *Hypervisor) Shutdown(ctx context.Context) error

Shutdown stops the VMM. Firecracker has no request that ends the process directly; it exits when the guest resets, which ShutdownVM brings about. Where that is unsupported, the caller has to end the process itself.

func (*Hypervisor) ShutdownVM

func (h *Hypervisor) ShutdownVM(ctx context.Context) error

ShutdownVM asks the guest to shut down by sending it Ctrl+Alt+Del, which Linux treats as a request to reboot. Firecracker exits when the guest resets, so this also ends the VMM. It is available on x86 only.

func (*Hypervisor) SnapshotVM

func (h *Hypervisor) SnapshotVM(ctx context.Context, destPath string) error

SnapshotVM writes a full snapshot of a paused guest into the directory destPath: its device state and its memory, as the files RestoreVM reads.

func (*Hypervisor) VMInfo added in v0.4.0

func (h *Hypervisor) VMInfo(ctx context.Context) (*hypervisor.VMInfo, error)

VMInfo reports the guest's state, and its memory including any hotplugged.

type Starter

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

Starter implements hypervisor.Starter for Firecracker.

func NewStarter

func NewStarter(binaryPath string) (*Starter, error)

NewStarter creates a Starter for a Firecracker binary. It invokes the binary once to parse and validate its version.

func (*Starter) Capabilities added in v0.4.0

func (s *Starter) Capabilities() hypervisor.Capabilities

Capabilities reports what Firecracker supports.

func (*Starter) Connect

func (s *Starter) Connect(socketPath string) (hypervisor.Hypervisor, error)

Connect returns a client for an already-running Firecracker VMM.

func (*Starter) DefaultKernelArgs added in v0.4.0

func (s *Starter) DefaultKernelArgs() string

DefaultKernelArgs returns the kernel command line Firecracker guests need: output on the serial console, no PCI bus, a reset on panic so that a wedged guest ends its VMM rather than lingering, and memory that a resize can take back.

func (*Starter) PowerOffEndsVM

func (s *Starter) PowerOffEndsVM() bool

PowerOffEndsVM is false: Firecracker has no ACPI power button, so a guest that powers off only halts. It exits when the guest resets.

func (*Starter) RestoreVM

func (s *Starter) RestoreVM(
	ctx context.Context, socketPath string, snapshotPath string, spec hypervisor.RestoreSpec,
) (*process.Process, hypervisor.Hypervisor, error)

RestoreVM launches Firecracker and restores a guest from a snapshot written by SnapshotVM. The guest is left paused; call ResumeVM.

Its memory is restored on demand. Firecracker maps the snapshot's memory file into the guest privately, so the kernel restores each page when the guest first uses it.

func (*Starter) StartVM

func (s *Starter) StartVM(
	ctx context.Context, socketPath string, spec hypervisor.VMSpec,
) (*process.Process, hypervisor.Hypervisor, error)

StartVM launches Firecracker, configures the guest and boots it. It returns the VMM process and a client for controlling it.

func (*Starter) Version

func (s *Starter) Version() string

Version returns the Firecracker binary version string.

type Version

type Version string

Version identifies a supported Firecracker release.

const DefaultVersion Version = "v1.17.0"

DefaultVersion is the version used when no explicit version is requested.

func SupportedVersions

func SupportedVersions() []Version

SupportedVersions returns the versions whose binaries are embedded.

Jump to

Keyboard shortcuts

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