create snapshot
diff --git a/acceptance/openstack/blockstorage_test.go b/acceptance/openstack/blockstorage_test.go
index 68c2b6a..fed4114 100644
--- a/acceptance/openstack/blockstorage_test.go
+++ b/acceptance/openstack/blockstorage_test.go
@@ -3,7 +3,9 @@
package openstack
import (
+ "fmt"
blockstorage "github.com/rackspace/gophercloud/openstack/blockstorage/v1"
+ "github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots"
"github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/rackspace/gophercloud/openstack/identity"
"github.com/rackspace/gophercloud/openstack/utils"
@@ -119,3 +121,53 @@
}
}
+
+func TestSnapshots(t *testing.T) {
+ client, err := getClient()
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ cv, 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": cv.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ }()
+
+ for i := 0; i < 60; i++ {
+ gv, err := volumes.Get(client, volumes.GetOpts{
+ "id": cv.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if gv.Status == "available" {
+ break
+ }
+ time.Sleep(2000 * time.Millisecond)
+ }
+
+ var css snapshots.Snapshot
+ css, err = snapshots.Create(client, snapshots.CreateOpts{
+ "volume_id": cv.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ fmt.Printf("%+v\n", css)
+}
diff --git a/openstack/blockstorage/v1/client.go b/openstack/blockstorage/v1/client.go
index dfce924..40cab6c 100644
--- a/openstack/blockstorage/v1/client.go
+++ b/openstack/blockstorage/v1/client.go
@@ -30,6 +30,10 @@
return fmt.Sprintf("%s/volumes/%s", c.endpoint, id)
}
+func (c *Client) GetSnapshotsURL() string {
+ return fmt.Sprintf("%s/snapshots", c.endpoint)
+}
+
func (c *Client) GetHeaders() (map[string]string, error) {
t, err := c.getAuthToken()
if err != nil {
diff --git a/openstack/blockstorage/v1/snapshots/requests.go b/openstack/blockstorage/v1/snapshots/requests.go
new file mode 100644
index 0000000..18f1074
--- /dev/null
+++ b/openstack/blockstorage/v1/snapshots/requests.go
@@ -0,0 +1,25 @@
+package snapshots
+
+import (
+ "github.com/racker/perigee"
+ blockstorage "github.com/rackspace/gophercloud/openstack/blockstorage/v1"
+)
+
+func Create(c *blockstorage.Client, opts CreateOpts) (Snapshot, error) {
+ var ss Snapshot
+ h, err := c.GetHeaders()
+ if err != nil {
+ return ss, err
+ }
+ url := c.GetSnapshotsURL()
+ _, err = perigee.Request("POST", url, perigee.Options{
+ Results: &struct {
+ Snapshot *Snapshot `json:"snapshot"`
+ }{&ss},
+ ReqBody: map[string]interface{}{
+ "snapshot": opts,
+ },
+ MoreHeaders: h,
+ })
+ return ss, err
+}
diff --git a/openstack/blockstorage/v1/snapshots/snapshots.go b/openstack/blockstorage/v1/snapshots/snapshots.go
new file mode 100644
index 0000000..8525f1a
--- /dev/null
+++ b/openstack/blockstorage/v1/snapshots/snapshots.go
@@ -0,0 +1,14 @@
+package snapshots
+
+type Snapshot struct {
+ Status string
+ Display_name string
+ Created_at string
+ Display_description string
+ Volume_id string
+ Metadata map[string]string
+ Id string
+ Size int
+}
+
+type CreateOpts map[string]interface{}