-
Notifications
You must be signed in to change notification settings - Fork 162
/
deployments.go
129 lines (95 loc) · 2.6 KB
/
deployments.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
128
129
package director
import (
"fmt"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
semver "github.com/cppforlife/go-semi-semantic/version"
)
type DeploymentResp struct {
Name string
Manifest string
Releases []DeploymentReleaseResp
Stemcells []DeploymentStemcellResp
Teams []string
CloudConfig string `json:"cloud_config"`
}
type DeploymentReleaseResp struct {
Name string
Version string
}
type DeploymentStemcellResp struct {
Name string
Version string
}
func (d DirectorImpl) Deployments() ([]Deployment, error) {
deps := []Deployment{}
resps, err := d.client.Deployments()
if err != nil {
return deps, err
}
for _, resp := range resps {
dep := &DeploymentImpl{client: d.client, name: resp.Name}
dep.fill(resp)
deps = append(deps, dep)
}
return deps, nil
}
func (d DirectorImpl) FindDeployment(name string) (Deployment, error) {
if len(name) == 0 {
return nil, bosherr.Error("Expected non-empty deployment name")
}
return &DeploymentImpl{client: d.client, name: name}, nil
}
func (c Client) Deployments() ([]DeploymentResp, error) {
var deps []DeploymentResp
err := c.clientRequest.Get("/deployments", &deps)
if err != nil {
return deps, bosherr.WrapErrorf(err, "Finding deployments")
}
return deps, nil
}
func (c Client) Deployment(name string) (DeploymentResp, error) {
var resp DeploymentResp
if len(name) == 0 {
return resp, bosherr.Error("Expected non-empty deployment name")
}
path := fmt.Sprintf("/deployments/%s", name)
err := c.clientRequest.Get(path, &resp)
if err != nil {
return resp, bosherr.WrapErrorf(err, "Finding deployment '%s'", name)
}
return resp, nil
}
func newReleasesFromResps(resps []DeploymentReleaseResp, client Client) ([]Release, error) {
var rels []Release
for _, resp := range resps {
parsedVersion, err := semver.NewVersionFromString(resp.Version)
if err != nil {
return nil, bosherr.WrapErrorf(
err, "Parsing version for release '%s/%s'", resp.Name, resp.Version)
}
rel := &ReleaseImpl{
client: client,
name: resp.Name,
version: parsedVersion,
}
rels = append(rels, rel)
}
return rels, nil
}
func newStemcellsFromResps(resps []DeploymentStemcellResp, client Client) ([]Stemcell, error) {
var stems []Stemcell
for _, resp := range resps {
parsedVersion, err := semver.NewVersionFromString(resp.Version)
if err != nil {
return nil, bosherr.WrapErrorf(
err, "Parsing version for stemcell '%s/%s'", resp.Name, resp.Version)
}
stemcell := StemcellImpl{
client: client,
name: resp.Name,
version: parsedVersion,
}
stems = append(stems, stemcell)
}
return stems, nil
}