From 946843982fae3fc048c8aea8777b8638386aa300 Mon Sep 17 00:00:00 2001 From: Ian Delahorne Date: Sun, 29 Jun 2014 23:45:50 -0500 Subject: [PATCH 1/2] 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. --- builder/openstack/server.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/builder/openstack/server.go b/builder/openstack/server.go index fb48659b1..47dee0557 100644 --- a/builder/openstack/server.go +++ b/builder/openstack/server.go @@ -33,12 +33,22 @@ type StateChangeConf struct { // an openstacn 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 } } From 3af14d3dc7334303deb2585f5ed99435538d50fe Mon Sep 17 00:00:00 2001 From: Ian Delahorne Date: Sun, 29 Jun 2014 23:50:01 -0500 Subject: [PATCH 2/2] Fix typo --- builder/openstack/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/openstack/server.go b/builder/openstack/server.go index 47dee0557..8a8f0f01f 100644 --- a/builder/openstack/server.go +++ b/builder/openstack/server.go @@ -30,7 +30,7 @@ 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) { servers, err := csp.ListServers()