feat: 移除ssh客户端改为本地bash
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/ssh"
|
||||
"be.ems/src/framework/cmd"
|
||||
"be.ems/src/framework/utils/file"
|
||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
@@ -135,12 +135,12 @@ func (r NeVersion) FindByNeTypeAndNeID(neType, neId string) model.NeVersion {
|
||||
//
|
||||
// action 安装行为:install upgrade rollback
|
||||
func (r NeVersion) Operate(action string, neVersion model.NeVersion, preinput map[string]string) (string, error) {
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := r.neInfoService.NeRunSSHClient(neVersion.NeType, neVersion.NeId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer sshClient.Close()
|
||||
// // 网元主机的SSH客户端
|
||||
// sshClient, err := r.neInfoService.NeRunSSHClient(neVersion.NeType, neVersion.NeId)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// defer sshClient.Close()
|
||||
|
||||
// ========= 文件传输阶段 =========
|
||||
softwarePath := neVersion.Path
|
||||
@@ -150,7 +150,7 @@ func (r NeVersion) Operate(action string, neVersion model.NeVersion, preinput ma
|
||||
if action == "rollback" {
|
||||
softwarePath = neVersion.PrePath
|
||||
}
|
||||
neFilePaths, err := r.operateFile(sshClient, softwarePath)
|
||||
neFilePaths, err := r.operateFile(softwarePath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func (r NeVersion) Operate(action string, neVersion model.NeVersion, preinput ma
|
||||
}
|
||||
|
||||
// ========= 执行阶段 =========
|
||||
commandLine, err := r.operateRun(sshClient, preinput, cmdStrArr, neVersion.NeType, okFlagStr)
|
||||
commandLine, err := r.operateRun(preinput, cmdStrArr, neVersion.NeType, okFlagStr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -189,16 +189,18 @@ func (r NeVersion) Operate(action string, neVersion model.NeVersion, preinput ma
|
||||
}
|
||||
|
||||
// operateFile 操作版本-文件传输阶段
|
||||
func (r NeVersion) operateFile(sshClient *ssh.ConnSSH, softwarePath string) ([]string, error) {
|
||||
// 网元主机的SSH客户端进行文件传输
|
||||
sftpClient, err := sshClient.NewClientSFTP()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer sftpClient.Close()
|
||||
func (r NeVersion) operateFile(softwarePath string) ([]string, error) {
|
||||
// // 网元主机的SSH客户端进行文件传输
|
||||
// sftpClient, err := sshClient.NewClientSFTP()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// defer sftpClient.Close()
|
||||
|
||||
nePath := "/tmp"
|
||||
copyFileToNeMap := map[string]string{}
|
||||
// nePath := "/tmp"
|
||||
// copyFileToNeMap := map[string]string{}
|
||||
|
||||
neFilePaths := []string{}
|
||||
|
||||
// 统一处理多个文件和单个文件的情况
|
||||
var softwarePaths []string
|
||||
@@ -215,19 +217,20 @@ func (r NeVersion) operateFile(sshClient *ssh.ConnSSH, softwarePath string) ([]s
|
||||
return nil, fmt.Errorf("file read failure")
|
||||
}
|
||||
|
||||
fileName := filepath.Base(path)
|
||||
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
|
||||
copyFileToNeMap[localFilePath] = neFilePath
|
||||
// fileName := filepath.Base(path)
|
||||
// neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
|
||||
// copyFileToNeMap[localFilePath] = neFilePath
|
||||
neFilePaths = append(neFilePaths, localFilePath)
|
||||
}
|
||||
|
||||
// 上传软件包到 /tmp
|
||||
neFilePaths := []string{}
|
||||
for k, v := range copyFileToNeMap {
|
||||
if err = sftpClient.CopyFileLocalToRemote(k, v); err != nil {
|
||||
return nil, fmt.Errorf("error uploading package")
|
||||
}
|
||||
neFilePaths = append(neFilePaths, v)
|
||||
}
|
||||
// // 上传软件包到 /tmp
|
||||
// neFilePaths := []string{}
|
||||
// for k, v := range copyFileToNeMap {
|
||||
// if err = sftpClient.CopyFileLocalToRemote(k, v); err != nil {
|
||||
// return nil, fmt.Errorf("error uploading package")
|
||||
// }
|
||||
// neFilePaths = append(neFilePaths, v)
|
||||
// }
|
||||
return neFilePaths, nil
|
||||
}
|
||||
|
||||
@@ -587,9 +590,9 @@ func (r NeVersion) operateCommand(action, neType string, neFilePaths []string) (
|
||||
}
|
||||
|
||||
// operateRun 操作版本-执行阶段
|
||||
func (r NeVersion) operateRun(sshClient *ssh.ConnSSH, preinput map[string]string, cmdStrArr []string, neType string, okFlagStr string) (string, error) {
|
||||
func (r NeVersion) operateRun(preinput map[string]string, cmdStrArr []string, neType string, okFlagStr string) (string, error) {
|
||||
// ssh连接会话
|
||||
clientSession, err := sshClient.NewClientSession(127, 42)
|
||||
clientSession, err := cmd.NewClientSession(127, 42)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("neinfo ssh client session new err")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user