This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
/
deploy_with_static.go
109 lines (91 loc) · 2.68 KB
/
deploy_with_static.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
103
104
105
106
107
108
109
package action
import (
"bytes"
"fmt"
"net"
"text/template"
bltclirunner "github.com/cloudfoundry-incubator/bosh-load-tests/action/clirunner"
bltassets "github.com/cloudfoundry-incubator/bosh-load-tests/assets"
"strings"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type deployWithStatic struct {
directorInfo DirectorInfo
flowNumber int
deploymentName string
cliRunner bltclirunner.Runner
fs boshsys.FileSystem
assetsProvider bltassets.Provider
usingLegacyManifest bool
}
func NewDeployWithStatic(
directorInfo DirectorInfo,
flowNumber int,
deploymentName string,
cliRunner bltclirunner.Runner,
fs boshsys.FileSystem,
assetsProvider bltassets.Provider,
usingLegacyManifest bool,
) *deployWithStatic {
return &deployWithStatic{
directorInfo: directorInfo,
flowNumber: flowNumber,
deploymentName: deploymentName,
cliRunner: cliRunner,
fs: fs,
assetsProvider: assetsProvider,
usingLegacyManifest: usingLegacyManifest,
}
}
var numInstancesPerFlow = 5
func (d *deployWithStatic) Execute() error {
d.cliRunner.SetEnv(d.directorInfo.URL)
manifestFilename := "manifest_with_static.yml"
if d.usingLegacyManifest == true {
manifestFilename = "legacy_manifest_with_static.yml"
}
manifestTemplatePath, err := d.assetsProvider.FullPath(manifestFilename)
if err != nil {
return err
}
manifestPath, err := d.fs.TempFile("manifest-test")
if err != nil {
return err
}
defer d.fs.RemoveAll(manifestPath.Name())
t := template.Must(template.ParseFiles(manifestTemplatePath))
buffer := bytes.NewBuffer([]byte{})
var staticIPs []string
for i := 0; i < numInstancesPerFlow; i++ {
staticIPs = append(staticIPs, d.GetNextIP(i))
}
data := manifestData{
DeploymentName: d.deploymentName,
DirectorUUID: d.directorInfo.UUID,
DeploymentIndex: d.flowNumber,
StaticIPs: strings.Join(staticIPs, ","),
NumInstances: numInstancesPerFlow,
}
err = t.Execute(buffer, data)
if err != nil {
return err
}
err = d.fs.WriteFile(manifestPath.Name(), buffer.Bytes())
if err != nil {
return err
}
deployWrapper := NewDeployWrapper(d.cliRunner)
_, err = deployWrapper.RunWithDebug("-d", d.deploymentName, "deploy", manifestPath.Name())
if err != nil {
return err
}
return nil
}
func (d *deployWithStatic) GetNextIP(i int) string {
ip := net.ParseIP(fmt.Sprintf("10.245.%d.0", d.flowNumber))
b := ip.To4()
reservedRange := 11 // reserve 10.245.0.0 to 10.245.0.10. bosh director lives at 10.245.0.3
instanceIndex := reservedRange + numInstancesPerFlow + i
b[3] = b[3] + byte(1+(instanceIndex%253))
return net.IPv4(b[0], b[1], b[2], b[3]).String()
}