Move stage display formatting to wwctl
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -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, "--", "--", "--")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ type requestContext struct {
|
||||
conf *warewulfconf.WarewulfYaml
|
||||
rinfo parsedRequest
|
||||
remoteNode node.Node
|
||||
statusStage string
|
||||
}
|
||||
|
||||
// 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,7 +54,7 @@ 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")
|
||||
}
|
||||
|
||||
@@ -74,7 +62,6 @@ func initHandleRequest(w http.ResponseWriter, req *http.Request) (*requestContex
|
||||
conf: conf,
|
||||
rinfo: rinfo,
|
||||
remoteNode: remoteNode,
|
||||
statusStage: statusStage,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user