diff --git a/internal/app/wwctl/node/add/main.go b/internal/app/wwctl/node/add/main.go index c08fb548..39d43b95 100644 --- a/internal/app/wwctl/node/add/main.go +++ b/internal/app/wwctl/node/add/main.go @@ -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 } diff --git a/internal/app/wwctl/node/delete/main.go b/internal/app/wwctl/node/delete/main.go index ed184291..8ce3f614 100644 --- a/internal/app/wwctl/node/delete/main.go +++ b/internal/app/wwctl/node/delete/main.go @@ -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") + } + } } diff --git a/internal/app/wwctl/node/status/main.go b/internal/app/wwctl/node/status/main.go index de201521..2d23099d 100644 --- a/internal/app/wwctl/node/status/main.go +++ b/internal/app/wwctl/node/status/main.go @@ -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 diff --git a/internal/app/wwctl/node/status/root.go b/internal/app/wwctl/node/status/root.go index 3423bc48..af385d41 100644 --- a/internal/app/wwctl/node/status/root.go +++ b/internal/app/wwctl/node/status/root.go @@ -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. diff --git a/internal/pkg/warewulfd/nodedb.go b/internal/pkg/warewulfd/nodedb.go index c9c09645..f5e05fe8 100644 --- a/internal/pkg/warewulfd/nodedb.go +++ b/internal/pkg/warewulfd/nodedb.go @@ -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 diff --git a/internal/pkg/warewulfd/status.go b/internal/pkg/warewulfd/status.go index ac87ef89..7711bbeb 100644 --- a/internal/pkg/warewulfd/status.go +++ b/internal/pkg/warewulfd/status.go @@ -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) { diff --git a/internal/pkg/warewulfd/warewulfd.go b/internal/pkg/warewulfd/warewulfd.go index 01baa656..2c5f4044 100644 --- a/internal/pkg/warewulfd/warewulfd.go +++ b/internal/pkg/warewulfd/warewulfd.go @@ -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) } } }()