diff --git a/sdk/common/machine.go b/sdk/common/machine.go index 64e86af2d2c6876fb3019b07ab134a255cd85298..dbb61531d42af4be3bedf6fd9e9e2984793bd985 100644 --- a/sdk/common/machine.go +++ b/sdk/common/machine.go @@ -1,16 +1,16 @@ package common type MachineNode struct { - UUID string - Department string - IP string - CPUArch string - OSInfo string - State int + UUID string `json:"uuid"` + Department string `json:"department"` + IP string `json:"ip"` + CPUArch string `json:"cpu_arch"` + OS string `json:"os` + State int `json:"state"` } type Batch struct { - BatchUUID string - DepartmentIDs []string - MachineUUIDs []string + BatchUUID string `json:"batch_id"` + DepartmentIDs []string `json:"department_ids"` + MachineUUIDs []string `json:"machine_uuids"` } diff --git a/sdk/plugin/client/script.go b/sdk/plugin/client/script.go index dc3d923d39229cd672d051918ce13a8aa411a95c..51b0056e23d86235560d3ecdbdc9f52cc36dba4a 100644 --- a/sdk/plugin/client/script.go +++ b/sdk/plugin/client/script.go @@ -1,36 +1,61 @@ package client import ( + "encoding/base64" "encoding/json" - "io" - "net/http" "gitee.com/openeuler/PilotGo-plugins/sdk/common" + "gitee.com/openeuler/PilotGo-plugins/sdk/utils/httputils" ) type CmdResult struct { MachineUUID string MachineIP string - Code int + RetCode int Stdout string Stderr string } -func (c *Client) RunScript(batch *common.Batch, cmd string) ([]*CmdResult, error) { - url := c.Server + "/api/v1/pluginapi/run_script" - req, err := http.NewRequest("POST", url, nil) +func (c *Client) RunCommand(batch *common.Batch, cmd string) ([]*CmdResult, error) { + url := c.Server + "/api/v1/pluginapi/run_command" + + p := &struct { + Batch *common.Batch `json:"batch"` + Command string `json:"command"` + }{ + Batch: batch, + Command: base64.StdEncoding.EncodeToString([]byte(cmd)), + } + + bs, err := httputils.Post(url, &httputils.Params{ + Body: p, + }) if err != nil { return nil, err } - hc := &http.Client{} - resp, err := hc.Do(req) - if err != nil { + res := []*CmdResult{} + if err := json.Unmarshal(bs, &res); err != nil { return nil, err } - defer resp.Body.Close() - bs, err := io.ReadAll(resp.Body) + return res, nil +} + +func (c *Client) RunScript(batch *common.Batch, script string) ([]*CmdResult, error) { + url := c.Server + "/api/v1/pluginapi/run_script" + + p := &struct { + Batch *common.Batch `json:"batch"` + Script string `json:"script"` + }{ + Batch: batch, + Script: base64.StdEncoding.EncodeToString([]byte(script)), + } + + bs, err := httputils.Post(url, &httputils.Params{ + Body: p, + }) if err != nil { return nil, err }