-
Notifications
You must be signed in to change notification settings - Fork 6
/
object_collector_tag_list.go
51 lines (47 loc) · 1.21 KB
/
object_collector_tag_list.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
package omcmd
import (
"context"
"fmt"
"github.com/opensvc/om3/core/naming"
"github.com/opensvc/om3/core/object"
"github.com/opensvc/om3/core/objectaction"
)
type (
CmdObjectCollectorTagList struct {
OptsGlobal
}
)
func (t *CmdObjectCollectorTagList) Run(selector, kind string) error {
mergedSelector := mergeSelector(selector, t.ObjectSelector, kind, "")
return objectaction.New(
objectaction.LocalFirst(),
objectaction.WithObjectSelector(mergedSelector),
objectaction.WithLocal(t.Local),
objectaction.WithOutput(t.Output),
objectaction.WithColor(t.Color),
objectaction.WithLocalFunc(func(ctx context.Context, p naming.Path) (interface{}, error) {
n, err := object.NewNode()
if err != nil {
return nil, err
}
cli, err := n.CollectorFeedClient()
if err != nil {
return nil, err
}
options := make(map[string]any)
type respType struct {
Ret int `json:"ret"`
Msg string `json:"msg"`
Data []string `json:"data"`
}
var resp respType
if err := cli.CallFor(&resp, "collector_list_tags", options); err != nil {
return nil, err
} else if resp.Ret == 0 {
return resp.Data, nil
} else {
return nil, fmt.Errorf("%s", resp.Msg)
}
}),
).Do()
}