capability

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 22 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 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

View Source
const (
	Pass    = "pass"
	Fail    = "fail"
	Unknown = "unknown"

	DefaultTimeout = 10 * time.Second
	MaxTimeout     = 120 * time.Second
	ReasonMax      = 200
)

Variables

View Source
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

func HardwareNeed(need string, h Hardware) (handled, ok bool, why string)

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

func ParseSize(s string) (uint64, bool)

ParseSize reads 12g, 512MB or 1.5T as bytes, 1024-based. A bare number is bytes.

func Scrub

func Scrub(s string) string

Scrub cuts text to ReasonMax characters on one line, with anything shaped like a credential taken out first.

func Size added in v0.3.0

func Size(n uint64) string

Size is n bytes as a short figure like 24g or 512m.

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

func NewAuditor(list List, scratch, file string) *Auditor

NewAuditor starts with list and any results saved in file.

func (*Auditor) Due

func (a *Auditor) Due() []string

Due is the capabilities whose newest result is older than their own cadence (every, else sixHours).

func (*Auditor) Probe

func (a *Auditor) Probe(ctx context.Context, c Cap) Result

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

func (a *Auditor) Run(ctx context.Context, ids []string) ([]Result, error)

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

func (a *Auditor) SetHardware(h Hardware)

SetHardware keeps the newest hardware probe.

func (*Auditor) SetList

func (a *Auditor) SetList(l List)

SetList swaps the declared list. Results of capabilities no longer declared are dropped.

func (*Auditor) Snapshot

func (a *Auditor) Snapshot() Snapshot

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

func ProbeHardware(ctx context.Context, disk string) Hardware

ProbeHardware reads this machine. disk is a path on the volume whose free space is reported, walked up to the nearest directory that exists.

func (Hardware) Summary added in v0.3.0

func (h Hardware) Summary() []string

Summary is the hardware as short lines for a reader.

type List

type List struct {
	Version int   `yaml:"version" json:"version"`
	Caps    []Cap `yaml:"caps" json:"caps"`
}

List is the declared list.

func Default

func Default() List

Default is the list atrium ships.

func Lint

func Lint(b []byte) (List, error)

Lint checks a hub list laid over the shipped one and answers the list as written.

func Load

func Load(path string) (List, error)

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.

func Parse

func Parse(b []byte) (List, error)

Parse reads a list and checks it: known kinds and pass rules, no duplicate id, every need resolves.

func WithHub

func WithHub(l List, hub []byte) (List, error)

WithHub lays the hub's list over l by id, so a room's own addition cannot loosen a hub entry.

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.

Jump to

Keyboard shortcuts

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