netplan

package
v0.0.0-...-63dd1cf Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package netplan provides shared helpers for writing Netplan configuration files with validation, rollback, and file-state tracking.

Index

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

func ComputeSHA256(
	data []byte,
) string

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

func SectionForInterface(
	execManager exec.Manager,
	interfaceName string,
) string

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

func SectionForType(
	ifaceType string,
) string

SectionForType maps a netplan interface type to its YAML section name.

Types

type AddressInfo

type AddressInfo struct {
	Prefix int      `json:"prefix"`
	Flags  []string `json:"flags"`
}

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.

func GetStatus

func GetStatus(
	execManager exec.Manager,
) (Status, error)

GetStatus runs "netplan status --format json" and parses the output.

Directories

Path Synopsis
dns
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.

Jump to

Keyboard shortcuts

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