-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathcpu.go
More file actions
56 lines (46 loc) · 1.19 KB
/
cpu.go
File metadata and controls
56 lines (46 loc) · 1.19 KB
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
package sdl
import (
"fmt"
"sort"
"gopkg.in/yaml.v3"
types "github.com/akash-network/akash-api/go/node/types/v1beta3"
)
type v2CPUAttributes types.Attributes
type v2ResourceCPU struct {
Units cpuQuantity `yaml:"units"`
Attributes v2CPUAttributes `yaml:"attributes,omitempty"`
}
func (sdl *v2CPUAttributes) UnmarshalYAML(node *yaml.Node) error {
var attr v2CPUAttributes
for i := 0; i+1 < len(node.Content); i += 2 {
switch node.Content[i].Value {
case "arch":
// Support both string and slice of strings
var archs []string
if node.Content[i+1].Kind == yaml.SequenceNode {
if err := node.Content[i+1].Decode(&archs); err != nil {
return err
}
} else {
var single string
if err := node.Content[i+1].Decode(&single); err != nil {
return err
}
archs = append(archs, single)
}
for _, value := range archs {
attr = append(attr, types.Attribute{
Key: fmt.Sprintf("capabilities/cpu/arch/%s", value),
Value: "true",
})
}
default:
return fmt.Errorf("unsupported cpu attribute \"%s\"", node.Content[i].Value)
}
}
sort.Slice(attr, func(i, j int) bool {
return attr[i].Key < attr[j].Key
})
*sdl = attr
return nil
}