vm

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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
}

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
	SSHPort       int
	Cmd           []string
	RemoveVm      bool

	MemoryFilePath string // Path for external snapshot memory file
	DiskSizeGB     int
	// 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) RunSSHWithUser added in v0.6.0

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

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)
	RunSSHWithUser(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) 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