blob: 37582065b9fa6695e5b0977de25b252f0e697d48 [file] [log] [blame]
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08001package flavors
2
3import (
4 "fmt"
5 "github.com/racker/perigee"
6)
7
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08008var ErrNotImplemented = fmt.Errorf("Flavors functionality not implemented.")
9
10type ListResults map[string]interface{}
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070011type GetResults map[string]interface{}
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080012
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070013// ListFilterOptions helps control the results returned by the List() function.
14// ChangesSince, if provided, instructs List to return only those things which have changed since the timestamp provided.
15// MinDisk and MinRam, if provided, elides flavors which do not meet your criteria.
16// For example, a flavor with a minDisk field of 10 will not be returned if you specify MinDisk set to 20.
17// Marker and Limit control paging.
18// Limit instructs List to refrain from sending excessively large lists of flavors.
19// Marker instructs List where to start listing from.
20// Typically, software will use the last ID of the previous call to List to set the Marker for the current call.
21type ListFilterOptions struct {
22 ChangesSince string
23 MinDisk, MinRam int
24 Marker string
25 Limit int
26}
27
28// List instructs OpenStack to provide a list of flavors.
29// You may provide criteria by which List curtails its results for easier processing.
30// See ListFilterOptions for more details.
31func List(c *Client, lfo ListFilterOptions) (ListResults, error) {
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080032 var lr ListResults
33
34 h, err := c.getListHeaders()
35 if err != nil {
36 return nil, err
37 }
38
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070039 err = perigee.Get(c.getListUrl(lfo), perigee.Options{
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080040 Results: &lr,
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080041 MoreHeaders: h,
42 })
43 return lr, err
44}
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070045
46// Get instructs OpenStack to provide details on a single flavor, identified by its ID.
47func Get(c *Client, id string) (GetResults, error) {
48 var gr GetResults
49 h, err := c.getListHeaders() // same for Get Flavor API
50 if err != nil {
51 return gr, err
52 }
53 err = perigee.Get(c.getGetUrl(id), perigee.Options{
54 Results: &gr,
55 MoreHeaders: h,
56 })
57 return gr, err
58}