Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 4 | "fmt" |
| 5 | "net/url" |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 6 | "strconv" |
Ash Wilson | 2ebb21c | 2014-09-08 15:01:32 -0400 | [diff] [blame] | 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | identity "github.com/rackspace/gophercloud/openstack/identity/v2" |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | type Client struct { |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 13 | endpoint string |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 14 | authority identity.AuthResults |
Ash Wilson | 2ebb21c | 2014-09-08 15:01:32 -0400 | [diff] [blame] | 15 | options gophercloud.AuthOptions |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 16 | } |
| 17 | |
Ash Wilson | 2ebb21c | 2014-09-08 15:01:32 -0400 | [diff] [blame] | 18 | func NewClient(e string, a identity.AuthResults, ao gophercloud.AuthOptions) *Client { |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 19 | return &Client{ |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 20 | endpoint: e, |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 21 | authority: a, |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 22 | options: ao, |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 23 | } |
| 24 | } |
| 25 | |
Samuel A. Falvo II | 38c6ad0 | 2014-05-06 18:09:46 -0700 | [diff] [blame] | 26 | func (c *Client) getListUrl(lfo ListFilterOptions) string { |
| 27 | v := url.Values{} |
| 28 | if lfo.ChangesSince != "" { |
| 29 | v.Set("changes-since", lfo.ChangesSince) |
| 30 | } |
| 31 | if lfo.MinDisk != 0 { |
| 32 | v.Set("minDisk", strconv.Itoa(lfo.MinDisk)) |
| 33 | } |
| 34 | if lfo.MinRam != 0 { |
| 35 | v.Set("minRam", strconv.Itoa(lfo.MinRam)) |
| 36 | } |
| 37 | if lfo.Marker != "" { |
| 38 | v.Set("marker", lfo.Marker) |
| 39 | } |
| 40 | if lfo.Limit != 0 { |
| 41 | v.Set("limit", strconv.Itoa(lfo.Limit)) |
| 42 | } |
| 43 | tail := "" |
| 44 | if len(v) > 0 { |
| 45 | tail = fmt.Sprintf("?%s", v.Encode()) |
| 46 | } |
| 47 | return fmt.Sprintf("%s/flavors/detail%s", c.endpoint, tail) |
| 48 | } |
| 49 | |
| 50 | func (c *Client) getGetUrl(id string) string { |
| 51 | return fmt.Sprintf("%s/flavors/%s", c.endpoint, id) |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | func (c *Client) getListHeaders() (map[string]string, error) { |
| 55 | t, err := identity.GetToken(c.authority) |
| 56 | if err != nil { |
| 57 | return map[string]string{}, err |
| 58 | } |
| 59 | |
| 60 | return map[string]string{ |
Ash Wilson | 2ebb21c | 2014-09-08 15:01:32 -0400 | [diff] [blame] | 61 | "X-Auth-Token": t.ID, |
Samuel A. Falvo II | 10decf9 | 2014-02-13 17:05:35 -0800 | [diff] [blame] | 62 | }, nil |
| 63 | } |