github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/api/cloudcontroller/ccv3/droplet.go (about) 1 package ccv3 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 8 ) 9 10 // Droplet represents a Cloud Controller droplet's metadata. A droplet is a set of 11 // compiled bits for a given application. 12 type Droplet struct { 13 //Buildpacks are the detected buildpacks from the staging process. 14 Buildpacks []DropletBuildpack `json:"buildpacks,omitempty"` 15 // CreatedAt is the timestamp that the Cloud Controller created the droplet. 16 CreatedAt string `json:"created_at"` 17 // GUID is the unique droplet identifier. 18 GUID string `json:"guid"` 19 // Image is the Docker image name. 20 Image string `json:"image"` 21 // Stack is the root filesystem to use with the buildpack. 22 Stack string `json:"stack,omitempty"` 23 // State is the current state of the droplet. 24 State constant.DropletState `json:"state"` 25 } 26 27 // DropletBuildpack is the name and output of a buildpack used to create a 28 // droplet. 29 type DropletBuildpack struct { 30 // Name is the buildpack name. 31 Name string `json:"name"` 32 //DetectOutput is the output during buildpack detect process. 33 DetectOutput string `json:"detect_output"` 34 } 35 36 // GetApplicationDropletCurrent returns the current droplet for a given 37 // application. 38 func (client *Client) GetApplicationDropletCurrent(appGUID string) (Droplet, Warnings, error) { 39 request, err := client.newHTTPRequest(requestOptions{ 40 RequestName: internal.GetApplicationDropletCurrentRequest, 41 URIParams: map[string]string{"app_guid": appGUID}, 42 }) 43 if err != nil { 44 return Droplet{}, nil, err 45 } 46 47 var responseDroplet Droplet 48 response := cloudcontroller.Response{ 49 Result: &responseDroplet, 50 } 51 err = client.connection.Make(request, &response) 52 return responseDroplet, response.Warnings, err 53 } 54 55 // GetDroplet returns a droplet with the given GUID. 56 func (client *Client) GetDroplet(dropletGUID string) (Droplet, Warnings, error) { 57 request, err := client.newHTTPRequest(requestOptions{ 58 RequestName: internal.GetDropletRequest, 59 URIParams: map[string]string{"droplet_guid": dropletGUID}, 60 }) 61 if err != nil { 62 return Droplet{}, nil, err 63 } 64 65 var responseDroplet Droplet 66 response := cloudcontroller.Response{ 67 Result: &responseDroplet, 68 } 69 err = client.connection.Make(request, &response) 70 71 return responseDroplet, response.Warnings, err 72 } 73 74 // GetDroplets lists droplets with optional filters. 75 func (client *Client) GetDroplets(query ...Query) ([]Droplet, Warnings, error) { 76 request, err := client.newHTTPRequest(requestOptions{ 77 RequestName: internal.GetDropletsRequest, 78 Query: query, 79 }) 80 if err != nil { 81 return nil, nil, err 82 } 83 84 var responseDroplets []Droplet 85 warnings, err := client.paginate(request, Droplet{}, func(item interface{}) error { 86 if droplet, ok := item.(Droplet); ok { 87 responseDroplets = append(responseDroplets, droplet) 88 } else { 89 return ccerror.UnknownObjectInListError{ 90 Expected: Droplet{}, 91 Unexpected: item, 92 } 93 } 94 return nil 95 }) 96 97 return responseDroplets, warnings, err 98 }