rpm&deb
This commit is contained in:
@@ -595,7 +595,6 @@ func DistributeSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
services.ResponseStatusOK204NoContent(w)
|
services.ResponseStatusOK204NoContent(w)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -669,6 +668,12 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
if !config.GetYamlConfig().OMC.TestMode {
|
if !config.GetYamlConfig().OMC.TestMode {
|
||||||
filePath := (*neVersion)[0]["file_path"]
|
filePath := (*neVersion)[0]["file_path"]
|
||||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||||
|
fileType, err := global.JudgeRpmOrDebPackage(filePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to JudgeRpmOrDebPackage:", err)
|
||||||
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
}
|
||||||
|
if fileType == 1 {
|
||||||
rpmCmd := fmt.Sprintf("sudo rpm -Uvh '%s'", filePath)
|
rpmCmd := fmt.Sprintf("sudo rpm -Uvh '%s'", filePath)
|
||||||
cmd := exec.Command("ssh", sshHost, rpmCmd)
|
cmd := exec.Command("ssh", sshHost, rpmCmd)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
@@ -678,6 +683,22 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if fileType == 2 {
|
||||||
|
dpkgCmd := fmt.Sprintf("sudo dpkg -i '%s'", filePath)
|
||||||
|
cmd := exec.Command("ssh", sshHost, dpkgCmd)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
log.Tracef("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)
|
||||||
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
||||||
@@ -759,7 +780,13 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if !config.GetYamlConfig().OMC.TestMode {
|
if !config.GetYamlConfig().OMC.TestMode {
|
||||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||||
rpmCmd := fmt.Sprintf("rpm -Uvh --oldpackage '%s'", filePath)
|
fileType, err := global.JudgeRpmOrDebPackage(filePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to JudgeRpmOrDebPackage:", err)
|
||||||
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
}
|
||||||
|
if fileType == 1 {
|
||||||
|
rpmCmd := fmt.Sprintf("sudo rpm -Uvh --oldpackage '%s'", filePath)
|
||||||
cmd := exec.Command("ssh", sshHost, rpmCmd)
|
cmd := exec.Command("ssh", sshHost, rpmCmd)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
log.Tracef("Exec output: %v", string(out))
|
log.Tracef("Exec output: %v", string(out))
|
||||||
@@ -768,6 +795,22 @@ func RollBackSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if fileType == 2 {
|
||||||
|
dpkgCmd := fmt.Sprintf("sudo dpkg -i '%s'", filePath)
|
||||||
|
cmd := exec.Command("ssh", sshHost, dpkgCmd)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
log.Tracef("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)
|
||||||
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
idNeVersion, _ := strconv.Atoi((*neVersion)[0]["id"])
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ var (
|
|||||||
ErrCMNotFoundRollbackNeVersion = errors.New("not found the rollback NE version")
|
ErrCMNotFoundRollbackNeVersion = errors.New("not found the rollback NE version")
|
||||||
|
|
||||||
ErrCMNotFoundTargetBackupFile = errors.New("not found the target NE backup")
|
ErrCMNotFoundTargetBackupFile = errors.New("not found the target NE backup")
|
||||||
|
ErrCMUnknownSoftwareFormat = errors.New("unknown software package format") // 未知软件包格式
|
||||||
|
|
||||||
// TRACE module error message
|
// TRACE module error message
|
||||||
ErrTraceFailedDistributeToNEs = errors.New("failed to distribute trace task to target NEs")
|
ErrTraceFailedDistributeToNEs = errors.New("failed to distribute trace task to target NEs")
|
||||||
|
|||||||
@@ -585,3 +585,31 @@ func ZipDirectoryFile(srcDir, dstZip string) error {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断软件包是rpm或者deb, 1:rpm, 2:deb, 0:unknown format
|
||||||
|
func JudgeRpmOrDebPackage(filePath string) (int, error) {
|
||||||
|
var fileType int = 0
|
||||||
|
file, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return fileType, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// Read the first 6 bytes of the file
|
||||||
|
header := make([]byte, 6)
|
||||||
|
_, err = file.Read(header)
|
||||||
|
if err != nil {
|
||||||
|
return fileType, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the magic numbers to determine the package format
|
||||||
|
if string(header) == "!<arch>" {
|
||||||
|
fileType = 1
|
||||||
|
} else if string(header) == "!<arch\n" || string(header) == "!<arch\r" {
|
||||||
|
fileType = 2
|
||||||
|
} else {
|
||||||
|
fileType = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileType, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user