feat: 安装包上传到网元主机执行安装命令

This commit is contained in:
TsMask
2024-04-11 17:07:23 +08:00
parent 513a5bb5fe
commit 5970a8b5f2
3 changed files with 185 additions and 42 deletions

View File

@@ -151,40 +151,44 @@ func (s *NeSoftwareController) Remove(c *gin.Context) {
c.JSON(200, result.OkMsg(msg))
}
// 网元软件包安装检查
// 网元软件包安装
//
// POST /checkInstall
func (s *NeSoftwareController) CheckInstall(c *gin.Context) {
// POST /install
func (s *NeSoftwareController) Install(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body model.NeSoftware
var body struct {
Action string `json:"action" binding:"required,oneof=install upgrade"` // 安装行为
Software model.NeSoftware `json:"software" binding:"required"` // 软件包信息
Preinput map[string]string `json:"preinput" binding:"required"` // 预先输入参数
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.HostId == "" {
if err != nil || body.Software.HostId == "" {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否存在软件包记录
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
NeType: body.NeType,
Name: body.Name,
Version: body.Version,
NeType: body.Software.NeType,
Name: body.Software.Name,
Version: body.Software.Version,
})
if len(neSoftwares) <= 0 {
body.CreateBy = ctx.LoginUserToUserName(c)
body.ID = s.neSoftwareService.Insert(body)
body.Software.CreateBy = ctx.LoginUserToUserName(c)
body.Software.ID = s.neSoftwareService.Insert(body.Software)
} else {
neSoftware := neSoftwares[0]
neSoftware.Path = body.Path
neSoftware.Description = body.Description
neSoftware.Path = body.Software.Path
neSoftware.Description = body.Software.Description
neSoftware.UpdateBy = ctx.LoginUserToUserName(c)
s.neSoftwareService.Update(neSoftware)
}
// 进行安装检查
cmdStrArr, err := s.neSoftwareService.UploadToNeHost(body)
output, err := s.neSoftwareService.InstallToNeHost(body.Action, body.Software, body.Preinput)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
return
}
c.JSON(200, result.OkData(cmdStrArr))
c.JSON(200, result.OkData(output))
}