forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpi_configs.go
54 lines (40 loc) · 1.05 KB
/
cpi_configs.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
package director
import (
"net/http"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type CPIConfig struct {
Properties string
}
func (d DirectorImpl) LatestCPIConfig() (CPIConfig, error) {
resps, err := d.client.CPIConfigs()
if err != nil {
return CPIConfig{}, err
}
if len(resps) == 0 {
return CPIConfig{}, bosherr.Error("No CPI config")
}
return resps[0], nil
}
func (d DirectorImpl) UpdateCPIConfig(manifest []byte) error {
return d.client.UpdateCPIConfig(manifest)
}
func (c Client) CPIConfigs() ([]CPIConfig, error) {
var resps []CPIConfig
err := c.clientRequest.Get("/cpi_configs?limit=1", &resps)
if err != nil {
return resps, bosherr.WrapErrorf(err, "Finding CPI configs")
}
return resps, nil
}
func (c Client) UpdateCPIConfig(manifest []byte) error {
path := "/cpi_configs"
setHeaders := func(req *http.Request) {
req.Header.Add("Content-Type", "text/yaml")
}
_, _, err := c.clientRequest.RawPost(path, manifest, setHeaders)
if err != nil {
return bosherr.WrapErrorf(err, "Updating CPI config")
}
return nil
}