mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 11:02:15 +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{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue