Commit 94684398 authored by Ian Delahorne's avatar Ian Delahorne

Workaround for gophercloud.ServerById crashing, fixes #1257

gophercloud.ServerById is broken in v0.1.0 - it will crash if you feed it a
non-existing server ID (see [rackspace/gophercloud #168](https://github.com/rackspace/gophercloud/issues/168))

Instead, list all servers and iterate over them. If the server id isn't found,
return "DELETED" as a state. Not perfect but it works until next version of
gophercloud is released.
parent 29d8bb60
...@@ -33,12 +33,22 @@ type StateChangeConf struct { ...@@ -33,12 +33,22 @@ type StateChangeConf struct {
// an openstacn server. // an openstacn server.
func ServerStateRefreshFunc(csp gophercloud.CloudServersProvider, s *gophercloud.Server) StateRefreshFunc { func ServerStateRefreshFunc(csp gophercloud.CloudServersProvider, s *gophercloud.Server) StateRefreshFunc {
return func() (interface{}, string, int, error) { return func() (interface{}, string, int, error) {
resp, err := csp.ServerById(s.Id) servers, err := csp.ListServers()
if err != nil { if err != nil {
log.Printf("Error on ServerStateRefresh: %s", err) log.Printf("Error on ServerStateRefresh: %s", err)
return nil, "", 0, 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 return resp, resp.Status, resp.Progress, nil
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment