A few usability fixes and put full node DB logic into warewulfd
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user