feat: 网元服务操作start restart stop reboot poweroff
This commit is contained in:
@@ -155,3 +155,52 @@ func (s *NeActionController) Files(c *gin.Context) {
|
||||
"rows": splitRows,
|
||||
}))
|
||||
}
|
||||
|
||||
// 网元服务操作
|
||||
//
|
||||
// PUT /service
|
||||
func (s *NeActionController) Service(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeID string `json:"neId" binding:"required"`
|
||||
Action string `json:"action" binding:"required,oneof=start restart stop reboot poweroff"` // 操作行为
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询网元获取IP
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
|
||||
if neInfo.NeId != body.NeID || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
|
||||
neTypeLower := strings.ToLower(neInfo.NeType)
|
||||
cmdStr := fmt.Sprintf("sudo service %s %s", neTypeLower, body.Action)
|
||||
if neTypeLower == "omc" {
|
||||
cmdStr = fmt.Sprintf("sudo /usr/local/bin/omcsvc.sh %s", body.Action)
|
||||
} else if neTypeLower == "ims" {
|
||||
if body.Action == "restart" {
|
||||
cmdStr = "sudo ims-stop && sudo ims-start"
|
||||
} else {
|
||||
cmdStr = fmt.Sprintf("sudo ims-%s", body.Action)
|
||||
}
|
||||
}
|
||||
|
||||
if body.Action == "reboot" {
|
||||
cmdStr = "sudo shutdown -r now"
|
||||
}
|
||||
if body.Action == "poweroff" {
|
||||
cmdStr = "sudo shutdown -h now"
|
||||
}
|
||||
|
||||
_, err := s.neInfoService.NeRunCMD(body.NeType, body.NeID, cmdStr)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
|
||||
@@ -36,6 +36,11 @@ func Setup(router *gin.Engine) {
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neAction", collectlogs.BUSINESS_TYPE_IMPORT)),
|
||||
controller.NewNeAction.PushFile,
|
||||
)
|
||||
neActionGroup.PUT("/service",
|
||||
middleware.PreAuthorize(nil),
|
||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neAction", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||
controller.NewNeAction.Service,
|
||||
)
|
||||
}
|
||||
|
||||
// 网元信息
|
||||
|
||||
Reference in New Issue
Block a user