netplan

package
v0.0.0-...-0a82276 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeEthernet = DeviceType("ethernet")
	TypeVLAN     = DeviceType("vlan")
	TypeBond     = DeviceType("bond")
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(in *Netplan) (out []byte, err error)

Marshal a Netplan instance into YAML.

Types

type AccessPoint

type AccessPoint struct {
	Password string `yaml:"password,omitempty"`
	Mode     string `yaml:"mode,omitempty"`
	Channel  int    `yaml:"channel,omitempty"`
}

type ActivationParams

type ActivationParams struct {
	Clock     clock.Clock
	Devices   []DeviceToBridge
	RunPrefix string
	Directory string
	Timeout   time.Duration
}

ActivationParams contains options to use when bridging interfaces

type ActivationResult

type ActivationResult struct {
	Stdout string
	Stderr string
	Code   int
}

ActivationResult captures the result of actively bridging the interfaces using ifup/ifdown.

func BridgeAndActivate

func BridgeAndActivate(params ActivationParams) (*ActivationResult, error)

BridgeAndActivate will parse a set of netplan yaml files in a directory, create a new netplan config with the provided interfaces bridged bridged, then reconfigure the network using the ifupdown package for the new bridges.

type Bond

type Bond struct {
	Interfaces []string `yaml:"interfaces,omitempty,flow"`
	Interface  `yaml:",inline"`
	Parameters BondParameters `yaml:"parameters,omitempty"`
}

Bond is the interface definition of the bonds: section of netplan

type BondParameters

type BondParameters struct {
	Mode               IntString `yaml:"mode,omitempty"`
	LACPRate           IntString `yaml:"lacp-rate,omitempty"`
	MIIMonitorInterval IntString `yaml:"mii-monitor-interval,omitempty"`
	MinLinks           *int      `yaml:"min-links,omitempty"`
	TransmitHashPolicy string    `yaml:"transmit-hash-policy,omitempty"`
	ADSelect           IntString `yaml:"ad-select,omitempty"`
	AllSlavesActive    *bool     `yaml:"all-slaves-active,omitempty"`
	ARPInterval        *int      `yaml:"arp-interval,omitempty"`
	ARPIPTargets       []string  `yaml:"arp-ip-targets,omitempty"`
	ARPValidate        IntString `yaml:"arp-validate,omitempty"`
	ARPAllTargets      IntString `yaml:"arp-all-targets,omitempty"`
	UpDelay            IntString `yaml:"up-delay,omitempty"`
	DownDelay          IntString `yaml:"down-delay,omitempty"`
	FailOverMACPolicy  IntString `yaml:"fail-over-mac-policy,omitempty"`
	// Netplan misspelled this as 'gratuitious-arp', not sure if it works with that name.
	// We may need custom handling of both spellings.
	GratuitousARP         *int      `yaml:"gratuitious-arp,omitempty"` // nolint: misspell
	PacketsPerSlave       *int      `yaml:"packets-per-slave,omitempty"`
	PrimaryReselectPolicy IntString `yaml:"primary-reselect-policy,omitempty"`
	ResendIGMP            *int      `yaml:"resend-igmp,omitempty"`
	// bonding.txt says that this can be a value from 1-0x7fffffff, should we be forcing it to be a hex value?
	LearnPacketInterval *int   `yaml:"learn-packet-interval,omitempty"`
	Primary             string `yaml:"primary,omitempty"`
}

For a definition of what netplan supports see here: https://github.com/CanonicalLtd/netplan/blob/7afef6af053794a400d96f89a81c938c08420783/src/parse.c#L1180 For a definition of what the parameters mean or what values they can contain, see here: https://www.kernel.org/doc/Documentation/networking/bonding.txt Note that most parameters can be specified as integers or as strings, which you need to be careful with YAML as it defaults to strongly typing them. TODO: (jam 2018-05-14) Should we be sorting the attributes alphabetically?

type Bridge

type Bridge struct {
	Interfaces []string `yaml:"interfaces,omitempty,flow"`
	Interface  `yaml:",inline"`
	Parameters BridgeParameters `yaml:"parameters,omitempty"`
}

type BridgeParameters

