A few usability fixes and put full node DB logic into warewulfd

This commit is contained in:
Gregory Kurtzer
2021-12-31 02:38:48 +00:00
parent 6b42362f37
commit 39ec7c0807
7 changed files with 79 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ package add
import (
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/hpcng/warewulf/pkg/hostlist"
"github.com/pkg/errors"
@@ -137,5 +138,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
count++
}
return errors.Wrap(nodeDB.Persist(), "failed to persist nodedb")
err = nodeDB.Persist()
if err != nil {
return errors.Wrap(err, "failed to persist new node")
}
err = warewulfd.DaemonReload()
if err != nil {
return errors.Wrap(err, "failed to reload warewulf daemon")
}
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/hpcng/warewulf/pkg/hostlist"
"github.com/manifoldco/promptui"
@@ -79,6 +80,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if err != nil {
return errors.Wrap(err, "failed to persist nodedb")
}
err = warewulfd.DaemonReload()
if err != nil {
return errors.Wrap(err, "failed to reload warewulf daemon")
}
}
}

View File

@@ -5,13 +5,12 @@ import (
"fmt"
"net/http"
"os"
"sort"
"strings"
"time"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/hpcng/warewulf/pkg/hostlist"
"github.com/spf13/cobra"
"golang.org/x/term"
)
@@ -29,18 +28,6 @@ type NodeStatus struct {
func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not get node list: %s\n", err)
os.Exit(1)
}
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -55,8 +42,9 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
statusURL := fmt.Sprintf("http://%s:%d/status", controller.Ipaddr, controller.Warewulf.Port)
for {
var elipsis bool
var height int
count := 4
var count int
rightnow := time.Now().Unix()
wwlog.Printf(wwlog.VERBOSE, "Connecting to: %s\n", statusURL)
@@ -86,26 +74,35 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
}
args = hostlist.Expand(args)
fmt.Printf("%-20s %-20s %-25s %-10s\n", "NODENAME", "STATUS", "SENT", "LASTSEEN (s)")
fmt.Printf("%s\n", strings.Repeat("=", 80))
for _, node := range node.FilterByName(nodes, args) {
id := node.Id.Get()
if _, ok := nodeStatus.Nodes[id]; ok {
keys := make([]string, 0, len(nodeStatus.Nodes))
for k := range nodeStatus.Nodes {
keys = append(keys, k)
}
sort.Strings(keys)
for _, id := range keys {
if nodeStatus.Nodes[id].Lastseen > 0 {
fmt.Printf("%-20s %-20s %-25s %-10d\n", id, nodeStatus.Nodes[id].Stage, nodeStatus.Nodes[id].Sent, rightnow-nodeStatus.Nodes[id].Lastseen)
} else {
fmt.Printf("%-20s %-20s %-25s %-10s\n", id, "--", "--", "--")
}
if count >= height && SetWatch {
if count+4 >= height && SetWatch {
if count+1 != len(keys) {
elipsis = true
}
break
}
count++
}
if SetWatch {
fmt.Printf("... ")
if elipsis {
fmt.Printf("... ")
}
time.Sleep(1000 * time.Millisecond)
} else {
break

View File

@@ -15,7 +15,7 @@ var (
)
func init() {
baseCmd.PersistentFlags().BoolVar(&SetWatch, "watch", false, "Watch the status automatically")
baseCmd.PersistentFlags().BoolVarP(&SetWatch, "watch", "w", false, "Watch the status automatically")
}
// GetRootCommand returns the root cobra.Command for the application.

View File

@@ -20,8 +20,6 @@ var (
func LoadNodeDB() error {
TmpMap := make(map[string]node.NodeInfo)
daemonLogf("(re)Loading the node Database\n")
DB, err := node.New()
if err != nil {
return err

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"time"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
)
@@ -24,6 +25,37 @@ var statusDB allStatus
func init() {
statusDB.Nodes = make(map[string]*NodeStatus)
err := LoadNodeStatus()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not prepopulate status DB with nodes: %s\n", err)
}
}
func LoadNodeStatus() error {
var newDB allStatus
newDB.Nodes = make(map[string]*NodeStatus)
DB, err := node.New()
if err != nil {
return err
}
nodes, err := DB.FindAllNodes()
if err != nil {
return err
}
for _, n := range nodes {
if _, ok := statusDB.Nodes[n.Id.Get()]; !ok {
newDB.Nodes[n.Id.Get()] = &NodeStatus{}
} else {
newDB.Nodes[n.Id.Get()] = statusDB.Nodes[n.Id.Get()]
}
}
statusDB = newDB
return nil
}
func updateStatus(nodeID, stage, sent, ipaddr string) {

View File

@@ -9,6 +9,7 @@ import (
"syscall"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
)
@@ -22,9 +23,15 @@ func RunServer() error {
go func() {
for range c {
daemonLogf("Recieved SIGHUP, reloading...\n")
err := LoadNodeDB()
if err != nil {
fmt.Printf("ERROR: Could not load database: %s\n", err)
wwlog.Printf(wwlog.ERROR, "Could not load node DB: %s\n", err)
}
err = LoadNodeStatus()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not prepopulate node status DB: %s\n", err)
}
}
}()