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 ¶
- type App
- func (a *App) BMCCredential(ctx context.Context, node string) (credentials.Credential, error)
- func (a *App) BMCOrder(node string) []string
- 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) 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) 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 ¶
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 (*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) Credentials ¶
func (a *App) Credentials() *credentials.Resolver
Credentials returns the credential resolver of the site.
func (*App) IPMIBackend ¶
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 ¶
Identities loads the configured age identities, once.
func (*App) IdentityPaths ¶
IdentityPaths returns the configured age identities as absolute paths.
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, which is what a command uses unless the administrator names another.
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) 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.
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.
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
// 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.