// WaitForStatus will continually poll a server until it successfully transitions to a specified // status. It will do this for at most the number of seconds specified. func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error { return gophercloud.WaitFor(secs, func() (bool, error) { current, err := Get(c, id).Extract() if err != nil { return false, err } if current.Status == status { return true, nil } 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 { return gophercloud.WaitFor(timeout, func() (bool, error) { // Poll resource _, err := Get(c, snapshot.ID).Extract() // Check for a 404 if casted, ok := err.(*gophercloud.UnexpectedResponseCodeError); ok && casted.Actual == 404 { return true, nil } else if err != nil { return false, err } return false, nil }) }
// WaitUntilComplete will continually poll a snapshot until it successfully // 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 { return gophercloud.WaitFor(timeout, func() (bool, error) { // Poll resource current, err := Get(c, snapshot.ID).Extract() if err != nil { return false, err } // Has it been built yet? if current.Progress == "100%" { return true, nil } return false, nil }) }