Add ListFlavors() and acceptance test.
This is required to support server creation acceptance testing. Without
the ability to detect flavors automatically, it isn't possible to
automate acceptance testing, as then a human operator would be required
to manually intervene while testing.
diff --git a/acceptance/06-list-flavors.go b/acceptance/06-list-flavors.go
new file mode 100644
index 0000000..ad56988
--- /dev/null
+++ b/acceptance/06-list-flavors.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "fmt"
+ "flag"
+ "github.com/rackspace/gophercloud"
+)
+
+var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.")
+var rgn = flag.String("r", "DFW", "Datacenter region to interrogate.")
+
+func main() {
+ provider, username, password := getCredentials()
+ flag.Parse()
+
+ auth, err := gophercloud.Authenticate(
+ provider,
+ gophercloud.AuthOptions{
+ Username: username,
+ Password: password,
+ },
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
+ Name: "cloudServersOpenStack",
+ Region: *rgn,
+ VersionId: "2",
+ UrlChoice: gophercloud.PublicURL,
+ })
+ if err != nil {
+ panic(err)
+ }
+
+ flavors, err := servers.ListFlavors()
+ if err != nil {
+ panic(err)
+ }
+
+ if !*quiet {
+ fmt.Println("ID,Name,MinRam,MinDisk")
+ for _, f := range flavors {
+ fmt.Printf("%s,\"%s\",%d,%d\n", f.Id, f.Name, f.Ram, f.Disk)
+ }
+ }
+}
diff --git a/flavors.go b/flavors.go
index 909a308..22c13c4 100644
--- a/flavors.go
+++ b/flavors.go
@@ -1,5 +1,24 @@
package gophercloud
+import (
+ "github.com/racker/perigee"
+)
+
+// See CloudServersProvider interface for details.
+func (gsp *genericServersProvider) ListFlavors() ([]Flavor, error) {
+ var fs []Flavor
+
+ url := gsp.endpoint + "/flavors"
+ err := perigee.Get(url, perigee.Options{
+ CustomClient: gsp.context.httpClient,
+ Results: &struct{ Flavors *[]Flavor }{&fs},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gsp.access.AuthToken(),
+ },
+ })
+ return fs, err
+}
+
// FlavorLink provides a reference to a flavor by either ID or by direct URL.
// Some services use just the ID, others use just the URL.
// This structure provides a common means of expressing both in a single field.
@@ -7,3 +26,28 @@
Id string `json:"id"`
Links []Link `json:"links"`
}
+
+// Flavor records represent (virtual) hardware configurations for server resources in a region.
+//
+// The Id field contains the flavor's unique identifier.
+// For example, this identifier will be useful when specifying which hardware configuration to use for a new server instance.
+//
+// The Disk and Ram fields provide a measure of storage space offered by the flavor, in GB and MB, respectively.
+//
+// The Name field provides a human-readable moniker for the flavor.
+//
+// Swap indicates how much space is reserved for swap.
+// If not provided, this field will be set to 0.
+//
+// VCpus indicates how many (virtual) CPUs are available for this flavor.
+type Flavor struct {
+ OsFlvDisabled bool `json:"OS-FLV-DISABLED:disabled"`
+ Disk int `json:"disk"`
+ Id string `json:"id"`
+ Links []Link `json:"links"`
+ Name string `json:"name"`
+ Ram int `json:"ram"`
+ RxTxFactor float64 `json:"rxtx_factor"`
+ Swap int `json:"swap"`
+ VCpus int `json:"vcpus"`
+}
diff --git a/interfaces.go b/interfaces.go
index ee02baf..649e756 100644
--- a/interfaces.go
+++ b/interfaces.go
@@ -26,5 +26,9 @@
// Images
ListImages() ([]Image, error)
+
+ // Flavors
+
+ ListFlavors() ([]Flavor, error)
}