Merge remote-tracking branch 'origin/main' into lichang

This commit is contained in:
TsMask
2024-04-17 10:57:07 +08:00
31 changed files with 440 additions and 265 deletions

View File

@@ -858,15 +858,20 @@ func PostNeServiceAction(w http.ResponseWriter, r *http.Request) {
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
switch neTypeLower {
case "omc":
actionCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh %s", config.GetYamlConfig().NE.OmcDir, action)
cmd := exec.Command("ssh", sshHost, actionCmd)
out, err := cmd.CombinedOutput()
log.Debugf("Exec output: %v", string(out))
if err != nil {
log.Errorf("Faile to execute ssh %s omc:%v", action, err)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
// send 204 to fe firstly
services.ResponseStatusOK204NoContent(w)
//actionCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh %s", config.GetYamlConfig().NE.OmcDir, action)
actionCmd := fmt.Sprintf("sudo systemctl %s restagent", action)
go RunSSHCmd(sshHost, actionCmd)
return
// cmd := exec.Command("ssh", sshHost, actionCmd)
// out, err := cmd.CombinedOutput()
// log.Debugf("Exec output: %v", string(out))
// if err != nil {
// log.Errorf("Faile to execute ssh %s omc:%v", action, err)
// services.ResponseInternalServerError500ProcessError(w, err)
// return
// }
case "ims":
switch action {
case "start", "stop":

View File

@@ -930,7 +930,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
return
}
services.ResponseStatusOK204NoContent(w)
RunSSHCmd(sshHost, runCmd)
go RunSSHCmd(sshHost, runCmd)
return
}
err = RunSSHCmd(sshHost, runCmd)

View File

@@ -51,16 +51,24 @@ var (
CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}"
)
var TIME_DELAY_AFTER_WRITE time.Duration = 200
var TIME_DEAD_LINE time.Duration = 10
var (
TIME_DELAY_AFTER_WRITE time.Duration = 200
TIME_DEAD_LINE time.Duration = 10
WIN_ROW_SIZE byte = 100
WIN_COL_SIZE byte = 100
BUFFER_SIZE int = 65535
)
func init() {
func InitMML() {
if config.GetYamlConfig().MML.Sleep != 0 {
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
}
if config.GetYamlConfig().MML.DeadLine != 0 {
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
}
WIN_ROW_SIZE = config.GetYamlConfig().MML.SizeRow
WIN_COL_SIZE = config.GetYamlConfig().MML.SizeCol
BUFFER_SIZE = config.GetYamlConfig().MML.BufferSize
}
func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
@@ -78,8 +86,7 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
return
}
var buf [100 * 1024]byte
//buf := make([]byte, 0)
buf := make([]byte, BUFFER_SIZE)
var n int
var mmlResult []string
port2 := 5002
@@ -90,6 +97,7 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
if neInfo != nil {
hostMML := fmt.Sprintf("%s:%d", neInfo.Ip, port2)
conn, err := net.Dial("tcp", hostMML)
//conn, err := net.Dial("tcp", hostMML)
if err != nil {
errMsg := fmt.Sprintf("Failed to dial %s: %v", hostMML, err)
log.Error(errMsg)
@@ -110,6 +118,9 @@ func PostMML2ToNF(w http.ResponseWriter, r *http.Request) {
// services.ResponseWithJson(w, http.StatusOK, response)
// return
// }
// 发送窗口大小设置命令
conn.Write([]byte{255, 251, 31}) // 发送WILL WINDOW SIZE
conn.Write([]byte{255, 250, 31, 0, WIN_ROW_SIZE, 0, WIN_COL_SIZE, 255, 240}) // 发送设置 WINDOW SIZE
conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second))
loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password)