3 Star 2 Fork 0

info-superbahn-ict / superbahn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
handler_delete.go 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
tangshibo 提交于 2021-11-19 12:29 . 11-19
package main
import (
"encoding/json"
"fmt"
"gitee.com/info-superbahn-ict/superbahn/pkg/supbagent/clireq"
"gitee.com/info-superbahn-ict/superbahn/sync/define"
"github.com/sirupsen/logrus"
)
func (r *AgentNervousClientPlugin) delete(args ...interface{}) (interface{}, error) {
// todo init
log := logrus.WithContext(r.ctx).WithFields(logrus.Fields{
define.LogsPrintCommonLabelOfFunction: "agent.plugin.host.cli.delete",
})
// todo 解码参数
var req = &clireq.ClientRequest{}
err := json.Unmarshal([]byte(args[0].(string)), req)
if err != nil {
log.Errorf("decoce bytes %v", err)
return nil, fmt.Errorf("decoce bytes %v", err)
}
log.Debugf("receive delete clireq %v", req)
// todo 处理 + return
return r.removeResource(req)
}
func (r *AgentNervousClientPlugin) removeResource(req *clireq.ClientRequest) (string, error) {
if req.DeleteAll == clireq.DeleteAll {
return "", r.removeAllResource()
} else {
logrus.WithContext(r.ctx).WithFields(logrus.Fields{
define.LogsPrintCommonLabelOfFunction: "agent.plugin.host.cli.delete",
}).Debugf("guid: %v", req.Guid)
if !r.api.GetContainerManager().ContainContainer(req.Guid) {
return "", fmt.Errorf("guid %v is nil", req.Guid)
}
if err := r.api.GetContainerManager().DeleteContainer(req.Guid, r.api.GetAgentNervous()); err != nil {
return "", fmt.Errorf("delete %v %v", req.Guid, err)
}
return fmt.Sprintf("DELETE %v SUCCEED", req.Guid), nil
}
}
func (r *AgentNervousClientPlugin) removeAllResource() error {
return r.api.GetContainerManager().DeleteAllContainers(r.api.GetAgentNervous())
}
Go
1
https://gitee.com/info-superbahn-ict/superbahn.git
git@gitee.com:info-superbahn-ict/superbahn.git
info-superbahn-ict
superbahn
superbahn
5fda629dab96

搜索帮助