juju: github.com/juju/juju/network/netplan Index | Files

package netplan

import "github.com/juju/juju/network/netplan"

Index

Package Files

activate.go netplan.go types.go

Constants

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

func Marshal Uses

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

func Unmarshal Uses

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

type AccessPoint Uses

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

type ActivationParams Uses

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 Uses

type ActivationResult struct {
    Stdout string
    Stderr string
    Code   int
}

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

func BridgeAndActivate Uses

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 Uses

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 Uses

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 Uses

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

type BridgeParameters Uses

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 Uses

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 Uses

type DeviceType string

type Ethernet Uses

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 Uses

type IntString struct {
    Int    *int
    String *string
}

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

func (IntString) MarshalYAML Uses

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

func (*IntString) UnmarshalYAML Uses

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

type Interface Uses

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 Uses

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 Uses

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

func ReadDirectory Uses

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

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

func (*Netplan) BridgeBondById Uses

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 Uses

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 Uses

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 Uses

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

func (*Netplan) FindBondByName Uses

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

func (*Netplan) FindDeviceByNameOrMAC Uses

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 Uses

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

func (*Netplan) FindEthernetByName Uses

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

func (*Netplan) FindVLANByMAC Uses

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

func (*Netplan) FindVLANByName Uses

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

func (*Netplan) MoveYamlsToBak Uses

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

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

func (*Netplan) Rollback Uses

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

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

func (*Netplan) Write Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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"`
}

Package netplan imports 13 packages (graph) and is imported by 6 packages. Updated 2019-09-03. Refresh now. Tools for package owners.