-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate.go
55 lines (49 loc) · 1.27 KB
/
generate.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
package main
import (
crand "crypto/rand"
"encoding/hex"
"math/rand"
"github.com/jimenez/mesos-APIproto/mesosproto"
)
func generateID() (string, error) {
id := make([]byte, 6)
n, err := crand.Read(id)
if n != len(id) || err != nil {
return "", err
}
return hex.EncodeToString(id), nil
}
func createRangeResource(name string, begin uint64) *mesosproto.Resource {
disk := mesosproto.Resource_DiskInfo{}
end := begin + 10000
return &mesosproto.Resource{
Name: &name,
Type: mesosproto.Value_RANGES.Enum(),
Ranges: &mesosproto.Value_Ranges{
Range: []*mesosproto.Value_Range{
&mesosproto.Value_Range{
Begin: &begin,
End: &end,
},
},
},
Disk: &disk,
}
}
func createScalarResource(name string, value float64) *mesosproto.Resource {
disk := mesosproto.Resource_DiskInfo{}
return &mesosproto.Resource{
Name: &name,
Type: mesosproto.Value_SCALAR.Enum(),
Scalar: &mesosproto.Value_Scalar{Value: &value},
Disk: &disk,
}
}
func resources() []*mesosproto.Resource {
return []*mesosproto.Resource{
createScalarResource("cpus", float64(rand.Intn(32))),
createScalarResource("mem", float64(rand.Intn(32)*1024)),
createScalarResource("disk", float64(rand.Intn(100000))),
createRangeResource("ports", uint64(1024+rand.Intn(10000))),
}
}