diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index a39723f96bd271886c05b08c8d6d7691bcd0fd77..661e6c54d36cddf85ac7ca6dd458eed6fbfa3fd4 100644 --- a/gala-ops/server/httphandler/agent.go +++ b/gala-ops/server/httphandler/agent.go @@ -51,7 +51,7 @@ func InstallGopher(ctx *gin.Context) { ctx.JSON(http.StatusOK, gin.H{ "code": 0, - "status": fmt.Sprintf("run remote script error:%s", err), + "status": "ok", "data": ret, }) } @@ -62,4 +62,48 @@ func UpgradeGopher(ctx *gin.Context) { func UninstallGopher(ctx *gin.Context) { // TODO + param := &struct { + Batch []string + }{} + if err := ctx.BindJSON(param); err != nil { + ctx.JSON(http.StatusBadRequest, gin.H{ + "code": -1, + "status": "parameter error", + }) + } + + cmd := "yum autoremove -y gala-gopher" + cmdResults, err := pluginclient.Client().RunScript(param.Batch, cmd) + if err != nil { + ctx.JSON(http.StatusBadRequest, gin.H{ + "code": -1, + "status": fmt.Sprintf("run remote script error:%s", err), + }) + } + + ret := []interface{}{} + for _, result := range cmdResults { + d := struct { + MachineUUID string + UninstallStatus string + Error string + }{ + MachineUUID: result.MachineUUID, + UninstallStatus: "ok", + Error: "", + } + + if result.Code != 0 { + d.UninstallStatus = "error" + d.Error = result.Stderr + } + + ret = append(ret, d) + } + + ctx.JSON(http.StatusOK, gin.H{ + "code": 0, + "status": "ok", + "data": ret, + }) }