type BridgeParameters struct {
	AgeingTime   *int           `yaml:"ageing-time,omitempty"`
	ForwardDelay IntString      `yaml:"forward-delay,omitempty"`
	HelloTime    *int           `yaml:"hello-time,omitempty"`
	MaxAge       *int           `yaml:"max-age,omitempty"`
	PathCost     map[string]int `yaml:"path-cost,omitempty"`
	PortPriority map[string]int `yaml:"port-priority,omitempty"`
	Priority     *int           `yaml:"priority,omitempty"`
	STP          *bool          `yaml:"stp,omitempty"`
}

type DeviceToBridge

type DeviceToBridge struct {
	// DeviceName is the name of the device on the machine that should
	// be bridged.
	DeviceName string

	// BridgeName is the name of the bridge that we want created.
	BridgeName string

	// MACAddress is the MAC address of the device to be bridged
	MACAddress string
}

DeviceToBridge gives the information about a particular device that should be bridged.

type DeviceType

type DeviceType string

type Ethernet

type Ethernet struct {
	Match     map[string]string `yaml:"match,omitempty"`
	Wakeonlan bool              `yaml:"wakeonlan,omitempty"`
	SetName   string            `yaml:"set-name,omitempty"`
	Interface `yaml:",inline"`
}

Ethernet defines fields for just Ethernet devices

type IntString

type IntString struct {
	Int    *int
	String *string
}

IntString is used to specialize values that can be integers or strings

func (IntString) MarshalYAML

func (i IntString) MarshalYAML() (interface{}, error)

func (*IntString) UnmarshalYAML

func (i *IntString) UnmarshalYAML(unmarshal func(interface{}) error) error

type Interface

type Interface struct {
	AcceptRA  *bool    `yaml:"accept-ra,omitempty"`
	Addresses []string `yaml:"addresses,omitempty"`
	// Critical doesn't have to be *bool because it is only used if True
	Critical bool `yaml:"critical,omitempty"`
	// DHCP4 defaults to true, so we must use a pointer to know if it was specified as false
	DHCP4          *bool         `yaml:"dhcp4,omitempty"`
	DHCP6          *bool         `yaml:"dhcp6,omitempty"`
	DHCPIdentifier string        `yaml:"dhcp-identifier,omitempty"` // "duid" or  "mac"
	Gateway4       string        `yaml:"gateway4,omitempty"`
	Gateway6       string        `yaml:"gateway6,omitempty"`
	Nameservers    Nameservers   `yaml:"nameservers,omitempty"`
	MACAddress     string        `yaml:"macaddress,omitempty"`
	MTU            int           `yaml:"mtu,omitempty"`
	Renderer       string        `yaml:"renderer,omitempty"` // NetworkManager or networkd
	Routes         []Route       `yaml:"routes,omitempty"`
	RoutingPolicy  []RoutePolicy `yaml:"routing-policy,omitempty"`
	// Optional doesn't have to be *bool because it is only used if True
	Optional bool `yaml:"optional,omitempty"`

	// Configure the link-local addresses to bring up. Valid options are
	// "ipv4" and "ipv6". According to the netplan reference, netplan will
	// only bring up ipv6 addresses if *no* link-local attribute is
	// specified. On the other hand, if an empty link-local attribute is
	// specified, this instructs netplan not to bring any ipv4/ipv6 address
	// up.
	LinkLocal *[]string `yaml:"link-local,omitempty"`

	// According to the netplan examples, this section typically includes
	// some OVS-specific configuration bits. However, MAAS may just
	// include an empty block to indicate the presence of an OVS-managed
	// bridge (LP1942328). As a workaround, we make this an optional map
	// so we can tell whether it is present (but empty) vs not being
	// present.
	//
	// See: https://github.com/canonical/netplan/blob/main/examples/openvswitch.yaml
	OVSParameters *map[string]interface{} `yaml:"openvswitch,omitempty"`
}

Interface includes all the fields that are common between all interfaces (ethernet, wifi, bridge, bond)

type Nameservers

type Nameservers struct {
	Search    []string `yaml:"search,omitempty,flow"`
	Addresses []string `yaml:"addresses,omitempty,flow"`
}

Representation of netplan YAML format as Go structures The order of fields is consistent with Netplan docs

type Netplan

type Netplan struct {
	Network Network `yaml:"network"`
	// contains filtered or unexported fields
}

func ReadDirectory

func ReadDirectory(dirPath string) (np Netplan, err error)

ReadDirectory reads the contents of a netplan directory and returns complete config.

