-
Notifications
You must be signed in to change notification settings - Fork 115
/
v1_apply_spec.go
102 lines (84 loc) · 2.87 KB
/
v1_apply_spec.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package applyspec
import (
"encoding/json"
"github.com/cloudfoundry/bosh-agent/agent/applier/models"
)
type V1ApplySpec struct {
PropertiesSpec PropertiesSpec `json:"properties"`
JobSpec JobSpec `json:"job"`
PackageSpecs map[string]PackageSpec `json:"packages"`
ConfigurationHash string `json:"configuration_hash"`
NetworkSpecs map[string]NetworkSpec `json:"networks"`
ResourcePoolSpecs interface{} `json:"resource_pool"`
Deployment string `json:"deployment"`
Name string `json:"name"`
// Since default value of int is 0 use pointer
// to indicate that state does not have an assigned index
// (json.Marshal will result in null instead of 0).
Index *int `json:"index"`
NodeID string `json:"id"`
AvailabilityZone string `json:"az"`
PersistentDisk int `json:"persistent_disk"`
RenderedTemplatesArchiveSpec *RenderedTemplatesArchiveSpec `json:"rendered_templates_archive"`
}
type PropertiesSpec struct {
LoggingSpec LoggingSpec `json:"logging"`
}
type LoggingSpec struct {
MaxLogFileSize string `json:"max_log_file_size"`
}
const (
NetworkSpecTypeDynamic = "dynamic"
)
type NetworkSpec struct {
// Instead of explicitly specifying all network fields,
// keep original hash that Director sent because
// Director will later fetch current apply spec via get_state
// and use absolute equality to determine network changes.
//
// Ideally we would explicitly call out fields (like in 40276d6 commit)
// and Director would check for equivalence instead of absolute hash equality.
Fields map[string]interface{}
}
// Jobs returns a list of pre-rendered job templates
// extracted from a single tarball provided by BOSH director.
func (s V1ApplySpec) Jobs() []models.Job {
jobsWithSource := []models.Job{}
if s.RenderedTemplatesArchiveSpec != nil {
for _, j := range s.JobSpec.JobTemplateSpecsAsJobs() {
j.Source = s.RenderedTemplatesArchiveSpec.AsSource(j)
j.Packages = s.Packages()
jobsWithSource = append(jobsWithSource, j)
}
}
return jobsWithSource
}
func (s V1ApplySpec) Packages() []models.Package {
packages := []models.Package{}
for _, value := range s.PackageSpecs {
packages = append(packages, value.AsPackage())
}
return packages
}
func (s V1ApplySpec) MaxLogFileSize() string {
fileSize := s.PropertiesSpec.LoggingSpec.MaxLogFileSize
if len(fileSize) > 0 {
return fileSize
}
return "50M"
}
func (s NetworkSpec) PopulateIPInfo(ip, netmask, gateway string) NetworkSpec {
if s.Fields == nil {
s.Fields = map[string]interface{}{}
}
s.Fields["ip"] = ip
s.Fields["netmask"] = netmask
s.Fields["gateway"] = gateway
return s
}
func (s *NetworkSpec) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &s.Fields)
}
func (s NetworkSpec) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Fields)
}