dokivm

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package dokivm provides virtual machine management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateID

func GenerateID() string

GenerateID generates a short VM ID.

func IsAvailable

func IsAvailable() bool

IsAvailable returns true if any microVM backend is available.

func Platform

func Platform() string

Platform returns the current platform string.

func RegisterBackend

func RegisterBackend(name string, factory func(*VMMConfig) (VMM, error))

RegisterBackend registers a VMM backend factory.

Types

type DriveConfig

type DriveConfig struct {
	Path       string
	ReadOnly   bool
	RootDevice bool
}

DriveConfig holds extra block device config.

type FilesystemConfig

type FilesystemConfig struct {
	Type   string // "virtiofs", "9p", "pmem"
	Source string
	Target string
	Tag    string
}

FilesystemConfig holds virtio-fs or 9p config.

type HypervisorInfo

type HypervisorInfo struct {
	Type      string // "kvm", "gunyah", "geniezone", "halla", "none"
	Backend   string // "crosvm", "firecracker", "qemu", "none"
	Available bool
	Path      string
}

HypervisorInfo returns information about the available hypervisor.

func DetectHypervisor

func DetectHypervisor() *HypervisorInfo

DetectHypervisor returns the detected hypervisor info.

type MicroVM

type MicroVM struct {
	ID        string
	VMM       VMM
	PID       int
	State     VMState
	CID       uint32
	TapDevice string
	CreatedAt time.Time
	StartedAt time.Time
}

MicroVM represents a running microVM.

type NetworkConfig

type NetworkConfig struct {
	Type       string // "tap", "bridge", "none", "host"
	TapName    string
	Bridge     string
	IP         string
	Gateway    string
	DNS        []string
	MacAddress string
}

NetworkConfig holds network configuration for a VM.

type VMConfig

type VMConfig struct {
	ID             string
	Kernel         string
	Rootfs         string
	Initrd         string
	CPUs           int
	Memory         int // MB
	Cmd            []string
	Env            []string
	Cwd            string
	Network        *NetworkConfig
	Vsock          *VsockConfig
	Filesystems    []FilesystemConfig
	KernelArgs     string
	Console        bool
	ReadOnlyRootfs bool
	ExtraDrives    []DriveConfig
}

VMConfig holds configuration for creating a microVM.

type VMM

type VMM interface {
	Create(ctx context.Context, cfg *VMConfig) (*MicroVM, error)
	Start(ctx context.Context, vmID string) error
	Stop(ctx context.Context, vmID string, timeout time.Duration) error
	Kill(ctx context.Context, vmID string) error
	State(ctx context.Context, vmID string) (VMState, error)
	Exec(ctx context.Context, vmID string, cmd []string, env []string, tty bool) error
	Attach(ctx context.Context, vmID string) error
	Logs(ctx context.Context, vmID string) (io.Reader, error)
	Stats(ctx context.Context, vmID string) (*VMStats, error)
	Cleanup(ctx context.Context, vmID string) error
	Name() string
}

VMM abstracts any microVM backend (crosvm, firecracker, qemu).

func NewVMM

func NewVMM(cfg *VMMConfig) (VMM, error)

NewVMM creates the best available VMM for the current platform.

type VMMConfig

type VMMConfig struct {
	ForceBackend string
	KernelPath   string
	WorkDir      string
	CNIBinDir    string
	CNIConfDir   string
	Debug        bool
}

VMMConfig holds global VMM configuration.

type VMState

type VMState string

VMState represents microVM lifecycle state.

const (
	VMStateCreated VMState = "created"
	VMStateRunning VMState = "running"
	VMStateStopped VMState = "stopped"
	VMStateFailed  VMState = "failed"
)

type VMStats

type VMStats struct {
	CPUPercent  float64
	MemoryMB    int64
	MemoryMaxMB int64
	NetRxBytes  int64
	NetTxBytes  int64
	DiskRead    int64
	DiskWrite   int64
}

VMStats holds resource usage statistics.

type VsockClient

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

VsockClient communicates with a microVM guest via vsock.

func NewVsockClient

func NewVsockClient(cid, port uint32) *VsockClient

NewVsockClient creates a vsock client for the given CID.

func (*VsockClient) Exec

func (v *VsockClient) Exec(_ context.Context, cmd []string, env []string, cwd string, tty bool, stdout, stderr io.Writer) error

Exec sends an exec command to the guest via vsock.

func (*VsockClient) HealthCheck

func (v *VsockClient) HealthCheck(_ context.Context) (string, error)

HealthCheck sends a health check probe.

func (*VsockClient) Signal

func (v *VsockClient) Signal(_ context.Context, sig string) error

Signal sends a signal to the guest process.

type VsockConfig

type VsockConfig struct {
	CID    uint32
	Port   uint32
	Socket string
}

VsockConfig holds vsock configuration.

type VsockMessage

type VsockMessage struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data,omitempty"`
	Cmd  []string        `json:"cmd,omitempty"`
	Env  []string        `json:"env,omitempty"`
	Cwd  string          `json:"cwd,omitempty"`
	Tty  bool            `json:"tty,omitempty"`
	Code int             `json:"code,omitempty"`
	Sig  string          `json:"sig,omitempty"`
}

VsockMessage represents a message exchanged via vsock.

Directories

Path Synopsis
Package crosvm provides crosvm-based VM backend.
Package crosvm provides crosvm-based VM backend.
Package firecracker provides Firecracker-based VM backend.
Package firecracker provides Firecracker-based VM backend.
Package network provides VM networking.
Package network provides VM networking.
Package qemu provides QEMU-based VM backend.
Package qemu provides QEMU-based VM backend.
Package rootfs builds root filesystems for VMs.
Package rootfs builds root filesystems for VMs.

Jump to

Keyboard shortcuts

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