merge: 合并代码20240531
This commit is contained in:
@@ -8,11 +8,13 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"be.ems/lib/core/utils/ctx"
|
||||
"be.ems/lib/dborm"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/services"
|
||||
"be.ems/restagent/config"
|
||||
|
||||
neModel "be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
@@ -503,22 +505,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)
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SoftwareStatusUploaded = "Uploaded"
|
||||
SoftwareStatusInactive = "Inactive"
|
||||
SoftwareStatusActive = "Active"
|
||||
SoftwareStatusUploaded = "3"
|
||||
SoftwareStatusInactive = "3"
|
||||
SoftwareStatusActive = "1"
|
||||
DigestsSignOkString = "digests signatures OK"
|
||||
SoftwareVerifiedOk = "Verified OK"
|
||||
)
|
||||
@@ -419,7 +419,7 @@ func DownloadSoftwareFile(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
fileName := (*neSoftware)[0]["file_name"]
|
||||
fileName := (*neSoftware)[0]["name"]
|
||||
path := (*neSoftware)[0]["path"]
|
||||
md5Sum := (*neSoftware)[0]["md5_sum"]
|
||||
|
||||
@@ -473,7 +473,7 @@ func DeleteSoftwareFile(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
fileName := (*neSoftware)[0]["file_name"]
|
||||
fileName := (*neSoftware)[0]["name"]
|
||||
path := (*neSoftware)[0]["path"]
|
||||
filePath := fmt.Sprintf("%s/%s", path, fileName)
|
||||
err = os.Remove(filePath)
|
||||
@@ -560,7 +560,7 @@ func DistributeSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
fileName := (*neSoftware)[0]["file_name"]
|
||||
fileName := (*neSoftware)[0]["name"]
|
||||
path := (*neSoftware)[0]["path"]
|
||||
srcFile := fmt.Sprintf("%s/%s", path, fileName)
|
||||
|
||||
@@ -611,7 +611,7 @@ func DistributeSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
Version: (*neSoftware)[0]["version"],
|
||||
FilePath: fmt.Sprintf("%s/software/%s/%s", config.GetYamlConfig().NE.OmcDir, neTypeLower, fileName),
|
||||
PreVersion: (*neVersion)[0]["version"],
|
||||
PreFile: (*neVersion)[0]["file_path"],
|
||||
PreFile: (*neVersion)[0]["path"],
|
||||
Status: SoftwareStatusInactive,
|
||||
}
|
||||
|
||||
@@ -695,21 +695,29 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
log.Trace("neVersion:", neVersion)
|
||||
|
||||
if !config.GetYamlConfig().OMC.TestMode {
|
||||
filePath := (*neVersion)[0]["file_path"]
|
||||
filePath := (*neVersion)[0]["path"]
|
||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||
srcFile := fmt.Sprintf("%s/actpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
|
||||
runCmd := fmt.Sprintf("sudo rm -f %s/actpkg.sh", config.GetYamlConfig().NE.ScpDir)
|
||||
err = RunSSHCmd(sshHost, runCmd)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to run cmd: %s", runCmd)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
srcFile := fmt.Sprintf("%s/actpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||
cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||
_, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
log.Errorf("Failed to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
runCmd := fmt.Sprintf("sudo %s/actpkg.sh '%s' %s",
|
||||
runCmd = fmt.Sprintf("sudo %s/actpkg.sh '%s' %s",
|
||||
config.GetYamlConfig().NE.ScpDir, filePath, neTypeUpper)
|
||||
if neTypeLower == "omc" {
|
||||
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
||||
@@ -897,6 +905,14 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if !config.GetYamlConfig().OMC.TestMode {
|
||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||
runCmd := fmt.Sprintf("sudo rm -f %s/rbkpkg.sh", config.GetYamlConfig().NE.ScpDir)
|
||||
err = RunSSHCmd(sshHost, runCmd)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to run cmd: %s", runCmd)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
srcFile := fmt.Sprintf("%s/rbkpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
|
||||
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||
@@ -909,7 +925,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
runCmd := fmt.Sprintf("sudo %s/rbkpkg.sh '%s' %s",
|
||||
runCmd = fmt.Sprintf("sudo %s/rbkpkg.sh '%s' %s",
|
||||
config.GetYamlConfig().NE.ScpDir, filePath, neTypeUpper)
|
||||
if neTypeLower == "omc" {
|
||||
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
||||
@@ -919,7 +935,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
PreVersion: "-",
|
||||
PreFile: "-",
|
||||
NewVersion: (*neVersion)[0]["version"],
|
||||
NewFile: (*neVersion)[0]["file_path"],
|
||||
NewFile: (*neVersion)[0]["path"],
|
||||
Status: SoftwareStatusActive,
|
||||
}
|
||||
|
||||
@@ -1021,7 +1037,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
PreVersion: "-",
|
||||
PreFile: "-",
|
||||
NewVersion: (*neVersion)[0]["version"],
|
||||
NewFile: (*neVersion)[0]["file_path"],
|
||||
NewFile: (*neVersion)[0]["path"],
|
||||
Status: SoftwareStatusActive,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user