-
Notifications
You must be signed in to change notification settings - Fork 6
/
object_compliance_auto.go
50 lines (46 loc) · 1.2 KB
/
object_compliance_auto.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
package omcmd
import (
"context"
"github.com/opensvc/om3/core/naming"
"github.com/opensvc/om3/core/object"
"github.com/opensvc/om3/core/objectaction"
)
type (
CmdObjectComplianceAuto struct {
OptsGlobal
Moduleset string
Module string
NodeSelector string
Force bool
Attach bool
}
)
func (t *CmdObjectComplianceAuto) Run(selector, kind string) error {
mergedSelector := mergeSelector(selector, t.ObjectSelector, kind, "")
return objectaction.New(
objectaction.LocalFirst(),
objectaction.WithLocal(t.Local),
objectaction.WithColor(t.Color),
objectaction.WithOutput(t.Output),
objectaction.WithObjectSelector(mergedSelector),
objectaction.WithRemoteNodes(t.NodeSelector),
objectaction.WithServer(t.Server),
objectaction.WithLocalFunc(func(ctx context.Context, p naming.Path) (interface{}, error) {
if o, err := object.NewSvc(p); err != nil {
return nil, err
} else {
comp, err := o.NewCompliance()
if err != nil {
return nil, err
}
run := comp.NewRun()
run.SetModulesetsExpr(t.Moduleset)
run.SetModulesExpr(t.Module)
run.SetForce(t.Force)
run.SetAttach(t.Attach)
err = run.Auto()
return run, err
}
}),
).Do()
}