vm

package
v1.4.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

This package is inspired from the code in https://gitlab.com/bootc-org/podman-bootc-cli/-/tree/main/pkg/vm as a very quick way to get bootc VMs running for testing purposes.

Documentation

Index

Constants

View Source
const DefaultDiskSizeGB = 10

Default disk size in GB for VM instances

Variables

This section is empty.

Functions

This section is empty.

Types

type JournalOpts added in v0.9.0

type JournalOpts struct {
	Unit     string
	Since    string // time string like "20 minutes ago" or empty for all logs
	LastBoot bool   // false by default, when true restricts logs to current boot
	// Lines, if > 0, passes journalctl -n Lines (most recent N entries matching other filters).
	Lines int
}

JournalOpts collects optional filters. Zero values mean "all units" / "start of journal".

type TestVM

type TestVM struct {
	TestDir           string
	VMName            string
	LibvirtUri        string //linux only
	DiskImagePath     string
	VMUser            string //user to use when connecting to the VM
	CloudInitDir      string
	NoCredentials     bool
	CloudInitData     bool
	SSHPassword       string
	SSHPrivateKeyPath util.SSHPrivateKeyPath // Path to SSH private key for key-based auth (alternative to SSHPassword)
	SSHPort           int
	Cmd               []string
	RemoveVm          bool

	MemoryFilePath string // Path for external snapshot memory file
	MemoryMiB      int    // VM memory in MiB; 0 means use default (2048)
	DiskSizeGB     int
	TPMDevice      string // Host TPM device path for passthrough (e.g., /dev/tpmrm0); empty uses swtpm emulator
	// SSHWaitTimeout is how long to wait for SSH to become ready. Zero uses the default (180s).
	// Use a longer value for first-boot VMs (e.g. imagebuild workflow) where cloud-init or sshd may start late.
	SSHWaitTimeout time.Duration
	// contains filtered or unexported fields
}

func (*TestVM) GetServiceLogs added in v0.10.0

func (v *TestVM) GetServiceLogs(serviceName string) (string, error)

GetServiceLogs returns the logs from the specified service using journalctl. This method uses the systemd invocation ID to get logs from the latest service invocation.

func (*TestVM) JournalLogs added in v0.9.0

func (v *TestVM) JournalLogs(opts JournalOpts) (string, error)

func (*TestVM) ParseCloudInit

func (v *TestVM) ParseCloudInit() error

func (*TestVM) RunSSH

func (v *TestVM) RunSSH(inputArgs []string, stdin *bytes.Buffer) (*bytes.Buffer, error)

func (*TestVM) RunSSHContext added in v1.3.0

func (v *TestVM) RunSSHContext(ctx context.Context, inputArgs []string, stdin *bytes.Buffer) (*bytes.Buffer, error)

RunSSHContext runs a command over SSH using the VM's default user and the provided context.

func (*TestVM) RunSSHWithUser added in v0.6.0

func (v *TestVM) RunSSHWithUser(inputArgs []string, stdin *bytes.Buffer, user string) (*bytes.Buffer, error)

func (*TestVM) RunSSHWithUserContext added in v1.4.0

func (v *TestVM) RunSSHWithUserContext(ctx context.Context, inputArgs []string, stdin *bytes.Buffer, user string) (*bytes.Buffer, error)

RunSSHWithUserContext runs a command over SSH using the requested user and context.

func (*TestVM) SSHCommand

func (v *TestVM) SSHCommand(inputArgs []string) *exec.Cmd

RunSSH runs a command over ssh or starts an interactive ssh connection if no command is provided

func (*TestVM) SSHCommandWithUser added in v0.6.0

func (v *TestVM) SSHCommandWithUser(inputArgs []string, user string) *exec.Cmd

func (*TestVM) WaitForSSHToBeReady

func (v *TestVM) WaitForSSHToBeReady() error

type TestVMInterface

