fix: 网元安装移除hostId使用网元ID
This commit is contained in:
@@ -162,7 +162,7 @@ func (s *NeSoftwareController) Install(c *gin.Context) {
|
|||||||
Preinput map[string]string `json:"preinput" binding:"required"` // 预先输入参数
|
Preinput map[string]string `json:"preinput" binding:"required"` // 预先输入参数
|
||||||
}
|
}
|
||||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||||
if err != nil || body.Software.HostId == "" {
|
if err != nil || body.Software.NeId == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ type NeSoftware struct {
|
|||||||
|
|
||||||
// ====== 非数据库字段属性 ======
|
// ====== 非数据库字段属性 ======
|
||||||
|
|
||||||
HostId string `json:"hostId,omitempty" gorm:"-"` // 已记录的主机ID
|
NeId string `json:"neId,omitempty" gorm:"-"` // 网元ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 表名称
|
// TableName 表名称
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"be.ems/src/framework/utils/file"
|
"be.ems/src/framework/utils/file"
|
||||||
"be.ems/src/framework/utils/ssh"
|
|
||||||
"be.ems/src/modules/network_element/model"
|
"be.ems/src/modules/network_element/model"
|
||||||
"be.ems/src/modules/network_element/repository"
|
"be.ems/src/modules/network_element/repository"
|
||||||
)
|
)
|
||||||
@@ -130,8 +129,8 @@ func (r *NeSoftwareImpl) CheckUniqueTypeAndNameAndVersion(neType, name, version,
|
|||||||
// action 安装行为:install upgrade
|
// action 安装行为:install upgrade
|
||||||
func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftware, preinput map[string]string) (string, error) {
|
func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftware, preinput map[string]string) (string, error) {
|
||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
filePath := file.ParseUploadFilePath(neSoftware.Path)
|
localFilePath := file.ParseUploadFilePath(neSoftware.Path)
|
||||||
if _, err := os.Stat(filePath); err != nil {
|
if _, err := os.Stat(localFilePath); err != nil {
|
||||||
return "", fmt.Errorf("file read failure")
|
return "", fmt.Errorf("file read failure")
|
||||||
}
|
}
|
||||||
fileName := filepath.Base(neSoftware.Path)
|
fileName := filepath.Base(neSoftware.Path)
|
||||||
@@ -141,14 +140,21 @@ func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftw
|
|||||||
nePath := "/tmp"
|
nePath := "/tmp"
|
||||||
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
|
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
|
||||||
|
|
||||||
// 检查网元主机
|
// 网元主机的SSH客户端
|
||||||
neHostInfo := NewNeHostImpl.SelectById(neSoftware.HostId)
|
sshClient, err := NewNeInfoImpl.NeRunSSHclient(neSoftware.NeType, neSoftware.NeId)
|
||||||
if neHostInfo.HostType != "ssh" || neHostInfo.HostID != neSoftware.HostId {
|
if err != nil {
|
||||||
return "", fmt.Errorf("no found host info")
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer sshClient.Close()
|
||||||
|
// 网元主机的SSH客户端进行文件传输
|
||||||
|
sftpClient, err := sshClient.NewClientSFTP()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer sftpClient.Close()
|
||||||
|
|
||||||
// 上传软件包到 /tmp
|
// 上传软件包到 /tmp
|
||||||
if err := ssh.FileSCPLocalToNe(neHostInfo.Addr, filePath, neFilePath); err != nil {
|
if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil {
|
||||||
return "", fmt.Errorf("error uploading package")
|
return "", fmt.Errorf("error uploading package")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,16 +211,8 @@ func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftw
|
|||||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("echo '%s' \n", okFlagStr))
|
cmdStrArr = append(cmdStrArr, fmt.Sprintf("echo '%s' \n", okFlagStr))
|
||||||
// ========= 安装命令 end =========
|
// ========= 安装命令 end =========
|
||||||
|
|
||||||
// ssh连接客户端
|
|
||||||
var connSSH ssh.ConnSSH
|
|
||||||
neHostInfo.CopyTo(&connSSH)
|
|
||||||
client, err := connSSH.NewClient()
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("neinfo ssh client new err")
|
|
||||||
}
|
|
||||||
defer client.Close()
|
|
||||||
// ssh连接会话
|
// ssh连接会话
|
||||||
clientSession, err := client.NewClientSession(80, 24)
|
clientSession, err := sshClient.NewClientSession(80, 24)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("neinfo ssh client session new err")
|
return "", fmt.Errorf("neinfo ssh client session new err")
|
||||||
}
|
}
|
||||||
@@ -223,12 +221,12 @@ func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftw
|
|||||||
firstRead := true // 首次命令进行记录日志信息
|
firstRead := true // 首次命令进行记录日志信息
|
||||||
logMsg := "" // 日志信息
|
logMsg := "" // 日志信息
|
||||||
done := make(chan bool) // 完成信号
|
done := make(chan bool) // 完成信号
|
||||||
|
// 超时退出 30s
|
||||||
|
timeoutTicker := time.NewTicker(30 * time.Second)
|
||||||
|
defer timeoutTicker.Stop()
|
||||||
// 实时读取SSH消息直接输出
|
// 实时读取SSH消息直接输出
|
||||||
msTicker := time.NewTicker(100 * time.Millisecond)
|
msTicker := time.NewTicker(100 * time.Millisecond)
|
||||||
defer msTicker.Stop()
|
defer msTicker.Stop()
|
||||||
// 超时退出
|
|
||||||
timeoutTicker := time.NewTicker(30 * time.Second)
|
|
||||||
defer timeoutTicker.Stop()
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|||||||
Reference in New Issue
Block a user