fix: 网元授权状态检查离线时获取更新激活码

This commit is contained in:
TsMask
2025-04-28 19:41:58 +08:00
parent f838e8f3d9
commit 68acc7fc17
2 changed files with 11 additions and 18 deletions

View File

@@ -146,11 +146,7 @@ func (s *NeLicenseController) Code(c *gin.Context) {
}
// 更新授权码
code, licensePath, err := s.neLicenseService.ReadLicenseInfo(neLicense)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
if code != "" && licensePath != "" {
neLicense.ActivationRequestCode = code
neLicense.LicensePath = licensePath
@@ -259,15 +255,12 @@ func (s *NeLicenseController) State(c *gin.Context) {
neLicense.Status = "1"
neLicense.SerialNum = fmt.Sprint(neState["sn"])
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
code, licensePath, err := s.neLicenseService.ReadLicenseInfo(neLicense)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
neLicense.ActivationRequestCode = code
neLicense.LicensePath = licensePath
} else {
neLicense.Status = "0"
// 更新授权码
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)
neLicense.ActivationRequestCode = code
neLicense.LicensePath = licensePath
}
// 更新授权信息

View File

@@ -97,7 +97,7 @@ func (r *NeLicense) SelectByNeTypeAndNeID(neType, neId string) model.NeLicense {
// ReadLicenseInfo 读取授权文件信息
// 返回激活申请码, 激活文件
func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string, error) {
func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string) {
neTypeLower := strings.ToLower(neLicense.NeType)
// 网管本地路径
omcPath := "/usr/local/etc/omc/ne_license"
@@ -111,24 +111,24 @@ func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string,
// 网元主机的SSH客户端
sshClient, err := NewNeInfo.NeRunSSHClient(neLicense.NeType, neLicense.NeId)
if err != nil {
return "", "", err
return "", ""
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
return "", "", err
return "", ""
}
defer sftpClient.Close()
// 复制授权申请码到本地
if err = sftpClient.CopyFileRemoteToLocal(nePath+"/Activation_request_code.txt", omcPath+"/Activation_request_code.txt"); err != nil {
return "", "", fmt.Errorf("please check if scp remote copy is allowed")
return "", ""
}
// 读取文件内容
bytes, err := os.ReadFile(omcPath + "/Activation_request_code.txt")
if err != nil {
return "", "", fmt.Errorf("file read failure")
return "", ""
}
// 复制激活文件到本地
@@ -136,7 +136,7 @@ func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string,
if err = sftpClient.CopyFileRemoteToLocal(nePath+"/system.ini", omcPath+"/system.ini"); err == nil {
licensePath = omcPath + "/system.ini"
}
return strings.TrimSpace(string(bytes)), licensePath, nil
return strings.TrimSpace(string(bytes)), licensePath
}
// UploadLicense 授权文件上传到网元主机