app

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0, LGPL-3.0 Imports: 35 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 app wires the configuration, the transport and the node model into the context every command runs against.

A command receives an App and asks it for targets, node sets and an executor. Nothing in a command reads the configuration or builds an ssh command line itself, so behaviour such as the dry run, the safety gate and the output format works the same everywhere.

Index

Constants

View Source
const (
	TransportRedfish = "redfish"
	TransportIPMI    = "ipmi"
)

The transports a service processor can be reached over.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Streams

	// Resolved is the merged configuration with its provenance.
	Resolved *config.Resolved
	// Spec is the merged configuration.
	Spec v1alpha1.EffectiveSpec
	// Namer turns node names into host names.
	Namer *naming.Namer
	// Inventory holds what is known about the nodes.
	Inventory *inventory.Inventory
	// Groups resolves @group references.
	Groups *groups.Resolver
	// SSH is the transport client; Runner is what commands run through,
	// which is a recorder during a dry run.
	SSH    *transport.Client
	Runner transport.Runner
	// ReadRunner runs the read-only lookups a command makes before it
	// changes anything, such as asking Slurm whether a node runs a job. It
	// is the real transport even in a dry run, so that the dry run reaches
	// the same decision the real run would.
	ReadRunner transport.Runner
	// DryRunRecorder holds what a dry run would have sent.
	DryRunRecorder *transport.Recorder
	// Gate guards the destructive commands.
	Gate *safety.Gate
	// Format is the output format.
	Format output.Format
	// contains filtered or unexported fields
}

App is the resolved context a command runs against.

func New

func New(ctx context.Context, streams Streams, opts Options) (*App, error)

New resolves the configuration and builds the command context.

func (*App) BMCCredential

func (a *App) BMCCredential(ctx context.Context, node string) (credentials.Credential, error)

BMCCredential resolves the account used for a node's service processor, honouring a vendor profile that names its own.

func (*App) BMCCredentialName added in v0.3.0

func (a *App) BMCCredentialName(node string) string

BMCCredentialName names the credential used for a node's service processor: the one its vendor profile names, else the site's. Nodes with the same name share one account, which is how a set is grouped for a backend that takes one account for many processors.

func (*App) BMCHost added in v0.3.0

func (a *App) BMCHost(node string) (string, error)

BMCHost returns the host name or address of a node's service processor: the bmcAddress the inventory records for it, else the name the naming rules give it. The inventory wins because it names the one machine the site wrote down, where a derived name is only as good as its DNS record.

A node whose service processor has neither is refused; nothing falls back to the node's own name, where the BMC password would be sent to the node.

func (*App) BMCHosts added in v0.3.0

func (a *App) BMCHosts(nodes *nodeset.NodeSet) (*nodeset.NodeSet, error)

BMCHosts maps every node of a set to its service processor, the way BMCHost does.

func (*App) BMCOrder

func (a *App) BMCOrder(node string) []string

BMCOrder returns the transport preference for a node, as configured.

func (*App) BMCTransports added in v0.3.0

func (a *App) BMCTransports(node string) ([]string, error)

BMCTransports returns the transports to try for a node, in order. An entry that names no transport is refused rather than read as Redfish, so a misspelt ipmi does not send the BMC account over another protocol.

func (*App) CheckClusters added in v0.3.0

func (a *App) CheckClusters() error

CheckClusters checks what every Cluster document reads, not only the one the current context names, so that config validate reports a cluster that no command has used yet.

func (*App) Context

func (a *App) Context() context.Context

Context returns the context bounding the command's remote work.

func (*App) Credentials

func (a *App) Credentials() *credentials.Resolver

Credentials returns the credential resolver of the site. It is safe for concurrent use, which the BMC commands need: they build one client per node in parallel.

func (*App) DryRun

func (a *App) DryRun() bool

DryRun reports whether nothing may actually be changed.

func (*App) Executor

func (a *App) Executor() *fanout.Executor

Executor returns a fan-out executor bound to the configured limits.

func (*App) IPMIBackend

func (a *App) IPMIBackend(ctx context.Context, node string) (*ipmi.Backend, error)

IPMIBackend builds the backend that runs the IPMI tools, on the host role bmc.ipmi.via names, with the account of the given node. Nothing runs the tools locally, so a site that names no role gets a usage error.

func (*App) Identities

func (a *App) Identities() ([]age.Identity, error)

Identities loads the configured age identities, once.

func (*App) IdentityPaths

func (a *App) IdentityPaths() []string

IdentityPaths returns the configured age identities as absolute paths.

func (*App) InventoryNode added in v0.3.0

func (a *App) InventoryNode(name string) (*inventory.Node, bool)

InventoryNode returns the inventory entry of the machine a name refers to.

Host names are not case sensitive and a trailing dot only makes a name absolute, so EXE0001 and exe0001. are exe0001, and so is exe1 when the inventory pads it. A name with a domain is the node only when it is the host name the naming rules give the node's short name; any other domain is another machine. Everything looked up per node goes through here, so that every spelling of a machine gets its own settings rather than the site's.

func (*App) Node

func (a *App) Node(name string) (transport.Target, error)

Node returns the target of a compute node, whose host name comes from the naming rules.

func (*App) NodeTargets

func (a *App) NodeTargets(ns *nodeset.NodeSet) ([]transport.Target, error)

NodeTargets returns a target for each node of a set, in expansion order.

func (*App) Path

func (a *App) Path(path string) string

Path resolves a configured path against the directory of the site document, so that a site can be kept in version control and moved.

