state

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStateDBInit  = errors.New("initialize state database")
	ErrRegisterVM   = errors.New("register VM")
	ErrUnregisterVM = errors.New("unregister VM")
	ErrListVMs      = errors.New("list VMs")
	ErrGetVM        = errors.New("get VM")
	ErrKillVM       = errors.New("kill VM")
	ErrRemoveVM     = errors.New("remove VM")
	ErrReadLog      = errors.New("read VM log")
	ErrWriteLog     = errors.New("write VM log")

	ErrNoAvailableSubnets   = errors.New("no available subnets")
	ErrSaveSubnetAllocation = errors.New("failed to save subnet allocation")
)

Functions

func CopyLogFile added in v0.2.4

func CopyLogFile(ctx context.Context, path string, w io.Writer, follow bool) error

CopyLogFile writes the current contents of path to w and, when follow is true, continues streaming appended data until ctx is cancelled.

func ReadLogFile added in v0.2.4

func ReadLogFile(path string) ([]byte, error)

ReadLogFile returns the current contents of path.

Types

type Manager

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

func NewManager

func NewManager() *Manager

func NewManagerWithDir

func NewManagerWithDir(baseDir string) *Manager

func (*Manager) DBPath added in v0.1.19

func (m *Manager) DBPath() string

func (*Manager) Dir

func (m *Manager) Dir(id string) string

func (*Manager) ExecSocketPath

func (m *Manager) ExecSocketPath(id string) string

func (*Manager) Get

func (m *Manager) Get(id string) (VMState, error)

func (*Manager) Kill

func (m *Manager) Kill(id string) error

func (*Manager) List

func (m *Manager) List() ([]VMState, error)

func (*Manager) LogPath

func (m *Manager) LogPath(id string) string

func (*Manager) Prune

func (m *Manager) Prune() ([]string, error)

func (*Manager) ReadLog added in v0.2.4

func (m *Manager) ReadLog(id string) ([]byte, error)

ReadLog returns the current contents of a VM log.

func (*Manager) Register

func (m *Manager) Register(id string, config interface{}) error

func (*Manager) Remove

func (m *Manager) Remove(id string) error

func (*Manager) SocketPath

func (m *Manager) SocketPath(id string) string

func (*Manager) StreamLog added in v0.2.4

func (m *Manager) StreamLog(ctx context.Context, id string, w io.Writer, follow bool) error

StreamLog writes the current VM log to w and, when follow is true, continues streaming appended data until ctx is cancelled.

func (*Manager) Unregister

func (m *Manager) Unregister(id string) error

type SubnetAllocator

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

SubnetAllocator manages unique /24 subnet allocation for VMs Uses 192.168.X.0/24 where X ranges from 100-254.

func NewSubnetAllocator

func NewSubnetAllocator() *SubnetAllocator

func NewSubnetAllocatorWithDir added in v0.1.19

func NewSubnetAllocatorWithDir(baseDir string) *SubnetAllocator

func (*SubnetAllocator) Allocate

func (a *SubnetAllocator) Allocate(vmID string) (*SubnetInfo, error)

Allocate assigns a unique subnet to a VM.

func (*SubnetAllocator) AllocationPath added in v0.1.19

func (a *SubnetAllocator) AllocationPath(vmID string) string

AllocationPath is retained for lifecycle/debug compatibility.

func (*SubnetAllocator) Cleanup

func (a *SubnetAllocator) Cleanup(mgr *Manager) error

Cleanup removes all stale subnet allocations (VMs that no longer exist).

func (*SubnetAllocator) Get

func (a *SubnetAllocator) Get(vmID string) (*SubnetInfo, error)

Get retrieves subnet info for a VM.

func (*SubnetAllocator) Release

func (a *SubnetAllocator) Release(vmID string) error

Release frees a subnet allocation.

type SubnetInfo

type SubnetInfo struct {
	Octet     int    `json:"octet"`      // Third octet (e.g., 100 for 192.168.100.0/24)
	GatewayIP string `json:"gateway_ip"` // Host TAP IP (e.g., 192.168.100.1)
	GuestIP   string `json:"guest_ip"`   // Guest IP (e.g., 192.168.100.2)
	Subnet    string `json:"subnet"`     // CIDR notation (e.g., 192.168.100.0/24)
	VMID      string `json:"vm_id"`
}

type VMState

type VMState struct {
	ID        string          `json:"id"`
	PID       int             `json:"pid"`
	Status    string          `json:"status"`
	Image     string          `json:"image"`
	CreatedAt time.Time       `json:"created_at"`
	Config    json.RawMessage `json:"config,omitempty"`
}

Jump to

Keyboard shortcuts

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