Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 4 | "github.com/racker/perigee" |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 5 | "github.com/rackspace/gophercloud" |
| 6 | "github.com/rackspace/gophercloud/pagination" |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 7 | ) |
| 8 | |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 9 | // ListOpts helps control the results returned by the List() function. |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 10 | // For example, a flavor with a minDisk field of 10 will not be returned if you specify MinDisk set to 20. |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 11 | // Typically, software will use the last ID of the previous call to List to set the Marker for the current call. |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 12 | type ListOpts struct { |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 13 | |
| 14 | // ChangesSince, if provided, instructs List to return only those things which have changed since the timestamp provided. |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 15 | ChangesSince string `q:"changes-since"` |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 16 | |
| 17 | // MinDisk and MinRAM, if provided, elides flavors which do not meet your criteria. |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 18 | MinDisk int `q:"minDisk"` |
| 19 | MinRAM int `q:"minRam"` |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 20 | |
| 21 | // Marker and Limit control paging. |
| 22 | // Marker instructs List where to start listing from. |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 23 | Marker string `q:"marker"` |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 24 | |
| 25 | // Limit instructs List to refrain from sending excessively large lists of flavors. |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 26 | Limit int `q:"limit"` |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | // List instructs OpenStack to provide a list of flavors. |
| 30 | // You may provide criteria by which List curtails its results for easier processing. |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 31 | // See ListOpts for more details. |
| 32 | func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager { |
| 33 | url := listURL(client) |
| 34 | if opts != nil { |
| 35 | query, err := gophercloud.BuildQueryString(opts) |
| 36 | if err != nil { |
| 37 | return pagination.Pager{Err: err} |
| 38 | } |
| 39 | url += query.String() |
| 40 | } |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 41 | createPage := func(r pagination.LastHTTPResponse) pagination.Page { |
Ash Wilson | 0d2c242 | 2014-09-25 14:50:45 -0400 | [diff] [blame] | 42 | return FlavorPage{pagination.LinkedPageBase{LastHTTPResponse: r}} |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 45 | return pagination.NewPager(client, url, createPage) |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 46 | } |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 47 | |
| 48 | // Get instructs OpenStack to provide details on a single flavor, identified by its ID. |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 49 | // Use ExtractFlavor to convert its result into a Flavor. |
Ash Wilson | 8a8b86f | 2014-09-25 11:26:51 -0400 | [diff] [blame] | 50 | func Get(client *gophercloud.ServiceClient, id string) GetResult { |
| 51 | var gr GetResult |
Jon Perritt | 9af0385 | 2014-10-07 13:41:35 -0500 | [diff] [blame] | 52 | gr.Err = perigee.Get(getURL(client, id), perigee.Options{ |
Ash Wilson | 8a8b86f | 2014-09-25 11:26:51 -0400 | [diff] [blame] | 53 | Results: &gr.Resp, |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 54 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 55 | }) |
Ash Wilson | 8a8b86f | 2014-09-25 11:26:51 -0400 | [diff] [blame] | 56 | return gr |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 57 | } |