From 172f9e8e0ca8d7cb438e4041bb4043de3cd1e0c4 Mon Sep 17 00:00:00 2001 From: Gzx1999 Date: Thu, 6 Apr 2023 18:13:30 +0800 Subject: [PATCH] add uninstall gala-gopher implement --- gala-ops/server/httphandler/agent.go | 46 +++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index a39723f9..661e6c54 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, + }) } -- Gitee