hostsetup

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostsetup does the host-side chores VirtoMir used to leave to the admin: installing the packages a feature needs (restic, FRR, iPXE + dnsmasq, cephadm + podman), turning on the IOMMU on the kernel command line for PCI passthrough, loading a software watchdog for HA, and the root SSH key ZFS replication sends with. Every command goes through a Runner and every file through Root, so all of it is tested without touching the host.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid")

ErrInvalid marks a request VirtoMir refuses (unknown feature, malformed key).

View Source
var ErrPassword = errors.New("password not accepted")

ErrPassword marks a password the target did not accept.

View Source
var ErrUnsupported = errors.New("unsupported")

ErrUnsupported marks a host VirtoMir cannot change by itself (no apt or dnf, an unknown boot loader); the message says what to do instead.

View Source
var Features = map[string]Feature{
	"offsite":   {Title: "Off-site copies (restic)", Apt: []string{"restic"}, Dnf: []string{"restic"}, Commands: []string{"restic"}},
	"physnet":   {Title: "BGP / EVPN routing (FRR)", Apt: []string{"frr"}, Dnf: []string{"frr"}, Commands: []string{"vtysh"}},
	"baremetal": {Title: "Network installs (dnsmasq + iPXE)", Apt: []string{"dnsmasq", "ipxe"}, Dnf: []string{"dnsmasq", "ipxe-bootimgs-x86"}, Commands: []string{"dnsmasq"}, AnyFile: []string{"/usr/lib/ipxe/undionly.kpxe", "/usr/share/ipxe/undionly.kpxe"}},
	"ceph":      {Title: "Ceph (cephadm + podman)", Apt: []string{"cephadm", "podman"}, Dnf: []string{"cephadm", "podman"}, Commands: []string{"cephadm", "podman"}},
}

Features VirtoMir installs by itself. The names are the API's.

Functions

This section is empty.

Types

type Exec

type Exec struct{}

Exec runs commands on this host.

func (Exec) Run

func (Exec) Run(ctx context.Context, name string, args ...string) ([]byte, error)

Run runs name with args; an error carries the command's standard error.

type Feature

type Feature struct {
	// Title names it for the user.
	Title string
	Apt   []string
	Dnf   []string
	// Commands are what must be on PATH afterwards (and tell whether it is installed).
	Commands []string
	// AnyFile: one of these must exist as well (files a package ships outside PATH; the
	// places differ between Debian and Fedora).
	AnyFile []string
}

Feature is something VirtoMir can set up by installing packages.

type IOMMUResult

type IOMMUResult struct {
	// Params were added to the kernel command line (empty: they were there already).
	Params []string `json:"params"`
	// Method is how: grubby, grub (with its config file) or kernel-cmdline; active when the
	// IOMMU was already on and nothing was changed.
	Method string `json:"method"`
	// RebootNeeded is true until the host has started with the new command line.
	RebootNeeded bool `json:"rebootNeeded"`
	// Backup is the copy of the file VirtoMir changed, to undo it by hand.
	Backup string `json:"backup,omitempty"`
}

IOMMUResult says what EnableIOMMU did.

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

Runner runs a command and returns its standard output.

type Setup

type Setup struct {
	Run Runner
	// Look finds a command on PATH (exec.LookPath on a real host).
	Look func(string) (string, error)
	// Root is where the host's files are ("" = /).
	Root string
}

Setup does the chores on one host.

func Host

func Host() *Setup

Host is the real host.

func (*Setup) Authorize

func (s *Setup) Authorize(key string) error

Authorize lets the holder of key sign in as root (appends it to authorized_keys once).

func (*Setup) CopyKey

func (s *Setup) CopyKey(ctx context.Context, host, password, key string) error

CopyKey signs in to host as root with password, once, and adds key to root's authorized_keys there (what ssh-copy-id does). The password is used for this one sign-in and kept nowhere. A host whose SSH identity is already in root's known_hosts must still present it: a changed one is refused.

func (*Setup) EnableIOMMU

func (s *Setup) EnableIOMMU(ctx context.Context) (IOMMUResult, error)

EnableIOMMU adds the IOMMU parameters to the kernel command line of every installed kernel, keeping a backup of the file it edits. The firmware switch (VT-d / AMD-Vi) cannot be set from Linux; the result says a reboot is needed.

func (*Setup) EnableWatchdog

func (s *Setup) EnableWatchdog(ctx context.Context) error

EnableWatchdog loads the kernel's software watchdog (softdog) when the host has no hardware one, and keeps it loaded across reboots.

func (*Setup) HasWatchdog

func (s *Setup) HasWatchdog() bool

HasWatchdog tells whether /dev/watchdog exists.

func (*Setup) Install

func (s *Setup) Install(ctx context.Context, feature string, report func(string)) error

Install installs the feature's packages with the host's package manager, then does what the feature needs beyond the package (FRR: the BGP daemon on and running). report tells the user which step runs.

func (*Setup) Installed

func (s *Setup) Installed(feature string) bool

Installed tells whether every command of the feature is on PATH.

func (*Setup) PublicKey

func (s *Setup) PublicKey(ctx context.Context, comment string) (string, error)

PublicKey returns root's SSH public key, making an ed25519 key first when root has none.

Jump to

Keyboard shortcuts

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