37 Star 403 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
actionhandler.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
package kontainerdriver
import (
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
v3 "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 {
// passing nil as the resource only works because just namespace is grabbed from it and nodedriver is not namespaced
if err := apiContext.AccessControl.CanDo(v3.KontainerDriverGroupVersionKind.Group, v3.KontainerDriverResource.Name, "update", apiContext, nil, apiContext.Schema); err != nil {
return err
}
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.5-rc9

搜索帮助