fix: 网元授权信息在线时更新授权信息,失败提示异常
This commit is contained in:
@@ -267,6 +267,7 @@ func (s *NeLicenseController) State(c *gin.Context) {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||
return
|
||||
}
|
||||
neLicense.Status = "0"
|
||||
|
||||
// 查询网元获取IP获取网元状态
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neLicense.NeType, neLicense.NeId)
|
||||
@@ -274,25 +275,24 @@ func (s *NeLicenseController) State(c *gin.Context) {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
neLicense.Status = "0"
|
||||
if neState, err := neService.NeState(neInfo); err == nil {
|
||||
neLicense.SerialNum = fmt.Sprint(neState["sn"])
|
||||
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
|
||||
neLicense.Status = "1"
|
||||
}
|
||||
|
||||
// 更新授权信息
|
||||
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
||||
neLicense.ActivationRequestCode = code
|
||||
neLicense.LicensePath = licensePath
|
||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.neLicenseService.Update(neLicense)
|
||||
if rows > 0 {
|
||||
// 在线时更新授权信息
|
||||
if neLicense.Status == "1" {
|
||||
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
||||
neLicense.ActivationRequestCode = code
|
||||
neLicense.LicensePath = licensePath
|
||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
s.neLicenseService.Update(neLicense)
|
||||
c.JSON(200, result.OkData(map[string]string{
|
||||
"sn": neLicense.SerialNum,
|
||||
"expire": neLicense.ExpiryDate,
|
||||
}))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, result.ErrMsg(fmt.Sprintf("%s service status exception", neLicense.NeType)))
|
||||
}
|
||||
|
||||
@@ -121,13 +121,13 @@ func (r *NeLicenseImpl) ReadLicenseInfo(neLicense model.NeLicense) (string, stri
|
||||
nePath := fmt.Sprintf("/usr/local/etc/%s/license", neTypeLower)
|
||||
|
||||
// 网元主机的SSH客户端
|
||||
sshclient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
||||
sshClient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
defer sshclient.Close()
|
||||
defer sshClient.Close()
|
||||
// 网元主机的SSH客户端进行文件传输
|
||||
sftpClient, err := sshclient.NewClientSFTP()
|
||||
sftpClient, err := sshClient.NewClientSFTP()
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
@@ -159,29 +159,29 @@ func (r *NeLicenseImpl) UploadLicense(neLicense model.NeLicense) error {
|
||||
return fmt.Errorf("file read failure")
|
||||
}
|
||||
|
||||
// 网元端授权文件路径
|
||||
neTypeLower := strings.ToLower(neLicense.NeType)
|
||||
neLicensePath := fmt.Sprintf("/usr/local/etc/%s/license", neTypeLower)
|
||||
// 修改文件夹权限
|
||||
NewNeInfoImpl.NeRunCMD(neLicense.NeType, neLicense.NeId, fmt.Sprintf("sudo chmod o+w %s/", neLicensePath))
|
||||
NewNeInfoImpl.NeRunCMD(neLicense.NeType, neLicense.NeId, fmt.Sprintf("sudo chmod o+w %s/system.ini", neLicensePath))
|
||||
// 尝试备份授权文件
|
||||
neLicensePathBack := fmt.Sprintf("%s/system_%s.ini", neLicensePath, time.Now().Format("20060102_150405"))
|
||||
NewNeInfoImpl.NeRunCMD(neLicense.NeType, neLicense.NeId, fmt.Sprintf("sudo cp -rf %s/system.ini %s", neLicensePath, neLicensePathBack))
|
||||
|
||||
// 网元主机的SSH客户端
|
||||
sshclient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
||||
sshClient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sshclient.Close()
|
||||
defer sshClient.Close()
|
||||
// 网元主机的SSH客户端进行文件传输
|
||||
sftpClient, err := sshclient.NewClientSFTP()
|
||||
sftpClient, err := sshClient.NewClientSFTP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sftpClient.Close()
|
||||
|
||||
// 网元端授权文件路径
|
||||
neTypeLower := strings.ToLower(neLicense.NeType)
|
||||
neLicensePath := fmt.Sprintf("/usr/local/etc/%s/license", neTypeLower)
|
||||
// 修改文件夹权限
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo chmod o+w %s/", neLicensePath))
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo chmod o+w %s/system.ini", neLicensePath))
|
||||
// 尝试备份授权文件
|
||||
neLicensePathBack := fmt.Sprintf("%s/system_%s.ini", neLicensePath, time.Now().Format("20060102_150405"))
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo cp -rf %s/system.ini %s", neLicensePath, neLicensePathBack))
|
||||
|
||||
// 上传授权文件去覆盖
|
||||
err = sftpClient.CopyFileLocalToRemote(omcLicensePath, neLicensePath+"/system.ini")
|
||||
if err != nil {
|
||||
@@ -196,7 +196,7 @@ func (r *NeLicenseImpl) UploadLicense(neLicense model.NeLicense) error {
|
||||
} else if neTypeLower == "omc" {
|
||||
cmdStr = "sudo /usr/local/omc/bin/omcsvc.sh restart"
|
||||
}
|
||||
NewNeInfoImpl.NeRunCMD(neLicense.NeType, neLicense.NeId, cmdStr)
|
||||
sshClient.RunCMD(cmdStr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user