First code for the HPC-on-demand portal. The portal is meant to front more than Proxmox - OpenStack is expected next - so the provider abstraction comes first and Proxmox is simply its first implementation. internal/model holds the vocabulary everything above reasons in; adding a provider means writing one package and registering it. The layered capability detection from the design is implemented and enforced. A PCI class code cannot identify InfiniBand: a ConnectX-4 Lx reports class 0x0200 because that variant is Ethernet-only, while a ConnectX-6 reports 0x0207 in IB mode and 0x0200 in Ethernet mode. Every capability claim therefore records how it was made - class, curated vendor:device map, or live agent - and Capability.Trusted refuses to schedule on a fabric until an agent confirms the link. Unconfirmed devices are still reported, since that gap is what an operator has to close. Passthrough viability comes from IOMMU group membership rather than device presence: sibling functions of one card are fine, an unrelated device in the group is not. Verified against a live Proxmox site, where it correctly classifies the Mellanox cards as roce rather than infiniband and withholds them from the schedulable set, while offering the Quadro K620 that does sit alone in its IOMMU group. Two bugs found and fixed while running it for real: - Query strings were appended to url.URL.Path, which is the decoded path, so String() escaped the "?" and /cluster/resources?type=vm silently stopped filtering. Guests were ignored and a node running 22 VMs reported all cores free. Regression test added. - Physical cores are now the schedulable total by default rather than being ignored, with a per-site cpu_overcommit for hosts where oversubscription is acceptable. An HPC tenant given oversubscribed cores just runs slowly. Secrets stay out of the catalogue: any setting may be written env:NAME. The Proxmox token needs PVEAuditor only.
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
// Package inventory loads the site catalogue and discovers all of it.
|
|
package inventory
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
"sync"
|
|
"time"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/ilkermanap/hpcod/internal/model"
|
|
"github.com/ilkermanap/hpcod/internal/provider"
|
|
)
|
|
|
|
// Catalogue is the configured set of backing clouds.
|
|
type Catalogue struct {
|
|
Sites []provider.SiteConfig `yaml:"sites"`
|
|
}
|
|
|
|
// Load reads a catalogue and instantiates every provider. Configuration errors
|
|
// are fatal here - a site we cannot even construct is an operator mistake, not
|
|
// a transient condition.
|
|
func Load(path string) ([]provider.Provider, error) {
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var cat Catalogue
|
|
if err := yaml.Unmarshal(raw, &cat); err != nil {
|
|
return nil, fmt.Errorf("%s: %w", path, err)
|
|
}
|
|
if len(cat.Sites) == 0 {
|
|
return nil, fmt.Errorf("%s: no sites defined", path)
|
|
}
|
|
|
|
seen := map[string]bool{}
|
|
out := make([]provider.Provider, 0, len(cat.Sites))
|
|
for _, sc := range cat.Sites {
|
|
if sc.ID == "" {
|
|
return nil, fmt.Errorf("%s: a site is missing its id", path)
|
|
}
|
|
if seen[sc.ID] {
|
|
return nil, fmt.Errorf("%s: duplicate site id %q", path, sc.ID)
|
|
}
|
|
seen[sc.ID] = true
|
|
|
|
p, err := provider.New(sc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, p)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// DiscoverAll queries every site concurrently. One slow or dead site must not
|
|
// hold up the rest, so each gets its own timeout and failures are recorded in
|
|
// the returned Site rather than aborting the sweep.
|
|
func DiscoverAll(ctx context.Context, provs []provider.Provider, perSite time.Duration) []model.Site {
|
|
out := make([]model.Site, len(provs))
|
|
var wg sync.WaitGroup
|
|
|
|
for i, p := range provs {
|
|
wg.Add(1)
|
|
go func(i int, p provider.Provider) {
|
|
defer wg.Done()
|
|
c, cancel := context.WithTimeout(ctx, perSite)
|
|
defer cancel()
|
|
|
|
s, err := p.Discover(c)
|
|
if err != nil {
|
|
s = model.Site{
|
|
ID: p.ID(), Kind: p.Kind(),
|
|
LastSeen: time.Now().UTC(), Error: err.Error(),
|
|
}
|
|
}
|
|
out[i] = s
|
|
}(i, p)
|
|
}
|
|
wg.Wait()
|
|
|
|
sort.Slice(out, func(i, j int) bool { return out[i].ID < out[j].ID })
|
|
return out
|
|
}
|