f-55: lab: l'outil devient labctl, noms et chemins neutres #55

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-12 16:18:50 +02:00
commit 070faec37a
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
9 changed files with 88 additions and 88 deletions

View file

@ -13,7 +13,7 @@ import (
"git.g3e.fr/syonad/two/internal/lab/topology"
)
const usage = `usage: lab <command> [options] <topology.yml> [dir]
const usage = `usage: labctl <command> [options] <topology.yml> [dir]
plan <topology.yml>
validate the topology and print the deterministic plan: addresses, cables, ports
@ -36,7 +36,7 @@ const usage = `usage: lab <command> [options] <topology.yml> [dir]
ssh [-run dir] <node> [command...]
open a shell on a node, or run a command on it, with the key generated by up
defaults: -run $HOME/lab-run, -cache $HOME/.cache/two-lab, -timeout 20m
defaults: -run $HOME/lab-run, -cache $HOME/.cache/labctl, -timeout 20m
`
type keyFiles []string
@ -79,12 +79,12 @@ func run(args []string, stdout, stderr io.Writer) int {
func load(path string, stderr io.Writer) (*topology.Plan, bool) {
t, err := topology.Load(path)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return nil, false
}
p, err := topology.Compute(t)
if err != nil {
fmt.Fprintf(stderr, "lab: %s:\n%v\n", path, err)
fmt.Fprintf(stderr, "labctl: %s:\n%v\n", path, err)
return nil, false
}
return p, true
@ -96,7 +96,7 @@ func plan(path string, stdout, stderr io.Writer) int {
return 1
}
if err := p.Write(stdout); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
return 0
@ -122,27 +122,27 @@ func renderCmd(args []string, stdout, stderr io.Writer) int {
}
dir, err := filepath.Abs(fs.Arg(1))
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
authorized, err := readKeys(keys)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
opts := render.Options{RunDir: dir, AuthorizedKeys: authorized}
if err := provision.ReadInputs(p, &opts); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
nodes, err := render.Render(p, opts)
if err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
for _, n := range nodes {
if err := provision.WriteFiles(n); err != nil {
fmt.Fprintf(stderr, "lab: %v\n", err)
fmt.Fprintf(stderr, "labctl: %v\n", err)
return 1
}
fmt.Fprintf(stdout, "%s\n", n.Dir)