blob: edeec66d871169c50b7990960a7affc032a829da [file] [log] [blame]
Samuel A. Falvo II10decf92014-02-13 17:05:35 -08001package flavors
2
3import (
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -07004 "fmt"
5 "net/url"
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -07006 "strconv"
Ash Wilson2ebb21c2014-09-08 15:01:32 -04007
8 "github.com/rackspace/gophercloud"
9 identity "github.com/rackspace/gophercloud/openstack/identity/v2"
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080010)
11
12type Client struct {
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080013 endpoint string
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080014 authority identity.AuthResults
Ash Wilson2ebb21c2014-09-08 15:01:32 -040015 options gophercloud.AuthOptions
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080016}
17
Ash Wilson2ebb21c2014-09-08 15:01:32 -040018func NewClient(e string, a identity.AuthResults, ao gophercloud.AuthOptions) *Client {
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080019 return &Client{
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080020 endpoint: e,
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080021 authority: a,
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080022 options: ao,
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080023 }
24}
25
Samuel A. Falvo II38c6ad02014-05-06 18:09:46 -070026func (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
50func (c *Client) getGetUrl(id string) string {
51 return fmt.Sprintf("%s/flavors/%s", c.endpoint, id)
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080052}
53
54func (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 Wilson2ebb21c2014-09-08 15:01:32 -040061 "X-Auth-Token": t.ID,
Samuel A. Falvo II10decf92014-02-13 17:05:35 -080062 }, nil
63}