type TestVMInterface interface {
	Run() error
	ForceDelete() error
	Shutdown() error
	Delete() error
	IsRunning() (bool, error)
	WaitForSSHToBeReady() error
	RunAndWaitForSSH() error
	SSHCommand(inputArgs []string) *exec.Cmd
	SSHCommandWithUser(nputArgs []string, user string) *exec.Cmd
	RunSSH(inputArgs []string, stdin *bytes.Buffer) (*bytes.Buffer, error)
	RunSSHContext(ctx context.Context, inputArgs []string, stdin *bytes.Buffer) (*bytes.Buffer, error)
	RunSSHWithUser(inputArgs []string, stdin *bytes.Buffer, user string) (*bytes.Buffer, error)
	RunSSHWithUserContext(ctx context.Context, inputArgs []string, stdin *bytes.Buffer, user string) (*bytes.Buffer, error)
	Exists() (bool, error)
	GetConsoleOutput() string
	EnsureConsoleStream() error
	JournalLogs(opts JournalOpts) (string, error)
	GetServiceLogs(serviceName string) (string, error)
	// Snapshot methods for performance optimization
	CreateSnapshot(name string) error
	RevertToSnapshot(name string) error
	DeleteSnapshot(name string) error
	Pause() error
	Resume() error
	HasSnapshot(name string) (bool, error)
	// Domain creation without starting
	CreateDomain() error
}

func StartAndWaitForSSH

func StartAndWaitForSSH(params TestVM) (vm TestVMInterface, err error)

type VMInLibvirt

type VMInLibvirt struct {
	TestVM
	// contains filtered or unexported fields
}

func NewVM

func NewVM(params TestVM) (vm *VMInLibvirt, err error)

func (*VMInLibvirt) CreateDomain added in v0.10.0

func (v *VMInLibvirt) CreateDomain() error

CreateDomain creates the libvirt domain without starting the VM

func (*VMInLibvirt) CreateSnapshot added in v0.10.0

func (v *VMInLibvirt) CreateSnapshot(name string) error

CreateSnapshot creates an external snapshot of the VM with memory state

func (*VMInLibvirt) Delete

func (v *VMInLibvirt) Delete() (err error)

Delete the VM definition

func (*VMInLibvirt) DeleteSnapshot added in v0.10.0

func (v *VMInLibvirt) DeleteSnapshot(name string) error

DeleteSnapshot deletes a specific snapshot

func (*VMInLibvirt) EnsureConsoleStream added in v0.10.0

func (v *VMInLibvirt) EnsureConsoleStream() error

EnsureConsoleStream ensures the console stream is properly established

func (*VMInLibvirt) Exists

func (v *VMInLibvirt) Exists() (bool, error)

func (*VMInLibvirt) ForceDelete

func (v *VMInLibvirt) ForceDelete() (err error)

ForceDelete stops and removes the VM

func (*VMInLibvirt) GetConsoleOutput

func (v *VMInLibvirt) GetConsoleOutput() string

cummulatively read console output from the VM

func (*VMInLibvirt) HasSnapshot added in v0.10.0

func (v *VMInLibvirt) HasSnapshot(name string) (bool, error)

HasSnapshot checks if a snapshot exists

func (*VMInLibvirt) IsRunning

func (v *VMInLibvirt) IsRunning() (exists bool, err error)

func (*VMInLibvirt) Pause added in v0.10.0

func (v *VMInLibvirt) Pause() error

Pause pauses the VM

func (*VMInLibvirt) Resume added in v0.10.0

func (v *VMInLibvirt) Resume() error

Resume resumes the VM

func (*VMInLibvirt) RevertPristineForPoolBootstrap added in v1.2.0

func (v *VMInLibvirt) RevertPristineForPoolBootstrap() error

RevertPristineForPoolBootstrap reverts to the pristine snapshot when reusing an existing domain (e.g. new e2e process / next suite) without SSH-based verification. The normal RevertToSnapshot path requires SSH first; pool BeforeSuite must reset guest state before WaitForSSH when a prior suite left a different bootc deployment or an unhealthy guest.

func (*VMInLibvirt) RevertToSnapshot added in v0.10.0

func (v *VMInLibvirt) RevertToSnapshot(name string) error

RevertToSnapshot reverts the VM to a specific snapshot with retry logic

func (*VMInLibvirt) Run

func (v *VMInLibvirt) Run() error

func (*VMInLibvirt) RunAndWaitForSSH

func (v *VMInLibvirt) RunAndWaitForSSH() error

func (*VMInLibvirt) Shutdown

func (v *VMInLibvirt) Shutdown() (err error)

Shutdown the VM

Jump to

Keyboard shortcuts

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