github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  	GUID       string                `json:"guid"`
    14  	State      constant.DropletState `json:"state"`
    15  	CreatedAt  string                `json:"created_at"`
    16  	Stack      string                `json:"stack,omitempty"`
    17  	Buildpacks []DropletBuildpack    `json:"buildpacks,omitempty"`
    18  	Image      string                `json:"image"`
    19  }
    20  
    21  type DropletBuildpack struct {
    22  	Name         string `json:"name"`
    23  	DetectOutput string `json:"detect_output"`
    24  }
    25  
    26  // GetApplicationDropletCurrent returns the current droplet for a given
    27  // application.
    28  func (client *Client) GetApplicationDropletCurrent(appGUID string) (Droplet, Warnings, error) {
    29  	request, err := client.newHTTPRequest(requestOptions{
    30  		RequestName: internal.GetApplicationDropletCurrentRequest,
    31  		URIParams:   map[string]string{"app_guid": appGUID},
    32  	})
    33  	if err != nil {
    34  		return Droplet{}, nil, err
    35  	}
    36  
    37  	var responseDroplet Droplet
    38  	response := cloudcontroller.Response{
    39  		Result: &responseDroplet,
    40  	}
    41  	err = client.connection.Make(request, &response)
    42  	return responseDroplet, response.Warnings, err
    43  }
    44  
    45  // GetDroplets lists droplets with optional filters.
    46  func (client *Client) GetDroplets(query ...Query) ([]Droplet, Warnings, error) {
    47  	request, err := client.newHTTPRequest(requestOptions{
    48  		RequestName: internal.GetDropletsRequest,
    49  		Query:       query,
    50  	})
    51  	if err != nil {
    52  		return nil, nil, err
    53  	}
    54  
    55  	var responseDroplets []Droplet
    56  	warnings, err := client.paginate(request, Droplet{}, func(item interface{}) error {
    57  		if droplet, ok := item.(Droplet); ok {
    58  			responseDroplets = append(responseDroplets, droplet)
    59  		} else {
    60  			return ccerror.UnknownObjectInListError{
    61  				Expected:   Droplet{},
    62  				Unexpected: item,
    63  			}
    64  		}
    65  		return nil
    66  	})
    67  
    68  	return responseDroplets, warnings, err
    69  }
    70  
    71  // GetDroplet returns a droplet with the given GUID.
    72  func (client *Client) GetDroplet(dropletGUID string) (Droplet, Warnings, error) {
    73  	request, err := client.newHTTPRequest(requestOptions{
    74  		RequestName: internal.GetDropletRequest,
    75  		URIParams:   map[string]string{"droplet_guid": dropletGUID},
    76  	})
    77  	if err != nil {
    78  		return Droplet{}, nil, err
    79  	}
    80  
    81  	var responseDroplet Droplet
    82  	response := cloudcontroller.Response{
    83  		Result: &responseDroplet,
    84  	}
    85  	err = client.connection.Make(request, &response)
    86  
    87  	return responseDroplet, response.Warnings, err
    88  }