Ash Wilson | 93757df | 2014-10-21 09:36:27 -0400 | [diff] [blame] | 1 | package servers |
| 2 | |
| 3 | import "github.com/rackspace/gophercloud" |
| 4 | |
| 5 | // WaitForStatus will continually poll a server until it successfully transitions to a specified |
| 6 | // status. It will do this for at most the number of seconds specified. |
| 7 | func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error { |
| 8 | return gophercloud.WaitFor(secs, func() (bool, error) { |
| 9 | current, err := Get(c, id).Extract() |
| 10 | if err != nil { |
| 11 | return false, err |
| 12 | } |
| 13 | |
| 14 | if current.Status == status { |
| 15 | return true, nil |
| 16 | } |
| 17 | |
| 18 | return false, nil |
| 19 | }) |
| 20 | } |