Merge pull request #1304 from lflux/fix-openstack-serverid-crash

Fix openstack ServerById crash
This commit is contained in:
Ross Smith II 2014-06-30 10:56:53 -07:00
commit be606418e6
1 changed files with 13 additions and 3 deletions

View File

@ -30,15 +30,25 @@ type StateChangeConf struct {
}
// ServerStateRefreshFunc returns a StateRefreshFunc that is used to watch
// an openstacn server.
// an openstack server.
func ServerStateRefreshFunc(csp gophercloud.CloudServersProvider, s *gophercloud.Server) StateRefreshFunc {
return func() (interface{}, string, int, error) {
resp, err := csp.ServerById(s.Id)
servers, err := csp.ListServers()
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
}
}
if found == false {
return nil, "DELETED", 0, nil
}
return resp, resp.Status, resp.Progress, nil
}
}