diff --git a/gala-ops/server/client/client.go b/gala-ops/server/client/client.go new file mode 100644 index 0000000000000000000000000000000000000000..3abe7d986f98375cdeb21a6ca5d327e12c4815f2 --- /dev/null +++ b/gala-ops/server/client/client.go @@ -0,0 +1,47 @@ +package client + +import ( + "github.com/gin-gonic/gin" + "openeuler.org/PilotGo/gala-ops-plugin/config" + "openeuler.org/PilotGo/gala-ops-plugin/httphandler" + "openeuler.org/PilotGo/plugin-sdk/plugin" +) + +const Version = "0.0.1" + +var globalClient *plugin.Client + +func init() { + globalClient = plugin.DefaultClient(&plugin.PluginInfo{ + Name: "gala-ops", + Version: Version, + Description: "gala-ops智能运维工具", + Author: "guozhengxin", + Email: "guozhengxin@kylinos.cn", + Url: "http://192.168.48.163:9999/plugin/grafana", + // ReverseDest: "http://192.168.48.163:3000/", + }) +} + +func Client() *plugin.Client { + return globalClient +} + +func StartClient(conf *config.HttpConf) { + registerHandlers(globalClient.HttpEngine) + + globalClient.Serve(conf.Addr) +} + +func registerHandlers(engine *gin.Engine) { + api := engine.Group("/plugin/gala-ops/api") + { + // 脚本执行结果接口 + api.PUT("/run_script_result", httphandler.RunScriptResult) + + // 安装/升级/卸载gala-gopher监控终端 + api.PUT("/install_gopher", httphandler.InstallGopher) + api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) + api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) + } +} diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go index 34fd20aca349b944bea98508a4b57aff9c9969b9..4545bb6822f186dbd60fb7aa4e138007d60d9dc2 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -3,41 +3,14 @@ package main import ( "fmt" - "github.com/gin-gonic/gin" + "openeuler.org/PilotGo/gala-ops-plugin/client" "openeuler.org/PilotGo/gala-ops-plugin/config" - "openeuler.org/PilotGo/gala-ops-plugin/httphandler" - "openeuler.org/PilotGo/plugin-sdk/plugin" ) -const Version = "0.0.1" - func main() { fmt.Println("hello gala-ops") config.Init() - client := plugin.DefaultClient(&plugin.PluginInfo{ - Name: "gala-ops", - Version: Version, - Description: "gala-ops智能运维工具", - Author: "guozhengxin", - Email: "guozhengxin@kylinos.cn", - Url: "http://192.168.48.163:9999/plugin/grafana", - // ReverseDest: "http://192.168.48.163:3000/", - }) - - client.Serve(":8888") - - registerHandlers(client.HttpEngine) - -} - -func registerHandlers(engine *gin.Engine) { - api := engine.Group("/plugin/gala-ops/api") - { - // 安装/升级/卸载gala-gopher监控终端 - api.PUT("/install_gopher", httphandler.InstallGopher) - api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) - api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) - } + client.StartClient(config.Config().Http) }