merge: 合并OMC分支
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,8 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
neInfo.UpdateTime = time.Now().Format(time.DateTime)
|
||||
//neInfo.UpdateTime = time.Now().Format(time.DateTime)
|
||||
neInfo.UpdateTime = time.Now()
|
||||
log.Debug("NE info:", neInfo)
|
||||
|
||||
//if !config.GetYamlConfig().OMC.Chk2Ne {
|
||||
@@ -166,7 +167,7 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port)
|
||||
//hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port)
|
||||
apiUri := fmt.Sprintf("%s/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig", config.DefaultUriPrefix, strings.ToLower(neInfo.NeType))
|
||||
apiUri := fmt.Sprintf("%s/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig?ne_id=%s", config.DefaultUriPrefix, strings.ToLower(neInfo.NeType), neInfo.NeId)
|
||||
requestURI2NF := fmt.Sprintf("%s%s", hostUri, apiUri)
|
||||
log.Debug("requestURI2NF:", requestURI2NF)
|
||||
|
||||
@@ -252,7 +253,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
neInfo := new(dborm.NeInfo)
|
||||
_ = json.Unmarshal(body, neInfo)
|
||||
neInfo.NeType = strings.ToUpper(neType)
|
||||
neInfo.UpdateTime = time.Now().Format(time.DateTime)
|
||||
neInfo.UpdateTime = time.Now()
|
||||
log.Debug("NE info:", neInfo)
|
||||
|
||||
//if !config.GetYamlConfig().OMC.Chk2Ne {
|
||||
@@ -276,7 +277,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port)
|
||||
//hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port)
|
||||
apiUri := fmt.Sprintf("%s/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig", config.DefaultUriPrefix, neTypeLower)
|
||||
apiUri := fmt.Sprintf("%s/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig?ne_id=%s", config.DefaultUriPrefix, neTypeLower, neInfo.NeId)
|
||||
requestURI2NF := fmt.Sprintf("%s%s", hostUri, apiUri)
|
||||
log.Debug("requestURI2NF:", requestURI2NF)
|
||||
|
||||
@@ -858,15 +859,20 @@ func PostNeServiceAction(w http.ResponseWriter, r *http.Request) {
|
||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||
switch neTypeLower {
|
||||
case "omc":
|
||||
actionCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh %s", config.GetYamlConfig().NE.OmcDir, action)
|
||||
cmd := exec.Command("ssh", sshHost, actionCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Errorf("Faile to execute ssh %s omc:%v", action, err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
// send 204 to fe firstly
|
||||
services.ResponseStatusOK204NoContent(w)
|
||||
//actionCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh %s", config.GetYamlConfig().NE.OmcDir, action)
|
||||
actionCmd := fmt.Sprintf("sudo systemctl %s restagent", action)
|
||||
go RunSSHCmd(sshHost, actionCmd)
|
||||
return
|
||||
// cmd := exec.Command("ssh", sshHost, actionCmd)
|
||||
// out, err := cmd.CombinedOutput()
|
||||
// log.Debugf("Exec output: %v", string(out))
|
||||
// if err != nil {
|
||||
// log.Errorf("Faile to execute ssh %s omc:%v", action, err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
case "ims":
|
||||
switch action {
|
||||
case "start", "stop":
|
||||
|
||||
@@ -3,7 +3,7 @@ package cm
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/core/utils/ctx"
|
||||
"nms_cxy/lib/core/ctx"
|
||||
"nms_cxy/lib/global"
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/lib/services"
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
neService "nms_cxy/src/modules/network_element/service"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
@@ -41,7 +42,7 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) {
|
||||
neInfo := neService.NewNeInfoImpl.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
|
||||
var response services.DataResponse
|
||||
if neInfo.NeId == neId {
|
||||
if neInfo.NeId == neId && neInfo.NeId != "" {
|
||||
requestURI2NF := fmt.Sprintf("http://%s:%v%s", neInfo.IP, neInfo.Port, r.RequestURI)
|
||||
log.Debug("requestURI2NF:", requestURI2NF)
|
||||
|
||||
@@ -77,7 +78,7 @@ func PostParamConfigToNF(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
neInfo := neService.NewNeInfoImpl.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
|
||||
if neInfo.NeId != neId {
|
||||
if neInfo.NeId != neId || neInfo.NeId == "" {
|
||||
log.Error("neId is empty")
|
||||
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||
return
|
||||
@@ -129,7 +130,7 @@ func PutParamConfigToNF(w http.ResponseWriter, r *http.Request) {
|
||||
neId := ctx.GetQuery(r, "ne_id")
|
||||
neInfo := neService.NewNeInfoImpl.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
|
||||
if neInfo.NeId != neId {
|
||||
if neInfo.NeId != neId || neInfo.NeId == "" {
|
||||
log.Error("neId is empty")
|
||||
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||
return
|
||||
@@ -182,7 +183,7 @@ func DeleteParamConfigToNF(w http.ResponseWriter, r *http.Request) {
|
||||
neId := ctx.GetQuery(r, "ne_id")
|
||||
neInfo := neService.NewNeInfoImpl.SelectNeInfoByNeTypeAndNeID(neType, neId)
|
||||
|
||||
if neInfo.NeId != neId {
|
||||
if neInfo.NeId != neId || neInfo.NeId == "" {
|
||||
log.Error("neId is empty")
|
||||
services.ResponseInternalServerError500DatabaseOperationFailed(w)
|
||||
return
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -213,6 +213,17 @@ func UploadSoftwareMultiFile(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseNotFound404UriNotExist(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("select * from ne_software where ne_type='%s' and version='%s'", neTypeUpper, version)
|
||||
neSoftwareInfo, _ := dborm.XormGetDataBySQL(sql)
|
||||
if len(*neSoftwareInfo) >= 1 {
|
||||
services.ResponseWithJson(w, 200, map[string]any{
|
||||
"code": 0,
|
||||
"msg": "Software version already exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
md5Param := services.GetUriParamString(r, "md5Sum", ",", false, false)
|
||||
|
||||
softwarePath := fmt.Sprintf("%s/%s", config.GetYamlConfig().OMC.Software, neTypeLower)
|
||||
@@ -314,7 +325,7 @@ func UploadSoftwareMultiFile(w http.ResponseWriter, r *http.Request) {
|
||||
result := verify_signature(config.GetYamlConfig().Auth.PublicKey, cmsFilePath, rpmFilePath)
|
||||
log.Debug("result:", result.String())
|
||||
if !strings.Contains(result.String(), SoftwareVerifiedOk) {
|
||||
err := global.ErrCMNotMatchSignFile
|
||||
err = global.ErrCMNotMatchSignFile
|
||||
log.Error(err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
@@ -408,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"]
|
||||
|
||||
@@ -462,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)
|
||||
@@ -549,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)
|
||||
|
||||
@@ -600,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,
|
||||
}
|
||||
|
||||
@@ -684,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"])
|
||||
@@ -886,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,
|
||||
@@ -898,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"])
|
||||
@@ -908,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,
|
||||
}
|
||||
|
||||
@@ -919,7 +946,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
services.ResponseStatusOK204NoContent(w)
|
||||
RunSSHCmd(sshHost, runCmd)
|
||||
go RunSSHCmd(sshHost, runCmd)
|
||||
return
|
||||
}
|
||||
err = RunSSHCmd(sshHost, runCmd)
|
||||
@@ -1010,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