/
get_node_system_san_path.go
52 lines (46 loc) · 1.45 KB
/
get_node_system_san_path.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
46
47
48
49
50
51
52
package daemonapi
import (
"errors"
"io/fs"
"net/http"
"github.com/labstack/echo/v4"
"github.com/opensvc/om3/core/client"
"github.com/opensvc/om3/core/object"
"github.com/opensvc/om3/daemon/api"
)
func (a *DaemonAPI) GetNodeSystemSANPath(ctx echo.Context, nodename api.InPathNodeName) error {
if a.localhost == nodename {
return a.getLocalNodeSystemSANPath(ctx)
}
return a.proxy(ctx, nodename, func(c *client.T) (*http.Response, error) {
return c.GetNodeSystemSANPath(ctx.Request().Context(), nodename)
})
}
func (a *DaemonAPI) getLocalNodeSystemSANPath(ctx echo.Context) error {
n, err := object.NewNode()
if err != nil {
return JSONProblemf(ctx, http.StatusInternalServerError, "New node", "%s", err)
}
data, err := n.LoadSystem()
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return JSONProblemf(ctx, http.StatusNotFound, "Load system cache", "waiting for cached value: %s", err)
} else {
return JSONProblemf(ctx, http.StatusInternalServerError, "Load system cache", "%s", err)
}
}
items := make(api.SANPathItems, len(data.Targets))
for i := 0; i < len(data.Targets); i++ {
items[i] = api.SANPath{
Initiator: api.SANPathInitiator{
Name: data.Targets[i].Initiator.Name,
Type: data.Targets[i].Initiator.Type,
},
Target: api.SANPathTarget{
Name: data.Targets[i].Target.Name,
Type: data.Targets[i].Target.Type,
},
}
}
return ctx.JSON(http.StatusOK, api.SANPathList{Kind: "SANPathList", Items: items})
}