Merge pull request #1307 from lflux/better-serverbyid-fix

Replace ListServers hack with update ServerById
This commit is contained in:
Ross Smith II 2014-07-01 06:40:19 -07:00
commit 5d0cd9676a
1 changed files with 10 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/mitchellh/multistep"
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"log"
"time"
@ -33,22 +34,18 @@ type StateChangeConf struct {
// an openstack server.
func ServerStateRefreshFunc(csp gophercloud.CloudServersProvider, s *gophercloud.Server) StateRefreshFunc {
return func() (interface{}, string, int, error) {
servers, err := csp.ListServers()
resp, err := csp.ServerById(s.Id)
if err != nil {
log.Printf("Error on ServerStateRefresh: %s", err)
return nil, "", 0, err
}
var resp *gophercloud.Server
found := false
for _, server := range servers {
if server.Id == s.Id {
found = true
resp = &server
urce, ok := err.(*perigee.UnexpectedResponseCodeError)
if ok && (urce.Actual == 404) {
log.Printf("404 on ServerStateRefresh, returning DELETED")
return nil, "DELETED", 0, nil
} else {
log.Printf("Error on ServerStateRefresh: %s", err)
return nil, "", 0, err
}
}
if found == false {
return nil, "DELETED", 0, nil
}
return resp, resp.Status, resp.Progress, nil
}
}