network

package
v0.0.0-...-f1366d8 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Interfaces = func() ([]HardwareInterface, error) {
	ifaces := []HardwareInterface{}
	interfaces, err := net.Interfaces()
	if err != nil {
		return ifaces, err
	}

	virtual := virtualInterfaces("/sys/devices/virtual/net/")

	for _, i := range interfaces {

		if i.Flags&net.FlagUp != 0 && bytes.Compare(i.HardwareAddr, nil) != 0 {

			if stringInSlice(i.Name, virtual) {
				continue
			}

			ifaces = append(ifaces, HardwareInterface{i.Name, i.HardwareAddr.String()})
		}
	}
	return ifaces, nil
}

Interfaces fetches the list of network interfaces

Functions

func TakeOver

func TakeOver() error

TakeOver takes over network configuration for the device by removing existing netplan files

Types

type AccessPoint

type AccessPoint struct {
	Password string `yaml:"password,omitempty"`
}

AccessPoint defines the credentials for a WiFi access point

type Ethernet

type Ethernet struct {
	Use          bool                   `yaml:"-"`
	Name         string                 `yaml:"-"`
	DHCP4        string                 `yaml:"dhcp4,omitempty"`
	Addresses    []string               `yaml:"addresses,omitempty"`
	NameServers  map[string][]string    `yaml:"nameservers,omitempty"`
	Gateway4     string                 `yaml:"gateway4,omitempty"`
	AccessPoints map[string]AccessPoint `yaml:"access-points,omitempty"`
}

Ethernet defines a single interface

type HardwareInterface

type HardwareInterface struct {
	Name       string
	MACAddress string
}

HardwareInterface represents a hardware network interface

type NMService

type NMService interface {
	Apply() error
	Current() *NetplanYAML
	Store(ethernet Ethernet) error
}

NMService is the interface for the netplan service

type NetManager

type NetManager struct {
	// contains filtered or unexported fields
}

NetManager implements actions for managing network manager

func NewNetworkManager

func NewNetworkManager(dBus dbus.Service) *NetManager

NewNetworkManager creates a network manager service

func (*NetManager) Apply

func (np *NetManager) Apply() error

Apply applies the network manager configuration using dbus

func (*NetManager) Current

func (np *NetManager) Current() *NetplanYAML

Current returns the current network manager settings

func (*NetManager) Store

func (np *NetManager) Store(ethernet Ethernet) error

Store stores the updated network settings

type Netplan

type Netplan struct {
	// contains filtered or unexported fields
}

Netplan implements actions for managing netplan

func NewNetplan

func NewNetplan(dBus dbus.Service) *Netplan

NewNetplan creates a netplan object from a config file

func (*Netplan) Apply

func (np *Netplan) Apply() error

Apply applies the netplan configuration using dbus

func (*Netplan) Current

func (np *Netplan) Current() *NetplanYAML

Current returns the current netplan settings

func (*Netplan) Store

func (np *Netplan) Store(ethernet Ethernet) error

Store stores the updated network settings

type NetplanService

type NetplanService interface {
	Apply() error
	Current() *NetplanYAML
	Store(ethernet Ethernet) error
}

NetplanService is the interface for the netplan service

type NetplanYAML

type NetplanYAML struct {
	Network Network `yaml:"network"`
}

NetplanYAML defines the structure of the netplan YAML file

type Network

type Network struct {
	Version   int                 `yaml:"version"`
	Renderer  string              `yaml:"renderer,omitempty"`
	Ethernets map[string]Ethernet `yaml:"ethernets,omitempty"`
	WiFis     map[string]Ethernet `yaml:"wifis,omitempty"`
}

Network defines then network subsection of the netplan YAML

type Service

type Service interface {
	Apply() error
	Current() *NetplanYAML
	Store(ethernet Ethernet) error
}

Service is the interface for the netplan/network-manager services

func Factory

func Factory(settings *config.Settings, dBus dbus.Service) Service

Factory creates the relevant netplan or network manager service

Jump to

Keyboard shortcuts

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