-
Notifications
You must be signed in to change notification settings - Fork 2
/
trekMappings.go
74 lines (56 loc) · 1.77 KB
/
trekMappings.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
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"log"
"github.com/hashicorp/nomad/api"
nomad "github.com/hashicorp/nomad/api"
)
func buildNetwork(networks []*api.NetworkResource) trekCommandNetwork {
network := trekCommandNetwork{}
network.DynamicPorts = make([]trekCommandPort, 0)
network.ReservedPorts = make([]trekCommandPort, 0)
if len(networks) > 1 {
log.Panicf("Found more than one network. Exiting...")
}
for _, reservedPort := range networks[0].ReservedPorts {
network.ReservedPorts = append(network.ReservedPorts, trekCommandPort{Name: reservedPort.Label, Number: reservedPort.Value})
}
for _, dynPort := range networks[0].DynamicPorts {
network.DynamicPorts = append(network.DynamicPorts, trekCommandPort{Name: dynPort.Label, Number: dynPort.Value})
}
return network
}
func buildEnv(env map[string]string) trekCommandEnvironment {
resultingEnv := trekCommandEnvironment{}
for key, value := range env {
resultingEnv[key] = trekCommandEnvironmentVariable{Value: value}
}
return resultingEnv
}
func buildTasks(tasks []*nomad.Task) []trekTask {
result := make([]trekTask, 0)
for _, task := range tasks {
result = append(result, trekTask{Name: task.Name})
}
return result
}
func buildAllocations(allocs []nomad.Allocation) []trekAllocation {
result := make([]trekAllocation, 0)
for _, alloc := range allocs {
result = append(result, trekAllocation{Name: alloc.Name})
}
return result
}
func buildTaskGroups(tgs []*nomad.TaskGroup) []trekTaskGroup {
result := make([]trekTaskGroup, 0)
for _, taskGroup := range tgs {
result = append(result, trekTaskGroup{Name: *taskGroup.Name})
}
return result
}
func buildJobs(jobs []nomad.Job) []trekJob {
result := make([]trekJob, 0)
for _, job := range jobs {
result = append(result, trekJob{Name: *job.Name})
}
return result
}