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 | |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 9 | // ListFilterOptions 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. |
| 12 | type ListFilterOptions 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. |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 15 | ChangesSince string |
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. |
| 18 | MinDisk, MinRAM int |
| 19 | |
| 20 | // Marker and Limit control paging. |
| 21 | // Marker instructs List where to start listing from. |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 22 | Marker string |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 23 | |
| 24 | // Limit instructs List to refrain from sending excessively large lists of flavors. |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 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. |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 31 | func List(client *gophercloud.ServiceClient, lfo ListFilterOptions) pagination.Pager { |
| 32 | createPage := func(r pagination.LastHTTPResponse) pagination.Page { |
Ash Wilson | 0d2c242 | 2014-09-25 14:50:45 -0400 | [diff] [blame] | 33 | return FlavorPage{pagination.LinkedPageBase{LastHTTPResponse: r}} |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame^] | 36 | return pagination.NewPager(client, listURL(client, lfo), createPage) |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 37 | } |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 38 | |
| 39 | // 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] | 40 | // Use ExtractFlavor to convert its result into a Flavor. |
Ash Wilson | 8a8b86f | 2014-09-25 11:26:51 -0400 | [diff] [blame] | 41 | func Get(client *gophercloud.ServiceClient, id string) GetResult { |
| 42 | var gr GetResult |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame^] | 43 | gr.Err = perigee.Get(flavorURL(client, id), perigee.Options{ |
Ash Wilson | 8a8b86f | 2014-09-25 11:26:51 -0400 | [diff] [blame] | 44 | Results: &gr.Resp, |
Ash Wilson | 16e75ef | 2014-09-17 09:54:57 -0400 | [diff] [blame] | 45 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 46 | }) |
Ash Wilson | 8a8b86f | 2014-09-25 11:26:51 -0400 | [diff] [blame] | 47 | return gr |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 48 | } |