Stateless (Warewulf-style) provisioning: profiles, node pools, overlays, dnsmasq export, compute image
Profiles bind a RAM-booted root image to overlay templates; assigning a machine allocates a node name and management IP, writes the per-MAC PXE entry with a per-node token and exports static leases for dnsmasq. Nodes pull rendered overlays (hosts, slurm.conf from inventory, gres.conf, SSH host key, munge key) through rollcall-overlay.service; the runtime refresh timer is the heartbeat. Adds the compute-debian13 image definition and a generic live-build root image script, CLI and web UI for profiles/assign. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
1430421a3f
commit
7fe7c26e22
38 files changed
+1543
-16
No files matched your search
+167
-3
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -97,8 +99,8 @@ func runClient(cmd string, args []string) error {
|
||||
if err := c.do("GET", "/api/v1/machines", nil, &ms); err != nil {
|
||||
return err
|
||||
}
|
||||
f := "%-16s %-12s %-28s %-16s %4s %7s %3s %7s %3s %2s %3s %s\n"
|
||||
fmt.Printf(f, "ID", "STATE", "MODEL", "SERIAL", "CPU", "RAM", "DSK", "STORAGE", "NIC", "IB", "GPU", "BMC")
|
||||
f := "%-16s %-12s %-10s %-10s %-14s %-24s %4s %7s %3s %7s %3s %2s %3s %s\n"
|
||||
fmt.Printf(f, "ID", "STATE", "NODE", "PROFILE", "MGMT-IP", "MODEL", "CPU", "RAM", "DSK", "STORAGE", "NIC", "IB", "GPU", "BMC")
|
||||
for _, m := range ms {
|
||||
bmc := "-"
|
||||
if m.BMC != nil {
|
||||
@@ -110,7 +112,7 @@ func runClient(cmd string, args []string) error {
|
||||
bmc = fmt.Sprintf("%s (%s,%s)", str(b["address"]), str(b["source"]), ok)
|
||||
}
|
||||
model := strings.TrimSpace(deref(m.Manufacturer) + " " + deref(m.Product))
|
||||
fmt.Printf(f, m.ID, m.State, trunc(model, 28), trunc(deref(m.Serial), 16), m.CPUs, human(m.MemoryBytes),
|
||||
fmt.Printf(f, m.ID, m.State, deref(m.NodeName), deref(m.Profile), deref(m.MgmtIP), trunc(model, 24), m.CPUs, human(m.MemoryBytes),
|
||||
fmt.Sprint(int(m.Disks)), human(m.StorageBytes), fmt.Sprint(m.NICs), fmt.Sprint(m.IBHCAs), fmt.Sprint(m.GPUs), bmc)
|
||||
}
|
||||
case "show":
|
||||
@@ -175,10 +177,172 @@ func runClient(cmd string, args []string) error {
|
||||
return err
|
||||
}
|
||||
fmt.Println("deleted", str(d["deleted"]))
|
||||
default:
|
||||
return c.statelessCmd(cmd, args)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) statelessCmd(cmd string, args []string) error {
|
||||
switch cmd {
|
||||
case "images":
|
||||
var imgs []obj
|
||||
if err := c.do("GET", "/api/v1/images", nil, &imgs); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%-24s %-9s %10s %10s %10s %s\n", "IMAGE", "COMPLETE", "KERNEL", "INITRD", "SQUASHFS", "BUILT")
|
||||
for _, i := range imgs {
|
||||
fmt.Printf("%-24s %-9v %10s %10s %10s %s\n", str(i["name"]), i["complete"], human(num(i["vmlinuz"])),
|
||||
human(num(i["initrd.img"])), human(num(i["filesystem.squashfs"])), str(i["built"]))
|
||||
}
|
||||
case "profile":
|
||||
if len(args) < 1 {
|
||||
usage()
|
||||
}
|
||||
switch args[0] {
|
||||
case "list":
|
||||
var ps []Profile
|
||||
if err := c.do("GET", "/api/v1/profiles", nil, &ps); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%-14s %-22s %-24s %-12s %s\n", "PROFILE", "IMAGE", "OVERLAYS", "NAMES", "APPEND")
|
||||
for _, p := range ps {
|
||||
fmt.Printf("%-14s %-22s %-24s %-12s %s\n", p.Name, p.Image, strings.Join(p.Overlays, ","), p.NameFormat, p.Append)
|
||||
}
|
||||
case "add":
|
||||
if len(args) < 2 {
|
||||
usage()
|
||||
}
|
||||
fs := flag.NewFlagSet("profile add", flag.ExitOnError)
|
||||
img := fs.String("image", "", "image directory name (required)")
|
||||
app := fs.String("append", "", "extra kernel parameters")
|
||||
ov := fs.String("overlays", "", "comma-separated overlay names")
|
||||
nf := fs.String("name-format", "node%03d", "node name format")
|
||||
vars := fs.String("vars", "{}", "profile variables as JSON")
|
||||
_ = fs.Parse(args[2:])
|
||||
p := Profile{Name: args[1], Image: *img, Append: *app, NameFormat: *nf}
|
||||
if *ov != "" {
|
||||
p.Overlays = strings.Split(*ov, ",")
|
||||
}
|
||||
if err := json.Unmarshal([]byte(*vars), &p.Vars); err != nil {
|
||||
return fmt.Errorf("-vars: %w", err)
|
||||
}
|
||||
var out Profile
|
||||
if err := c.do("POST", "/api/v1/profiles", p, &out); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("profile %s: image=%s overlays=%v\n", out.Name, out.Image, out.Overlays)
|
||||
case "rm":
|
||||
if len(args) < 2 {
|
||||
usage()
|
||||
}
|
||||
var d obj
|
||||
if err := c.do("DELETE", "/api/v1/profiles/"+args[1], nil, &d); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("deleted", str(d["deleted"]))
|
||||
default:
|
||||
usage()
|
||||
}
|
||||
case "assign":
|
||||
if len(args) < 2 {
|
||||
usage()
|
||||
}
|
||||
fs := flag.NewFlagSet("assign", flag.ExitOnError)
|
||||
name := fs.String("name", "", "node name (default: next free from the profile's name format)")
|
||||
boot := fs.Bool("boot", false, "set bootdev pxe and power-cycle via BMC")
|
||||
_ = fs.Parse(args[2:])
|
||||
var d obj
|
||||
if err := c.do("POST", "/api/v1/machines/"+args[0]+"/assign", obj{"profile": args[1], "name": *name, "boot": *boot}, &d); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s -> %s as %s mgmt=%s ib=%s\n", str(d["id"]), str(d["profile"]), str(d["name"]), str(d["mgmt_ip"]), str(d["ib_ip"]))
|
||||
if d["ipmi"] != nil {
|
||||
fmt.Println(str(d["ipmi"]))
|
||||
}
|
||||
case "unassign":
|
||||
if len(args) < 1 {
|
||||
usage()
|
||||
}
|
||||
var d obj
|
||||
if err := c.do("POST", "/api/v1/machines/"+args[0]+"/unassign", nil, &d); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s -> %s\n", str(d["id"]), str(d["state"]))
|
||||
case "overlay":
|
||||
if len(args) < 1 {
|
||||
usage()
|
||||
}
|
||||
fs := flag.NewFlagSet("overlay", flag.ExitOnError)
|
||||
stage := fs.String("stage", "system", "system or runtime")
|
||||
extract := fs.String("extract", "", "extract into this directory instead of listing")
|
||||
_ = fs.Parse(args[1:])
|
||||
data, err := c.raw("GET", "/api/v1/machines/"+args[0]+"/overlay?stage="+*stage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tr := tar.NewReader(bytes.NewReader(data))
|
||||
for {
|
||||
h, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if *extract == "" {
|
||||
fmt.Printf("%s %8d %s\n", os.FileMode(h.Mode).String(), h.Size, h.Name)
|
||||
continue
|
||||
}
|
||||
dst := filepath.Join(*extract, h.Name)
|
||||
if h.Typeflag == tar.TypeDir {
|
||||
_ = os.MkdirAll(dst, 0o755)
|
||||
continue
|
||||
}
|
||||
_ = os.MkdirAll(filepath.Dir(dst), 0o755)
|
||||
f, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(h.Mode))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = io.Copy(f, tr)
|
||||
f.Close()
|
||||
}
|
||||
case "render":
|
||||
if len(args) < 2 {
|
||||
usage()
|
||||
}
|
||||
fs := flag.NewFlagSet("render", flag.ExitOnError)
|
||||
stage := fs.String("stage", "system", "system or runtime")
|
||||
_ = fs.Parse(args[2:])
|
||||
data, err := c.raw("GET", "/api/v1/render/"+args[0]+"/"+strings.TrimPrefix(args[1], "/")+"?stage="+*stage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.Stdout.Write(data)
|
||||
default:
|
||||
usage()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) raw(method, path string) ([]byte, error) {
|
||||
req, err := http.NewRequest(method, c.base+path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, _ := io.ReadAll(resp.Body)
|
||||
if resp.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("%s: %s", resp.Status, strings.TrimSpace(string(data)))
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func trunc(s string, n int) string {
|
||||
if len(s) > n {
|
||||
return s[:n]
|
||||
|
||||
Reference in new issue
Block a user