diff --git a/configmanage/server/service/host.go b/configmanage/server/service/host.go index 5b36d2f4849053ec3c3a15d1bacbd0bf40e1bc08..f09b6d9f8c5a50bb1119d3b17f6346e6cf580943 100644 --- a/configmanage/server/service/host.go +++ b/configmanage/server/service/host.go @@ -48,6 +48,18 @@ func (hc *HostConfig) toHostFile() HostFile { } } +func toHostConfig(hf *HostFile) HostConfig { + return HostConfig{ + UUID: hf.UUID, + ConfigInfoUUID: hf.ConfigInfoUUID, + Path: hf.Path, + Name: hf.Name, + Content: hf.Content, + Version: hf.Version, + IsActive: hf.IsActive, + } +} + func (hc *HostConfig) Record() error { //检查info的uuid是否存在 ci, err := GetInfoByUUID(hc.ConfigInfoUUID) @@ -162,3 +174,22 @@ func (hc *HostConfig) Collect() error { func GetHostFilesByConfigUUID(uuid string) ([]HostFile, error) { return internal.GetHostFilesByConfigUUID(uuid) } + +// 查看某台机器某种类型的的历史配置信息 +func GetHostFilesByNode(nodeid string) ([]HostConfig, error) { + // 查找本台机器所属的配置uuid + config_nodes, err := internal.GetConfigNodesByNode(nodeid) + if err != nil { + return nil, err + } + var hcs []HostConfig + for _, v := range config_nodes { + hf, err := internal.GetHostFileByInfoUUID(v.ConfigInfoUUID, nil) + if err != nil { + return nil, err + } + hc := toHostConfig(&hf) + hcs = append(hcs, hc) + } + return hcs, nil +} diff --git a/configmanage/server/service/host_test.go b/configmanage/server/service/host_test.go index bbb2711a93189ab4bc8b7dc7761c727b386d17e5..89c38df301cc5741a3048d4996ae493c3471ae8b 100644 --- a/configmanage/server/service/host_test.go +++ b/configmanage/server/service/host_test.go @@ -68,3 +68,16 @@ func TestGetHostFilesByConfigUUID(t *testing.T) { } fmt.Println(len(files)) } + +func TestGetHostFilesByNode(t *testing.T) { + // 设置测试数据 + nodeid := "11111111-5f8e-42df-b2d0-49bf55cfeb56" + + // 调用被测试的函数 + rcs, err := GetHostFilesByNode(nodeid) + if err != nil { + fmt.Printf("GetHostFilesByNode error: %s\n", err) + os.Exit(-1) + } + fmt.Println(len(rcs)) +}