virt

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 25 Imported by: ? modules, 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.

Documentation

Index

Constants

View Source
const DockerComposeProjectPrefix = "workstation-windsor-"

DockerComposeProjectPrefix is the prefix of the com.docker.compose.project label of a context.

View Source
const (
	IncusNetworkName = "incusbr0"
)
View Source
const WindsorNetworkPrefix = "windsor-"

WindsorNetworkPrefix is the prefix of the Docker network of a context, for example windsor-local.

Variables

View Source
var RETRY_WAIT = func() int {
	return map[bool]int{true: 0, false: 2}[os.Getenv("CI") == "true"]
}()

RETRY_WAIT is the number of seconds between VM retries. It is 0 when CI is "true".

Functions

This section is empty.

Types

type BaseVirt

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

BaseVirt holds the dependencies that every Virt implementation shares.

func NewBaseVirt

func NewBaseVirt(rt *runtime.Runtime) *BaseVirt

NewBaseVirt returns a BaseVirt for rt. It panics when rt, its shell, or its config handler is nil.

type ColimaVirt

type ColimaVirt struct {
	*BaseVirt
}

ColimaVirt is the VirtualMachine for Colima.

func NewColimaVirt

func NewColimaVirt(rt *runtime.Runtime) *ColimaVirt

NewColimaVirt returns a ColimaVirt for rt. It panics when rt is nil.

func (*ColimaVirt) Down

func (v *ColimaVirt) Down(ctx context.Context) error

Down stops and deletes the Colima VM, ensuring resources are reclaimed. Attempts graceful shutdown, then deletes the VM. Returns an error if deletion fails.

func (*ColimaVirt) Up

func (v *ColimaVirt) Up(ctx context.Context) error

Up starts the Colima VM and configures its network settings. It initializes the VM with the appropriate configuration and waits for it to become ready. If the VM is already running, it skips the start operation and reuses the existing VM. It returns an error with a remediation when the mounts of the running VM differ from colima.yaml. The VM address is set in the configuration handler for later use. Kills stuck processes before starting if VM is not already running to prevent vmnet/daemon issues. Returns an error if the VM fails to start or if the address cannot be set.

func (*ColimaVirt) WriteConfig

func (v *ColimaVirt) WriteConfig() error

WriteConfig writes ~/.colima/windsor-<context>/colima.yaml from the context and the host resources. It writes a temporary file and then renames it to the final file. It does nothing when workstation.runtime is not colima.

type ContainerRuntime

type ContainerRuntime interface {
	Virt
}

ContainerRuntime is a Virt that runs containers.

type DockerVirt

type DockerVirt struct {
	*BaseVirt
}

DockerVirt is the ContainerRuntime for platform docker.

func NewDockerVirt

func NewDockerVirt(rt *runtime.Runtime) *DockerVirt

NewDockerVirt returns a DockerVirt for rt. It panics when rt is nil.

func (*DockerVirt) Down

func (v *DockerVirt) Down(ctx context.Context) error

Down removes the containers, the named volumes, and the network of the context, and nothing else. It finds the containers and volumes by the label com.docker.compose.project=workstation-windsor-<context>. It does nothing when DOCKER_HOST names a unix socket that does not exist, because the VM is gone. It shows each failure as a warning and always returns nil.

func (*DockerVirt) Up

func (v *DockerVirt) Up(ctx context.Context) error

Up checks that the Docker daemon answers, because Terraform or compose start the containers. It returns one error that names the endpoint when the daemon does not answer.

func (*DockerVirt) WriteConfig

func (v *DockerVirt) WriteConfig() error

WriteConfig does nothing.

type IncusInstance added in v0.9.0

type IncusInstance struct {
	Name            string                 `json:"name"`
	Status          string                 `json:"status"`
	StatusCode      int                    `json:"status_code"`
	Type            string                 `json:"type"`
	ExpandedDevices map[string]interface{} `json:"expanded_devices"`
}

IncusInstance represents an Incus instance parsed from JSON output. It contains the instance name, status information, type, and expanded device configurations as returned by the Incus CLI when listing instances.

type IncusInstanceConfig added in v0.9.0

type IncusInstanceConfig struct {
	Name      string
	Type      string
	Image     string
	Config    map[string]string
	Devices   map[string]map[string]string
	Profiles  []string
	IPv4      string
	Network   string
	Resources map[string]string
}

