virt

package
v0.5.7-RC1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 to wait between retries when starting or stopping a VM If running in CI, no wait is performed

Functions

This section is empty.

Types

type BaseVirt

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

func NewBaseVirt

func NewBaseVirt(injector di.Injector) *BaseVirt

NewBaseVirt creates a new BaseVirt instance

func (*BaseVirt) Initialize

func (v *BaseVirt) Initialize() error

Initialize is a method that initializes the virt environment

type ColimaVirt

type ColimaVirt struct {
	*BaseVirt
}

ColimaVirt implements the VirtInterface and VMInterface for Colima

func NewColimaVirt

func NewColimaVirt(injector di.Injector) *ColimaVirt

NewColimaVirt creates a new instance of ColimaVirt using a DI injector

func (*ColimaVirt) Down

func (v *ColimaVirt) Down() error

Down stops and deletes the Colima VM First stops the VM and then deletes it to ensure a clean shutdown Returns an error if either the stop or delete operation fails

func (*ColimaVirt) GetVMInfo

func (v *ColimaVirt) GetVMInfo() (VMInfo, error)

GetVMInfo returns the information about the Colima VM Retrieves the VM details from the Colima CLI and parses the JSON output Converts memory and disk values from bytes to gigabytes for easier consumption Returns a VMInfo struct with the parsed information or an error if retrieval fails

func (*ColimaVirt) PrintInfo

func (v *ColimaVirt) PrintInfo() error

PrintInfo prints the information about the Colima VM Retrieves the VM information and formats it in a tabular display Shows the VM name, architecture, CPU count, memory, disk size, and IP address Returns an error if the VM information cannot be retrieved

func (*ColimaVirt) Up

func (v *ColimaVirt) Up() error

Up starts the Colima VM and configures its network settings Initializes the VM with the appropriate configuration and waits for it to be ready Sets the VM address in the configuration handler for later use 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 the Colima configuration file with VM settings Generates a configuration based on the current context and system properties Creates a temporary file and then renames it to the final configuration file Returns an error if any step of the configuration process fails

type ContainerInfo

type ContainerInfo struct {
	Name    string
	Address string
	Labels  map[string]string
}

type ContainerRuntime

type ContainerRuntime interface {
	Virt
	GetContainerInfo(name ...string) ([]ContainerInfo, error)
}

ContainerRuntime defines methods for container operations

type DockerVirt

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

DockerVirt implements the ContainerInterface for Docker

func NewDockerVirt

func NewDockerVirt(injector di.Injector) *DockerVirt

NewDockerVirt creates a new instance of DockerVirt using a DI injector

func (*DockerVirt) Down

func (v *DockerVirt) Down() error

Down stops all Docker containers managed by Windsor and removes associated volumes to ensure a clean shutdown. It verifies Docker is enabled, checks the daemon is running, and executes docker compose down with the --remove-orphans and --volumes flags.

func (*DockerVirt) GetContainerInfo

func (v *DockerVirt) GetContainerInfo(name ...string) ([]ContainerInfo, error)

GetContainerInfo retrieves detailed information about Docker containers managed by Windsor, including their names, IP addresses, and labels. It filters containers by Windsor-managed labels and context, and optionally by service name if provided. For each container, it retrieves network settings to determine IP addresses.

func (*DockerVirt) Initialize

func (v *DockerVirt) Initialize() error

Initialize resolves all dependencies for DockerVirt, including services from the DI container, Docker configuration status, and determines the appropriate docker compose command to use. It alphabetizes services and verifies Docker is enabled.

func (*DockerVirt) PrintInfo

func (v *DockerVirt) PrintInfo() error

PrintInfo displays a formatted table of running Docker containers with their names, IP addresses, and roles. It retrieves container information using GetContainerInfo and presents it in a tabular format for easy reading. If no containers are running, it displays an appropriate message.

func (*DockerVirt) Up

func (v *DockerVirt) Up() error

Up starts docker compose in detached mode with retry logic for reliability. It verifies Docker is enabled, checks the daemon is running, sets the compose file path, and attempts to start services with up to 3 retries if initial attempts fail.

func (*DockerVirt) WriteConfig

func (v *DockerVirt) WriteConfig() error

WriteConfig generates and writes the Docker Compose configuration file by combining settings from all services. It creates the necessary directory structure, retrieves the full compose configuration, serializes it to YAML, and writes it to the .windsor directory with appropriate permissions.

type MockVirt

type MockVirt struct {
	InitializeFunc       func() error
	UpFunc               func(verbose ...bool) error
	DownFunc             func() error
	PrintInfoFunc        func() error
	WriteConfigFunc      func() error
	GetVMInfoFunc        func() (VMInfo, error)
	GetContainerInfoFunc func(name ...string) ([]ContainerInfo, 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() error

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

func (*MockVirt) GetContainerInfo

func (m *MockVirt) GetContainerInfo(name ...string) ([]ContainerInfo, error)

GetContainerInfo retrieves information about the mock containers. If a custom GetContainerInfoFunc is provided, it will use that function instead.

func (*MockVirt) GetVMInfo

func (m *MockVirt) GetVMInfo() (VMInfo, error)

GetVMInfo retrieves information about the mock VM. If a custom GetVMInfoFunc is provided, it will use that function instead.

func (*MockVirt) Initialize

func (m *MockVirt) Initialize() error

Initialize initializes the mock virt. If a custom InitializeFunc is provided, it will use that function instead.

func (*MockVirt) PrintInfo

func (m *MockVirt) PrintInfo() error

PrintInfo prints information about the mock virt. If a custom PrintInfoFunc is provided, it will use that function instead.

func (*MockVirt) Up

func (m *MockVirt) Up() 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 added in v0.5.7

type Shims struct {
	Setenv         func(key, value string) error
	UnmarshalJSON  func(data []byte, v any) error
	UserHomeDir    func() (string, error)
	MkdirAll       func(path string, perm os.FileMode) error
	WriteFile      func(name string, data []byte, perm os.FileMode) error
	Rename         func(oldpath, newpath string) error
	GOARCH         func() string
	NumCPU         func() int
	VirtualMemory  func() (*mem.VirtualMemoryStat, error)
	MarshalYAML    func(v any) ([]byte, error)
	NewYAMLEncoder func(w io.Writer, opts ...yaml.EncodeOption) YAMLEncoder
}

Shims provides mockable wrappers around system and runtime functions

func NewShims added in v0.5.7

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

type VMInfo

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

VMInfo is a struct that holds the information about the VM

type Virt

type Virt interface {
	Initialize() error
	Up() error
	Down() error
	PrintInfo() error
	WriteConfig() error
}

Virt defines methods for the virt operations

type VirtualMachine

type VirtualMachine interface {
	Virt
	GetVMInfo() (VMInfo, error)
}

VirtualMachine defines methods for VirtualMachine operations

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