func (*App) PreferredBMCTransport

func (a *App) PreferredBMCTransport(node string) string

PreferredBMCTransport returns the first transport of the order, or Redfish when the order is not valid.

func (*App) Print

func (a *App) Print(r output.Result) error

Print renders a result in the selected format. A jq program stops with the command's context, when the command is interrupted or cancelled.

func (*App) Printf

func (a *App) Printf(format string, args ...any)

Printf writes a message to the error stream, which is where progress and notes go so that they never mix into parsed output.

func (*App) ReadOnRole added in v0.3.0

func (a *App) ReadOnRole(ctx context.Context, role string, req transport.Request) (*transport.Result, error)

ReadOnRole is RunOnRole for a command that only reads. It runs through ReadRunner, so a dry run reaches the host and sees what the real run would.

func (*App) RedfishClient

func (a *App) RedfishClient(ctx context.Context, node string) (*redfish.Client, error)

RedfishClient builds a client for a node's service processor.

func (*App) RemoteFile

func (a *App) RemoteFile(ctx context.Context, role, path string, ttl time.Duration) ([]byte, error)

RemoteFile reads a file from an infrastructure host, reusing a cached copy while it is younger than ttl.

A configuration such as dhcpd.conf is read once per command and often several times in a row, and fetching it again for each node turned a node set query into one connection per node.

The file is read through ReadRunner, so a dry run sees the same file the real run would.

func (*App) Role

func (a *App) Role(name string) (transport.Target, error)

Role returns the target of an infrastructure role.

func (*App) RoleNames

func (a *App) RoleNames() []string

RoleNames lists the configured host roles in sorted order.

func (*App) RunOnRole

func (a *App) RunOnRole(ctx context.Context, role string, req transport.Request) (*transport.Result, error)

RunOnRole runs one command on an infrastructure host and returns the result, failing the command when it did not succeed.

func (*App) SecretContent

func (a *App) SecretContent(file v1alpha1.SecretFile) ([]byte, error)

SecretContent decrypts one secret file of the site into memory, from its own age encrypted file or from a key of a Secret document.

func (*App) SecretValue

func (a *App) SecretValue(ref v1alpha1.SecretKeyRef) ([]byte, error)

SecretValue decrypts the Secret document a reference names, once per process, and returns the value of the key. The plaintext stays in memory.

func (*App) SecretValues

func (a *App) SecretValues(name string) (map[string][]byte, error)

SecretValues decrypts a whole Secret document.

func (*App) Select

func (a *App) Select(expr string) (*nodeset.NodeSet, error)

Select parses a node set expression, resolving group references.

An empty expression falls back to what -n or the environment named, so a session can select a set once and then work with it. An expression replaces a set from the environment, which is only a default, but not one from -n: the two together are refused rather than one of them dropped.

func (*App) SelectOptional

func (a *App) SelectOptional(expr string) (*nodeset.NodeSet, error)

SelectOptional is Select without the requirement that anything is selected; it returns nil when nothing was named.

func (*App) Slurm

func (a *App) Slurm() (*slurm.Client, error)

Slurm returns a client for the workload manager, which runs its clients on the host role the cluster names.

func (*App) StatePath

func (a *App) StatePath(parts ...string) string

StatePath returns a path inside the state directory.

func (*App) Timeout

func (a *App) Timeout() v1alpha1.Duration

Timeout returns the command timeout for remote execution.

func (*App) VendorProfile

func (a *App) VendorProfile(node string) v1alpha1.VendorProfile

VendorProfile returns the BMC overrides for a node's hardware vendor.

type Options

type Options struct {
	// ConfigFiles replaces the search path when it is set.
	ConfigFiles []string
	// Context selects the context.
	Context string
	// Nodes is the default node set, from -n or the environment.
	Nodes string
	// NodesFromFlag says Nodes came from -n, so a node set given as an
	// argument as well is a contradiction rather than an override.
	NodesFromFlag bool
	// Format is the -o value.
	Format string
	// Set are the --set assignments.
	Set map[string]string
	// DryRun reports what would be done and changes nothing.
	DryRun bool
	// AssumeYes answers the confirmations in advance.
	AssumeYes bool
	// Force allows protected hosts to be touched.
	Force bool
	// Fanout overrides how many hosts are worked on at once.
	Fanout int
	// SiteHostsOnly refuses a node that is neither in the inventory nor in
	// one of the site's domains. The MCP server sets it for the commands an
	// agent runs.
	SiteHostsOnly bool
	// Env reads environment variables; nil reads the process environment.
	Env func(string) string
	// Runner replaces the ssh transport for everything a command runs. A
	// dry run sets it to a recorder, and the tests use it to drive the
	// commands without a cluster.
	Runner transport.Runner
}

Options are the global flags, resolved before a command runs.

type Streams

type Streams struct {
	In       io.Reader
	Out      io.Writer
	Err      io.Writer
	IsTTY    bool
	StateDir string
	CacheDir string
}

Streams are the input and output a command talks to. Tests replace them with buffers.

func DefaultStreams

func DefaultStreams() Streams

DefaultStreams returns the process streams.

Whether there is a terminal decides whether a destructive command may ask for a confirmation or has to refuse, so it is asked of the terminal itself rather than inferred from the file mode: /dev/null is a character device too, and a command run with stdin closed would otherwise be prompted and then read an immediate end of file.

A state or cache directory that cannot be known is left empty, and New refuses to run without it.

Jump to

Keyboard shortcuts

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