Documentation
¶
Overview ¶
Package capability is a room's inventory of what it can do: a declared list of named claims, a probe for each, and the newest result of every probe. It imports nothing from the daemon, the hub or the store.
A probe is an argv list and never a shell string. The only commands that run are the ones in the declared list, and an asker names ids from it. Output is cut and scrubbed before it is kept, and the raw output never leaves this package.
Index ¶
Constants ¶
const ( Pass = "pass" Fail = "fail" Unknown = "unknown" DefaultTimeout = 10 * time.Second MaxTimeout = 120 * time.Second ReasonMax = 200 )
Variables ¶
var ErrBusy = errors.New("a capability run is already going")
ErrBusy is a run asked for while one is going.
Functions ¶
func HardwareNeed ¶ added in v0.3.0
HardwareNeed judges a need about hardware: gpu, gpu:cuda, gpu:rocm, gpu:metal, and vram, ram, disk or cores with >= a figure (vram>=12g, cores>=8). vram is the largest one device has, ram is total and disk is free space. handled is false for a need that is not about hardware.
func ParseSize ¶ added in v0.3.0
ParseSize reads 12g, 512MB or 1.5T as bytes, 1024-based. A bare number is bytes.
Types ¶
type Auditor ¶
type Auditor struct {
// Scratch is a directory the room made for probes that write, and nothing else is written to.
Scratch string
// Repos is where ${ATRIUM_REPOS} points when the environment does not say.
Repos string
// File, when set, is where results are kept across a restart.
File string
Now func() time.Time
// contains filtered or unexported fields
}
Auditor runs the declared probes and keeps the newest result of each.
func NewAuditor ¶
NewAuditor starts with list and any results saved in file.
func (*Auditor) Due ¶
Due is the capabilities whose newest result is older than their own cadence (every, else sixHours).
func (*Auditor) Probe ¶
Probe runs one capability's probe and judges it. It never returns an error: a probe that cannot run is a result.
func (*Auditor) Run ¶
Run probes the named capabilities, or all of them when ids is empty, and anything they need first. Ids not in the declared list are refused before anything runs.
func (*Auditor) SetHardware ¶ added in v0.3.0
SetHardware keeps the newest hardware probe.
type Cap ¶
type Cap struct {
ID string `yaml:"id" json:"id"`
Kind string `yaml:"kind" json:"kind"`
Probe []string `yaml:"probe" json:"-"`
// Dir is where the probe runs. ${NAME} is read from the environment, and ${SCRATCH} is a directory the room made.
Dir string `yaml:"dir,omitempty" json:"-"`
Timeout string `yaml:"timeout,omitempty" json:"-"`
Pass string `yaml:"pass,omitempty" json:"-"`
Match string `yaml:"match,omitempty" json:"-"`
Version string `yaml:"version,omitempty" json:"-"`
Needs []string `yaml:"needs,omitempty" json:"needs,omitempty"`
// Optional shows a failure neutral everywhere. NotExpected does the same on the rooms it names.
Optional bool `yaml:"optional,omitempty" json:"optional,omitempty"`
NotExpected []string `yaml:"not_expected,omitempty" json:"not_expected,omitempty"`
Every string `yaml:"every,omitempty" json:"every,omitempty"`
Fix string `yaml:"fix,omitempty" json:"fix,omitempty"`
}
Cap is one declared capability.
type GPU ¶ added in v0.3.0
type GPU struct {
Name string `json:"name"`
VRAM uint64 `json:"vram_bytes,omitempty"`
API string `json:"api,omitempty"`
Unified bool `json:"unified,omitempty"`
}
GPU is one graphics device. API is cuda, rocm or metal. Unified is memory shared with the CPU, counted as VRAM.
type Hardware ¶ added in v0.3.0
type Hardware struct {
At string `json:"at"`
CPU string `json:"cpu,omitempty"`
Cores int `json:"cores,omitempty"`
RAM uint64 `json:"ram_bytes,omitempty"`
RAMFree uint64 `json:"ram_free_bytes,omitempty"`
DiskPath string `json:"disk_path,omitempty"`
DiskFree uint64 `json:"disk_free_bytes,omitempty"`
GPUs []GPU `json:"gpus,omitempty"`
}
Hardware is what a room's machine has, probed read-only. A field a probe could not read is left empty.
func ProbeHardware ¶ added in v0.3.0
ProbeHardware reads this machine. disk is a path on the volume whose free space is reported, walked up to the nearest directory that exists.
type List ¶
type List struct {
Version int `yaml:"version" json:"version"`
Caps []Cap `yaml:"caps" json:"caps"`
}
List is the declared list.
func Load ¶
Load is the shipped list with the room's own additions from path laid over it. A local entry adds or replaces by id. A missing file is no additions, and a file that does not parse is an error so the room says so instead of dropping it.
type Result ¶
type Result struct {
Cap string `json:"cap"`
State string `json:"state"`
Version string `json:"version,omitempty"`
Reason string `json:"reason,omitempty"`
At string `json:"at"`
MS int64 `json:"ms,omitempty"`
}
Result is the outcome of one probe.
type Snapshot ¶
type Snapshot struct {
Version int `json:"list_ver"`
Caps []Cap `json:"caps"`
Results []Result `json:"results"`
Running []string `json:"running,omitempty"`
Hardware *Hardware `json:"hardware,omitempty"`
}
Snapshot is the declared list and the newest result of each capability, with a running probe shown as such.