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
- type App
- func (a *App) BMCCredential(ctx context.Context, node string) (credentials.Credential, error)
- func (a *App) BMCCredentialName(node string) string
- func (a *App) BMCHost(node string) (string, error)
- func (a *App) BMCHosts(nodes *nodeset.NodeSet) (*nodeset.NodeSet, error)
- func (a *App) BMCOrder(node string) []string
- func (a *App) BMCTransports(node string) ([]string, error)
- func (a *App) CheckClusters() error
- func (a *App) Context() context.Context
- func (a *App) Credentials() *credentials.Resolver
- func (a *App) DryRun() bool
- func (a *App) Executor() *fanout.Executor
- func (a *App) IPMIBackend(ctx context.Context, node string) (*ipmi.Backend, error)
- func (a *App) Identities() ([]age.Identity, error)
- func (a *App) IdentityPaths() []string
- func (a *App) InventoryNode(name string) (*inventory.Node, bool)
- func (a *App) Node(name string) (transport.Target, error)
- func (a *App) NodeTargets(ns *nodeset.NodeSet) ([]transport.Target, error)
- func (a *App) Path(path string) string
- func (a *App) PreferredBMCTransport(node string) string
- func (a *App) Print(r output.Result) error
- func (a *App) Printf(format string, args ...any)
- func (a *App) ReadOnRole(ctx context.Context, role string, req transport.Request) (*transport.Result, error)
- func (a *App) RedfishClient(ctx context.Context, node string) (*redfish.Client, error)
- func (a *App) RemoteFile(ctx context.Context, role, path string, ttl time.Duration) ([]byte, error)
- func (a *App) Role(name string) (transport.Target, error)
- func (a *App) RoleNames() []string
- func (a *App) RunOnRole(ctx context.Context, role string, req transport.Request) (*transport.Result, error)
- func (a *App) SecretContent(file v1alpha1.SecretFile) ([]byte, error)
- func (a *App) SecretValue(ref v1alpha1.SecretKeyRef) ([]byte, error)
- func (a *App) SecretValues(name string) (map[string][]byte, error)
- func (a *App) Select(expr string) (*nodeset.NodeSet, error)
- func (a *App) SelectOptional(expr string) (*nodeset.NodeSet, error)
- func (a *App) Slurm() (*slurm.Client, error)
- func (a *App) StatePath(parts ...string) string
- func (a *App) Timeout() v1alpha1.Duration
- func (a *App) VendorProfile(node string) v1alpha1.VendorProfile
- type Options
- type Streams
Constants ¶
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 (*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
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
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
BMCHosts maps every node of a set to its service processor, the way BMCHost does.
func (*App) BMCTransports ¶ added in v0.3.0
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
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) 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) IPMIBackend ¶
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 ¶
Identities loads the configured age identities, once.
func (*App) IdentityPaths ¶
IdentityPaths returns the configured age identities as absolute paths.
func (*App) InventoryNode ¶ added in v0.3.0
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 ¶
Node returns the target of a compute node, whose host name comes from the naming rules.
func (*App) NodeTargets ¶
NodeTargets returns a target for each node of a set, in expansion order.
func (*App) Path ¶
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 ¶
PreferredBMCTransport returns the first transport of the order, or Redfish when the order is not valid.
func (*App) Print ¶
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 ¶
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 ¶
RedfishClient builds a client for a node's service processor.
func (*App) RemoteFile ¶
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) 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 ¶
SecretValues decrypts a whole Secret document.
func (*App) Select ¶
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 ¶
SelectOptional is Select without the requirement that anything is selected; it returns nil when nothing was named.
func (*App) Slurm ¶
Slurm returns a client for the workload manager, which runs its clients on the host role the cluster names.
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.