merge: 合并OMC分支

This commit is contained in:
TsMask
2024-07-10 14:18:48 +08:00
parent 17c0011c6b
commit 625ed57a50
260 changed files with 9167 additions and 14857 deletions

View File

@@ -7,12 +7,14 @@ import (
"os"
"os/exec"
"strings"
"time"
"nms_cxy/lib/core/ctx"
"nms_cxy/lib/dborm"
"nms_cxy/lib/log"
"nms_cxy/lib/services"
"nms_cxy/omc/config"
neModel "nms_cxy/src/modules/network_element/model"
neService "nms_cxy/src/modules/network_element/service"
"github.com/gorilla/mux"
)
@@ -154,21 +156,21 @@ func DeleteLcenseFile(w http.ResponseWriter, r *http.Request) {
services.ResponseStatusOK204NoContent(w)
}
type MMLRequest struct {
MML []string `json:"mml"`
}
// type MMLRequest struct {
// MML []string `json:"mml"`
// }
var TIME_DELAY_AFTER_WRITE time.Duration = 200
var TIME_DEAD_LINE time.Duration = 10
// var TIME_DELAY_AFTER_WRITE time.Duration = 200
// var TIME_DEAD_LINE time.Duration = 10
func init() {
if config.GetYamlConfig().MML.Sleep != 0 {
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
}
if config.GetYamlConfig().MML.DeadLine != 0 {
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
}
}
// func init() {
// if config.GetYamlConfig().MML.Sleep != 0 {
// TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
// }
// if config.GetYamlConfig().MML.DeadLine != 0 {
// TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
// }
// }
func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) {
log.Info("UploadLicenseFileData processing... ")
@@ -274,12 +276,13 @@ func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) {
}
// backup system.ini to system.ini.bak
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
cpCmd := fmt.Sprintf("sudo cp -f %s/system.ini %s/system.ini.bak", neLicensePath, neLicensePath)
cpCmd := fmt.Sprintf("sudo test -f %s/system.ini && cp -f %s/system.ini %s/system.ini.bak||echo 0",
neLicensePath, neLicensePath, neLicensePath)
cmd = exec.Command("ssh", sshHost, cpCmd)
out, err = cmd.CombinedOutput()
log.Debugf("Exec output: %v", string(out))
if err != nil {
log.Error("Faile to execute cp command:", err)
log.Errorf("Faile to execute cp command:%v, cmd:%s", err, cpCmd)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
@@ -503,22 +506,54 @@ func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) {
}
}
*/
neLicense := dborm.NeLicense{
NeType: neTypeUpper,
NeID: neId,
Status: "ACTIVE",
Path: licensePath,
FileName: licenseFileName,
Comment: comment,
// neLicense := dborm.NeLicense{
// NeType: neTypeUpper,
// NeID: neId,
// Status: "ACTIVE",
// Path: licensePath,
// FileName: licenseFileName,
// Comment: comment,
// }
// log.Debug("neLicense:", neLicense)
// _, err = dborm.XormInsertTableOne("ne_license", neLicense)
// if err != nil {
// log.Error("Faile to XormInsertTableOne:", err)
// services.ResponseInternalServerError500ProcessError(w, err)
// }
neLicense := neModel.NeLicense{
NeType: neTypeUpper,
NeId: neId,
Status: "0",
LicensePath: neFilePath,
Remark: comment,
}
log.Debug("neLicense:", neLicense)
_, err = dborm.XormInsertTableOne("ne_license", neLicense)
if err != nil {
log.Error("Faile to XormInsertTableOne:", err)
services.ResponseInternalServerError500ProcessError(w, err)
return
// 检查是否存在授权记录
neLicense2 := neService.NewNeLicenseImpl.SelectByNeTypeAndNeID(neTypeUpper, neId)
if neLicense2.NeId != neId {
// 读取授权码
code, _ := neService.NewNeLicenseImpl.ReadLicenseInfo(neLicense)
neLicense.ActivationRequestCode = code
neLicense.CreateBy = ctx.LoginUserToUserName(r)
insertId := neService.NewNeLicenseImpl.Insert(neLicense)
if insertId != "" {
services.ResponseStatusOK204NoContent(w)
return
}
} else {
neLicense2.UpdateBy = ctx.LoginUserToUserName(r)
upRows := neService.NewNeLicenseImpl.Update(neLicense2)
if upRows > 0 {
services.ResponseStatusOK204NoContent(w)
return
}
}
services.ResponseStatusOK204NoContent(w)
services.ResponseInternalServerError500ProcessError(w, err)
}