app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: GPL-3.0, LGPL-3.0 Imports: 30 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

This section is empty.

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
	// 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) BMCOrder

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

BMCOrder returns the transport preference for a node.

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.

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 the configuration names or locally when it names none.

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) 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, which is what a command uses unless the administrator names another.

func (*App) Print

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

Print renders a result in the selected format.

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) 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.

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.

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
	// 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
	// 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.

Jump to

Keyboard shortcuts

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