func (*Netplan) BridgeBondById

func (np *Netplan) BridgeBondById(deviceId string, bridgeName string) (err error)

BridgeBondById takes a deviceId and creates a bridge with this device using this devices config

func (*Netplan) BridgeEthernetById

func (np *Netplan) BridgeEthernetById(deviceId string, bridgeName string) (err error)

BridgeEthernetById takes a deviceId and creates a bridge with this device using this devices config

func (*Netplan) BridgeVLANById

func (np *Netplan) BridgeVLANById(deviceId string, bridgeName string) (err error)

BridgeVLANById takes a deviceId and creates a bridge with this device using this devices config

func (*Netplan) FindBondByMAC

func (np *Netplan) FindBondByMAC(mac string) (device string, err error)

func (*Netplan) FindBondByName

func (np *Netplan) FindBondByName(name string) (device string, err error)

func (*Netplan) FindDeviceByNameOrMAC

func (np *Netplan) FindDeviceByNameOrMAC(name, mac string) (string, DeviceType, error)

FindDeviceByMACOrName will look for an Ethernet, VLAN or Bond matching the Name of the device or its MAC address. Name is preferred to MAC address.

func (*Netplan) FindEthernetByMAC

func (np *Netplan) FindEthernetByMAC(mac string) (device string, err error)

func (*Netplan) FindEthernetByName

func (np *Netplan) FindEthernetByName(name string) (device string, err error)

func (*Netplan) FindVLANByMAC

func (np *Netplan) FindVLANByMAC(mac string) (device string, err error)

func (*Netplan) FindVLANByName

func (np *Netplan) FindVLANByName(name string) (device string, err error)

func (*Netplan) MoveYamlsToBak

func (np *Netplan) MoveYamlsToBak() (err error)

MoveYamlsToBak moves source .yaml files in a directory to .yaml.bak.(timestamp), except

func (*Netplan) Rollback

func (np *Netplan) Rollback() (err error)

Rollback moves backed up files to original locations and removes written file

func (*Netplan) Write

func (np *Netplan) Write(inPath string) (filePath string, err error)

Write writes merged netplan yaml to file specified by path. If path is empty filename is autogenerated

type Network

type Network struct {
	Version   int                 `yaml:"version"`
	Renderer  string              `yaml:"renderer,omitempty"`
	Ethernets map[string]Ethernet `yaml:"ethernets,omitempty"`
	Wifis     map[string]Wifi     `yaml:"wifis,omitempty"`
	Bridges   map[string]Bridge   `yaml:"bridges,omitempty"`
	Bonds     map[string]Bond     `yaml:"bonds,omitempty"`
	VLANs     map[string]VLAN     `yaml:"vlans,omitempty"`
	Routes    []Route             `yaml:"routes,omitempty"`
}

type Route

type Route struct {
	From   string `yaml:"from,omitempty"`
	OnLink *bool  `yaml:"on-link,omitempty"`
	Scope  string `yaml:"scope,omitempty"`
	Table  *int   `yaml:"table,omitempty"`
	To     string `yaml:"to,omitempty"`
	Type   string `yaml:"type,omitempty"`
	Via    string `yaml:"via,omitempty"`
	Metric *int   `yaml:"metric,omitempty"`
}

type RoutePolicy

type RoutePolicy struct {
	From          string `yaml:"from,omitempty"`
	Mark          *int   `yaml:"mark,omitempty"`
	Priority      *int   `yaml:"priority,omitempty"`
	Table         *int   `yaml:"table,omitempty"`
	To            string `yaml:"to,omitempty"`
	TypeOfService *int   `yaml:"type-of-service,omitempty"`
}

type VLAN

type VLAN struct {
	Id        *int   `yaml:"id,omitempty"`
	Link      string `yaml:"link,omitempty"`
	Interface `yaml:",inline"`
}

VLAN represents the structures for defining VLAN sections

type Wifi

type Wifi struct {
	Match        map[string]string      `yaml:"match,omitempty"`
	SetName      string                 `yaml:"set-name,omitempty"`
	Wakeonlan    bool                   `yaml:"wakeonlan,omitempty"`
	AccessPoints map[string]AccessPoint `yaml:"access-points,omitempty"`
	Interface    `yaml:",inline"`
}

Jump to

Keyboard shortcuts

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