qemu

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package qemu implements the local VM manager using QEMU.

Index

Constants

View Source
const NET_CIDR = "192.168.1.0/24"
View Source
const NET_END = "192.168.1.20"
View Source
const NET_MACPREFIX = "52:52:00:00:00:"
View Source
const NET_MASK = "255.255.255.0"
View Source
const NET_START = "192.168.1.1"
View Source
const NET_SUBNET = "192.168.1.0"

Networking constants Alternatives: NET_CIDR="172.18.0.0/16" NET_START="172.18.0.1" # 172.18.0.1 NET_END="192.18.0.2" # 172.18.255.254 NET_MASK="255.255.0.0" # /16

Variables

This section is empty.

Functions

func NetMacAddress

func NetMacAddress(suffix string) string

func NewQemu

func NewQemu(opts Options) vm.Manager

NewQemu creates a new qemu VM manager from explicit options.

func NormalizeKernelCmdline

func NormalizeKernelCmdline(arch, raw string) string

NormalizeKernelCmdline adapts the manifest's raw boot-entry cmdline for local QEMU direct boot while preserving device/root arguments.

func QemuArguments

func QemuArguments(monitor bool, arch, vmImage, cloudInitDataISOPath, serialConsolePath, cpus, memory string, directBoot *vm.DirectBootOptions, ports []vm.PortForward) []string

QemuArguments builds the command arguments to pass to qemu based on the architecture specified. cloudInitDataISOPath is the path to a NoCloud cidata ISO that delivers user-data to the guest. When directBoot is present, QEMU loads the kernel/initrd directly and the qcow2 remains attached as the virtio root disk. When monitor is true, qemu is also started with "-monitor stdio" so the operator can interact with it from the terminal that launched `podplane local start --monitor`.

func QemuBinary

func QemuBinary(arch string) string

QemuBinary returns the qemu binary name based on the arch

func QemuRequiredBinaries

func QemuRequiredBinaries(arch string) []string

QemuRequiredBinaries returns the required binaries for qemu

Types

type Options

type Options struct {
	// Arch is the target architecture, e.g. "amd64" or "arm64".
	Arch string

	// ClusterID is used to derive a stable per-cluster VM name
	// ("podplane-local-<ClusterID>").
	ClusterID string

	// DataDir is the on-disk root for durable VM data (qcow2 images).
	// Concretely: <DataDir>/vms/<vmname>.<arch>.image.qcow2.
	DataDir string

	// RuntimeDir is the on-disk root for ephemeral VM runtime files (PIDs).
	// Concretely: <RuntimeDir>/vms/<vmname>.<arch>.pid.json.
	RuntimeDir string
}

type Qemu

type Qemu struct {
	VMName string
	// contains filtered or unexported fields
}

Qemu handles interactions with qemu

func (*Qemu) Addr

func (m *Qemu) Addr() string

func (*Qemu) CloudInitDataDiskPath

func (m *Qemu) CloudInitDataDiskPath() string

CloudInitDataDiskPath returns the path to the cloud-init data ISO image for a VM

func (*Qemu) Console

func (m *Qemu) Console() error

Console attaches the terminal to the VM's serial console Unix socket.

func (*Qemu) Create

func (m *Qemu) Create(baseImage string) error

Create creates a new Qemu VM image, using the supplied base image path as the qcow2 backing file.

func (*Qemu) Delete

func (m *Qemu) Delete() error

Delete deletes a qemu VM

func (*Qemu) Exists

func (m *Qemu) Exists() (bool, error)

Exists checks if a Qemu VM image exists on disk

func (*Qemu) PID

func (m *Qemu) PID() (int, error)

PID returns the process ID of the running VM, or 0 if not running.

func (*Qemu) Running

func (m *Qemu) Running() (bool, error)

Running checks if a Qemu VM is currently running, first by loading our PID file, then by verifying the process is running.

func (*Qemu) SerialConsolePath

func (m *Qemu) SerialConsolePath() string

SerialConsolePath returns the path to the QEMU serial console Unix socket.

func (*Qemu) SetOutput

func (m *Qemu) SetOutput(output io.Writer)

SetOutput sets where user-facing qemu lifecycle messages and child process output are written.

func (*Qemu) Shell

func (m *Qemu) Shell(ctx context.Context, command string, sshPort int, identityFile string, opts vm.ShellOptions) ([]byte, error)

Shell opens a shell session into a qemu VM, or if a command is provided, executes that command instead of opening interactive shell

func (*Qemu) Start

func (m *Qemu) Start(userData, cpus, memory, sshAuthorizedKey string, monitor bool, boot *vm.DirectBootOptions, ports []vm.PortForward) error

Start starts a qemu VM. The userData string is the rendered cloud-init user-data script; it is written into a NoCloud cidata ISO and attached to the VM as a cdrom drive.

func (*Qemu) Stop

func (m *Qemu) Stop() error

Stop stops a qemu VM

func (*Qemu) Sync

func (m *Qemu) Sync(from, to, chown string, excludes []string, sshPort int, identityFile string) error

Sync rsync's files into the running local cluster qemu VM.

func (*Qemu) VMImageDirectory

func (m *Qemu) VMImageDirectory() string

VMImageDirectory returns the path to the directory for VM image files

func (*Qemu) VMImagePath

func (m *Qemu) VMImagePath() string

VMImagePath returns the path to the VM image file for the given arch

func (*Qemu) VMPIDDirectory

func (m *Qemu) VMPIDDirectory() string

VMPIDDirectory return the path to the directory for VM PID files

func (*Qemu) VMPIDFile

func (m *Qemu) VMPIDFile() (pid.PIDFile, error)

VMPIDFile returns a pid.PIDFile for the VM

func (*Qemu) VMPIDFilename

func (m *Qemu) VMPIDFilename() string

VMPIDFilename returns the filename to use for a VM PID file

Jump to

Keyboard shortcuts

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