mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 09:01:12 +00:00
chore: clean types and align
This commit is contained in:
parent
3a256dc6e2
commit
caeb9dfaa7
3 changed files with 45 additions and 46 deletions
|
|
@ -26,18 +26,28 @@ type NetworkAllocation struct {
|
||||||
GuestMAC string
|
GuestMAC string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuestIP returns the guest IP address.
|
|
||||||
func (n NetworkAllocation) GuestIP() netip.Addr {
|
|
||||||
return n.GuestCIDR.Addr()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NetworkAllocator allocates /30 tap networks to machines.
|
// NetworkAllocator allocates /30 tap networks to machines.
|
||||||
type NetworkAllocator struct {
|
type NetworkAllocator struct {
|
||||||
basePrefix netip.Prefix
|
basePrefix netip.Prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNetworkAllocator returns a new /30 allocator rooted at the provided IPv4
|
// NetworkProvisioner prepares the host-side tap device for a machine.
|
||||||
// prefix.
|
type NetworkProvisioner interface {
|
||||||
|
Ensure(context.Context, NetworkAllocation) error
|
||||||
|
Remove(context.Context, NetworkAllocation) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPTapProvisioner provisions tap devices through the `ip` CLI.
|
||||||
|
type IPTapProvisioner struct {
|
||||||
|
runCommand func(context.Context, string, ...string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// GuestIP returns the guest IP address.
|
||||||
|
func (n NetworkAllocation) GuestIP() netip.Addr {
|
||||||
|
return n.GuestCIDR.Addr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewNetworkAllocator returns a new /30 allocator rooted at the provided IPv4 prefix.
|
||||||
func NewNetworkAllocator(cidr string) (*NetworkAllocator, error) {
|
func NewNetworkAllocator(cidr string) (*NetworkAllocator, error) {
|
||||||
cidr = strings.TrimSpace(cidr)
|
cidr = strings.TrimSpace(cidr)
|
||||||
if cidr == "" {
|
if cidr == "" {
|
||||||
|
|
@ -107,17 +117,6 @@ func (a *NetworkAllocator) networkForIndex(index int) (NetworkAllocation, error)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkProvisioner prepares the host-side tap device for a machine.
|
|
||||||
type NetworkProvisioner interface {
|
|
||||||
Ensure(context.Context, NetworkAllocation) error
|
|
||||||
Remove(context.Context, NetworkAllocation) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// IPTapProvisioner provisions tap devices through the `ip` CLI.
|
|
||||||
type IPTapProvisioner struct {
|
|
||||||
runCommand func(context.Context, string, ...string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewIPTapProvisioner returns a provisioner backed by `ip`.
|
// NewIPTapProvisioner returns a provisioner backed by `ip`.
|
||||||
func NewIPTapProvisioner() *IPTapProvisioner {
|
func NewIPTapProvisioner() *IPTapProvisioner {
|
||||||
return &IPTapProvisioner{
|
return &IPTapProvisioner{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MachineID uniquely identifies a single microVM on a host.
|
// MachineID uniquely identifies a single firecracler microVM
|
||||||
type MachineID string
|
type MachineID string
|
||||||
|
|
||||||
// MachineSpec describes the minimum machine inputs required to boot a guest.
|
// MachineSpec describes the minimum machine inputs required to boot a guest.
|
||||||
|
|
@ -21,6 +21,20 @@ type MachineSpec struct {
|
||||||
Vsock *VsockSpec
|
Vsock *VsockSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DriveSpec describes an additional guest block device.
|
||||||
|
type DriveSpec struct {
|
||||||
|
ID string
|
||||||
|
Path string
|
||||||
|
ReadOnly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// VsockSpec describes a single host-guest vsock device.
|
||||||
|
type VsockSpec struct {
|
||||||
|
ID string
|
||||||
|
CID uint32
|
||||||
|
Path string
|
||||||
|
}
|
||||||
|
|
||||||
// Validate reports whether the machine specification is usable for boot.
|
// Validate reports whether the machine specification is usable for boot.
|
||||||
func (s MachineSpec) Validate() error {
|
func (s MachineSpec) Validate() error {
|
||||||
if strings.TrimSpace(string(s.ID)) == "" {
|
if strings.TrimSpace(string(s.ID)) == "" {
|
||||||
|
|
@ -54,13 +68,6 @@ func (s MachineSpec) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DriveSpec describes an additional guest block device.
|
|
||||||
type DriveSpec struct {
|
|
||||||
ID string
|
|
||||||
Path string
|
|
||||||
ReadOnly bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate reports whether the drive specification is usable.
|
// Validate reports whether the drive specification is usable.
|
||||||
func (d DriveSpec) Validate() error {
|
func (d DriveSpec) Validate() error {
|
||||||
if strings.TrimSpace(d.ID) == "" {
|
if strings.TrimSpace(d.ID) == "" {
|
||||||
|
|
@ -72,20 +79,13 @@ func (d DriveSpec) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// VsockSpec describes a single host-guest vsock device.
|
|
||||||
type VsockSpec struct {
|
|
||||||
ID string
|
|
||||||
CID uint32
|
|
||||||
Path string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate reports whether the vsock specification is usable.
|
// Validate reports whether the vsock specification is usable.
|
||||||
func (v VsockSpec) Validate() error {
|
func (v VsockSpec) Validate() error {
|
||||||
if strings.TrimSpace(v.ID) == "" {
|
if strings.TrimSpace(v.ID) == "" {
|
||||||
return fmt.Errorf("vsock id is required")
|
return fmt.Errorf("vsock id is required")
|
||||||
}
|
}
|
||||||
if v.CID == 0 {
|
if v.CID == 0 {
|
||||||
return fmt.Errorf("vsock cid must be non-zero")
|
return fmt.Errorf("vsock cid must be non zero")
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(v.Path) == "" {
|
if strings.TrimSpace(v.Path) == "" {
|
||||||
return fmt.Errorf("vsock path is required")
|
return fmt.Errorf("vsock path is required")
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,18 @@ import "time"
|
||||||
// Phase represents the lifecycle phase of a local microVM.
|
// Phase represents the lifecycle phase of a local microVM.
|
||||||
type Phase string
|
type Phase string
|
||||||
|
|
||||||
|
// MachineState describes the current host local state for a machine.
|
||||||
|
type MachineState struct {
|
||||||
|
ID MachineID
|
||||||
|
Phase Phase
|
||||||
|
PID int
|
||||||
|
RuntimeHost string
|
||||||
|
SocketPath string
|
||||||
|
TapName string
|
||||||
|
StartedAt *time.Time
|
||||||
|
Error string
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// PhaseProvisioning means host-local resources are still being prepared.
|
// PhaseProvisioning means host-local resources are still being prepared.
|
||||||
PhaseProvisioning Phase = "provisioning"
|
PhaseProvisioning Phase = "provisioning"
|
||||||
|
|
@ -17,15 +29,3 @@ const (
|
||||||
// PhaseError means the runtime observed a terminal failure.
|
// PhaseError means the runtime observed a terminal failure.
|
||||||
PhaseError Phase = "error"
|
PhaseError Phase = "error"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MachineState describes the current host-local state for a machine.
|
|
||||||
type MachineState struct {
|
|
||||||
ID MachineID
|
|
||||||
Phase Phase
|
|
||||||
PID int
|
|
||||||
RuntimeHost string
|
|
||||||
SocketPath string
|
|
||||||
TapName string
|
|
||||||
StartedAt *time.Time
|
|
||||||
Error string
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue