mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Add node management endpoints to handle listing and retrieving node details
This commit is contained in:
@@ -784,6 +784,12 @@ func (h *Handler) RemoteOpenAIProxy(w http.ResponseWriter, r *http.Request, mode
|
|||||||
io.Copy(w, resp.Body)
|
io.Copy(w, resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NodeResponse represents a sanitized node configuration for API responses
|
||||||
|
type NodeResponse struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
}
|
||||||
|
|
||||||
// ParseCommandRequest represents the request body for command parsing
|
// ParseCommandRequest represents the request body for command parsing
|
||||||
type ParseCommandRequest struct {
|
type ParseCommandRequest struct {
|
||||||
Command string `json:"command"`
|
Command string `json:"command"`
|
||||||
@@ -943,3 +949,78 @@ func (h *Handler) ParseVllmCommand() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListNodes godoc
|
||||||
|
// @Summary List all configured nodes
|
||||||
|
// @Description Returns a list of all nodes configured in the server
|
||||||
|
// @Tags nodes
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @Produces json
|
||||||
|
// @Success 200 {array} NodeResponse "List of nodes"
|
||||||
|
// @Failure 500 {string} string "Internal Server Error"
|
||||||
|
// @Router /nodes [get]
|
||||||
|
func (h *Handler) ListNodes() http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Convert to sanitized response format
|
||||||
|
nodeResponses := make([]NodeResponse, len(h.cfg.Nodes))
|
||||||
|
for i, node := range h.cfg.Nodes {
|
||||||
|
nodeResponses[i] = NodeResponse{
|
||||||
|
Name: node.Name,
|
||||||
|
Address: node.Address,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
if err := json.NewEncoder(w).Encode(nodeResponses); err != nil {
|
||||||
|
http.Error(w, "Failed to encode nodes: "+err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNode godoc
|
||||||
|
// @Summary Get details of a specific node
|
||||||
|
// @Description Returns the details of a specific node by name
|
||||||
|
// @Tags nodes
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @Produces json
|
||||||
|
// @Param name path string true "Node Name"
|
||||||
|
// @Success 200 {object} NodeResponse "Node details"
|
||||||
|
// @Failure 400 {string} string "Invalid name format"
|
||||||
|
// @Failure 404 {string} string "Node not found"
|
||||||
|
// @Failure 500 {string} string "Internal Server Error"
|
||||||
|
// @Router /nodes/{name} [get]
|
||||||
|
func (h *Handler) GetNode() http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
name := chi.URLParam(r, "name")
|
||||||
|
if name == "" {
|
||||||
|
http.Error(w, "Node name cannot be empty", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var nodeConfig *config.NodeConfig
|
||||||
|
for i := range h.cfg.Nodes {
|
||||||
|
if h.cfg.Nodes[i].Name == name {
|
||||||
|
nodeConfig = &h.cfg.Nodes[i]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if nodeConfig == nil {
|
||||||
|
http.Error(w, "Node not found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to sanitized response format
|
||||||
|
nodeResponse := NodeResponse{
|
||||||
|
Name: nodeConfig.Name,
|
||||||
|
Address: nodeConfig.Address,
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
if err := json.NewEncoder(w).Encode(nodeResponse); err != nil {
|
||||||
|
http.Error(w, "Failed to encode node: "+err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,6 +60,15 @@ func SetupRouter(handler *Handler) *chi.Mux {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Node management endpoints
|
||||||
|
r.Route("/nodes", func(r chi.Router) {
|
||||||
|
r.Get("/", handler.ListNodes()) // List all nodes
|
||||||
|
|
||||||
|
r.Route("/{name}", func(r chi.Router) {
|
||||||
|
r.Get("/", handler.GetNode())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Instance management endpoints
|
// Instance management endpoints
|
||||||
r.Route("/instances", func(r chi.Router) {
|
r.Route("/instances", func(r chi.Router) {
|
||||||
r.Get("/", handler.ListInstances()) // List all instances
|
r.Get("/", handler.ListInstances()) // List all instances
|
||||||
|
|||||||
Reference in New Issue
Block a user