Removing superfluous stuff
diff --git a/rackspace/blockstorage/v1/snapshots/results.go b/rackspace/blockstorage/v1/snapshots/results.go
index e7b0847..0fab282 100644
--- a/rackspace/blockstorage/v1/snapshots/results.go
+++ b/rackspace/blockstorage/v1/snapshots/results.go
@@ -1,9 +1,6 @@
package snapshots
import (
- "fmt"
- "time"
-
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
@@ -59,10 +56,6 @@
VolumeID string `mapstructure:"volume_id"`
}
-type commonResult struct {
- gophercloud.Result
-}
-
// CreateResult represents the result of a create operation
type CreateResult struct {
os.CreateResult
@@ -121,46 +114,36 @@
// transitions to a specified state. It will do this for at most the number of
// seconds specified.
func (snapshot Snapshot) WaitUntilComplete(c *gophercloud.ServiceClient, timeout int) error {
- start := time.Now().Second()
- var err error
- for {
+ return gophercloud.WaitFor(timeout, func() (bool, error) {
+ // Poll resource
current, err := Get(c, snapshot.ID).Extract()
-
if err != nil {
- break
- }
- if timeout > 0 && time.Now().Second()-start >= timeout {
- err = fmt.Errorf("A timeout occurred")
- break
+ return false, err
}
+ // Has it been built yet?
if current.Progress == "100%" {
- break
+ return true, nil
}
- }
- return err
+ return false, nil
+ })
}
+// WaitUntilDeleted will continually poll a snapshot until it has been
+// successfully deleted, i.e. returns a 404 status.
func (snapshot Snapshot) WaitUntilDeleted(c *gophercloud.ServiceClient, timeout int) error {
- start := time.Now().Second()
- var err error
- for {
+ return gophercloud.WaitFor(timeout, func() (bool, error) {
+ // Poll resource
_, err := Get(c, snapshot.ID).Extract()
- // We actually want an error here
+ // Check for a 404
if casted, ok := err.(*perigee.UnexpectedResponseCodeError); ok && casted.Actual == 404 {
- err = nil
- break
+ return true, nil
} else if err != nil {
- break
+ return false, err
}
- if timeout > 0 && time.Now().Second()-start >= timeout {
- err = fmt.Errorf("A timeout occurred")
- break
- }
- }
-
- return err
+ return false, nil
+ })
}
diff --git a/rackspace/blockstorage/v1/volumes/results.go b/rackspace/blockstorage/v1/volumes/results.go
index cec41e0..c7c2cc4 100644
--- a/rackspace/blockstorage/v1/volumes/results.go
+++ b/rackspace/blockstorage/v1/volumes/results.go
@@ -1,19 +1,15 @@
package volumes
import (
- "github.com/rackspace/gophercloud"
os "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/rackspace/gophercloud/pagination"
"github.com/mitchellh/mapstructure"
)
+// Volume wraps an Openstack volume
type Volume os.Volume
-type commonResult struct {
- gophercloud.Result
-}
-
// CreateResult represents the result of a create operation
type CreateResult struct {
os.CreateResult
@@ -58,7 +54,7 @@
return commonExtract(r.Body, r.Err)
}
-// ExtractSnapshots extracts and returns Volumes. It is used while iterating over a volumes.List call.
+// ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call.
func ExtractVolumes(page pagination.Page) ([]Volume, error) {
var response struct {
Volumes []Volume `json:"volumes"`