Documentation
¶
Overview ¶
Package netplan provides shared helpers for writing Netplan configuration files with validation, rollback, and file-state tracking.
Index ¶
- func ApplyConfig(ctx context.Context, logger *slog.Logger, fs avfs.VFS, ...) (bool, error)
- func ComputeSHA256(data []byte) string
- func RemoveConfig(ctx context.Context, logger *slog.Logger, fs avfs.VFS, ...) (bool, error)
- func SectionForInterface(execManager exec.Manager, interfaceName string) string
- func SectionForType(ifaceType string) string
- type AddressInfo
- type InterfaceStatus
- type RouteStatus
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyConfig ¶
func ApplyConfig( ctx context.Context, logger *slog.Logger, fs avfs.VFS, stateKV jetstream.KeyValue, execManager exec.Manager, hostname string, path string, content []byte, metadata map[string]string, ) (bool, error)
ApplyConfig writes a Netplan configuration file to disk, validates it with `netplan generate`, applies it with `netplan apply`, and tracks the file state in the KV store. Returns (true, nil) when the file was written and applied, (false, nil) when the content is unchanged.
func ComputeSHA256 ¶
ComputeSHA256 returns the hex-encoded SHA-256 hash of the given data.
func RemoveConfig ¶
func RemoveConfig( ctx context.Context, logger *slog.Logger, fs avfs.VFS, stateKV jetstream.KeyValue, execManager exec.Manager, hostname string, path string, ) (bool, error)
RemoveConfig removes a Netplan configuration file from disk, applies the change with `netplan apply`, and marks the file state as undeployed in the KV store. Returns (true, nil) when the file was removed and applied, (false, nil) when the file does not exist.
func SectionForInterface ¶
SectionForInterface returns the Netplan YAML section name for an interface by querying netplan status. Falls back to "ethernets" if the interface type cannot be determined.
func SectionForType ¶
SectionForType maps a netplan interface type to its YAML section name.
Types ¶
type AddressInfo ¶
AddressInfo holds prefix length and flags for an address.
type InterfaceStatus ¶
type InterfaceStatus struct {
Index int `json:"index"`
AdminState string `json:"adminstate"`
OperState string `json:"operstate"`
Type string `json:"type"`
Backend string `json:"backend"`
ID string `json:"id"`
MACAddress string `json:"macaddress"`
Vendor string `json:"vendor"`
Addresses []map[string]AddressInfo `json:"addresses"`
DNSAddresses []string `json:"dns_addresses"`
Routes []RouteStatus `json:"routes"`
Interfaces []string `json:"interfaces"`
Bridge string `json:"bridge"`
TunnelMode string `json:"tunnel_mode"`
}
InterfaceStatus represents one interface from netplan status.
func (InterfaceStatus) AddressFamily ¶
func (s InterfaceStatus) AddressFamily() string
AddressFamily returns "inet" for IPv4, "inet6" for IPv6, or "inet" if the first non-link-local address cannot be determined.
func (InterfaceStatus) HasDefaultRoute ¶
func (s InterfaceStatus) HasDefaultRoute() bool
HasDefaultRoute returns true if any route has To == "default".
func (InterfaceStatus) IPv4 ¶
func (s InterfaceStatus) IPv4() string
IPv4 returns the first non-link-local IPv4 address for this interface.
func (InterfaceStatus) IPv6 ¶
func (s InterfaceStatus) IPv6() string
IPv6 returns the first non-link-local IPv6 address for this interface.
func (InterfaceStatus) IsDHCP ¶
func (s InterfaceStatus) IsDHCP() bool
IsDHCP returns true if any address has a "dhcp" flag.
type RouteStatus ¶
type RouteStatus struct {
To string `json:"to"`
Via string `json:"via"`
From string `json:"from"`
Family int `json:"family"`
Metric int `json:"metric"`
Type string `json:"type"`
Scope string `json:"scope"`
Protocol string `json:"protocol"`
Table string `json:"table"`
}
RouteStatus represents a single route from netplan status.
type Status ¶
type Status map[string]InterfaceStatus
Status holds the parsed output of netplan status --format json. Keys are interface names, values are the interface status.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dns provides DNS configuration management.
|
Package dns provides DNS configuration management. |
|
mocks
Package mocks provides mock implementations for testing.
|
Package mocks provides mock implementations for testing. |
|
Package iface provides network interface configuration management via Netplan.
|
Package iface provides network interface configuration management via Netplan. |
|
mocks
Package mocks provides mock implementations for testing.
|
Package mocks provides mock implementations for testing. |
|
Package route provides network route configuration management via Netplan.
|
Package route provides network route configuration management via Netplan. |
|
mocks
Package mocks provides mock implementations for testing.
|
Package mocks provides mock implementations for testing. |