Documentation
¶
Overview ¶
Package iface provides network interface configuration management via Netplan.
Index ¶
- Variables
- func ValidateInterfaceName(name string) error
- type Darwin
- func (d *Darwin) Create(_ context.Context, _ InterfaceEntry) (*InterfaceResult, error)
- func (d *Darwin) Delete(_ context.Context, _ string) (*InterfaceResult, error)
- func (d *Darwin) Get(_ context.Context, _ string) (*InterfaceEntry, error)
- func (d *Darwin) List(_ context.Context) ([]InterfaceEntry, error)
- func (d *Darwin) Update(_ context.Context, _ InterfaceEntry) (*InterfaceResult, error)
- type Debian
- func (d *Debian) Create(ctx context.Context, entry InterfaceEntry) (*InterfaceResult, error)
- func (d *Debian) Delete(ctx context.Context, name string) (*InterfaceResult, error)
- func (d *Debian) Get(_ context.Context, name string) (*InterfaceEntry, error)
- func (d *Debian) List(_ context.Context) ([]InterfaceEntry, error)
- func (d *Debian) Update(ctx context.Context, entry InterfaceEntry) (*InterfaceResult, error)
- type InterfaceEntry
- type InterfaceResult
- type Linux
- func (l *Linux) Create(_ context.Context, _ InterfaceEntry) (*InterfaceResult, error)
- func (l *Linux) Delete(_ context.Context, _ string) (*InterfaceResult, error)
- func (l *Linux) Get(_ context.Context, _ string) (*InterfaceEntry, error)
- func (l *Linux) List(_ context.Context) ([]InterfaceEntry, error)
- func (l *Linux) Update(_ context.Context, _ InterfaceEntry) (*InterfaceResult, error)
- type Provider
Constants ¶
This section is empty.
Variables ¶
var ValidName = regexp.MustCompile(`^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$`)
ValidName matches alphanumeric characters and dashes.
Functions ¶
func ValidateInterfaceName ¶
ValidateInterfaceName checks that the interface name is non-empty and matches the allowed pattern (alphanumeric and dashes).
Types ¶
type Darwin ¶
type Darwin struct{}
Darwin implements the Provider interface for Darwin (macOS). All methods return ErrUnsupported as Netplan is not available on macOS.
func NewDarwinProvider ¶
func NewDarwinProvider() *Darwin
NewDarwinProvider factory to create a new Darwin instance.
func (*Darwin) Create ¶
func (d *Darwin) Create( _ context.Context, _ InterfaceEntry, ) (*InterfaceResult, error)
Create returns ErrUnsupported on Darwin.
func (*Darwin) List ¶
func (d *Darwin) List( _ context.Context, ) ([]InterfaceEntry, error)
List returns ErrUnsupported on Darwin.
func (*Darwin) Update ¶
func (d *Darwin) Update( _ context.Context, _ InterfaceEntry, ) (*InterfaceResult, error)
Update returns ErrUnsupported on Darwin.
type Debian ¶
type Debian struct {
provider.FactsAware
// contains filtered or unexported fields
}
Debian implements the Provider interface for Debian-family systems. It writes Netplan YAML files to /etc/netplan/ with an osapi- prefix and tracks state in the file-state KV for idempotency.
func NewDebianProvider ¶
func NewDebianProvider( logger *slog.Logger, fs avfs.VFS, stateKV jetstream.KeyValue, execManager exec.Manager, hostname string, ) *Debian
NewDebianProvider factory to create a new Debian instance.
func (*Debian) Create ¶
func (d *Debian) Create( ctx context.Context, entry InterfaceEntry, ) (*InterfaceResult, error)
Create deploys a new Netplan interface configuration file. Fails if a managed file already exists for the interface name.
func (*Debian) Delete ¶
Delete removes a managed Netplan interface configuration file. If no managed file exists, returns Changed: false (idempotent).
func (*Debian) List ¶
func (d *Debian) List( _ context.Context, ) ([]InterfaceEntry, error)
List returns all network interfaces from netplan status.
func (*Debian) Update ¶
func (d *Debian) Update( ctx context.Context, entry InterfaceEntry, ) (*InterfaceResult, error)
Update redeploys an existing Netplan interface configuration file. Fails if no managed file exists for the interface name.
type InterfaceEntry ¶
type InterfaceEntry struct {
Name string `json:"name"`
IPv4 string `json:"ipv4,omitempty"`
IPv6 string `json:"ipv6,omitempty"`
MAC string `json:"mac,omitempty"`
Family string `json:"family,omitempty"`
DHCP4 *bool `json:"dhcp4,omitempty"`
DHCP6 *bool `json:"dhcp6,omitempty"`
Addresses []string `json:"addresses,omitempty"`
Gateway4 string `json:"gateway4,omitempty"`
Gateway6 string `json:"gateway6,omitempty"`
MTU int `json:"mtu,omitempty"`
MACAddress string `json:"mac_address,omitempty"`
WakeOnLAN *bool `json:"wakeonlan,omitempty"`
Primary bool `json:"primary,omitempty"`
}
InterfaceEntry represents a network interface. For list/get operations, the read-only fields (IPv4, IPv6, MAC, Family) are populated from the system. For create/update, the config fields (DHCP, Addresses, Gateway, etc.) are used to generate Netplan YAML.
type InterfaceResult ¶
type InterfaceResult struct {
Name string `json:"name"`
Changed bool `json:"changed"`
Error string `json:"error,omitempty"`
}
InterfaceResult is the outcome of a create/update/delete operation.
type Linux ¶
type Linux struct{}
Linux implements the Provider interface for generic Linux. All methods return ErrUnsupported as this is a generic Linux stub.
func NewLinuxProvider ¶
func NewLinuxProvider() *Linux
NewLinuxProvider factory to create a new Linux instance.
func (*Linux) Create ¶
func (l *Linux) Create( _ context.Context, _ InterfaceEntry, ) (*InterfaceResult, error)
Create returns ErrUnsupported on generic Linux.
func (*Linux) List ¶
func (l *Linux) List( _ context.Context, ) ([]InterfaceEntry, error)
List returns ErrUnsupported on generic Linux.
func (*Linux) Update ¶
func (l *Linux) Update( _ context.Context, _ InterfaceEntry, ) (*InterfaceResult, error)
Update returns ErrUnsupported on generic Linux.
type Provider ¶
type Provider interface {
// List returns all managed network interface configurations.
List(ctx context.Context) ([]InterfaceEntry, error)
// Get returns a single interface configuration by name.
Get(ctx context.Context, name string) (*InterfaceEntry, error)
// Create deploys a new interface configuration via Netplan.
Create(ctx context.Context, entry InterfaceEntry) (*InterfaceResult, error)
// Update redeploys an existing interface configuration via Netplan.
Update(ctx context.Context, entry InterfaceEntry) (*InterfaceResult, error)
// Delete removes an interface configuration via Netplan.
Delete(ctx context.Context, name string) (*InterfaceResult, error)
}
Provider manages network interface configuration via Netplan.