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"
|
"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) {
|
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
|
||||||
controller := warewulfconf.Get()
|
controller := warewulfconf.Get()
|
||||||
@@ -102,11 +125,11 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if rightnow-o.Lastseen >= int64(controller.Warewulf.UpdateInterval*2) {
|
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) {
|
} 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 {
|
} 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 {
|
} else {
|
||||||
color.HiBlack("%-20s %-20s %-25s %-10s\n", o.NodeName, "--", "--", "--")
|
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 == "" {
|
} else if stageFile == "" {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
wwlog.Error("No resource selected")
|
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 {
|
} else {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
wwlog.Error("Not found: %s", stageFile)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ import (
|
|||||||
|
|
||||||
// requestContext holds the validated results of the parsed request
|
// requestContext holds the validated results of the parsed request
|
||||||
type requestContext struct {
|
type requestContext struct {
|
||||||
conf *warewulfconf.WarewulfYaml
|
conf *warewulfconf.WarewulfYaml
|
||||||
rinfo parsedRequest
|
rinfo parsedRequest
|
||||||
remoteNode node.Node
|
remoteNode node.Node
|
||||||
statusStage string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// initHandleRequest performs common initial request parsing, security checks,
|
// 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())
|
remoteNode, err := GetNodeOrSetDiscoverable(rinfo.hwaddr, conf.Warewulf.AutobuildOverlays())
|
||||||
if err != nil && err != node.ErrNoUnconfigured {
|
if err != nil && err != node.ErrNoUnconfigured {
|
||||||
wwlog.ErrorExc(err, "")
|
wwlog.ErrorExc(err, "")
|
||||||
@@ -66,15 +54,14 @@ func initHandleRequest(w http.ResponseWriter, req *http.Request) (*requestContex
|
|||||||
if remoteNode.AssetKey != "" && remoteNode.AssetKey != rinfo.assetkey {
|
if remoteNode.AssetKey != "" && remoteNode.AssetKey != rinfo.assetkey {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
wwlog.Denied("incorrect asset key: node %s: %s", remoteNode.Id(), rinfo.assetkey)
|
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 nil, fmt.Errorf("incorrect asset key")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &requestContext{
|
return &requestContext{
|
||||||
conf: conf,
|
conf: conf,
|
||||||
rinfo: rinfo,
|
rinfo: rinfo,
|
||||||
remoteNode: remoteNode,
|
remoteNode: remoteNode,
|
||||||
statusStage: statusStage,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user