feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 1 | package volumes |
| 2 | |
| 3 | import ( |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 5 | ) |
| 6 | |
| 7 | // WaitForStatus will continually poll the resource, checking for a particular |
| 8 | // status. It will do this for the amount of seconds defined. |
| 9 | func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error { |
| 10 | return gophercloud.WaitFor(secs, func() (bool, error) { |
| 11 | current, err := Get(c, id).Extract() |
| 12 | if err != nil { |
| 13 | return false, err |
| 14 | } |
| 15 | |
| 16 | if current.Status == status { |
| 17 | return true, nil |
| 18 | } |
| 19 | |
| 20 | return false, nil |
| 21 | }) |
| 22 | } |