This commit is contained in:
2023-09-16 20:08:56 +08:00
parent ee9592c9d1
commit 97cca20b51

View File

@@ -6,6 +6,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"os/exec"
"strings" "strings"
"time" "time"
@@ -598,15 +599,23 @@ func ImportCmToNF(w http.ResponseWriter, r *http.Request) {
scpZipCmd = fmt.Sprintf("scp -r %s %s@[%s]:%s", filePath, scpZipCmd = fmt.Sprintf("scp -r %s %s@[%s]:%s", filePath,
config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.ScpDir) config.GetYamlConfig().NE.User, neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
} }
neFilePath := config.GetYamlConfig().NE.ScpDir + "/" + fileName err = ExecCmd(scpZipCmd)
unzipCmd := fmt.Sprintf("sudo unzip -o %s -d %s", neFilePath, config.GetYamlConfig().NE.EtcDir)
err = ExecCmd(fmt.Sprintf("%s && %s", scpZipCmd, unzipCmd))
if err != nil { if err != nil {
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip) log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
services.ResponseInternalServerError500ProcessError(w, err) services.ResponseInternalServerError500ProcessError(w, err)
return return
} }
neFilePath := config.GetYamlConfig().NE.ScpDir + "/" + fileName
unzipCmd := fmt.Sprintf("ssh sudo unzip -o %s -d %s", neFilePath, config.GetYamlConfig().NE.EtcDir)
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
cmd := exec.Command("ssh", sshHost, unzipCmd)
out, err := cmd.CombinedOutput()
log.Tracef("Exec output: %v", string(out))
if err != nil {
log.Error("Faile to execute rpm command:", err)
services.ResponseInternalServerError500ProcessError(w, err)
return
}
services.ResponseStatusOK204NoContent(w) services.ResponseStatusOK204NoContent(w)
} }