get volume type
diff --git a/acceptance/openstack/blockstorage/v1/volumeTypes_test.go b/acceptance/openstack/blockstorage/v1/volumeTypes_test.go
index 0d0b638..3801f16 100644
--- a/acceptance/openstack/blockstorage/v1/volumeTypes_test.go
+++ b/acceptance/openstack/blockstorage/v1/volumeTypes_test.go
@@ -21,8 +21,9 @@
var cvt *volumeTypes.VolumeType
for i := 0; i < numVolTypes; i++ {
cvt, err = volumeTypes.Create(client, volumeTypes.CreateOpts{
- ExtraSpecs: map[string]string{
+ ExtraSpecs: map[string]interface{}{
"capabilities": "gpu",
+ "priority": 3,
},
Name: "gophercloud-test-volumeType-" + strconv.Itoa(i),
})
@@ -38,7 +39,19 @@
return
}
}()
- t.Logf("created volume type: %+v\n", cvt)
+ t.Logf("Created volume type: %+v\n", cvt)
}
+ gr, err := volumeTypes.Get(client, cvt.ID)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ v, err := volumeTypes.ExtractVolumeType(gr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ t.Logf("Got volume type: %+v\n", v)
+
}
diff --git a/openstack/blockstorage/v1/volumeTypes/requests.go b/openstack/blockstorage/v1/volumeTypes/requests.go
index 9ce60a3..326ea78 100644
--- a/openstack/blockstorage/v1/volumeTypes/requests.go
+++ b/openstack/blockstorage/v1/volumeTypes/requests.go
@@ -1,21 +1,20 @@
package volumeTypes
import (
- "fmt"
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/utils"
)
type CreateOpts struct {
- ExtraSpecs map[string]string
+ ExtraSpecs map[string]interface{}
Name string
}
func Create(client *gophercloud.ServiceClient, opts CreateOpts) (*VolumeType, error) {
type volumeType struct {
- ExtraSpecs map[string]string `json:"extra_specs,omitempty"`
- Name *string `json:"name,omitempty"`
+ ExtraSpecs map[string]interface{} `json:"extra_specs,omitempty"`
+ Name *string `json:"name,omitempty"`
}
type request struct {
@@ -45,9 +44,6 @@
return nil, err
}
- fmt.Printf("req: %+v\n", reqBody)
- fmt.Printf("res: %+v\n", respBody)
-
return &respBody.VolumeType, nil
}
@@ -59,3 +55,12 @@
})
return err
}
+
+func Get(client *gophercloud.ServiceClient, id string) (GetResult, error) {
+ var gr GetResult
+ _, err := perigee.Request("GET", volumeTypeURL(client, id), perigee.Options{
+ Results: &gr,
+ MoreHeaders: client.Provider.AuthenticatedHeaders(),
+ })
+ return gr, err
+}
diff --git a/openstack/blockstorage/v1/volumeTypes/results.go b/openstack/blockstorage/v1/volumeTypes/results.go
index 36de240..cf2356f 100644
--- a/openstack/blockstorage/v1/volumeTypes/results.go
+++ b/openstack/blockstorage/v1/volumeTypes/results.go
@@ -1,11 +1,11 @@
package volumeTypes
import (
-//"fmt"
+ "fmt"
-//"github.com/rackspace/gophercloud/pagination"
+ //"github.com/rackspace/gophercloud/pagination"
-//"github.com/mitchellh/mapstructure"
+ "github.com/mitchellh/mapstructure"
)
type VolumeType struct {
@@ -13,3 +13,16 @@
ID string `json:"id" mapstructure:"id"`
Name string `json:"name" mapstructure:"name"`
}
+
+type GetResult map[string]interface{}
+
+func ExtractVolumeType(gr GetResult) (*VolumeType, error) {
+ var response struct {
+ VolumeType *VolumeType `mapstructure:"volume_type"`
+ }
+ err := mapstructure.Decode(gr, &response)
+ if err != nil {
+ return nil, fmt.Errorf("volumeTypes: Error decoding volumeTypes.GetResult: %v", err)
+ }
+ return response.VolumeType, nil
+}