Allow resetting a node to maintenance mode.

This commit is contained in:
2025-11-08 22:57:35 +00:00
parent c623843d53
commit b00dffd2b6
3 changed files with 69 additions and 7 deletions

View File

@@ -96,6 +96,7 @@ func (api *API) RegisterRoutes(r *mux.Router) {
r.HandleFunc("/api/v1/instances/{name}/nodes/{node}", api.NodeGet).Methods("GET")
r.HandleFunc("/api/v1/instances/{name}/nodes/{node}", api.NodeUpdate).Methods("PUT")
r.HandleFunc("/api/v1/instances/{name}/nodes/{node}/apply", api.NodeApply).Methods("POST")
r.HandleFunc("/api/v1/instances/{name}/nodes/{node}/reset", api.NodeReset).Methods("POST")
r.HandleFunc("/api/v1/instances/{name}/nodes/{node}", api.NodeDelete).Methods("DELETE")
// PXE Asset management (schematic@version composite key)

View File

@@ -371,3 +371,28 @@ func (api *API) NodeDiscoveryCancel(w http.ResponseWriter, r *http.Request) {
"message": "Discovery cancelled successfully",
})
}
// NodeReset resets a node to maintenance mode
func (api *API) NodeReset(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
instanceName := vars["name"]
nodeIdentifier := vars["node"]
// Validate instance exists
if err := api.instance.ValidateInstance(instanceName); err != nil {
respondError(w, http.StatusNotFound, fmt.Sprintf("Instance not found: %v", err))
return
}
// Reset node
nodeMgr := node.NewManager(api.dataDir, instanceName)
if err := nodeMgr.Reset(instanceName, nodeIdentifier); err != nil {
respondError(w, http.StatusInternalServerError, fmt.Sprintf("Failed to reset node: %v", err))
return
}
respondJSON(w, http.StatusOK, map[string]string{
"message": "Node reset successfully - now in maintenance mode",
"node": nodeIdentifier,
})
}