blob: 4b89b1a36c0c2be89f51cb52b1f6c11f60ca7f77 [file] [log] [blame]
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08001package flavors
2
3import (
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08004 "github.com/racker/perigee"
Ash Wilson16e75ef2014-09-17 09:54:57 -04005 "github.com/rackspace/gophercloud"
6 "github.com/rackspace/gophercloud/pagination"
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08007)
8
Jon Perritt9af03852014-10-07 13:41:35 -05009// ListOpts helps control the results returned by the List() function.
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070010// For example, a flavor with a minDisk field of 10 will not be returned if you specify MinDisk set to 20.
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070011// Typically, software will use the last ID of the previous call to List to set the Marker for the current call.
Jon Perritt9af03852014-10-07 13:41:35 -050012type ListOpts struct {
Ash Wilson16e75ef2014-09-17 09:54:57 -040013
14 // ChangesSince, if provided, instructs List to return only those things which have changed since the timestamp provided.
Jon Perritt9af03852014-10-07 13:41:35 -050015 ChangesSince string `q:"changes-since"`
Ash Wilson16e75ef2014-09-17 09:54:57 -040016
17 // MinDisk and MinRAM, if provided, elides flavors which do not meet your criteria.
Jon Perritt9af03852014-10-07 13:41:35 -050018 MinDisk int `q:"minDisk"`
19 MinRAM int `q:"minRam"`
Ash Wilson16e75ef2014-09-17 09:54:57 -040020
21 // Marker and Limit control paging.
22 // Marker instructs List where to start listing from.
Jon Perritt9af03852014-10-07 13:41:35 -050023 Marker string `q:"marker"`
Ash Wilson16e75ef2014-09-17 09:54:57 -040024
25 // Limit instructs List to refrain from sending excessively large lists of flavors.
Jon Perritt9af03852014-10-07 13:41:35 -050026 Limit int `q:"limit"`
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070027}
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 Perritt9af03852014-10-07 13:41:35 -050031// See ListOpts for more details.
32func 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 Wilson16e75ef2014-09-17 09:54:57 -040041 createPage := func(r pagination.LastHTTPResponse) pagination.Page {
Ash Wilson0d2c2422014-09-25 14:50:45 -040042 return FlavorPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080043 }
44
Jon Perritt9af03852014-10-07 13:41:35 -050045 return pagination.NewPager(client, url, createPage)
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080046}
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070047
48// Get instructs OpenStack to provide details on a single flavor, identified by its ID.
Ash Wilson16e75ef2014-09-17 09:54:57 -040049// Use ExtractFlavor to convert its result into a Flavor.
Ash Wilson8a8b86f2014-09-25 11:26:51 -040050func Get(client *gophercloud.ServiceClient, id string) GetResult {
51 var gr GetResult
Jon Perritt9af03852014-10-07 13:41:35 -050052 gr.Err = perigee.Get(getURL(client, id), perigee.Options{
Ash Wilson8a8b86f2014-09-25 11:26:51 -040053 Results: &gr.Resp,
Ash Wilson16e75ef2014-09-17 09:54:57 -040054 MoreHeaders: client.Provider.AuthenticatedHeaders(),
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070055 })
Ash Wilson8a8b86f2014-09-25 11:26:51 -040056 return gr
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070057}