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")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neLicense.noData")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
neLicense.Status = "0"
|
||||||
|
|
||||||
// 查询网元获取IP获取网元状态
|
// 查询网元获取IP获取网元状态
|
||||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neLicense.NeType, neLicense.NeId)
|
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")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
neLicense.Status = "0"
|
|
||||||
if neState, err := neService.NeState(neInfo); err == nil {
|
if neState, err := neService.NeState(neInfo); err == nil {
|
||||||
neLicense.SerialNum = fmt.Sprint(neState["sn"])
|
neLicense.SerialNum = fmt.Sprint(neState["sn"])
|
||||||
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
|
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
|
||||||
neLicense.Status = "1"
|
neLicense.Status = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新授权信息
|
// 在线时更新授权信息
|
||||||
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
if neLicense.Status == "1" {
|
||||||
neLicense.ActivationRequestCode = code
|
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
|
||||||
neLicense.LicensePath = licensePath
|
neLicense.ActivationRequestCode = code
|
||||||
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
neLicense.LicensePath = licensePath
|
||||||
rows := s.neLicenseService.Update(neLicense)
|
neLicense.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
if rows > 0 {
|
s.neLicenseService.Update(neLicense)
|
||||||
c.JSON(200, result.OkData(map[string]string{
|
c.JSON(200, result.OkData(map[string]string{
|
||||||
"sn": neLicense.SerialNum,
|
"sn": neLicense.SerialNum,
|
||||||
"expire": neLicense.ExpiryDate,
|
"expire": neLicense.ExpiryDate,
|
||||||
}))
|
}))
|
||||||
return
|
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)
|
nePath := fmt.Sprintf("/usr/local/etc/%s/license", neTypeLower)
|
||||||
|
|
||||||
// 网元主机的SSH客户端
|
// 网元主机的SSH客户端
|
||||||
sshclient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
sshClient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
defer sshclient.Close()
|
defer sshClient.Close()
|
||||||
// 网元主机的SSH客户端进行文件传输
|
// 网元主机的SSH客户端进行文件传输
|
||||||
sftpClient, err := sshclient.NewClientSFTP()
|
sftpClient, err := sshClient.NewClientSFTP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
@@ -159,29 +159,29 @@ func (r *NeLicenseImpl) UploadLicense(neLicense model.NeLicense) error {
|
|||||||
return fmt.Errorf("file read failure")
|
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客户端
|
// 网元主机的SSH客户端
|
||||||
sshclient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
sshClient, err := NewNeInfoImpl.NeRunSSHclient(neLicense.NeType, neLicense.NeId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer sshclient.Close()
|
defer sshClient.Close()
|
||||||
// 网元主机的SSH客户端进行文件传输
|
// 网元主机的SSH客户端进行文件传输
|
||||||
sftpClient, err := sshclient.NewClientSFTP()
|
sftpClient, err := sshClient.NewClientSFTP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer sftpClient.Close()
|
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")
|
err = sftpClient.CopyFileLocalToRemote(omcLicensePath, neLicensePath+"/system.ini")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -196,7 +196,7 @@ func (r *NeLicenseImpl) UploadLicense(neLicense model.NeLicense) error {
|
|||||||
} else if neTypeLower == "omc" {
|
} else if neTypeLower == "omc" {
|
||||||
cmdStr = "sudo /usr/local/omc/bin/omcsvc.sh restart"
|
cmdStr = "sudo /usr/local/omc/bin/omcsvc.sh restart"
|
||||||
}
|
}
|
||||||
NewNeInfoImpl.NeRunCMD(neLicense.NeType, neLicense.NeId, cmdStr)
|
sshClient.RunCMD(cmdStr)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user