Documentation
¶
Overview ¶
Package inventory models the set of machines hlab manages and the rules for selecting subsets of them.
Index ¶
- Constants
- type Container
- type Host
- type Interface
- type Inventory
- func (i *Inventory) ByAddress(address string, port int) (Host, bool)
- func (i *Inventory) GroupNames() []string
- func (i *Inventory) Groups() map[string][]string
- func (i *Inventory) Host(name string) (Host, bool)
- func (i *Inventory) Hosts() []Host
- func (i *Inventory) Managed() []Host
- func (i *Inventory) Select(expr string) (selected, skipped []Host, err error)
- func (i *Inventory) SelectAll(expr string) ([]Host, error)
- func (i *Inventory) Unmanaged() []Host
- type NetworkInfo
Constants ¶
const ( IfaceEthernet = "ethernet" IfaceWiFi = "wifi" IfaceBridge = "bridge" IfaceVirtual = "virtual" IfaceLoopback = "loopback" )
Interface kinds, as reported by the collector.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
Runtime string `yaml:"runtime" json:"runtime"`
Name string `yaml:"name" json:"name"`
Image string `yaml:"image,omitempty" json:"image,omitempty"`
Status string `yaml:"status,omitempty" json:"status,omitempty"`
}
Container is a running container on a managed machine.
type Host ¶
type Host struct {
Name string `yaml:"name" json:"name"`
Address string `yaml:"address" json:"address"`
Port int `yaml:"port,omitempty" json:"port"`
// Managed reports whether hlab has credentials for this machine. Only
// managed machines are reachable, so only they can be selected by commands
// that connect.
//
// It has no yaml tag because the on-disk form needs to tell an absent key
// from an explicit false: see config.hostEntry.
Managed bool `yaml:"-" json:"managed"`
// Access details, meaningful only when Managed.
User string `yaml:"user,omitempty" json:"user,omitempty"`
IdentityFile string `yaml:"identityFile,omitempty" json:"identityFile,omitempty"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
// Observed fields, refreshed by each scan.
Hostname string `yaml:"hostname,omitempty" json:"hostname,omitempty"`
OS string `yaml:"os,omitempty" json:"os,omitempty"`
Banner string `yaml:"banner,omitempty" json:"banner,omitempty"`
FirstSeen time.Time `yaml:"firstSeen,omitempty" json:"firstSeen,omitempty"`
LastSeen time.Time `yaml:"lastSeen,omitempty" json:"lastSeen,omitempty"`
// Durable attributes of the machine, filled in by `hlab discover services`.
// Volatile state — running services, listening ports, containers — is
// deliberately not here: it belongs in the facts store, so this file stays
// something a person can read and edit.
Kernel string `yaml:"kernel,omitempty" json:"kernel,omitempty"`
Arch string `yaml:"arch,omitempty" json:"arch,omitempty"`
CPUs int `yaml:"cpus,omitempty" json:"cpus,omitempty"`
MemoryMB int64 `yaml:"memoryMB,omitempty" json:"memoryMB,omitempty"`
Network *NetworkInfo `yaml:"network,omitempty" json:"network,omitempty"`
// Containers are recorded here rather than in the facts store because they
// describe what a machine is *for*, not what it happens to be doing: a
// homelab's containers change about as often as its installed services.
Containers []Container `yaml:"containers,omitempty" json:"containers,omitempty"`
LastCollected time.Time `yaml:"lastCollected,omitempty" json:"lastCollected,omitempty"`
}
Host is one machine hlab knows about, whether or not it manages it.
A single record accumulates everything learned about a machine: what a scan observed, and — once enrolled — how to reach it. Managed reports which of those two states it is in.
type Interface ¶
type Interface struct {
Name string `yaml:"name" json:"name"`
// Type is ethernet, wifi, bridge, virtual or loopback, determined from
// /sys rather than guessed from the name.
Type string `yaml:"type,omitempty" json:"type,omitempty"`
MAC string `yaml:"mac,omitempty" json:"mac,omitempty"`
MTU int `yaml:"mtu,omitempty" json:"mtu,omitempty"`
// Up is the administrative state; Carrier is whether a link is actually
// present — a cable plugged in, or a wireless association. An interface can
// be up with no carrier, which is exactly the case that must not be
// mistaken for a working connection.
Up bool `yaml:"up" json:"up"`
Carrier bool `yaml:"carrier" json:"carrier"`
// SpeedMbps is the negotiated link speed, where the driver reports one.
SpeedMbps int `yaml:"speedMbps,omitempty" json:"speedMbps,omitempty"`
// DHCP reports whether any address on this interface was leased rather
// than configured statically.
DHCP bool `yaml:"dhcp" json:"dhcp"`
Addresses []string `yaml:"addresses,omitempty,flow" json:"addresses,omitempty"`
}
Interface is one network interface on a machine.
The MAC address matters beyond diagnostics: it identifies the hardware across DHCP changes, so a machine that moves address can still be recognised.
type Inventory ¶
type Inventory struct {
// contains filtered or unexported fields
}
Inventory is the resolved set of hosts plus named groups.
func New ¶
New builds an inventory, validating that host names are unique and that every group member refers to a real host.
func (*Inventory) ByAddress ¶
ByAddress looks a machine up by address and port, which is how scan results are matched to existing records.
func (*Inventory) GroupNames ¶
GroupNames returns the sorted list of group names.
func (*Inventory) Select ¶
Select resolves a target expression to machines that can actually be reached, i.e. managed ones. Commands that connect must use this rather than SelectAll: an unmanaged machine has no credentials, so targeting it could only fail, and silently including every device on the network in `all` would be dangerous.
Matching unmanaged machines are reported in skipped so callers can say so.
type NetworkInfo ¶
type NetworkInfo struct {
Gateway string `yaml:"gateway,omitempty" json:"gateway,omitempty"`
DNS []string `yaml:"dns,omitempty,flow" json:"dns,omitempty"`
Search []string `yaml:"search,omitempty,flow" json:"search,omitempty"`
// Manager is what owns the network configuration on this machine —
// NetworkManager, netplan, dhcpcd and so on. It decides how the
// configuration can later be changed.
Manager string `yaml:"manager,omitempty" json:"manager,omitempty"`
Interfaces []Interface `yaml:"interfaces,omitempty" json:"interfaces,omitempty"`
}
NetworkInfo is how a machine is attached to the network.
func (*NetworkInfo) ActiveWiFi ¶
func (n *NetworkInfo) ActiveWiFi() []Interface
ActiveWiFi returns the wireless interfaces that are currently associated.
func (*NetworkInfo) MACs ¶
func (n *NetworkInfo) MACs() []string
MACs returns every MAC address observed on the machine.
func (*NetworkInfo) PrimaryAddress ¶
func (n *NetworkInfo) PrimaryAddress() string
PrimaryAddress returns the first non-loopback IPv4 address, which is the one worth showing in a table.
func (*NetworkInfo) WiFiRedundant ¶
func (n *NetworkInfo) WiFiRedundant() bool
WiFiRedundant reports machines where wireless is active while a working ethernet link is also present — the candidates for turning WiFi off.
func (*NetworkInfo) WorkingEthernet ¶
func (n *NetworkInfo) WorkingEthernet() []Interface
WorkingEthernet returns the ethernet interfaces that are up, carrying a link and hold an address — the ones a machine is genuinely reachable over.