marge: 合并代码
This commit is contained in:
@@ -527,7 +527,7 @@ func DistributeSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
log.Debug("neSoftware:", neSoftware)
|
||||
log.Trace("neSoftware:", neSoftware)
|
||||
|
||||
sql = fmt.Sprintf("select * from ne_version where ne_type='%s' and ne_id='%s'", neTypeUpper, neId)
|
||||
neVersion, err := dborm.XormGetDataBySQL(sql)
|
||||
@@ -536,13 +536,13 @@ func DistributeSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
log.Debug("neVersion:", neVersion)
|
||||
log.Trace("neVersion:", neVersion)
|
||||
|
||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||
mkdirCmd := fmt.Sprintf("sudo mkdir -p %s/software/%s", config.GetYamlConfig().NE.OmcDir, neTypeLower)
|
||||
cmd := exec.Command("ssh", sshHost, mkdirCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to mkdir:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
@@ -557,7 +557,7 @@ func DistributeSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||
cmd = exec.Command("scp", "-r", srcFile, scpDir)
|
||||
out, err = cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
@@ -568,7 +568,7 @@ func DistributeSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
config.GetYamlConfig().NE.OmcDir, neTypeLower)
|
||||
cmd = exec.Command("ssh", sshHost, cpCmd)
|
||||
out, err = cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute cp command:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
@@ -667,7 +667,7 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
log.Debug("neVersion:", neSoftware)
|
||||
log.Trace("neSoftware:", neSoftware)
|
||||
|
||||
sql = fmt.Sprintf("select * from ne_version where ne_type='%s' and ne_id='%s' and version='%s'", neTypeUpper, neId, version)
|
||||
neVersion, err := dborm.XormGetDataBySQL(sql)
|
||||
@@ -681,62 +681,104 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
log.Debug("neVersion:", neVersion)
|
||||
log.Trace("neVersion:", neVersion)
|
||||
|
||||
if !config.GetYamlConfig().OMC.TestMode {
|
||||
filePath := (*neVersion)[0]["file_path"]
|
||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||
fileType := global.IsRpmOrDebPackage(filePath)
|
||||
if fileType == 1 {
|
||||
rpmCmd := fmt.Sprintf("sudo rpm -Uvh '%s'", filePath)
|
||||
cmd := exec.Command("ssh", sshHost, rpmCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute rpm command:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
} else if fileType == 2 {
|
||||
dpkgCmd := fmt.Sprintf("sudo dpkg -i --force-all '%s'", filePath)
|
||||
err := RunSSHCmd(sshHost, dpkgCmd)
|
||||
if err != nil {
|
||||
log.Error("Faile to execute dpkg command:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
// timeout := time.Duration(config.GetYamlConfig().OMC.CmdTimeout) * time.Second
|
||||
// ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时
|
||||
// defer cancel()
|
||||
// cmd := exec.CommandContext(ctx, "ssh", sshHost, dpkgCmd)
|
||||
// var stdout, stderr bytes.Buffer
|
||||
// cmd.Stdout = &stdout
|
||||
// cmd.Stderr = &stderr
|
||||
// err := cmd.Start()
|
||||
// if err != nil {
|
||||
// log.Error("Faile to execute dpkg command: %v, err: %s", err, stderr.String())
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
// out, err := cmd.CombinedOutput()
|
||||
// log.Debugf("Exec output: %v", string(out))
|
||||
// if err != nil {
|
||||
// log.Error("Faile to execute dpkg command:", err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
} else {
|
||||
err := global.ErrCMUnknownSoftwareFormat
|
||||
log.Error(err)
|
||||
srcFile := fmt.Sprintf("%s/actpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
|
||||
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||
cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||
_, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
runCmd := fmt.Sprintf("sudo %s/actpkg.sh '%s' %s",
|
||||
config.GetYamlConfig().NE.ScpDir, filePath, neTypeUpper)
|
||||
if neTypeLower == "omc" {
|
||||
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
||||
neVersionData := dborm.NeVersion{
|
||||
Status: SoftwareStatusActive,
|
||||
}
|
||||
|
||||
_, err = dborm.XormUpdateTableById(idNeVersion, "ne_version", neVersionData)
|
||||
if err != nil {
|
||||
log.Error("Faile to UpdateTableById:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
services.ResponseStatusOK204NoContent(w)
|
||||
go RunSSHCmd(sshHost, runCmd)
|
||||
return
|
||||
}
|
||||
err = RunSSHCmd(sshHost, runCmd)
|
||||
if err != nil {
|
||||
log.Errorf("Faile to execute command: %s, error: %v", runCmd, err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
// fileType := global.IsRpmOrDebPackage(filePath)
|
||||
// if fileType == 1 {
|
||||
// srcFile := fmt.Sprintf("%s/spawnrpm.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
|
||||
// scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||
// neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||
// cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||
// _, err := cmd.CombinedOutput()
|
||||
// if err != nil {
|
||||
// log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// dpkgCmd := fmt.Sprintf("sudo %s/spawnrpm.sh '%s'",
|
||||
// config.GetYamlConfig().NE.ScpDir, filePath)
|
||||
// err = RunSSHCmd(sshHost, dpkgCmd)
|
||||
// if err != nil {
|
||||
// log.Errorf("Faile to execute dpkg command: %s, error: %v", dpkgCmd, err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
// } else if fileType == 2 {
|
||||
// srcFile := fmt.Sprintf("%s/spawndpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
|
||||
// scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||
// neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||
// cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||
// _, err := cmd.CombinedOutput()
|
||||
// if err != nil {
|
||||
// log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// dpkgCmd := fmt.Sprintf("sudo %s/spawndpkg.sh '%s'",
|
||||
// config.GetYamlConfig().NE.ScpDir, filePath)
|
||||
// err = RunSSHCmd(sshHost, dpkgCmd)
|
||||
// if err != nil {
|
||||
// log.Errorf("Faile to execute dpkg command: %s, error: %v", dpkgCmd, err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
// } else {
|
||||
// err := global.ErrCMUnknownSoftwareFormat
|
||||
// log.Error(err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
switch neTypeLower {
|
||||
case "omc":
|
||||
restartCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh restart", config.GetYamlConfig().NE.OmcDir)
|
||||
cmd := exec.Command("ssh", sshHost, restartCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute ssh restart omc:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
@@ -746,9 +788,9 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
restartCmd := "sudo ims-stop && sudo ims-start"
|
||||
cmd := exec.Command("ssh", sshHost, restartCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute ssh sudo systemctl command:", err)
|
||||
log.Error("Faile to execute ssh command: %s, error: %v", restartCmd, err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
@@ -756,7 +798,7 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
restartCmd := fmt.Sprintf("sudo systemctl restart %s.service", neTypeLower)
|
||||
cmd := exec.Command("ssh", sshHost, restartCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute ssh sudo systemctl command:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
@@ -844,39 +886,94 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if !config.GetYamlConfig().OMC.TestMode {
|
||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||
fileType := global.IsRpmOrDebPackage(filePath)
|
||||
if fileType == 1 {
|
||||
rpmCmd := fmt.Sprintf("sudo rpm -Uvh --oldpackage '%s'", filePath)
|
||||
cmd := exec.Command("ssh", sshHost, rpmCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute rpm command:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
} else if fileType == 2 {
|
||||
dpkgCmd := fmt.Sprintf("sudo dpkg -i --force-all '%s'", filePath)
|
||||
cmd := exec.Command("ssh", sshHost, dpkgCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute dpkg command:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
err := global.ErrCMUnknownSoftwareFormat
|
||||
log.Error(err)
|
||||
srcFile := fmt.Sprintf("%s/rbkpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
|
||||
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||
neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||
cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||
_, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
runCmd := fmt.Sprintf("sudo %s/rbkpkg.sh '%s' %s",
|
||||
config.GetYamlConfig().NE.ScpDir, filePath, neTypeUpper)
|
||||
if neTypeLower == "omc" {
|
||||
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
||||
neVersionData := dborm.NeVersion{
|
||||
Version: (*neVersion)[0]["pre_version"],
|
||||
FilePath: (*neVersion)[0]["pre_file"],
|
||||
PreVersion: "-",
|
||||
PreFile: "-",
|
||||
NewVersion: (*neVersion)[0]["version"],
|
||||
NewFile: (*neVersion)[0]["file_path"],
|
||||
Status: SoftwareStatusActive,
|
||||
}
|
||||
|
||||
_, err = dborm.XormUpdateTableById(idNeVersion, "ne_version", neVersionData)
|
||||
if err != nil {
|
||||
log.Error("Faile to UpdateTableById:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
services.ResponseStatusOK204NoContent(w)
|
||||
RunSSHCmd(sshHost, runCmd)
|
||||
return
|
||||
}
|
||||
err = RunSSHCmd(sshHost, runCmd)
|
||||
if err != nil {
|
||||
log.Errorf("Faile to execute command: %s, error: %v", runCmd, err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
// fileType := global.IsRpmOrDebPackage(filePath)
|
||||
// if fileType == 1 {
|
||||
// rpmCmd := fmt.Sprintf("sudo rpm -Uvh --oldpackage '%s'", filePath)
|
||||
// cmd := exec.Command("ssh", sshHost, rpmCmd)
|
||||
// _, err := cmd.CombinedOutput()
|
||||
// if err != nil {
|
||||
// log.Error("Faile to execute rpm command:", err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
// } else if fileType == 2 {
|
||||
// srcFile := fmt.Sprintf("%s/spawndpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||
|
||||
// scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||
// neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||
// cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||
// _, err := cmd.CombinedOutput()
|
||||
// if err != nil {
|
||||
// log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
// var inputStr string = "n"
|
||||
// if config.GetYamlConfig().NE.DpkgOverwrite {
|
||||
// inputStr = "y"
|
||||
// }
|
||||
// dpkgCmd := fmt.Sprintf("sudo %s/spawndpkg.sh %s '%s'",
|
||||
// config.GetYamlConfig().NE.ScpDir, inputStr, filePath)
|
||||
// err = RunSSHCmd(sshHost, dpkgCmd)
|
||||
// if err != nil {
|
||||
// log.Errorf("Faile to execute dpkg command: %s, error: %v", dpkgCmd, err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
// } else {
|
||||
// err := global.ErrCMUnknownSoftwareFormat
|
||||
// log.Error(err)
|
||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||
// return
|
||||
// }
|
||||
switch neTypeLower {
|
||||
case "omc":
|
||||
restartCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh restart", config.GetYamlConfig().NE.OmcDir)
|
||||
cmd := exec.Command("ssh", sshHost, restartCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute ssh restart omc:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
@@ -886,9 +983,9 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
restartCmd := "sudo ims-stop && sudo ims-start"
|
||||
cmd := exec.Command("ssh", sshHost, restartCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute ssh sudo systemctl command:", err)
|
||||
log.Error("Faile to execute ssh command: %s, error: %v", restartCmd, err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
@@ -896,7 +993,7 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||
restartCmd := fmt.Sprintf("sudo systemctl restart %s.service", neTypeLower)
|
||||
cmd := exec.Command("ssh", sshHost, restartCmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
log.Debugf("Exec output: %v", string(out))
|
||||
log.Tracef("Exec output: %v", string(out))
|
||||
if err != nil {
|
||||
log.Error("Faile to execute ssh sudo systemctl command:", err)
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
|
||||
Reference in New Issue
Block a user