-
Notifications
You must be signed in to change notification settings - Fork 4
/
zlog.go
61 lines (51 loc) · 1.2 KB
/
zlog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Package workloads includes workloads types (vm, zdb, QSFS, public IP, gateway name, gateway fqdn, disk)
package workloads
import (
"crypto/md5"
"encoding/hex"
"github.com/threefoldtech/zos/pkg/gridtypes"
"github.com/threefoldtech/zos/pkg/gridtypes/zos"
)
// Zlog logger struct
type Zlog struct {
Zmachine string `json:"zmachine"`
Output string `json:"output"`
}
// ZosWorkload generates a zlog workload
func (zlog *Zlog) ZosWorkload() gridtypes.Workload {
url := []byte(zlog.Output)
urlHash := md5.Sum(url)
return gridtypes.Workload{
Version: 0,
Name: gridtypes.Name(hex.EncodeToString(urlHash[:])),
Type: zos.ZLogsType,
Data: gridtypes.MustMarshal(zos.ZLogs{
ZMachine: gridtypes.Name(zlog.Zmachine),
Output: zlog.Output,
}),
}
}
func zlogs(dl *gridtypes.Deployment, name string) []Zlog {
var res []Zlog
for _, wl := range dl.ByType(zos.ZLogsType) {
if !wl.Result.State.IsOkay() {
continue
}
dataI, err := wl.WorkloadData()
if err != nil {
continue
}
data, ok := dataI.(*zos.ZLogs)
if !ok {
continue
}
if data.ZMachine.String() != name {
continue
}
res = append(res, Zlog{
Output: data.Output,
Zmachine: name,
})
}
return res
}