Documentation ¶
Index ¶
- Constants
- func Marshal(in *Netplan) (out []byte, err error)
- func Unmarshal(in []byte, out *Netplan) error
- type AccessPoint
- type ActivationParams
- type ActivationResult
- type Bond
- type BondParameters
- type Bridge
- type BridgeParameters
- type DeviceToBridge
- type DeviceType
- type Ethernet
- type IntString
- type Interface
- type Nameservers
- type Netplan
- func (np *Netplan) BridgeBondById(deviceId string, bridgeName string) (err error)
- func (np *Netplan) BridgeEthernetById(deviceId string, bridgeName string) (err error)
- func (np *Netplan) BridgeVLANById(deviceId string, bridgeName string) (err error)
- func (np *Netplan) FindBondByMAC(mac string) (device string, err error)
- func (np *Netplan) FindBondByName(name string) (device string, err error)
- func (np *Netplan) FindDeviceByNameOrMAC(name, mac string) (string, DeviceType, error)
- func (np *Netplan) FindEthernetByMAC(mac string) (device string, err error)
- func (np *Netplan) FindEthernetByName(name string) (device string, err error)
- func (np *Netplan) FindVLANByMAC(mac string) (device string, err error)
- func (np *Netplan) FindVLANByName(name string) (device string, err error)
- func (np *Netplan) MoveYamlsToBak() (err error)
- func (np *Netplan) Rollback() (err error)
- func (np *Netplan) Write(inPath string) (filePath string, err error)
- type Network
- type Route
- type RoutePolicy
- type VLAN
- type Wifi
Constants ¶
const ( TypeEthernet = DeviceType("ethernet") TypeVLAN = DeviceType("vlan") TypeBond = DeviceType("bond") )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccessPoint ¶
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 ¶
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 *int `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 *int `yaml:"up-delay,omitempty"` DownDelay *int `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 *int `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 ¶
IntString is used to specialize values that can be integers or strings
func (IntString) MarshalYAML ¶
func (*IntString) UnmarshalYAML ¶
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"` }
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 ¶
ReadDirectory reads the contents of a netplan directory and returns complete config.
func (*Netplan) BridgeBondById ¶
BridgeBondById takes a deviceId and creates a bridge with this device using this devices config
func (*Netplan) BridgeEthernetById ¶
BridgeEthernetById takes a deviceId and creates a bridge with this device using this devices config
func (*Netplan) BridgeVLANById ¶
BridgeVLANById takes a deviceId and creates a bridge with this device using this devices config
func (*Netplan) FindBondByMAC ¶
func (*Netplan) FindBondByName ¶
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 (*Netplan) FindEthernetByName ¶
func (*Netplan) FindVLANByMAC ¶
func (*Netplan) FindVLANByName ¶
func (*Netplan) MoveYamlsToBak ¶
MoveYamlsToBak moves source .yaml files in a directory to .yaml.bak.(timestamp), except
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"` }