Commit 0da4aa6f authored by Ian Delahorne's avatar Ian Delahorne

Replace ListServers hack with update ServerById

[gophercloud#168](https://github.com/rackspace/gophercloud/issues/168) has been
patched to not panic on non-existing server id's. If an error is returned,
check if the error is a 404 first before bailing.
parent 25ff0f04
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/racker/perigee"
"github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud"
"log" "log"
"time" "time"
...@@ -33,22 +34,18 @@ type StateChangeConf struct { ...@@ -33,22 +34,18 @@ type StateChangeConf struct {
// an openstack server. // an openstack 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) {
servers, err := csp.ListServers() resp, err := csp.ServerById(s.Id)
if err != nil { if err != nil {
log.Printf("Error on ServerStateRefresh: %s", err) urce, ok := err.(*perigee.UnexpectedResponseCodeError)
return nil, "", 0, err if ok && (urce.Actual == 404) {
} log.Printf("404 on ServerStateRefresh, returning DELETED")
var resp *gophercloud.Server
found := false return nil, "DELETED", 0, nil
for _, server := range servers { } else {
if server.Id == s.Id { log.Printf("Error on ServerStateRefresh: %s", err)
found = true return nil, "", 0, err
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