merge lbaasv2, portsbinding, volumes v2; remove 'rackspace' refs; update docs
diff --git a/openstack/blockstorage/v1/volumes/requests.go b/openstack/blockstorage/v1/volumes/requests.go
index 9850cfa..d668591 100644
--- a/openstack/blockstorage/v1/volumes/requests.go
+++ b/openstack/blockstorage/v1/volumes/requests.go
@@ -17,9 +17,9 @@
type CreateOpts struct {
Size int `json:"size" required:"true"`
Availability string `json:"availability,omitempty"`
- Description string `json:"description,omitempty"`
+ Description string `json:"display_description,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
- Name string `json:"name,omitempty"`
+ Name string `json:"display_name,omitempty"`
SnapshotID string `json:"snapshot_id,omitempty"`
SourceVolID string `json:"source_volid,omitempty"`
ImageID string `json:"imageRef,omitempty"`
@@ -74,7 +74,7 @@
// List only volumes that contain Metadata.
Metadata map[string]string `q:"metadata"`
// List only volumes that have Name as the display name.
- Name string `q:"name"`
+ Name string `q:"display_name"`
// List only volumes that have a status of Status.
Status string `q:"status"`
}
@@ -110,8 +110,8 @@
// to the volumes.Update function. For more information about the parameters, see
// the Volume object.
type UpdateOpts struct {
- Name string `json:"name,omitempty"`
- Description string `json:"description,omitempty"`
+ Name string `json:"display_name,omitempty"`
+ Description string `json:"display_description,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
diff --git a/openstack/blockstorage/v1/volumes/results.go b/openstack/blockstorage/v1/volumes/results.go
index 09d1ba6..b056b8c 100644
--- a/openstack/blockstorage/v1/volumes/results.go
+++ b/openstack/blockstorage/v1/volumes/results.go
@@ -9,40 +9,28 @@
type Volume struct {
// Current status of the volume.
Status string `json:"status"`
-
// Human-readable display name for the volume.
Name string `json:"display_name"`
-
// Instances onto which the volume is attached.
Attachments []map[string]interface{} `json:"attachments"`
-
// This parameter is no longer used.
AvailabilityZone string `json:"availability_zone"`
-
// Indicates whether this is a bootable volume.
Bootable string `json:"bootable"`
-
// The date when this volume was created.
CreatedAt gophercloud.JSONRFC3339Milli `json:"created_at"`
-
// Human-readable description for the volume.
Description string `json:"display_description"`
-
// The type of volume to create, either SATA or SSD.
VolumeType string `json:"volume_type"`
-
// The ID of the snapshot from which the volume was created
SnapshotID string `json:"snapshot_id"`
-
// The ID of another block storage volume from which the current volume was created
SourceVolID string `json:"source_volid"`
-
// Arbitrary key-value pairs defined by the user.
Metadata map[string]string `json:"metadata"`
-
// Unique identifier for the volume.
ID string `json:"id"`
-
// Size of the volume in GB.
Size int `json:"size"`
}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/doc.go b/openstack/blockstorage/v2/extensions/volumeactions/doc.go
new file mode 100644
index 0000000..0935fdb
--- /dev/null
+++ b/openstack/blockstorage/v2/extensions/volumeactions/doc.go
@@ -0,0 +1,5 @@
+// Package volumeactions provides information and interaction with volumes in the
+// OpenStack Block Storage service. A volume is a detachable block storage
+// device, akin to a USB hard drive. It can only be attached to one instance at
+// a time.
+package volumeactions
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/requests.go b/openstack/blockstorage/v2/extensions/volumeactions/requests.go
new file mode 100644
index 0000000..05a76f7
--- /dev/null
+++ b/openstack/blockstorage/v2/extensions/volumeactions/requests.go
@@ -0,0 +1,174 @@
+package volumeactions
+
+import (
+ "github.com/gophercloud/gophercloud"
+)
+
+// AttachOptsBuilder allows extensions to add additional parameters to the
+// Attach request.
+type AttachOptsBuilder interface {
+ ToVolumeAttachMap() (map[string]interface{}, error)
+}
+
+// AttachMode describes the attachment mode for volumes.
+type AttachMode string
+
+// These constants determine how a volume is attached
+const (
+ ReadOnly AttachMode = "ro"
+ ReadWrite AttachMode = "rw"
+)
+
+// AttachOpts contains options for attaching a Volume.
+type AttachOpts struct {
+ // The mountpoint of this volume
+ MountPoint string `json:"mountpoint,omitempty"`
+ // The nova instance ID, can't set simultaneously with HostName
+ InstanceUUID string `json:"instance_uuid,omitempty"`
+ // The hostname of baremetal host, can't set simultaneously with InstanceUUID
+ HostName string `json:"host_name,omitempty"`
+ // Mount mode of this volume
+ Mode AttachMode `json:"mode,omitempty"`
+}
+
+// ToVolumeAttachMap assembles a request body based on the contents of a
+// AttachOpts.
+func (opts AttachOpts) ToVolumeAttachMap() (map[string]interface{}, error) {
+ return gophercloud.BuildRequestBody(opts, "os-attach")
+}
+
+// Attach will attach a volume based on the values in AttachOpts.
+func Attach(client *gophercloud.ServiceClient, id string, opts AttachOptsBuilder) (r AttachResult) {
+ b, err := opts.ToVolumeAttachMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+ _, r.Err = client.Post(attachURL(client, id), b, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+ return
+}
+
+// DetachOptsBuilder allows extensions to add additional parameters to the
+// Detach request.
+type DetachOptsBuilder interface {
+ ToVolumeDetachMap() (map[string]interface{}, error)
+}
+
+type DetachOpts struct {
+ AttachmentID string `json:"attachment_id,omitempty"`
+}
+
+// ToVolumeDetachMap assembles a request body based on the contents of a
+// DetachOpts.
+func (opts DetachOpts) ToVolumeDetachMap() (map[string]interface{}, error) {
+ return gophercloud.BuildRequestBody(opts, "os-detach")
+}
+
+// Detach will detach a volume based on volume id.
+func Detach(client *gophercloud.ServiceClient, id string, opts DetachOptsBuilder) (r DetachResult) {
+ b, err := opts.ToVolumeDetachMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+ _, r.Err = client.Post(detachURL(client, id), b, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+ return
+}
+
+// Reserve will reserve a volume based on volume id.
+func Reserve(client *gophercloud.ServiceClient, id string) (r ReserveResult) {
+ b := map[string]interface{}{"os-reserve": make(map[string]interface{})}
+ _, r.Err = client.Post(reserveURL(client, id), b, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{200, 201, 202},
+ })
+ return
+}
+
+// Unreserve will unreserve a volume based on volume id.
+func Unreserve(client *gophercloud.ServiceClient, id string) (r UnreserveResult) {
+ b := map[string]interface{}{"os-unreserve": make(map[string]interface{})}
+ _, r.Err = client.Post(unreserveURL(client, id), b, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{200, 201, 202},
+ })
+ return
+}
+
+// InitializeConnectionOptsBuilder allows extensions to add additional parameters to the
+// InitializeConnection request.
+type InitializeConnectionOptsBuilder interface {
+ ToVolumeInitializeConnectionMap() (map[string]interface{}, error)
+}
+
+// InitializeConnectionOpts hosts options for InitializeConnection.
+type InitializeConnectionOpts struct {
+ IP string `json:"ip,omitempty"`
+ Host string `json:"host,omitempty"`
+ Initiator string `json:"initiator,omitempty"`
+ Wwpns []string `json:"wwpns,omitempty"`
+ Wwnns string `json:"wwnns,omitempty"`
+ Multipath *bool `json:"multipath,omitempty"`
+ Platform string `json:"platform,omitempty"`
+ OSType string `json:"os_type,omitempty"`
+}
+
+// ToVolumeInitializeConnectionMap assembles a request body based on the contents of a
+// InitializeConnectionOpts.
+func (opts InitializeConnectionOpts) ToVolumeInitializeConnectionMap() (map[string]interface{}, error) {
+ b, err := gophercloud.BuildRequestBody(opts, "connector")
+ return map[string]interface{}{"os-initialize_connection": b}, err
+}
+
+// InitializeConnection initializes iscsi connection.
+func InitializeConnection(client *gophercloud.ServiceClient, id string, opts InitializeConnectionOptsBuilder) (r InitializeConnectionResult) {
+ b, err := opts.ToVolumeInitializeConnectionMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+ _, r.Err = client.Post(initializeConnectionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200, 201, 202},
+ })
+ return
+}
+
+// TerminateConnectionOptsBuilder allows extensions to add additional parameters to the
+// TerminateConnection request.
+type TerminateConnectionOptsBuilder interface {
+ ToVolumeTerminateConnectionMap() (map[string]interface{}, error)
+}
+
+// TerminateConnectionOpts hosts options for TerminateConnection.
+type TerminateConnectionOpts struct {
+ IP string `json:"ip,omitempty"`
+ Host string `json:"host,omitempty"`
+ Initiator string `json:"initiator,omitempty"`
+ Wwpns []string `json:"wwpns,omitempty"`
+ Wwnns string `json:"wwnns,omitempty"`
+ Multipath *bool `json:"multipath,omitempty"`
+ Platform string `json:"platform,omitempty"`
+ OSType string `json:"os_type,omitempty"`
+}
+
+// ToVolumeTerminateConnectionMap assembles a request body based on the contents of a
+// TerminateConnectionOpts.
+func (opts TerminateConnectionOpts) ToVolumeTerminateConnectionMap() (map[string]interface{}, error) {
+ b, err := gophercloud.BuildRequestBody(opts, "connector")
+ return map[string]interface{}{"os-terminate_connection": b}, err
+}
+
+// TerminateConnection terminates iscsi connection.
+func TerminateConnection(client *gophercloud.ServiceClient, id string, opts TerminateConnectionOptsBuilder) (r TerminateConnectionResult) {
+ b, err := opts.ToVolumeTerminateConnectionMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+ _, r.Err = client.Post(teminateConnectionURL(client, id), b, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+ return
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/results.go b/openstack/blockstorage/v2/extensions/volumeactions/results.go
new file mode 100644
index 0000000..9bf6a7b
--- /dev/null
+++ b/openstack/blockstorage/v2/extensions/volumeactions/results.go
@@ -0,0 +1,46 @@
+package volumeactions
+
+import "github.com/gophercloud/gophercloud"
+
+// AttachResult contains the response body and error from a Get request.
+type AttachResult struct {
+ gophercloud.ErrResult
+}
+
+// DetachResult contains the response body and error from a Get request.
+type DetachResult struct {
+ gophercloud.ErrResult
+}
+
+// ReserveResult contains the response body and error from a Get request.
+type ReserveResult struct {
+ gophercloud.ErrResult
+}
+
+// UnreserveResult contains the response body and error from a Get request.
+type UnreserveResult struct {
+ gophercloud.ErrResult
+}
+
+// TerminateConnectionResult contains the response body and error from a Get request.
+type TerminateConnectionResult struct {
+ gophercloud.ErrResult
+}
+
+type commonResult struct {
+ gophercloud.Result
+}
+
+// Extract will get the Volume object out of the commonResult object.
+func (r commonResult) Extract() (map[string]interface{}, error) {
+ var s struct {
+ ConnectionInfo map[string]interface{} `json:"connection_info"`
+ }
+ err := r.ExtractInto(&s)
+ return s.ConnectionInfo, err
+}
+
+// InitializeConnectionResult contains the response body and error from a Get request.
+type InitializeConnectionResult struct {
+ commonResult
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/testing/fixtures.go b/openstack/blockstorage/v2/extensions/volumeactions/testing/fixtures.go
new file mode 100644
index 0000000..da661a6
--- /dev/null
+++ b/openstack/blockstorage/v2/extensions/volumeactions/testing/fixtures.go
@@ -0,0 +1,183 @@
+package testing
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ th "github.com/gophercloud/gophercloud/testhelper"
+ fake "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+func MockAttachResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-attach":
+ {
+ "mountpoint": "/mnt",
+ "mode": "rw",
+ "instance_uuid": "50902f4f-a974-46a0-85e9-7efc5e22dfdd"
+ }
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{}`)
+ })
+}
+
+func MockDetachResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-detach": {}
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{}`)
+ })
+}
+
+func MockReserveResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-reserve": {}
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{}`)
+ })
+}
+
+func MockUnreserveResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-unreserve": {}
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{}`)
+ })
+}
+
+func MockInitializeConnectionResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-initialize_connection":
+ {
+ "connector":
+ {
+ "ip":"127.0.0.1",
+ "host":"stack",
+ "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
+ "multipath": false,
+ "platform": "x86_64",
+ "os_type": "linux2"
+ }
+ }
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{
+"connection_info": {
+ "data": {
+ "target_portals": [
+ "172.31.17.48:3260"
+ ],
+ "auth_method": "CHAP",
+ "auth_username": "5MLtcsTEmNN5jFVcT6ui",
+ "access_mode": "rw",
+ "target_lun": 0,
+ "volume_id": "cd281d77-8217-4830-be95-9528227c105c",
+ "target_luns": [
+ 0
+ ],
+ "target_iqns": [
+ "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c"
+ ],
+ "auth_password": "x854ZY5Re3aCkdNL",
+ "target_discovered": false,
+ "encrypted": false,
+ "qos_specs": null,
+ "target_iqn": "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c",
+ "target_portal": "172.31.17.48:3260"
+ },
+ "driver_volume_type": "iscsi"
+ }
+ }`)
+ })
+}
+
+func MockTerminateConnectionResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
+ func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "os-terminate_connection":
+ {
+ "connector":
+ {
+ "ip":"127.0.0.1",
+ "host":"stack",
+ "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
+ "multipath": true,
+ "platform": "x86_64",
+ "os_type": "linux2"
+ }
+ }
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `{}`)
+ })
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/testing/requests_test.go b/openstack/blockstorage/v2/extensions/volumeactions/testing/requests_test.go
new file mode 100644
index 0000000..ed047d5
--- /dev/null
+++ b/openstack/blockstorage/v2/extensions/volumeactions/testing/requests_test.go
@@ -0,0 +1,91 @@
+package testing
+
+import (
+ "testing"
+
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/extensions/volumeactions"
+ th "github.com/gophercloud/gophercloud/testhelper"
+ "github.com/gophercloud/gophercloud/testhelper/client"
+ "github.com/jrperritt/gophercloud"
+)
+
+func TestAttach(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockAttachResponse(t)
+
+ options := &volumeactions.AttachOpts{
+ MountPoint: "/mnt",
+ Mode: "rw",
+ InstanceUUID: "50902f4f-a974-46a0-85e9-7efc5e22dfdd",
+ }
+ err := volumeactions.Attach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestDetach(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockDetachResponse(t)
+
+ err := volumeactions.Detach(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", &volumeactions.DetachOpts{}).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestReserve(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockReserveResponse(t)
+
+ err := volumeactions.Reserve(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestUnreserve(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockUnreserveResponse(t)
+
+ err := volumeactions.Unreserve(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c").ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestInitializeConnection(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockInitializeConnectionResponse(t)
+
+ options := &volumeactions.InitializeConnectionOpts{
+ IP: "127.0.0.1",
+ Host: "stack",
+ Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
+ Multipath: gophercloud.Disabled,
+ Platform: "x86_64",
+ OSType: "linux2",
+ }
+ _, err := volumeactions.InitializeConnection(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).Extract()
+ th.AssertNoErr(t, err)
+}
+
+func TestTerminateConnection(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockTerminateConnectionResponse(t)
+
+ options := &volumeactions.TerminateConnectionOpts{
+ IP: "127.0.0.1",
+ Host: "stack",
+ Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
+ Multipath: gophercloud.Enabled,
+ Platform: "x86_64",
+ OSType: "linux2",
+ }
+ err := volumeactions.TerminateConnection(client.ServiceClient(), "cd281d77-8217-4830-be95-9528227c105c", options).ExtractErr()
+ th.AssertNoErr(t, err)
+}
diff --git a/openstack/blockstorage/v2/extensions/volumeactions/urls.go b/openstack/blockstorage/v2/extensions/volumeactions/urls.go
new file mode 100644
index 0000000..4ddcca0
--- /dev/null
+++ b/openstack/blockstorage/v2/extensions/volumeactions/urls.go
@@ -0,0 +1,27 @@
+package volumeactions
+
+import "github.com/gophercloud/gophercloud"
+
+func attachURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("volumes", id, "action")
+}
+
+func detachURL(c *gophercloud.ServiceClient, id string) string {
+ return attachURL(c, id)
+}
+
+func reserveURL(c *gophercloud.ServiceClient, id string) string {
+ return attachURL(c, id)
+}
+
+func unreserveURL(c *gophercloud.ServiceClient, id string) string {
+ return attachURL(c, id)
+}
+
+func initializeConnectionURL(c *gophercloud.ServiceClient, id string) string {
+ return attachURL(c, id)
+}
+
+func teminateConnectionURL(c *gophercloud.ServiceClient, id string) string {
+ return attachURL(c, id)
+}
diff --git a/openstack/blockstorage/v2/volumes/doc.go b/openstack/blockstorage/v2/volumes/doc.go
new file mode 100644
index 0000000..307b8b1
--- /dev/null
+++ b/openstack/blockstorage/v2/volumes/doc.go
@@ -0,0 +1,5 @@
+// Package volumes provides information and interaction with volumes in the
+// OpenStack Block Storage service. A volume is a detachable block storage
+// device, akin to a USB hard drive. It can only be attached to one instance at
+// a time.
+package volumes
diff --git a/openstack/blockstorage/v2/volumes/requests.go b/openstack/blockstorage/v2/volumes/requests.go
new file mode 100644
index 0000000..18c9cb2
--- /dev/null
+++ b/openstack/blockstorage/v2/volumes/requests.go
@@ -0,0 +1,182 @@
+package volumes
+
+import (
+ "github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/pagination"
+)
+
+// CreateOptsBuilder allows extensions to add additional parameters to the
+// Create request.
+type CreateOptsBuilder interface {
+ ToVolumeCreateMap() (map[string]interface{}, error)
+}
+
+// CreateOpts contains options for creating a Volume. This object is passed to
+// the volumes.Create function. For more information about these parameters,
+// see the Volume object.
+type CreateOpts struct {
+ // The size of the volume, in GB
+ Size int `json:"size" required:"true"`
+ // The availability zone
+ AvailabilityZone string `json:"availability_zone,omitempty"`
+ // ConsistencyGroupID is the ID of a consistency group
+ ConsistencyGroupID string `json:"consistencygroup_id,omitempty"`
+ // The volume description
+ Description string `json:"description,omitempty"`
+ // One or more metadata key and value pairs to associate with the volume
+ Metadata map[string]string `json:"metadata,omitempty"`
+ // The volume name
+ Name string `json:"name,omitempty"`
+ // the ID of the existing volume snapshot
+ SnapshotID string `json:"snapshot_id,omitempty"`
+ // SourceReplica is a UUID of an existing volume to replicate with
+ SourceReplica string `json:"source_replica,omitempty"`
+ // the ID of the existing volume
+ SourceVolID string `json:"source_volid,omitempty"`
+ // The ID of the image from which you want to create the volume.
+ // Required to create a bootable volume.
+ ImageID string `json:"imageRef,omitempty"`
+ // The associated volume type
+ VolumeType string `json:"volume_type,omitempty"`
+}
+
+// ToVolumeCreateMap assembles a request body based on the contents of a
+// CreateOpts.
+func (opts CreateOpts) ToVolumeCreateMap() (map[string]interface{}, error) {
+ return gophercloud.BuildRequestBody(opts, "volume")
+}
+
+// Create will create a new Volume based on the values in CreateOpts. To extract
+// the Volume object from the response, call the Extract method on the
+// CreateResult.
+func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
+ b, err := opts.ToVolumeCreateMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+ _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+ return
+}
+
+// Delete will delete the existing Volume with the provided ID.
+func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
+ _, r.Err = client.Delete(deleteURL(client, id), nil)
+ return
+}
+
+// Get retrieves the Volume with the provided ID. To extract the Volume object
+// from the response, call the Extract method on the GetResult.
+func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
+ _, r.Err = client.Get(getURL(client, id), &r.Body, nil)
+ return
+}
+
+// ListOptsBuilder allows extensions to add additional parameters to the List
+// request.
+type ListOptsBuilder interface {
+ ToVolumeListQuery() (string, error)
+}
+
+// ListOpts holds options for listing Volumes. It is passed to the volumes.List
+// function.
+type ListOpts struct {
+ // admin-only option. Set it to true to see all tenant volumes.
+ AllTenants bool `q:"all_tenants"`
+ // List only volumes that contain Metadata.
+ Metadata map[string]string `q:"metadata"`
+ // List only volumes that have Name as the display name.
+ Name string `q:"name"`
+ // List only volumes that have a status of Status.
+ Status string `q:"status"`
+}
+
+// ToVolumeListQuery formats a ListOpts into a query string.
+func (opts ListOpts) ToVolumeListQuery() (string, error) {
+ q, err := gophercloud.BuildQueryString(opts)
+ return q.String(), err
+}
+
+// List returns Volumes optionally limited by the conditions provided in ListOpts.
+func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
+ url := listURL(client)
+ if opts != nil {
+ query, err := opts.ToVolumeListQuery()
+ if err != nil {
+ return pagination.Pager{Err: err}
+ }
+ url += query
+ }
+
+ return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
+ return VolumePage{pagination.SinglePageBase(r)}
+ })
+}
+
+// UpdateOptsBuilder allows extensions to add additional parameters to the
+// Update request.
+type UpdateOptsBuilder interface {
+ ToVolumeUpdateMap() (map[string]interface{}, error)
+}
+
+// UpdateOpts contain options for updating an existing Volume. This object is passed
+// to the volumes.Update function. For more information about the parameters, see
+// the Volume object.
+type UpdateOpts struct {
+ Name string `json:"name,omitempty"`
+ Description string `json:"description,omitempty"`
+ Metadata map[string]string `json:"metadata,omitempty"`
+}
+
+// ToVolumeUpdateMap assembles a request body based on the contents of an
+// UpdateOpts.
+func (opts UpdateOpts) ToVolumeUpdateMap() (map[string]interface{}, error) {
+ return gophercloud.BuildRequestBody(opts, "volume")
+}
+
+// Update will update the Volume with provided information. To extract the updated
+// Volume from the response, call the Extract method on the UpdateResult.
+func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
+ b, err := opts.ToVolumeUpdateMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+ _, r.Err = client.Put(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
+ })
+ return
+}
+
+// IDFromName is a convienience function that returns a server's ID given its name.
+func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) {
+ count := 0
+ id := ""
+ pages, err := List(client, nil).AllPages()
+ if err != nil {
+ return "", err
+ }
+
+ all, err := ExtractVolumes(pages)
+ if err != nil {
+ return "", err
+ }
+
+ for _, s := range all {
+ if s.Name == name {
+ count++
+ id = s.ID
+ }
+ }
+
+ switch count {
+ case 0:
+ return "", gophercloud.ErrResourceNotFound{Name: name, ResourceType: "volume"}
+ case 1:
+ return id, nil
+ default:
+ return "", gophercloud.ErrMultipleResourcesFound{Name: name, Count: count, ResourceType: "volume"}
+ }
+}
diff --git a/openstack/blockstorage/v2/volumes/results.go b/openstack/blockstorage/v2/volumes/results.go
new file mode 100644
index 0000000..96864ae
--- /dev/null
+++ b/openstack/blockstorage/v2/volumes/results.go
@@ -0,0 +1,120 @@
+package volumes
+
+import (
+ "github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/pagination"
+)
+
+type Attachment struct {
+ ID string `json:"id"`
+ VolumeID string `json:"volume_id"`
+ ServerID string `json:"instance_uuid"`
+ HostName string `json:"attached_host"`
+ Device string `json:"mountpoint"`
+ AttachedAt gophercloud.JSONRFC3339MilliNoZ `json:"attach_time"`
+}
+
+// Volume contains all the information associated with an OpenStack Volume.
+type Volume struct {
+ // Unique identifier for the volume.
+ ID string `json:"id"`
+ // Current status of the volume.
+ Status string `json:"status"`
+ // Size of the volume in GB.
+ Size int `json:"size"`
+ // AvailabilityZone is which availability zone the volume is in.
+ AvailabilityZone string `json:"availability_zone"`
+ // The date when this volume was created.
+ CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
+ // The date when this volume was last updated
+ UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
+ // Instances onto which the volume is attached.
+ Attachments []Attachment `json:"attachments"`
+ // Human-readable display name for the volume.
+ Name string `json:"name"`
+ // Human-readable description for the volume.
+ Description string `json:"description"`
+ // The type of volume to create, either SATA or SSD.
+ VolumeType string `json:"volume_type"`
+ // The ID of the snapshot from which the volume was created
+ SnapshotID string `json:"snapshot_id"`
+ // The ID of another block storage volume from which the current volume was created
+ SourceVolID string `json:"source_volid"`
+ // Arbitrary key-value pairs defined by the user.
+ Metadata map[string]string `json:"metadata"`
+ // UserID is the id of the user who created the volume.
+ UserID string `json:"user_id"`
+ // Indicates whether this is a bootable volume.
+ Bootable string `json:"bootable"`
+ // Encrypted denotes if the volume is encrypted.
+ Encrypted bool `json:"encrypted"`
+ // ReplicationStatus is the status of replication.
+ ReplicationStatus string `json:"replication_status"`
+ // ConsistencyGroupID is the consistency group ID.
+ ConsistencyGroupID string `json:"consistencygroup_id"`
+ // Multiattach denotes if the volume is multi-attach capable.
+ Multiattach bool `json:"multiattach"`
+}
+
+/*
+THESE BELONG IN EXTENSIONS:
+// ReplicationDriverData contains data about the replication driver.
+ReplicationDriverData string `json:"os-volume-replication:driver_data"`
+// ReplicationExtendedStatus contains extended status about replication.
+ReplicationExtendedStatus string `json:"os-volume-replication:extended_status"`
+// TenantID is the id of the project that owns the volume.
+TenantID string `json:"os-vol-tenant-attr:tenant_id"`
+*/
+
+// VolumePage is a pagination.pager that is returned from a call to the List function.
+type VolumePage struct {
+ pagination.SinglePageBase
+}
+
+// IsEmpty returns true if a ListResult contains no Volumes.
+func (r VolumePage) IsEmpty() (bool, error) {
+ volumes, err := ExtractVolumes(r)
+ return len(volumes) == 0, err
+}
+
+// ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call.
+func ExtractVolumes(r pagination.Page) ([]Volume, error) {
+ var s struct {
+ Volumes []Volume `json:"volumes"`
+ }
+ err := (r.(VolumePage)).ExtractInto(&s)
+ return s.Volumes, err
+}
+
+type commonResult struct {
+ gophercloud.Result
+}
+
+// Extract will get the Volume object out of the commonResult object.
+func (r commonResult) Extract() (*Volume, error) {
+ var s struct {
+ Volume *Volume `json:"volume"`
+ }
+ err := r.ExtractInto(&s)
+ return s.Volume, err
+}
+
+// CreateResult contains the response body and error from a Create request.
+type CreateResult struct {
+ commonResult
+}
+
+// GetResult contains the response body and error from a Get request.
+type GetResult struct {
+ commonResult
+}
+
+// UpdateResult contains the response body and error from an Update request.
+type UpdateResult struct {
+ commonResult
+}
+
+// DeleteResult contains the response body and error from a Delete request.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
diff --git a/openstack/blockstorage/v2/volumes/testing/fixtures.go b/openstack/blockstorage/v2/volumes/testing/fixtures.go
new file mode 100644
index 0000000..d4b9da0
--- /dev/null
+++ b/openstack/blockstorage/v2/volumes/testing/fixtures.go
@@ -0,0 +1,202 @@
+package testing
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ th "github.com/gophercloud/gophercloud/testhelper"
+ fake "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+func MockListResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/detail", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+
+ fmt.Fprintf(w, `
+ {
+ "volumes": [
+ {
+ "volume_type": "lvmdriver-1",
+ "created_at": "2015-09-17T03:35:03.000000",
+ "bootable": "false",
+ "name": "vol-001",
+ "os-vol-mig-status-attr:name_id": null,
+ "consistencygroup_id": null,
+ "source_volid": null,
+ "os-volume-replication:driver_data": null,
+ "multiattach": false,
+ "snapshot_id": null,
+ "replication_status": "disabled",
+ "os-volume-replication:extended_status": null,
+ "encrypted": false,
+ "os-vol-host-attr:host": null,
+ "availability_zone": "nova",
+ "attachments": [
+ {
+ "id": "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf",
+ "volume_id": "289da7f8-6440-407c-9fb4-7db01ec49164",
+ "instance_uuid": "d1c4788b-9435-42e2-9b81-29f3be1cd01f",
+ "attached_host": "stack",
+ "mountpoint": "/dev/vdc"
+ }
+ ],
+ "id": "289da7f8-6440-407c-9fb4-7db01ec49164",
+ "size": 75,
+ "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
+ "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
+ "os-vol-mig-status-attr:migstat": null,
+ "metadata": {"foo": "bar"},
+ "status": "available",
+ "description": null
+ },
+ {
+ "volume_type": "lvmdriver-1",
+ "created_at": "2015-09-17T03:32:29.000000",
+ "bootable": "false",
+ "name": "vol-002",
+ "os-vol-mig-status-attr:name_id": null,
+ "consistencygroup_id": null,
+ "source_volid": null,
+ "os-volume-replication:driver_data": null,
+ "multiattach": false,
+ "snapshot_id": null,
+ "replication_status": "disabled",
+ "os-volume-replication:extended_status": null,
+ "encrypted": false,
+ "os-vol-host-attr:host": null,
+ "availability_zone": "nova",
+ "attachments": [],
+ "id": "96c3bda7-c82a-4f50-be73-ca7621794835",
+ "size": 75,
+ "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
+ "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
+ "os-vol-mig-status-attr:migstat": null,
+ "metadata": {},
+ "status": "available",
+ "description": null
+ }
+ ]
+}
+ `)
+ })
+}
+
+func MockGetResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `
+{
+ "volume": {
+ "volume_type": "lvmdriver-1",
+ "created_at": "2015-09-17T03:32:29.000000",
+ "bootable": "false",
+ "name": "vol-001",
+ "os-vol-mig-status-attr:name_id": null,
+ "consistencygroup_id": null,
+ "source_volid": null,
+ "os-volume-replication:driver_data": null,
+ "multiattach": false,
+ "snapshot_id": null,
+ "replication_status": "disabled",
+ "os-volume-replication:extended_status": null,
+ "encrypted": false,
+ "os-vol-host-attr:host": null,
+ "availability_zone": "nova",
+ "attachments": [{
+ "attachment_id": "dbce64e3-f3b9-4423-a44f-a2b15deffa1b",
+ "id": "3eafc6f5-ed74-456d-90fb-f253f594dbae",
+ "volume_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+ "server_id": "d1c4788b-9435-42e2-9b81-29f3be1cd01f",
+ "host_name": "stack",
+ "device": "/dev/vdd"
+ }],
+ "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+ "size": 75,
+ "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
+ "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
+ "os-vol-mig-status-attr:migstat": null,
+ "metadata": {},
+ "status": "available",
+ "description": null
+ }
+}
+ `)
+ })
+}
+
+func MockCreateResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "volume": {
+ "name": "vol-001",
+ "size": 75
+ }
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, `
+{
+ "volume": {
+ "size": 75,
+ "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+ "metadata": {},
+ "created_at": "2015-09-17T03:32:29.044216",
+ "encrypted": false,
+ "bootable": "false",
+ "availability_zone": "nova",
+ "attachments": [],
+ "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
+ "status": "creating",
+ "description": null,
+ "volume_type": "lvmdriver-1",
+ "name": "vol-001",
+ "replication_status": "disabled",
+ "consistencygroup_id": null,
+ "source_volid": null,
+ "snapshot_id": null,
+ "multiattach": false
+ }
+}
+ `)
+ })
+}
+
+func MockDeleteResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+func MockUpdateResponse(t *testing.T) {
+ th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `
+{
+ "volume": {
+ "name": "vol-002"
+ }
+}
+ `)
+ })
+}
diff --git a/openstack/blockstorage/v2/volumes/testing/requests_test.go b/openstack/blockstorage/v2/volumes/testing/requests_test.go
new file mode 100644
index 0000000..147beb5
--- /dev/null
+++ b/openstack/blockstorage/v2/volumes/testing/requests_test.go
@@ -0,0 +1,212 @@
+package testing
+
+import (
+ "testing"
+ "time"
+
+ "github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
+ "github.com/gophercloud/gophercloud/pagination"
+ th "github.com/gophercloud/gophercloud/testhelper"
+ "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+func TestList(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockListResponse(t)
+
+ count := 0
+
+ volumes.List(client.ServiceClient(), &volumes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := volumes.ExtractVolumes(page)
+ if err != nil {
+ t.Errorf("Failed to extract volumes: %v", err)
+ return false, err
+ }
+
+ expected := []volumes.Volume{
+ {
+ ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
+ Name: "vol-001",
+ Attachments: []volumes.Attachment{{
+ ID: "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf",
+ VolumeID: "289da7f8-6440-407c-9fb4-7db01ec49164",
+ ServerID: "d1c4788b-9435-42e2-9b81-29f3be1cd01f",
+ HostName: "stack",
+ Device: "/dev/vdc",
+ }},
+ AvailabilityZone: "nova",
+ Bootable: "false",
+ ConsistencyGroupID: "",
+ CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 17, 3, 35, 3, 0, time.UTC)),
+ Description: "",
+ Encrypted: false,
+ Metadata: map[string]string{"foo": "bar"},
+ Multiattach: false,
+ //TenantID: "304dc00909ac4d0da6c62d816bcb3459",
+ //ReplicationDriverData: "",
+ //ReplicationExtendedStatus: "",
+ ReplicationStatus: "disabled",
+ Size: 75,
+ SnapshotID: "",
+ SourceVolID: "",
+ Status: "available",
+ UserID: "ff1ce52c03ab433aaba9108c2e3ef541",
+ VolumeType: "lvmdriver-1",
+ },
+ {
+ ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
+ Name: "vol-002",
+ Attachments: []volumes.Attachment{},
+ AvailabilityZone: "nova",
+ Bootable: "false",
+ ConsistencyGroupID: "",
+ CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 17, 3, 32, 29, 0, time.UTC)),
+ Description: "",
+ Encrypted: false,
+ Metadata: map[string]string{},
+ Multiattach: false,
+ //TenantID: "304dc00909ac4d0da6c62d816bcb3459",
+ //ReplicationDriverData: "",
+ //ReplicationExtendedStatus: "",
+ ReplicationStatus: "disabled",
+ Size: 75,
+ SnapshotID: "",
+ SourceVolID: "",
+ Status: "available",
+ UserID: "ff1ce52c03ab433aaba9108c2e3ef541",
+ VolumeType: "lvmdriver-1",
+ },
+ }
+
+ th.CheckDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+
+ if count != 1 {
+ t.Errorf("Expected 1 page, got %d", count)
+ }
+}
+
+func TestListAll(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockListResponse(t)
+
+ allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages()
+ th.AssertNoErr(t, err)
+ actual, err := volumes.ExtractVolumes(allPages)
+ th.AssertNoErr(t, err)
+
+ expected := []volumes.Volume{
+ {
+ ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
+ Name: "vol-001",
+ Attachments: []volumes.Attachment{{
+ ID: "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf",
+ VolumeID: "289da7f8-6440-407c-9fb4-7db01ec49164",
+ ServerID: "d1c4788b-9435-42e2-9b81-29f3be1cd01f",
+ HostName: "stack",
+ Device: "/dev/vdc",
+ }},
+ AvailabilityZone: "nova",
+ Bootable: "false",
+ ConsistencyGroupID: "",
+ CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 17, 3, 35, 3, 0, time.UTC)),
+ Description: "",
+ Encrypted: false,
+ Metadata: map[string]string{"foo": "bar"},
+ Multiattach: false,
+ //TenantID: "304dc00909ac4d0da6c62d816bcb3459",
+ //ReplicationDriverData: "",
+ //ReplicationExtendedStatus: "",
+ ReplicationStatus: "disabled",
+ Size: 75,
+ SnapshotID: "",
+ SourceVolID: "",
+ Status: "available",
+ UserID: "ff1ce52c03ab433aaba9108c2e3ef541",
+ VolumeType: "lvmdriver-1",
+ },
+ {
+ ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
+ Name: "vol-002",
+ Attachments: []volumes.Attachment{},
+ AvailabilityZone: "nova",
+ Bootable: "false",
+ ConsistencyGroupID: "",
+ CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 17, 3, 32, 29, 0, time.UTC)),
+ Description: "",
+ Encrypted: false,
+ Metadata: map[string]string{},
+ Multiattach: false,
+ //TenantID: "304dc00909ac4d0da6c62d816bcb3459",
+ //ReplicationDriverData: "",
+ //ReplicationExtendedStatus: "",
+ ReplicationStatus: "disabled",
+ Size: 75,
+ SnapshotID: "",
+ SourceVolID: "",
+ Status: "available",
+ UserID: "ff1ce52c03ab433aaba9108c2e3ef541",
+ VolumeType: "lvmdriver-1",
+ },
+ }
+
+ th.CheckDeepEquals(t, expected, actual)
+
+}
+
+func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockGetResponse(t)
+
+ v, err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertEquals(t, v.Name, "vol-001")
+ th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+}
+
+func TestCreate(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockCreateResponse(t)
+
+ options := &volumes.CreateOpts{Size: 75, Name: "vol-001"}
+ n, err := volumes.Create(client.ServiceClient(), options).Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertEquals(t, n.Size, 75)
+ th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+}
+
+func TestDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockDeleteResponse(t)
+
+ res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ th.AssertNoErr(t, res.Err)
+}
+
+func TestUpdate(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockUpdateResponse(t)
+
+ options := volumes.UpdateOpts{Name: "vol-002"}
+ v, err := volumes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
+ th.AssertNoErr(t, err)
+ th.CheckEquals(t, "vol-002", v.Name)
+}
diff --git a/openstack/blockstorage/v2/volumes/urls.go b/openstack/blockstorage/v2/volumes/urls.go
new file mode 100644
index 0000000..1707249
--- /dev/null
+++ b/openstack/blockstorage/v2/volumes/urls.go
@@ -0,0 +1,23 @@
+package volumes
+
+import "github.com/gophercloud/gophercloud"
+
+func createURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL("volumes")
+}
+
+func listURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL("volumes", "detail")
+}
+
+func deleteURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("volumes", id)
+}
+
+func getURL(c *gophercloud.ServiceClient, id string) string {
+ return deleteURL(c, id)
+}
+
+func updateURL(c *gophercloud.ServiceClient, id string) string {
+ return deleteURL(c, id)
+}
diff --git a/openstack/blockstorage/v2/volumes/util.go b/openstack/blockstorage/v2/volumes/util.go
new file mode 100644
index 0000000..e86c1b4
--- /dev/null
+++ b/openstack/blockstorage/v2/volumes/util.go
@@ -0,0 +1,22 @@
+package volumes
+
+import (
+ "github.com/gophercloud/gophercloud"
+)
+
+// WaitForStatus will continually poll the resource, checking for a particular
+// status. It will do this for the amount of seconds defined.
+func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error {
+ return gophercloud.WaitFor(secs, func() (bool, error) {
+ current, err := Get(c, id).Extract()
+ if err != nil {
+ return false, err
+ }
+
+ if current.Status == status {
+ return true, nil
+ }
+
+ return false, nil
+ })
+}