persist

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package persist manages network configuration persistence to target OS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderNetplan

func RenderNetplan(cfg *NetworkConfig) string

RenderNetplan renders the configuration as netplan YAML. DNS and routes are placed under the first rendered stanza: ethernet if present, otherwise bond, otherwise VLAN.

func RenderNetworkdUnit

func RenderNetworkdUnit(iface *InterfaceConfig) string

RenderNetworkdUnit renders a systemd-networkd .network unit for an interface.

func Write

func Write(rootDir string, family OSFamily, cfg *NetworkConfig) error

Write renders and writes the network configuration to the target OS root. rootDir is the mount point of the target root filesystem (e.g., "/newroot").

Types

type BondConfig

type BondConfig struct {
	Name       string   `json:"name"`
	Members    []string `json:"members"`
	Mode       string   `json:"mode"`
	Address    string   `json:"address,omitempty"`
	Gateway    string   `json:"gateway,omitempty"`
	MTU        int      `json:"mtu,omitempty"`
	LACPRate   string   `json:"lacpRate,omitempty"`
	HashPolicy string   `json:"hashPolicy,omitempty"`
}

BondConfig describes a network bond.

type DNSConfig

type DNSConfig struct {
	Servers []string `json:"servers,omitempty"`
	Search  []string `json:"search,omitempty"`
}

DNSConfig holds DNS settings.

type InterfaceConfig

type InterfaceConfig struct {
	Name    string `json:"name"`
	MAC     string `json:"mac,omitempty"`
	DHCP    bool   `json:"dhcp,omitempty"`
	Address string `json:"address,omitempty"` // CIDR notation.
	Gateway string `json:"gateway,omitempty"`
	MTU     int    `json:"mtu,omitempty"`
}

InterfaceConfig describes a network interface.

type NetworkConfig

type NetworkConfig struct {
	Interfaces []InterfaceConfig `json:"interfaces,omitempty"`
	Bonds      []BondConfig      `json:"bonds,omitempty"`
	VLANs      []VLANConfig      `json:"vlans,omitempty"`
	DNS        DNSConfig         `json:"dns,omitempty"`
	Routes     []RouteConfig     `json:"routes,omitempty"`
}

NetworkConfig holds the complete network configuration to persist.

func (*NetworkConfig) Validate

func (c *NetworkConfig) Validate() error

Validate checks the network configuration.

type OSFamily

type OSFamily string

OSFamily represents the target OS family.

const (
	// Ubuntu uses netplan YAML.
	Ubuntu OSFamily = "ubuntu"
	// RHEL uses NetworkManager keyfiles.
	RHEL OSFamily = "rhel"
	// Flatcar uses systemd-networkd units.
	Flatcar OSFamily = "flatcar"
)

func ParseOSFamily

func ParseOSFamily(s string) (OSFamily, error)

ParseOSFamily parses an OS family string.

func (OSFamily) ConfigPath

func (f OSFamily) ConfigPath() string

ConfigPath returns the relative network config directory for the OS family.

type RouteConfig

type RouteConfig struct {
	Destination string `json:"destination"`
	Gateway     string `json:"gateway"`
	Metric      int    `json:"metric,omitempty"`
}

RouteConfig describes a static route.

type VLANConfig

type VLANConfig struct {
	Name    string `json:"name"`
	Parent  string `json:"parent"`
	ID      int    `json:"id"`
	DHCP    bool   `json:"dhcp,omitempty"`
	Address string `json:"address,omitempty"`
}

VLANConfig describes a VLAN interface.

Jump to

Keyboard shortcuts

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