From 0da4aa6f2417c3e3a4417af7d49441c0b4b6e7fb Mon Sep 17 00:00:00 2001 From: Ian Delahorne Date: Mon, 30 Jun 2014 19:51:48 -0500 Subject: [PATCH] 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. --- builder/openstack/server.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/builder/openstack/server.go b/builder/openstack/server.go index 8a8f0f01f..dbe2f52ef 100644 --- a/builder/openstack/server.go +++ b/builder/openstack/server.go @@ -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 } }