-
Notifications
You must be signed in to change notification settings - Fork 6
/
object_purge.go
57 lines (53 loc) · 1.54 KB
/
object_purge.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
53
54
55
56
57
package omcmd
import (
"context"
"github.com/opensvc/om3/core/actioncontext"
"github.com/opensvc/om3/core/naming"
"github.com/opensvc/om3/core/object"
"github.com/opensvc/om3/core/objectaction"
)
type (
CmdObjectPurge struct {
OptsGlobal
OptsAsync
OptsLock
OptsResourceSelector
OptTo
NodeSelector string
Force bool
Leader bool
}
)
func (t *CmdObjectPurge) Run(selector, kind string) error {
mergedSelector := mergeSelector(selector, t.ObjectSelector, kind, "")
return objectaction.New(
objectaction.WithObjectSelector(mergedSelector),
objectaction.WithRID(t.RID),
objectaction.WithTag(t.Tag),
objectaction.WithSubset(t.Subset),
objectaction.WithLocal(t.Local),
objectaction.WithOutput(t.Output),
objectaction.WithColor(t.Color),
objectaction.WithRemoteNodes(t.NodeSelector),
objectaction.WithAsyncTarget("purged"),
objectaction.WithAsyncTime(t.Time),
objectaction.WithAsyncWait(t.Wait),
objectaction.WithAsyncWatch(t.Watch),
objectaction.WithProgress(!t.Quiet && t.Log == ""),
objectaction.WithLocalFunc(func(ctx context.Context, p naming.Path) (interface{}, error) {
o, err := object.NewActor(p)
if err != nil {
return nil, err
}
ctx = actioncontext.WithLockDisabled(ctx, t.Disable)
ctx = actioncontext.WithLockTimeout(ctx, t.Timeout)
ctx = actioncontext.WithTo(ctx, t.To)
ctx = actioncontext.WithForce(ctx, t.Force)
ctx = actioncontext.WithLeader(ctx, t.Leader)
if err := o.Unprovision(ctx); err != nil {
return nil, err
}
return nil, o.Delete(ctx)
}),
).Do()
}