diff --git a/internal/app/wwctl/node/status/main.go b/internal/app/wwctl/node/status/main.go index 7244c22b..1e917297 100644 --- a/internal/app/wwctl/node/status/main.go +++ b/internal/app/wwctl/node/status/main.go @@ -16,6 +16,29 @@ import ( "golang.org/x/term" ) +func displayStage(stage string) string { + switch stage { + case "efiboot": + return "EFI" + case "grub": + return "GRUB" + case "ipxe": + return "IPXE" + case "kernel": + return "KERNEL" + case "image": + return "IMAGE" + case "system": + return "SYSTEM OVERLAY" + case "runtime": + return "RUNTIME OVERLAY" + case "initramfs": + return "INITRAMFS" + default: + return strings.ToUpper(stage) + } +} + func CobraRunE(cmd *cobra.Command, args []string) (err error) { controller := warewulfconf.Get() @@ -102,11 +125,11 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) { continue } if rightnow-o.Lastseen >= int64(controller.Warewulf.UpdateInterval*2) { - color.Red("%-20s %-20s %-25s %-10d\n", o.NodeName, o.Stage, o.Sent, rightnow-o.Lastseen) + color.Red("%-20s %-20s %-25s %-10d\n", o.NodeName, displayStage(o.Stage), o.Sent, rightnow-o.Lastseen) } else if rightnow-o.Lastseen >= int64(controller.Warewulf.UpdateInterval+5) { - color.Yellow("%-20s %-20s %-25s %-10d\n", o.NodeName, o.Stage, o.Sent, rightnow-o.Lastseen) + color.Yellow("%-20s %-20s %-25s %-10d\n", o.NodeName, displayStage(o.Stage), o.Sent, rightnow-o.Lastseen) } else { - fmt.Printf("%-20s %-20s %-25s %-10d\n", o.NodeName, o.Stage, o.Sent, rightnow-o.Lastseen) + fmt.Printf("%-20s %-20s %-25s %-10d\n", o.NodeName, displayStage(o.Stage), o.Sent, rightnow-o.Lastseen) } } else { color.HiBlack("%-20s %-20s %-25s %-10s\n", o.NodeName, "--", "--", "--") diff --git a/internal/pkg/warewulfd/helpers.go b/internal/pkg/warewulfd/helpers.go index 15fdaf08..f3ec78ac 100644 --- a/internal/pkg/warewulfd/helpers.go +++ b/internal/pkg/warewulfd/helpers.go @@ -140,16 +140,16 @@ func sendResponse(w http.ResponseWriter, req *http.Request, stageFile string, tm } } - updateStatus(ctx.remoteNode.Id(), ctx.statusStage, path.Base(stageFile), ctx.rinfo.ipaddr) + updateStatus(ctx.remoteNode.Id(), ctx.rinfo.stage, path.Base(stageFile), ctx.rinfo.ipaddr) } else if stageFile == "" { w.WriteHeader(http.StatusBadRequest) wwlog.Error("No resource selected") - updateStatus(ctx.remoteNode.Id(), ctx.statusStage, "BAD_REQUEST", ctx.rinfo.ipaddr) + updateStatus(ctx.remoteNode.Id(), ctx.rinfo.stage, "BAD_REQUEST", ctx.rinfo.ipaddr) } else { w.WriteHeader(http.StatusNotFound) wwlog.Error("Not found: %s", stageFile) - updateStatus(ctx.remoteNode.Id(), ctx.statusStage, "NOT_FOUND", ctx.rinfo.ipaddr) + updateStatus(ctx.remoteNode.Id(), ctx.rinfo.stage, "NOT_FOUND", ctx.rinfo.ipaddr) } } diff --git a/internal/pkg/warewulfd/parser.go b/internal/pkg/warewulfd/parser.go index ef70e98d..c7ae0285 100644 --- a/internal/pkg/warewulfd/parser.go +++ b/internal/pkg/warewulfd/parser.go @@ -14,10 +14,9 @@ import ( // requestContext holds the validated results of the parsed request type requestContext struct { - conf *warewulfconf.WarewulfYaml - rinfo parsedRequest - remoteNode node.Node - statusStage string + conf *warewulfconf.WarewulfYaml + rinfo parsedRequest + remoteNode node.Node } // initHandleRequest performs common initial request parsing, security checks, @@ -45,17 +44,6 @@ func initHandleRequest(w http.ResponseWriter, req *http.Request) (*requestContex } } - status_stages := map[string]string{ - "efiboot": "EFI", - "grub": "GRUB", - "ipxe": "IPXE", - "kernel": "KERNEL", - "system": "SYSTEM_OVERLAY", - "runtime": "RUNTIME_OVERLAY", - "initramfs": "INITRAMFS"} - - statusStage := status_stages[rinfo.stage] - remoteNode, err := GetNodeOrSetDiscoverable(rinfo.hwaddr, conf.Warewulf.AutobuildOverlays()) if err != nil && err != node.ErrNoUnconfigured { wwlog.ErrorExc(err, "") @@ -66,15 +54,14 @@ func initHandleRequest(w http.ResponseWriter, req *http.Request) (*requestContex if remoteNode.AssetKey != "" && remoteNode.AssetKey != rinfo.assetkey { w.WriteHeader(http.StatusUnauthorized) wwlog.Denied("incorrect asset key: node %s: %s", remoteNode.Id(), rinfo.assetkey) - updateStatus(remoteNode.Id(), statusStage, "BAD_ASSET", rinfo.ipaddr) + updateStatus(remoteNode.Id(), rinfo.stage, "BAD_ASSET", rinfo.ipaddr) return nil, fmt.Errorf("incorrect asset key") } return &requestContext{ - conf: conf, - rinfo: rinfo, - remoteNode: remoteNode, - statusStage: statusStage, + conf: conf, + rinfo: rinfo, + remoteNode: remoteNode, }, nil }