forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
droplet.go
77 lines (65 loc) · 2.1 KB
/
droplet.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
package ccv3
import (
"net/url"
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
)
type DropletState string
const (
DropletStateStaged DropletState = "STAGED"
DropletStateFailed DropletState = "FAILED"
DropletStateCopying DropletState = "COPYING"
DropletStateExpired DropletState = "EXPIRED"
)
type Droplet struct {
GUID string `json:"guid"`
State DropletState `json:"state"`
CreatedAt string `json:"created_at"`
Stack string `json:"stack,omitempty"`
Buildpacks []DropletBuildpack `json:"buildpacks,omitempty"`
Image string `json:"image"`
}
type DropletBuildpack struct {
Name string `json:"name"`
DetectOutput string `json:"detect_output"`
}
// GetApplicationDroplets returns the Droplets for a given app
func (client *Client) GetApplicationDroplets(appGUID string, query url.Values) ([]Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetAppDropletsRequest,
URIParams: map[string]string{"app_guid": appGUID},
Query: query,
})
if err != nil {
return nil, nil, err
}
var responseDroplets []Droplet
warnings, err := client.paginate(request, Droplet{}, func(item interface{}) error {
if droplet, ok := item.(Droplet); ok {
responseDroplets = append(responseDroplets, droplet)
} else {
return ccerror.UnknownObjectInListError{
Expected: Droplet{},
Unexpected: item,
}
}
return nil
})
return responseDroplets, warnings, err
}
func (client *Client) GetDroplet(dropletGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletRequest,
URIParams: map[string]string{"droplet_guid": dropletGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
Result: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
}