get snapshot
diff --git a/acceptance/openstack/blockstorage_test.go b/acceptance/openstack/blockstorage_test.go
index 0cd1d56..dab7266 100644
--- a/acceptance/openstack/blockstorage_test.go
+++ b/acceptance/openstack/blockstorage_test.go
@@ -3,7 +3,7 @@
package openstack
import (
- "fmt"
+ //"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"
@@ -129,6 +129,8 @@
return
}
+ var css snapshots.Snapshot
+
cv, err := volumes.Create(client, volumes.CreateOpts{
"size": 1,
"display_name": "test-volume",
@@ -138,12 +140,21 @@
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++ {
+ gss, _ := snapshots.Get(client, snapshots.GetOpts{
+ "id": css.Id,
+ })
+ if gss.Status == "" {
+ err = volumes.Delete(client, volumes.DeleteOpts{
+ "id": cv.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ break
+ }
+ time.Sleep(5000 * time.Millisecond)
}
}()
@@ -161,7 +172,6 @@
time.Sleep(2000 * time.Millisecond)
}
- var css snapshots.Snapshot
css, err = snapshots.Create(client, snapshots.CreateOpts{
"volume_id": cv.Id,
"display_name": "test-snapshot",
@@ -170,15 +180,26 @@
t.Error(err)
return
}
- time.Sleep(20000 * time.Millisecond)
defer func() {
- err = snapshots.Delete(client, snapshots.DeleteOpts{
- "id": cv.Id,
- })
- if err != nil {
- t.Error(err)
- return
+ for i := 0; i < 60; i++ {
+ gss, err := snapshots.Get(client, snapshots.GetOpts{
+ "id": css.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if gss.Status == "available" {
+ err = snapshots.Delete(client, snapshots.DeleteOpts{
+ "id": css.Id,
+ })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ break
+ }
+ time.Sleep(2000 * time.Millisecond)
}
}()
- fmt.Printf("%+v\n", css)
}
diff --git a/openstack/blockstorage/v1/snapshots/requests.go b/openstack/blockstorage/v1/snapshots/requests.go
index 90c2ec3..1fc3e27 100644
--- a/openstack/blockstorage/v1/snapshots/requests.go
+++ b/openstack/blockstorage/v1/snapshots/requests.go
@@ -24,6 +24,22 @@
return ss, err
}
+func Get(c *blockstorage.Client, opts GetOpts) (Snapshot, error) {
+ var ss Snapshot
+ h, err := c.GetHeaders()
+ if err != nil {
+ return ss, err
+ }
+ url := c.GetSnapshotURL(opts["id"])
+ _, err = perigee.Request("GET", url, perigee.Options{
+ Results: &struct {
+ Snapshot *Snapshot `json:"snapshot"`
+ }{&ss},
+ MoreHeaders: h,
+ })
+ return ss, err
+}
+
func Delete(c *blockstorage.Client, opts DeleteOpts) error {
h, err := c.GetHeaders()
if err != nil {
diff --git a/openstack/blockstorage/v1/snapshots/snapshots.go b/openstack/blockstorage/v1/snapshots/snapshots.go
index 6a76f85..bd5510a 100644
--- a/openstack/blockstorage/v1/snapshots/snapshots.go
+++ b/openstack/blockstorage/v1/snapshots/snapshots.go
@@ -12,4 +12,5 @@
}
type CreateOpts map[string]interface{}
+type GetOpts map[string]string
type DeleteOpts map[string]string