instance

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: ISC Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCloudInit

func DefaultCloudInit() (string, error)

DefaultCloudInit generates a minimal cloud-init config that creates a user matching the current user. SSH key injection is handled by the user-ssh preboot layer rather than being baked into cloud-init at init time.

func EnsureVolume

func EnsureVolume(instanceName string, vol project.Volume, progress io.Writer) (bool, error)

EnsureVolume creates a volume's qcow2 file if it doesn't already exist. Returns true if the volume was newly created (needs formatting), false if it already existed.

func Exists

func Exists(name string) bool

Exists returns true if the instance already exists.

func InstanceDir

func InstanceDir(name string) (string, error)

InstanceDir returns the directory for an instance.

func RemoveVolume

func RemoveVolume(fullName string, force bool) error

RemoveVolume deletes a volume by its full name (instance-volumename). If force is false, it refuses to delete a volume attached to a running instance.

func RetainedVolumeSummary

func RetainedVolumeSummary(instanceName string) string

RetainedVolumeSummary returns a human-readable summary of volumes that were preserved during a destroy operation.

func RunPrebootHooks

func RunPrebootHooks(p *project.Project, instanceName, cloudInitPath string, progress io.Writer) error

RunPrebootHooks executes preboot hooks for all layers that have them. The cloudInitPath is a writable file that hooks can edit in place. Returns the final cloud-init content after all hooks have run.

func ValidateCloudInit added in v0.2.4

func ValidateCloudInit(content string) (string, error)

ValidateCloudInit checks that cloud-init content is well-formed. It ensures the #cloud-config header is present (prepending it if missing) and that the body looks like valid YAML key-value pairs.

func VolumeCloudInit

func VolumeCloudInit(blocks []project.Volume, networks []project.Volume, newVolumes map[string]bool) string

VolumeCloudInit generates cloud-init YAML stanzas for disk_setup, fs_setup, and mounts for the given block volumes. Only newly created volumes get disk_setup and fs_setup entries (to format them). All block volumes get mount entries. Network mounts also get mount entries.

func VolumeDisksForStart

func VolumeDisksForStart(instanceName string, blocks []project.Volume, networks []project.Volume) (diskArgs []string, fsArgs []string, err error)

VolumeDisksForStart returns the virt-install --disk arguments for block volumes and --filesystem arguments for virtiofs/9p mounts.

func VolumeLabel

func VolumeLabel(volumeName string) string

VolumeLabel returns the filesystem label for a volume.

func VolumePath

func VolumePath(instanceName, volumeName string) (string, error)

VolumePath returns the path for a volume's qcow2 file.

func VolumesDir

func VolumesDir() (string, error)

VolumesDir returns the directory where volumes are stored.

Types

type Instance

type Instance struct {
	Name     string // Instance name (default: project directory name)
	Dir      string // Instance directory path
	DiskPath string // Path to COW overlay disk
	ISOPath  string // Path to cloud-init ISO
	Domain   string // libvirt domain name (tank-<name>)
}

Instance represents a running or stopped VM instance.

func Create

func Create(name, buildImagePath, cloudInitYAML string, progress io.Writer) (*Instance, error)

Create creates a new instance with a COW overlay disk.

func Load

func Load(name string) (*Instance, error)

Load loads an existing instance by name.

func (*Instance) Destroy

func (inst *Instance) Destroy(progress io.Writer) error

Destroy forcefully stops and undefines the VM, then removes instance files.

func (*Instance) IPAddress

func (inst *Instance) IPAddress() (string, error)

IPAddress returns the VM's IPv4 address via virsh domifaddr. Returns empty string if no address is found (e.g., VM still booting).

func (*Instance) IsRunning

func (inst *Instance) IsRunning() bool

IsRunning checks if the VM is currently running.

func (*Instance) Start

func (inst *Instance) Start(cpus, memoryMB int, volumeDisks []string, volumeFS []string, progress io.Writer) error

Start starts the VM using virt-install.

func (*Instance) Stop

func (inst *Instance) Stop(progress io.Writer) error

Stop stops the VM (graceful shutdown).

type VolumeInfo

type VolumeInfo struct {
	Name         string // full name: instance-volumename
	InstanceName string // instance name
	VolumeName   string // volume name (without instance prefix)
	Path         string // full path to qcow2
	Size         int64  // file size on disk
}

VolumeInfo holds information about an existing volume on disk.

func ListVolumes

func ListVolumes(instanceFilter string) ([]VolumeInfo, error)

ListVolumes lists all volumes in the volumes directory. If instanceFilter is non-empty, only volumes for that instance are returned and volume names are parsed by stripping the instance prefix. If instanceFilter is empty, all volumes are returned. Instance names are resolved by matching against known instances first, then falling back to splitting on the last dash.

Jump to

Keyboard shortcuts

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