代码拉取完成,页面将自动刷新
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 {
// 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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。