fixes to creat and list volumes
diff --git a/openstack/blockstorage/v1/volumes/requests.go b/openstack/blockstorage/v1/volumes/requests.go
index 18f8a41..b6f3edf 100644
--- a/openstack/blockstorage/v1/volumes/requests.go
+++ b/openstack/blockstorage/v1/volumes/requests.go
@@ -3,22 +3,21 @@
import (
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/openstack/utils"
"github.com/rackspace/gophercloud/pagination"
- "github.com/rackspace/gophercloud/utils"
)
type VolumeOpts struct {
- Availability string
- Description string
- ImageID string
- Metadata map[string]string
- Name string
- Size int
- SnapshotID string
- Type string
+ Availability string
+ Description string
+ Metadata map[string]string
+ Name string
+ Size int
+ SnapshotID, SourceVolID, ImageID string
+ VolumeType string
}
-func Create(client *gophercloud.ServiceClient, opts VolumeOpts) (Volume, error) {
+func Create(client *gophercloud.ServiceClient, opts VolumeOpts) (*Volume, error) {
type volume struct {
Availability *string `json:"availability_zone,omitempty"`
@@ -55,9 +54,9 @@
var respBody response
- _, err = perigee.Request("POST", volumesURL(client), perigee.Options{
- MoreHeaders: c.Provider.AuthenticatedHeaders(),
- OkCodes: []int{201},
+ _, err := perigee.Request("POST", volumesURL(client), perigee.Options{
+ MoreHeaders: client.Provider.AuthenticatedHeaders(),
+ OkCodes: []int{200, 201},
ReqBody: &reqBody,
Results: &respBody,
})
@@ -69,30 +68,15 @@
}
func List(client *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
- var url string
-
- query := utils.BuildQuery(opts.Params)
-
- if !opts.Full {
- url = c.volumesURL()
- } else {
- url = c.volumeURL("detail")
- }
createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- p := ListResult{
- pagination.MarkerPageBase{
- LastHTTPResponse: r,
- },
- }
- p.MarkerPageBase.Owner = p
- return p
+ return ListResult{pagination.SinglePageBase(r)}
}
- pager := pagination.NewPager(client, url, createPage)
- return pager
+ return pagination.NewPager(client, volumesURL(client), createPage)
}
+/*
func Get(c *blockstorage.Client, opts GetOpts) (Volume, error) {
var v Volume
h, err := c.GetHeaders()
@@ -120,3 +104,4 @@
})
return err
}
+*/
diff --git a/openstack/blockstorage/v1/volumes/results.go b/openstack/blockstorage/v1/volumes/results.go
index 230543c..bceaedf 100644
--- a/openstack/blockstorage/v1/volumes/results.go
+++ b/openstack/blockstorage/v1/volumes/results.go
@@ -22,28 +22,36 @@
Size int
}
-type VolumePage struct {
- pagination.LinkedPageBase
+type ListOpts struct {
+ // AllTenants is an admin-only option. Set it to true to see a tenant volumes.
+ AllTenants bool
+ // List only volumes that contain Metadata.
+ Metadata map[string]string
+ // List only volumes that have Name as the display name.
+ Name string
+ // List only volumes that have a status of Status.
+ Status string
}
-func (p VolumPage) IsEmpty() (bool, error) {
- volumes, err := ExtractVolumes(p)
+// ListResult is a *http.Response that is returned from a call to the List function.
+type ListResult struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a ListResult contains no container names.
+func (r ListResult) IsEmpty() (bool, error) {
+ volumes, err := ExtractVolumes(r)
if err != nil {
return true, err
}
return len(volumes) == 0, nil
}
-func ExtractVolumes(page pagination.page) ([]Volume, error) {
+func ExtractVolumes(page pagination.Page) ([]Volume, error) {
var response struct {
Volumes []Volume `json:"volumes"`
}
- err := mapstructure.Decode(page.(VolumePage).Body, &response)
+ err := mapstructure.Decode(page.(ListResult).Body, &response)
return response.Volumes, err
}
-
-type CreateOpts map[string]interface{}
-type ListOpts map[string]bool
-type GetOpts map[string]string
-type DeleteOpts map[string]string
diff --git a/openstack/utils/utils.go b/openstack/utils/utils.go
index 1d09d9e..c5d8767 100644
--- a/openstack/utils/utils.go
+++ b/openstack/utils/utils.go
@@ -71,3 +71,17 @@
query = query[:len(query)-1]
return query
}
+
+func MaybeString(original string) *string {
+ if original != "" {
+ return &original
+ }
+ return nil
+}
+
+func MaybeInt(original int) *int {
+ if original != 0 {
+ return &original
+ }
+ return nil
+}
diff --git a/utils.go b/utils.go
deleted file mode 100644
index a7d6e66..0000000
--- a/utils.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package utils
-
-func MaybeString(original string) *string {
- if original != "" {
- return &original
- }
- return nil
-}
-
-func MaybeInt(original int) {
- if original != 0 {
- return &original
- }
- return nil
-}