net

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 10 Imported by: 0

README

network

Network can apply changes to /etc/network/interfaces and /etc/frr/frr.conf.

It was intentionally created to provide a common means to:

  • apply validation
  • render interfaces/frr.conf files
  • reload required services to apply changes

Requirements

Network lib relies on ifupdown2 and systemd. It also is assumed frr is installed as systemd service.

Usage

Make use network lib:

package main

import "github.com/metal-stack/metal-networker/pkg/net"

func main() {
	// TODO
}

Documentation

Overview

Package net contains code to apply changes to network interfaces and FRR (Free Range Routing).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applier

type Applier interface {
	Apply(tpl template.Template, tmpFile, destFile string, reload bool) error
	Render(writer io.Writer, tpl template.Template) error
	Reload() error
	Validate() error
	Compare(tmpFile, destFile string) bool
}

Applier is an interface to render changes and reload services to apply them.

func NewNetworkApplier

func NewNetworkApplier(data interface{}, validator Validator, reloader Reloader) Applier

NewNetworkApplier creates a new NewNetworkApplier.

type DBusReloader

type DBusReloader struct {
	ServiceFilename string
}

DBusReloader applies a systemd unit reload to apply reloading.

func NewDBusReloader

func NewDBusReloader(service string) DBusReloader

NewDBusReloader is a reloader for systemd units with dbus.

func (DBusReloader) Reload

func (r DBusReloader) Reload() error

Reload reloads a systemd unit.

type DBusStartReloader

type DBusStartReloader struct {
	ServiceFilename string
}

DBusStartReloader applies the strategy of starting a systemd unit that applies the reload.

func (DBusStartReloader) Reload

func (r DBusStartReloader) Reload() error

Reload starts a systemd unit.

type DBusTemplateValidator

type DBusTemplateValidator struct {
	TemplateName, InstanceName string
}

DBusTemplateValidator starts a dbus template (templatename@instancename.service) to apply validation.

func (DBusTemplateValidator) Validate

func (v DBusTemplateValidator) Validate() error

Validate applies validation by starting a dbus templated instance.

type NetworkApplier

type NetworkApplier struct {
	Data      interface{}
	Validator Validator
	Reloader  Reloader
}

NetworkApplier holds the toolset for applying network configuration changes.

func (*NetworkApplier) Apply

func (n *NetworkApplier) Apply(tpl template.Template, tmpFile, destFile string, reload bool) error

Apply applies the current configuration with the given template.

func (*NetworkApplier) Compare

func (n *NetworkApplier) Compare(source, target string) bool

Compare compare source and target for hash equality.

func (*NetworkApplier) Reload

func (n *NetworkApplier) Reload() error

Reload reloads the necessary services when the network interfaces configuration was changed.

func (*NetworkApplier) Render

func (n *NetworkApplier) Render(w io.Writer, tpl template.Template) error

Render renders the network interfaces to the given writer using the given template.

func (*NetworkApplier) Validate

func (n *NetworkApplier) Validate() error

Validate applies the given validator to validate current changes.

type Reloader

type Reloader interface {
	Reload() error
}

Reloader triggers the reload to carry out the changes of an applier.

type Renderer

type Renderer struct {
}

Renderer is a thing to render content.

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, data interface{}, tpl template.Template) error

Render renders the given template using the given data into the provided writer.

type Validator

type Validator interface {
	Validate() error
}

Validator is an interface to apply common validation.

Jump to

Keyboard shortcuts

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