-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.go
35 lines (30 loc) · 1.13 KB
/
build.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
package machina
import "fmt"
// Build takes the machina virtual machine definition present in m and merges
// it with the applicable tag definitions present in sys. It returns the
// merged definition.
func Build(m Machine, sys System) (merged Definition, err error) {
// Collect all of the tag definitions
defs, err := sys.Tag.Collect(m.Tags...)
if err != nil {
return Definition{}, fmt.Errorf("failed to build machine %s: %v", m.Name, err)
}
// Merge the machine's definition with its tag definitions
defs = append([]Definition{m.Definition}, defs...)
merged = MergeDefinitions(defs...)
// Generate group IDs, world wide names, device IDs and hardware addresses
// as necessary. Use the machine's identifiers as a seed state for
// deterministic generation of values.
seed := m.Info().Seed()
merged.Privileges = merged.Privileges.Populate(seed)
for i, volume := range merged.Volumes {
merged.Volumes[i] = volume.Populate(seed)
}
for i, conn := range merged.Connections {
merged.Connections[i] = conn.Populate(seed)
}
for i, device := range merged.Devices {
merged.Devices[i] = device.Populate(seed)
}
return merged, nil
}