diff --git a/configmanage/server/service/sshd.go b/configmanage/server/service/sshd.go index fedb94ee7025d40b77f3becff4764ff68da0e0f5..25ddf1bc9ac540703aa2285e67529fffb469e305 100644 --- a/configmanage/server/service/sshd.go +++ b/configmanage/server/service/sshd.go @@ -13,6 +13,7 @@ import ( "gitee.com/openeuler/PilotGo/sdk/plugin/client" "gitee.com/openeuler/PilotGo/sdk/utils/httputils" "github.com/google/uuid" + "openeuler.org/PilotGo/configmanage-plugin/global" "openeuler.org/PilotGo/configmanage-plugin/internal" ) @@ -83,7 +84,7 @@ func (sdc *SSHDConfig) Load() error { } // TODO: -func (sdc *SSHDConfig) Apply() (json.RawMessage, error) { +func (sdc *SSHDConfig) Apply() ([]NodeResult, error) { // 从数据库获取下发的信息 sdf, err := internal.GetSSHDFileByUUID(sdc.UUID) if err != nil { @@ -107,21 +108,21 @@ func (sdc *SSHDConfig) Apply() (json.RawMessage, error) { } // 从hc中解析下发的文件内容,逐一进行下发 - Repofile := common.File{} - err = json.Unmarshal([]byte(sdf.Content), &Repofile) + sshdfile := common.File{} + err = json.Unmarshal([]byte(sdf.Content), &sshdfile) if err != nil { return nil, err } - result := "" + results := []NodeResult{} de := Deploy{ DeployBatch: common.Batch{ BatchIds: batchids, DepartmentIDs: departids, MachineUUIDs: nodes, }, - DeployPath: Repofile.Path, - DeployFileName: Repofile.Name, - DeployText: Repofile.Content, + DeployPath: sshdfile.Path, + DeployFileName: sshdfile.Name, + DeployText: sshdfile.Content, } url := "http://" + client.GetClient().Server() + "/api/v1/pluginapi/file_deploy" r, err := httputils.Post(url, &httputils.Params{ @@ -149,17 +150,23 @@ func (sdc *SSHDConfig) Apply() (json.RawMessage, error) { // 将执行失败的文件、机器信息和原因添加到结果字符串中 for _, d := range data { if d.Error != "" { - result = result + Repofile.Content + "文件" + d.UUID + ":" + d.Error + "\n" + results = append(results, NodeResult{ + Type: global.SSHD, + NodeUUID: d.UUID, + Detail: sshdfile.Content, + Result: false, + Err: d.Error, + }) } } // TODO:部分成功如何修改数据库 - if result == "" { + if results == nil { //下发成功修改数据库应用版本 err = sdf.UpdateByuuid() return nil, err } - return nil, errors.New(result + "failed to apply SSHDConfig") + return results, errors.New("failed to apply SSHDConfig") } func (sdc *SSHDConfig) Collect() error {