Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "github.com/racker/perigee" |
| 6 | ) |
| 7 | |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 8 | var ErrNotImplemented = fmt.Errorf("Flavors functionality not implemented.") |
| 9 | |
| 10 | type ListResults map[string]interface{} |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame^] | 11 | type GetResults map[string]interface{} |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 12 | |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame^] | 13 | // 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. |
| 21 | type 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. |
| 31 | func List(c *Client, lfo ListFilterOptions) (ListResults, error) { |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 32 | var lr ListResults |
| 33 | |
| 34 | h, err := c.getListHeaders() |
| 35 | if err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame^] | 39 | err = perigee.Get(c.getListUrl(lfo), perigee.Options{ |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 40 | Results: &lr, |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 41 | MoreHeaders: h, |
| 42 | }) |
| 43 | return lr, err |
| 44 | } |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame^] | 45 | |
| 46 | // Get instructs OpenStack to provide details on a single flavor, identified by its ID. |
| 47 | func 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 | } |