Documentation
¶
Overview ¶
Package hostnet creates and removes bridges, bonds and VLAN interfaces on the host (ADR-0042) through whatever already manages the host's network: netplan, NetworkManager or systemd-networkd. VirtoMir never runs a network stack of its own.
A wrong network change can cut the host off, including the browser that made it. So every change is a transaction that must be confirmed from the browser within a deadline (by default two minutes); a confirmation that cannot reach the host is no confirmation, and the change is rolled back: files restored, created devices deleted, the previous configuration applied again. The pending transaction is saved first, so a daemon that dies in between rolls back when it starts.
Index ¶
- Variables
- type Manager
- func (m *Manager) Confirm(id string) error
- func (m *Manager) Create(ctx context.Context, s Spec) (*Pending, error)
- func (m *Manager) Delete(ctx context.Context, name string) (*Pending, error)
- func (m *Manager) Records() []Record
- func (m *Manager) Recover()
- func (m *Manager) Rollback(id string) error
- func (m *Manager) Status() Status
- type Pending
- type Record
- type Runner
- type Spec
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalid = errors.New("invalid") ErrRefused = errors.New("refused") )
ErrInvalid and ErrRefused classify errors for the API (400 / 409).
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
Root string // "/" on a host; tests use a temporary directory
StateDir string
Run Runner
Log *slog.Logger
// Interfaces lists the host's interfaces (hostinfo); Window is the confirmation time.
Interfaces func() []hostinfo.Interface
Window time.Duration
LookPath func(string) (string, error)
// contains filtered or unexported fields
}
Manager applies changes one at a time.
func New ¶
New returns a manager for the real host. It rolls back a change left unconfirmed by a previous run.
func (*Manager) Create ¶
Create adds an interface; it must be confirmed with Confirm before the window ends.
func (*Manager) Recover ¶
func (m *Manager) Recover()
Recover rolls back a change a previous run left unconfirmed.
type Pending ¶
type Pending struct {
ID string `json:"id"`
What string `json:"what"`
Backend string `json:"backend"`
Started time.Time `json:"started"`
Deadline time.Time `json:"deadline"`
Files []fileSnap `json:"files,omitempty"`
Undo []cmd `json:"undo,omitempty"`
Reapply []cmd `json:"reapply,omitempty"`
}
Pending is a change waiting for confirmation.
type Record ¶
type Record struct {
Spec
Backend string `json:"backend"`
Created time.Time `json:"created"`
// netplan: the address keys taken from TakeAddressFrom, to give back on removal.
Moved string `json:"moved,omitempty"`
// netplan: port definitions VirtoMir added (ports netplan did not know before).
Added []string `json:"added,omitempty"`
// NetworkManager: the connection each port had before, to bring back on removal, and
// the commands that made it (to restore it if a removal is rolled back).
OldConns map[string]string `json:"oldConns,omitempty"`
Recreate []cmd `json:"recreate,omitempty"`
}
Record is an interface VirtoMir created, with what is needed to remove it cleanly.
type Spec ¶
type Spec struct {
Kind string `json:"kind"` // bridge, bond, vlan
Name string `json:"name"`
// Ports: bridge ports or bond members.
Ports []string `json:"ports,omitempty"`
BondMode string `json:"bondMode,omitempty"` // active-backup (default), 802.3ad, balance-alb, balance-tlb, balance-xor, broadcast, balance-rr
STP bool `json:"stp,omitempty"`
// vlan: Parent interface and VLAN ID.
Parent string `json:"parent,omitempty"`
VLAN int `json:"vlan,omitempty"`
// TakeAddressFrom names a port whose IP configuration (DHCP or static addresses,
// routes, DNS) moves to the new bridge or bond: the usual way to put the host's own
// uplink into a bridge for machines without losing the host's address.
TakeAddressFrom string `json:"takeAddressFrom,omitempty"`
}
Spec is a new host interface.
type Status ¶
type Status struct {
Backend string `json:"backend"` // netplan, networkmanager, networkd, "" (unsupported)
Reason string `json:"reason,omitempty"`
Pending *Pending `json:"pending,omitempty"`
Created []Record `json:"created"`
}
Status is what the UI shows: the backend in charge, the pending change, VirtoMir's own interfaces.