blob: 1d33f58ad560aa6c0702eb6e0a7493c3307fec9b [file] [log] [blame]
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08001package flavors
2
3import (
Ash Wilson16e75ef2014-09-17 09:54:57 -04004 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/pagination"
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08006)
7
Jon Perritt04851d32014-10-14 02:07:13 -05008// ListOptsBuilder allows extensions to add additional parameters to the
9// List request.
10type ListOptsBuilder interface {
Jon Perritt26780d52014-10-14 11:35:58 -050011 ToFlavorListQuery() (string, error)
Jon Perritt04851d32014-10-14 02:07:13 -050012}
13
Jon Perritt9af03852014-10-07 13:41:35 -050014// ListOpts helps control the results returned by the List() function.
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070015// 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 -070016// 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 -050017type ListOpts struct {
Ash Wilson16e75ef2014-09-17 09:54:57 -040018
19 // ChangesSince, if provided, instructs List to return only those things which have changed since the timestamp provided.
Jon Perritt9af03852014-10-07 13:41:35 -050020 ChangesSince string `q:"changes-since"`
Ash Wilson16e75ef2014-09-17 09:54:57 -040021
22 // MinDisk and MinRAM, if provided, elides flavors which do not meet your criteria.
Jon Perritt9af03852014-10-07 13:41:35 -050023 MinDisk int `q:"minDisk"`
24 MinRAM int `q:"minRam"`
Ash Wilson16e75ef2014-09-17 09:54:57 -040025
26 // Marker and Limit control paging.
27 // Marker instructs List where to start listing from.
Jon Perritt9af03852014-10-07 13:41:35 -050028 Marker string `q:"marker"`
Ash Wilson16e75ef2014-09-17 09:54:57 -040029
30 // Limit instructs List to refrain from sending excessively large lists of flavors.
Jon Perritt9af03852014-10-07 13:41:35 -050031 Limit int `q:"limit"`
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070032}
33
Jon Perritt26780d52014-10-14 11:35:58 -050034// ToFlavorListQuery formats a ListOpts into a query string.
35func (opts ListOpts) ToFlavorListQuery() (string, error) {
Jon Perritt04851d32014-10-14 02:07:13 -050036 q, err := gophercloud.BuildQueryString(opts)
37 if err != nil {
38 return "", err
39 }
40 return q.String(), nil
41}
42
Ash Wilson8a0e24b2014-10-24 14:14:36 -040043// ListDetail instructs OpenStack to provide a list of flavors.
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070044// You may provide criteria by which List curtails its results for easier processing.
Jon Perritt9af03852014-10-07 13:41:35 -050045// See ListOpts for more details.
Ash Wilson8a0e24b2014-10-24 14:14:36 -040046func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
Jon Perritt9af03852014-10-07 13:41:35 -050047 url := listURL(client)
48 if opts != nil {
Jon Perritt26780d52014-10-14 11:35:58 -050049 query, err := opts.ToFlavorListQuery()
Jon Perritt9af03852014-10-07 13:41:35 -050050 if err != nil {
51 return pagination.Pager{Err: err}
52 }
Jon Perritt04851d32014-10-14 02:07:13 -050053 url += query
Jon Perritt9af03852014-10-07 13:41:35 -050054 }
Ash Wilsonb8b16f82014-10-20 10:19:49 -040055 createPage := func(r pagination.PageResult) pagination.Page {
56 return FlavorPage{pagination.LinkedPageBase{PageResult: r}}
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080057 }
58
Jon Perritt9af03852014-10-07 13:41:35 -050059 return pagination.NewPager(client, url, createPage)
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080060}
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070061
62// Get instructs OpenStack to provide details on a single flavor, identified by its ID.
Ash Wilson16e75ef2014-09-17 09:54:57 -040063// Use ExtractFlavor to convert its result into a Flavor.
Ash Wilson8a8b86f2014-09-25 11:26:51 -040064func Get(client *gophercloud.ServiceClient, id string) GetResult {
65 var gr GetResult
Ash Wilson7cb4dab2015-02-12 16:22:58 -050066 _, gr.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
67 JSONResponse: &gr.Body,
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070068 })
Ash Wilson8a8b86f2014-09-25 11:26:51 -040069 return gr
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070070}