forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actionhandler.go
43 lines (34 loc) · 1.11 KB
/
actionhandler.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
package kontainerdriver
import (
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
type ActionHandler struct {
KontainerDrivers v3.KontainerDriverInterface
KontainerDriverLister v3.KontainerDriverLister
}
func (a ActionHandler) ActionHandler(actionName string, action *types.Action, apiContext *types.APIContext) error {
switch actionName {
case "activate":
return a.activate(apiContext)
case "deactivate":
return a.deactivate(apiContext)
}
return httperror.NewAPIError(httperror.NotFound, "not found")
}
func (a ActionHandler) activate(apiContext *types.APIContext) error {
return a.setDriverActiveStatus(apiContext, true)
}
func (a ActionHandler) deactivate(apiContext *types.APIContext) error {
return a.setDriverActiveStatus(apiContext, false)
}
func (a ActionHandler) setDriverActiveStatus(apiContext *types.APIContext, status bool) error {
driver, err := a.KontainerDriverLister.Get("", apiContext.ID)
if err != nil {
return err
}
driver.Spec.Active = status
_, err = a.KontainerDrivers.Update(driver)
return err
}