IncusInstanceConfig represents the complete configuration for creating an Incus instance. It contains all necessary parameters including instance name, type, image, network settings, device configurations, profiles, and resource limits required for instance creation.

type IncusOperation added in v0.9.0

type IncusOperation struct {
	ID         string         `json:"id"`
	Class      string         `json:"class"`
	CreatedAt  string         `json:"created_at"`
	UpdatedAt  string         `json:"updated_at"`
	Status     string         `json:"status"`
	StatusCode int            `json:"status_code"`
	Resources  map[string]any `json:"resources"`
	Metadata   map[string]any `json:"metadata"`
	MayCancel  bool           `json:"may_cancel"`
	Err        string         `json:"err"`
}

IncusOperation represents an Incus operation parsed from JSON output. It contains operation metadata including ID, status, timestamps, resources affected, and error information as returned by the Incus CLI when listing operations.

type IncusRemote added in v0.9.0

type IncusRemote struct {
	Name     string `json:"name"`
	URL      string `json:"url"`
	Protocol string `json:"protocol"`
	Public   bool   `json:"public"`
}

IncusRemote represents an Incus remote repository parsed from JSON output. It contains the remote name, URL, protocol type, and public access flag as returned by the Incus CLI when listing configured remotes.

type IncusVirt added in v0.9.0

type IncusVirt struct {
	*ColimaVirt
	// contains filtered or unexported fields
}

IncusVirt implements both the ContainerRuntime and VirtualMachine interfaces for Incus. It embeds ColimaVirt to inherit Colima VM functionality. Instance creation is handled by Terraform in the stack.

func NewIncusVirt added in v0.9.0

func NewIncusVirt(rt *runtime.Runtime) *IncusVirt

NewIncusVirt returns an IncusVirt for rt that embeds a ColimaVirt for the VM.

func (*IncusVirt) Down added in v0.9.0

func (v *IncusVirt) Down(ctx context.Context) error

Down stops the Colima daemon and deletes the VM. Off platform incus, it only deletes the VM.

func (*IncusVirt) Up added in v0.9.0

func (v *IncusVirt) Up(ctx context.Context) error

Up starts the Colima VM through ColimaVirt.Up when the VM is not running. When the VM is running, it adds the docker and ghcr remotes that Incus does not have yet. Workstation calls Up once as the VirtualMachine and once as the ContainerRuntime.

type MockVirt

type MockVirt struct {
	UpFunc          func(verbose ...bool) error
	DownFunc        func() error
	WriteConfigFunc func() error
}

MockVirt is a struct that simulates a virt environment for testing purposes.

func NewMockVirt

func NewMockVirt() *MockVirt

NewMockVirt creates a new instance of MockVirt.

func (*MockVirt) Down

func (m *MockVirt) Down(_ context.Context) error

Down stops the mock virt. If a custom DownFunc is provided, it will use that function instead.

func (*MockVirt) Up

func (m *MockVirt) Up(_ context.Context) error

Up starts the mock virt. If a custom UpFunc is provided, it will use that function instead.

func (*MockVirt) WriteConfig

func (m *MockVirt) WriteConfig() error

WriteConfig writes the configuration of the mock virt. If a custom WriteConfigFunc is provided, it will use that function instead.

type Shims

type Shims struct {
	shims.Shims
	GOARCH         func() string
	NumCPU         func() int
	VirtualMemory  func() (*mem.VirtualMemoryStat, error)
	NewYAMLEncoder func(w io.Writer, opts ...yaml.EncodeOption) YAMLEncoder
}

Shims holds the shared system call primitives and the host shims of the virt package.

func NewShims

func NewShims() *Shims

NewShims returns a Shims with every field set to its real implementation.

type VMInfo

type VMInfo struct {
	Address string
	Arch    string
	CPUs    int
	Disk    int
	Memory  int
	Name    string
}

VMInfo holds the address and the resources of a VM.

type Virt

type Virt interface {
	Up(ctx context.Context) error
	Down(ctx context.Context) error
	WriteConfig() error
}

Virt starts, stops, and writes the configuration of a VM or a container runtime.

type VirtualMachine

type VirtualMachine interface {
	Virt
}

VirtualMachine is a Virt that runs a VM.

type YAMLEncoder

type YAMLEncoder interface {
	Encode(v any) error
	Close() error
}

YAMLEncoder is an interface for encoding YAML data.

Jump to

Keyboard shortcuts

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