mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 03:00:42 +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
|
||||
}
|
||||
|
||||
// GuestIP returns the guest IP address.
|
||||
func (n NetworkAllocation) GuestIP() netip.Addr {
|
||||
return n.GuestCIDR.Addr()
|
||||
}
|
||||
|
||||
// NetworkAllocator allocates /30 tap networks to machines.
|
||||
type NetworkAllocator struct {
|
||||
basePrefix netip.Prefix
|
||||
}
|
||||
|
||||
// NewNetworkAllocator returns a new /30 allocator rooted at the provided IPv4
|
||||
// prefix.
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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) {
|
||||
cidr = strings.TrimSpace(cidr)
|
||||
if cidr == "" {
|
||||
|
|
@ -107,17 +117,6 @@ func (a *NetworkAllocator) networkForIndex(index int) (NetworkAllocation, error)
|
|||
}, 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`.
|
||||
func NewIPTapProvisioner() *IPTapProvisioner {
|
||||
return &IPTapProvisioner{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// MachineID uniquely identifies a single microVM on a host.
|
||||
// MachineID uniquely identifies a single firecracler microVM
|
||||
type MachineID string
|
||||
|
||||
// MachineSpec describes the minimum machine inputs required to boot a guest.
|
||||
|
|
@ -21,6 +21,20 @@ type MachineSpec struct {
|
|||
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.
|
||||
func (s MachineSpec) Validate() error {
|
||||
if strings.TrimSpace(string(s.ID)) == "" {
|
||||
|
|
@ -54,13 +68,6 @@ func (s MachineSpec) Validate() error {
|
|||
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.
|
||||
func (d DriveSpec) Validate() error {
|
||||
if strings.TrimSpace(d.ID) == "" {
|
||||
|
|
@ -72,20 +79,13 @@ func (d DriveSpec) Validate() error {
|
|||
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.
|
||||
func (v VsockSpec) Validate() error {
|
||||
if strings.TrimSpace(v.ID) == "" {
|
||||
return fmt.Errorf("vsock id is required")
|
||||
}
|
||||
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) == "" {
|
||||
return fmt.Errorf("vsock path is required")
|
||||
|
|
|
|||
|
|
@ -5,6 +5,18 @@ import "time"
|
|||
// Phase represents the lifecycle phase of a local microVM.
|
||||
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 (
|
||||
// PhaseProvisioning means host-local resources are still being prepared.
|
||||
PhaseProvisioning Phase = "provisioning"
|
||||
|
|
@ -17,15 +29,3 @@ const (
|
|||
// PhaseError means the runtime observed a terminal failure.
|
||||
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