forked from cloudfoundry/bosh-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boshcli.go
127 lines (110 loc) · 2.82 KB
/
boshcli.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package actors
import (
"fmt"
"os/exec"
)
type BOSHCLI struct{}
func NewBOSHCLI() BOSHCLI {
return BOSHCLI{}
}
func (BOSHCLI) DirectorExists(address, caCertPath string) (bool, error) {
_, err := exec.Command("bosh",
"--ca-cert", caCertPath,
"-e", address,
"env",
).Output()
return err == nil, err
}
func (BOSHCLI) Env(address, caCertPath string) (string, error) {
env, err := exec.Command("bosh",
"--ca-cert", caCertPath,
"-e", address,
"env",
).Output()
return string(env), err
}
func (BOSHCLI) CloudConfig(address, caCertPath, username, password string) (string, error) {
cloudConfig, err := exec.Command("bosh",
"--ca-cert", caCertPath,
"--client", username,
"--client-secret", password,
"-e", address,
"cloud-config",
).Output()
return string(cloudConfig), err
}
func (BOSHCLI) DeleteEnv(stateFilePath, manifestPath string) error {
_, err := exec.Command(
"bosh",
"delete-env",
fmt.Sprintf("--state=%s", stateFilePath),
manifestPath,
).Output()
return err
}
func (BOSHCLI) Deploy(address, caCertPath, username, password, deployment, manifest, varsStore string, opsFiles []string, vars map[string]string) error {
args := []string{
"--ca-cert", caCertPath,
"--client", username,
"--client-secret", password,
"-e", address,
"-d", deployment,
"deploy", manifest,
"--vars-store", varsStore,
"-n",
}
for _, opsFile := range opsFiles {
args = append(args, "-o", opsFile)
}
for key, value := range vars {
args = append(args, "-v", fmt.Sprintf("%s=%s", key, value))
}
return exec.Command("bosh", args...).Run()
}
func (BOSHCLI) UploadRelease(address, caCertPath, username, password, releasePath string) error {
err := exec.Command("bosh",
"--ca-cert", caCertPath,
"--client", username,
"--client-secret", password,
"-e", address,
"upload-release", releasePath,
).Run()
if err != nil {
fmt.Printf("bosh upload-release output: %s\n", string(err.(*exec.ExitError).Stderr))
}
return err
}
func (BOSHCLI) UploadStemcell(address, caCertPath, username, password, stemcellPath string) error {
return exec.Command("bosh",
"--ca-cert", caCertPath,
"--client", username,
"--client-secret", password,
"-e", address,
"upload-stemcell", stemcellPath,
).Run()
}
func (BOSHCLI) VMs(address, caCertPath, username, password, deployment string) (string, error) {
output, err := exec.Command("bosh",
"--ca-cert", caCertPath,
"--client", username,
"--client-secret", password,
"-e", address,
"-d", deployment,
"vms",
).Output()
if err != nil {
return "", err
}
return string(output), nil
}
func (BOSHCLI) DeleteDeployment(address, caCertPath, username, password, deployment string) error {
return exec.Command("bosh",
"--ca-cert", caCertPath,
"--client", username,
"--client-secret", password,
"-e", address,
"-d", deployment,
"delete-deployment",
"-n",
).Run()
}