Merge pull request #1304 from lflux/fix-openstack-serverid-crash
Fix openstack ServerById crash
This commit is contained in:
commit
be606418e6
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue