Record whether a node is adopted and which modules were taken on it (hq ADR 0100)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/novox/mesh-controller/internal/inventory"
|
||||
)
|
||||
|
||||
// A node is adopted or converged (novox/hq ADR 0100), and it is said to be adopted wherever the
|
||||
// mesh reports a node's state: node list, node show, status and the board.
|
||||
|
||||
// showMode is the node show lines about a node's mode and what was taken on it.
|
||||
func showMode(ctx context.Context, inv *inventory.Inventory, node inventory.Node) error {
|
||||
if !node.Adopted {
|
||||
fmt.Printf(" mode converged\n")
|
||||
return nil
|
||||
}
|
||||
fmt.Printf(" mode adopted since %s\n",
|
||||
node.AdoptedSince.Local().Format(time.DateTime))
|
||||
taken, err := inv.Taken(ctx, node.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(taken) == 0 {
|
||||
fmt.Printf(" taken nothing yet\n")
|
||||
} else {
|
||||
fmt.Printf(" taken %s\n", strings.Join(taken, ", "))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// adoptedNodes are the names of every adopted node, in the order given.
|
||||
func adoptedNodes(nodes []inventory.Node) []string {
|
||||
var out []string
|
||||
for _, n := range nodes {
|
||||
if n.Adopted {
|
||||
out = append(out, n.Name)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user