/
get_node.go
45 lines (41 loc) · 1.02 KB
/
get_node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package daemonapi
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/opensvc/om3/core/node"
"github.com/opensvc/om3/daemon/api"
)
func (a *DaemonAPI) GetNodes(ctx echo.Context, params api.GetNodesParams) error {
meta := Meta{
Context: ctx,
Node: params.Node,
}
name := "GetNodes"
log := LogHandler(ctx, name)
if err := meta.Expand(); err != nil {
log.Errorf("%s: %s", name, err)
return JSONProblem(ctx, http.StatusInternalServerError, "Server error", "expand selection")
}
configs := node.ConfigData.GetAll()
l := make(api.NodeItems, 0)
for _, config := range configs {
if !meta.HasNode(config.Node) {
continue
}
monitor := node.MonitorData.Get(config.Node)
status := node.StatusData.Get(config.Node)
d := api.NodeItem{
Kind: "NodeItem",
Meta: api.NodeMeta{
Node: config.Node,
},
Data: api.Node{
Config: config.Value,
Monitor: monitor,
Status: status,
},
}
l = append(l, d)
}
return ctx.JSON(http.StatusOK, api.NodeList{Kind: "NodeList", Items: l})
}