list volumes
diff --git a/acceptance/openstack/blockstorage_test.go b/acceptance/openstack/blockstorage_test.go
index 11025a0..68c2b6a 100644
--- a/acceptance/openstack/blockstorage_test.go
+++ b/acceptance/openstack/blockstorage_test.go
@@ -3,15 +3,18 @@
package openstack
import (
- "fmt"
blockstorage "github.com/rackspace/gophercloud/openstack/blockstorage/v1"
"github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/rackspace/gophercloud/openstack/identity"
"github.com/rackspace/gophercloud/openstack/utils"
"os"
+ "strconv"
"testing"
+ "time"
)
+var numVols = 2
+
func getClient() (*blockstorage.Client, error) {
ao, err := utils.AuthOptions()
if err != nil {
@@ -60,27 +63,59 @@
t.Error(err)
return
}
- nv, err := volumes.Create(client, volumes.CreateOpts{
- "size": 1,
- "display_name": "test-volume",
- })
- if err != nil {
- t.Error(err)
- return
- }
- defer func() {
- err = volumes.Delete(client, volumes.DeleteOpts{
- "id": nv.Id,
+ var cv volumes.Volume
+ for i := 0; i < numVols; i++ {
+ cv, err := volumes.Create(client, volumes.CreateOpts{
+ "size": 1,
+ "display_name": "test-volume" + strconv.Itoa(i),
})
- }()
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer func() {
+ time.Sleep(10000 * time.Millisecond)
+ err = volumes.Delete(client, volumes.DeleteOpts{
+ "id": cv.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ }()
+ }
- gv, err := volumes.Get(client, volumes.GetOpts{
- "id": nv.Id,
+ vols, err := volumes.List(client, volumes.ListOpts{
+ "full": true,
})
if err != nil {
t.Error(err)
return
}
- fmt.Printf("%+v\n", gv)
+ if len(vols) != numVols {
+ t.Errorf("Expected %d volumes, got %d", numVols, len(vols))
+ return
+ }
+
+ vols, err = volumes.List(client, volumes.ListOpts{
+ "full": false,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if len(vols) != numVols {
+ t.Errorf("Expected %d volumes, got %d", numVols, len(vols))
+ return
+ }
+
+ _, err = volumes.Get(client, volumes.GetOpts{
+ "id": cv.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
}
diff --git a/openstack/blockstorage/v1/volumes/requests.go b/openstack/blockstorage/v1/volumes/requests.go
index 5dcbca0..c4a72c2 100644
--- a/openstack/blockstorage/v1/volumes/requests.go
+++ b/openstack/blockstorage/v1/volumes/requests.go
@@ -24,6 +24,27 @@
return v, err
}
+func List(c *blockstorage.Client, opts ListOpts) ([]Volume, error) {
+ var v []Volume
+ var url string
+ h, err := c.GetHeaders()
+ if err != nil {
+ return v, err
+ }
+ if full := opts["full"]; full {
+ url = c.GetVolumesURL()
+ } else {
+ url = c.GetVolumeURL("detail")
+ }
+ _, err = perigee.Request("GET", url, perigee.Options{
+ Results: &struct {
+ Volume *[]Volume `json:"volumes"`
+ }{&v},
+ MoreHeaders: h,
+ })
+ return v, err
+}
+
func Get(c *blockstorage.Client, opts GetOpts) (Volume, error) {
var v Volume
h, err := c.GetHeaders()
diff --git a/openstack/blockstorage/v1/volumes/volumes.go b/openstack/blockstorage/v1/volumes/volumes.go
index 741e4bf..8120863 100644
--- a/openstack/blockstorage/v1/volumes/volumes.go
+++ b/openstack/blockstorage/v1/volumes/volumes.go
@@ -16,5 +16,6 @@
Size int
}
type CreateOpts map[string]interface{}
+type ListOpts map[string]bool
type GetOpts map[string]string
type DeleteOpts map[string]string