func withServer(api gophercloud.CloudServersProvider, f func(string)) { id, err := createServer(api, "", "", "", "") if err != nil { panic(err) } for { s, err := api.ServerById(id) if err != nil { panic(err) } if s.Status == "ACTIVE" { break } time.Sleep(10 * time.Second) } f(id) // I've learned that resizing an instance can fail if a delete request // comes in prior to its completion. This ends up leaving the server // in an error state, and neither the resize NOR the delete complete. // This is a bug in OpenStack, as far as I'm concerned, but thankfully, // there's an easy work-around -- just wait for your server to return to // active state first! waitForServerState(api, id, "ACTIVE") err = api.DeleteServerById(id) if err != nil { panic(err) } }