update ExtractFlavors function and unit tests
diff --git a/rackspace/compute/v2/flavors/delegate.go b/rackspace/compute/v2/flavors/delegate.go
index 4878f9d..081ea47 100644
--- a/rackspace/compute/v2/flavors/delegate.go
+++ b/rackspace/compute/v2/flavors/delegate.go
@@ -41,8 +41,3 @@
_, res.Err = client.Get(getURL(client, id), &res.Body, nil)
return res
}
-
-// ExtractFlavors interprets a page of List results as Flavors.
-func ExtractFlavors(page pagination.Page) ([]os.Flavor, error) {
- return os.ExtractFlavors(page)
-}
diff --git a/rackspace/compute/v2/flavors/fixtures.go b/rackspace/compute/v2/flavors/fixtures.go
index 894f916..957dccf 100644
--- a/rackspace/compute/v2/flavors/fixtures.go
+++ b/rackspace/compute/v2/flavors/fixtures.go
@@ -2,10 +2,6 @@
package flavors
-import (
- os "github.com/rackspace/gophercloud/openstack/compute/v2/flavors"
-)
-
// ListOutput is a sample response of a flavor List request.
const ListOutput = `
{
@@ -103,7 +99,7 @@
// Performance1Flavor is the expected result of parsing GetOutput, or the first element of
// ListOutput.
-var Performance1Flavor = os.Flavor{
+var Performance1Flavor = Flavor{
ID: "performance1-1",
Disk: 20,
RAM: 1024,
@@ -111,10 +107,16 @@
RxTxFactor: 200.0,
Swap: 0,
VCPUs: 1,
+ ExtraSpecs: ExtraSpecs{
+ NumDataDisks: 0,
+ Class: "performance1",
+ DiskIOIndex: 0,
+ PolicyClass: "performance_flavor",
+ },
}
// Performance2Flavor is the second result expected from parsing ListOutput.
-var Performance2Flavor = os.Flavor{
+var Performance2Flavor = Flavor{
ID: "performance1-2",
Disk: 40,
RAM: 2048,
@@ -122,8 +124,14 @@
RxTxFactor: 400.0,
Swap: 0,
VCPUs: 2,
+ ExtraSpecs: ExtraSpecs{
+ NumDataDisks: 0,
+ Class: "performance1",
+ DiskIOIndex: 0,
+ PolicyClass: "performance_flavor",
+ },
}
// ExpectedFlavorSlice is the slice of Flavor structs that are expected to be parsed from
// ListOutput.
-var ExpectedFlavorSlice = []os.Flavor{Performance1Flavor, Performance2Flavor}
+var ExpectedFlavorSlice = []Flavor{Performance1Flavor, Performance2Flavor}
diff --git a/rackspace/compute/v2/flavors/results.go b/rackspace/compute/v2/flavors/results.go
index 411256d..e9efcdc 100644
--- a/rackspace/compute/v2/flavors/results.go
+++ b/rackspace/compute/v2/flavors/results.go
@@ -5,6 +5,8 @@
"github.com/jrperritt/gophercloud"
"github.com/mitchellh/mapstructure"
+ os "github.com/rackspace/gophercloud/openstack/compute/v2/flavors"
+ "github.com/rackspace/gophercloud/pagination"
)
// ExtraSpecs provide additional information about the flavor.
@@ -77,3 +79,26 @@
}
return v, nil
}
+
+// ExtractFlavors provides access to the list of flavors in a page acquired from the List operation.
+func ExtractFlavors(page pagination.Page) ([]Flavor, error) {
+ casted := page.(os.FlavorPage).Body
+ var container struct {
+ Flavors []Flavor `mapstructure:"flavors"`
+ }
+
+ cfg := &mapstructure.DecoderConfig{
+ DecodeHook: defaulter,
+ Result: &container,
+ }
+ decoder, err := mapstructure.NewDecoder(cfg)
+ if err != nil {
+ return container.Flavors, err
+ }
+ err = decoder.Decode(casted)
+ if err != nil {
+ return container.Flavors, err
+ }
+
+ return container.Flavors, nil
+}