consistency changes
diff --git a/openstack/compute/v2/flavors/requests.go b/openstack/compute/v2/flavors/requests.go
index 47eb172..4b89b1a 100644
--- a/openstack/compute/v2/flavors/requests.go
+++ b/openstack/compute/v2/flavors/requests.go
@@ -6,41 +6,50 @@
"github.com/rackspace/gophercloud/pagination"
)
-// ListFilterOptions helps control the results returned by the List() function.
+// ListOpts helps control the results returned by the List() function.
// For example, a flavor with a minDisk field of 10 will not be returned if you specify MinDisk set to 20.
// Typically, software will use the last ID of the previous call to List to set the Marker for the current call.
-type ListFilterOptions struct {
+type ListOpts struct {
// ChangesSince, if provided, instructs List to return only those things which have changed since the timestamp provided.
- ChangesSince string
+ ChangesSince string `q:"changes-since"`
// MinDisk and MinRAM, if provided, elides flavors which do not meet your criteria.
- MinDisk, MinRAM int
+ MinDisk int `q:"minDisk"`
+ MinRAM int `q:"minRam"`
// Marker and Limit control paging.
// Marker instructs List where to start listing from.
- Marker string
+ Marker string `q:"marker"`
// Limit instructs List to refrain from sending excessively large lists of flavors.
- Limit int
+ Limit int `q:"limit"`
}
// List instructs OpenStack to provide a list of flavors.
// You may provide criteria by which List curtails its results for easier processing.
-// See ListFilterOptions for more details.
-func List(client *gophercloud.ServiceClient, lfo ListFilterOptions) pagination.Pager {
+// See ListOpts for more details.
+func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
+ url := listURL(client)
+ if opts != nil {
+ query, err := gophercloud.BuildQueryString(opts)
+ if err != nil {
+ return pagination.Pager{Err: err}
+ }
+ url += query.String()
+ }
createPage := func(r pagination.LastHTTPResponse) pagination.Page {
return FlavorPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
}
- return pagination.NewPager(client, listURL(client, lfo), createPage)
+ return pagination.NewPager(client, url, createPage)
}
// Get instructs OpenStack to provide details on a single flavor, identified by its ID.
// Use ExtractFlavor to convert its result into a Flavor.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var gr GetResult
- gr.Err = perigee.Get(flavorURL(client, id), perigee.Options{
+ gr.Err = perigee.Get(getURL(client, id), perigee.Options{
Results: &gr.Resp,
MoreHeaders: client.Provider.AuthenticatedHeaders(),
})
diff --git a/openstack/compute/v2/flavors/requests_test.go b/openstack/compute/v2/flavors/requests_test.go
index e1b6b4f..7c3fb9a 100644
--- a/openstack/compute/v2/flavors/requests_test.go
+++ b/openstack/compute/v2/flavors/requests_test.go
@@ -6,27 +6,20 @@
"reflect"
"testing"
- "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
)
const tokenID = "blerb"
-func serviceClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{
- Provider: &gophercloud.ProviderClient{TokenID: tokenID},
- Endpoint: testhelper.Endpoint(),
- }
-}
-
func TestListFlavors(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
testhelper.Mux.HandleFunc("/flavors/detail", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenID)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
r.ParseForm()
@@ -66,9 +59,8 @@
}
})
- client := serviceClient()
pages := 0
- err := List(client, ListFilterOptions{}).EachPage(func(page pagination.Page) (bool, error) {
+ err := List(fake.ServiceClient(), &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
pages++
actual, err := ExtractFlavors(page)
@@ -101,7 +93,7 @@
testhelper.Mux.HandleFunc("/flavors/12345", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenID)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `
@@ -118,8 +110,7 @@
`)
})
- client := serviceClient()
- actual, err := Get(client, "12345").Extract()
+ actual, err := Get(fake.ServiceClient(), "12345").Extract()
if err != nil {
t.Fatalf("Unable to get flavor: %v", err)
}
diff --git a/openstack/compute/v2/flavors/urls.go b/openstack/compute/v2/flavors/urls.go
index 9e5b562..683c107 100644
--- a/openstack/compute/v2/flavors/urls.go
+++ b/openstack/compute/v2/flavors/urls.go
@@ -1,37 +1,13 @@
package flavors
import (
- "fmt"
- "net/url"
- "strconv"
-
"github.com/rackspace/gophercloud"
)
-func listURL(client *gophercloud.ServiceClient, lfo ListFilterOptions) string {
- v := url.Values{}
- if lfo.ChangesSince != "" {
- v.Set("changes-since", lfo.ChangesSince)
- }
- if lfo.MinDisk != 0 {
- v.Set("minDisk", strconv.Itoa(lfo.MinDisk))
- }
- if lfo.MinRAM != 0 {
- v.Set("minRam", strconv.Itoa(lfo.MinRAM))
- }
- if lfo.Marker != "" {
- v.Set("marker", lfo.Marker)
- }
- if lfo.Limit != 0 {
- v.Set("limit", strconv.Itoa(lfo.Limit))
- }
- tail := ""
- if len(v) > 0 {
- tail = fmt.Sprintf("?%s", v.Encode())
- }
- return client.ServiceURL("flavors", "detail") + tail
+func getURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("flavors", id)
}
-func flavorURL(client *gophercloud.ServiceClient, id string) string {
- return client.ServiceURL("flavors", id)
+func listURL(client *gophercloud.ServiceClient) string {
+ return client.ServiceURL("flavors", "detail")
}