inventory

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: GPL-3.0, LGPL-3.0 Imports: 10 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 inventory answers questions about the nodes of a site: their attributes, where they sit, what address they have and what they boot.

It replaces the genders file, the rack spreadsheet and the boot path table the shell tools read separately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BootPath

func BootPath(inv *Inventory, rules []v1alpha1.BootPathRule, node string) (string, bool, error)

BootPath returns the boot path configured for a node: the one on its inventory entry, else the first cluster rule that names it.

A node matched by more than one rule is an error rather than a silent first-match, because two rules pointing at different installations is a mistake worth stopping for.

Types

type Document added in v0.3.0

type Document struct {
	Spec v1alpha1.NodeInventorySpec
	// Where returns where entry i, counted from zero, was written, such as
	// "inventory.yaml:31:7". It may be nil, or return "" when that is not
	// known.
	Where func(entry int) string
}

Document is one NodeInventory together with a way to say where each of its entries was written, so that an error can point at the lines to fix.

type Inventory

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

Inventory holds the nodes of a site, indexed by name.

func FromDocuments added in v0.3.0

func FromDocuments(docs ...Document) (*Inventory, error)

FromDocuments is New for documents that know where their entries were written.

Addresses, service processor addresses, cids and MACs identify one machine, so two nodes sharing one are refused: a copied entry would otherwise send an action meant for one machine to another. An address must be an IP address and a MAC a MAC address, because both end up in the names of files on the PXE server and in DHCP.

A host is named the same way in every entry. Padding and case are not part of a host's identity, so exe1, exe0001 and EXE1 are one machine; an entry spelling a host differently from the entry that first named it would either make a second record for the same machine or silently merge into the first, and which one the author meant cannot be told, so it is refused. A name is written in lower case, because that is how every lookup asks for it.

func New

func New(specs ...v1alpha1.NodeInventorySpec) (*Inventory, error)

New builds an inventory from the NodeInventory documents of a site.

Entries are applied in order, so a general entry may be written first and refined by a later one naming fewer nodes. Fields that describe a single machine may only be set by an entry that names exactly one node.

func (*Inventory) All

func (inv *Inventory) All() []*Node

All returns every node in name order.

func (*Inventory) AttributeKeys

func (inv *Inventory) AttributeKeys() []string

AttributeKeys lists every attribute name in the inventory.

func (*Inventory) AttributeValues

func (inv *Inventory) AttributeValues(key string) []string

AttributeValues lists the distinct values of an attribute, in sorted order.

func (*Inventory) InRack

func (inv *Inventory) InRack(rack string) *nodeset.NodeSet

InRack returns the nodes of one rack. It reads the rack attribute and compares it exactly, the way the @rack: group does, so that the two never disagree about what a rack holds.

func (*Inventory) Len

func (inv *Inventory) Len() int

Len reports how many nodes the inventory knows.

func (*Inventory) Lookup

func (inv *Inventory) Lookup(name string) (*Node, bool)

Lookup returns a node by name.

func (*Inventory) Names

func (inv *Inventory) Names() []string

Names returns every known node name in sorted order.

func (*Inventory) NodeSet

func (inv *Inventory) NodeSet() *nodeset.NodeSet

NodeSet returns every known node as a set.

func (*Inventory) Racks

func (inv *Inventory) Racks() []string

Racks lists the racks the inventory knows, in sorted order.

func (*Inventory) Select

func (inv *Inventory) Select(ns *nodeset.NodeSet) (known []*Node, unknown []string)

Select returns the nodes of a set that the inventory knows, and the names of those it does not.

A name is matched through the node set, so that a set written as exe[1-2] finds the nodes an inventory wrote as exe0001 and exe0002: padding is a display property, not part of a host's identity.

func (*Inventory) WithAttribute

func (inv *Inventory) WithAttribute(key, value string) *nodeset.NodeSet

WithAttribute returns the nodes whose attribute has the given value. An empty value matches every node that carries the attribute at all, the way a genders attribute without a value did.

type Node

type Node struct {
	Name       string            `json:"name" yaml:"name"`
	Attributes map[string]string `json:"attributes,omitempty" yaml:"attributes,omitempty"`
	Rack       string            `json:"rack,omitempty" yaml:"rack,omitempty"`
	Level      string            `json:"level,omitempty" yaml:"level,omitempty"`
	Address    string            `json:"address,omitempty" yaml:"address,omitempty"`
	BMCAddress string            `json:"bmcAddress,omitempty" yaml:"bmcAddress,omitempty"`
	CID        string            `json:"cid,omitempty" yaml:"cid,omitempty"`
	MACs       []string          `json:"macs,omitempty" yaml:"macs,omitempty"`
	BootPath   string            `json:"bootPath,omitempty" yaml:"bootPath,omitempty"`
}

Node is everything the inventory knows about one machine.

Jump to

Keyboard shortcuts

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