iface

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package iface provides network interface configuration management via Netplan.

Index

Constants

This section is empty.

Variables

View Source
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

func ValidateInterfaceName(
	name string,
) error

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) Delete

func (d *Darwin) Delete(
	_ context.Context,
	_ string,
) (*InterfaceResult, error)

Delete returns ErrUnsupported on Darwin.

func (*Darwin) Get

func (d *Darwin) Get(
	_ context.Context,
	_ string,
) (*InterfaceEntry, error)

Get 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

func (d *Debian) Delete(
	ctx context.Context,
	name string,
) (*InterfaceResult, error)

Delete removes a managed Netplan interface configuration file. If no managed file exists, returns Changed: false (idempotent).

func (*Debian) Get

func (d *Debian) Get(
	ctx context.Context,
	name string,
) (*InterfaceEntry, error)

Get returns a single interface by name.

func (*Debian) List

func (d *Debian) List(
	ctx 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) Delete

func (l *Linux) Delete(
	_ context.Context,
	_ string,
) (*InterfaceResult, error)

Delete returns ErrUnsupported on generic Linux.

func (*Linux) Get

func (l *Linux) Get(
	_ context.Context,
	_ string,
) (*InterfaceEntry, error)

Get 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.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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