From 341cfb2c2dbab77a23ac3193c7602ea4a0920f33 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Mon, 17 Jun 2013 14:22:29 +0200 Subject: [PATCH] builder/digitalocean: improve error messages from DO api --- builder/digitalocean/api.go | 8 ++++++-- builder/digitalocean/step_create_droplet.go | 5 ++++- builder/digitalocean/step_create_ssh_key.go | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/builder/digitalocean/api.go b/builder/digitalocean/api.go index 85c3c63a9..72e4752cc 100644 --- a/builder/digitalocean/api.go +++ b/builder/digitalocean/api.go @@ -156,7 +156,7 @@ func NewRequest(d DigitalOceanClient, path string, params string) (map[string]in // Catch all non-200 status and return an error if resp.StatusCode != 200 { - err = errors.New(fmt.Sprintf("recieved non-200 status from digitalocean: %d", resp.StatusCode)) + err = errors.New(fmt.Sprintf("Recieved non-200 HTTP status from DigitalOcean: %d", resp.StatusCode)) log.Printf("response from digital ocean: %v", decodedResponse) return decodedResponse, err } @@ -170,7 +170,11 @@ func NewRequest(d DigitalOceanClient, path string, params string) (map[string]in // Catch all non-OK statuses from DO and return an error status := decodedResponse["status"] if status != "OK" { - err = errors.New(fmt.Sprintf("recieved non-OK status from digitalocean: %d", status)) + // Get the actual error message if there is one + if status == "ERROR" { + status = decodedResponse["error_message"] + } + err = errors.New(fmt.Sprintf("Recieved bad status from DigitalOcean: %v", status)) log.Printf("response from digital ocean: %v", decodedResponse) return decodedResponse, err } diff --git a/builder/digitalocean/step_create_droplet.go b/builder/digitalocean/step_create_droplet.go index a3ffdf9b3..1a2dff3e3 100644 --- a/builder/digitalocean/step_create_droplet.go +++ b/builder/digitalocean/step_create_droplet.go @@ -63,8 +63,11 @@ func (s *stepCreateDroplet) Cleanup(state map[string]interface{}) { err := client.DestroyDroplet(s.dropletId) + curlstr := fmt.Sprintf("curl '%v/droplets/%v/destroy?client_id=%v&api_key=%v'", + DIGITALOCEAN_API_URL, s.dropletId, c.ClientID, c.APIKey) + if err != nil { ui.Error(fmt.Sprintf( - "Error destroying droplet. Please destroy it manually: %v", s.dropletId)) + "Error destroying droplet. Please destroy it manually: %v", curlstr)) } } diff --git a/builder/digitalocean/step_create_ssh_key.go b/builder/digitalocean/step_create_ssh_key.go index 6046f3e58..6f0025a92 100644 --- a/builder/digitalocean/step_create_ssh_key.go +++ b/builder/digitalocean/step_create_ssh_key.go @@ -71,12 +71,17 @@ func (s *stepCreateSSHKey) Cleanup(state map[string]interface{}) { client := state["client"].(*DigitalOceanClient) ui := state["ui"].(packer.Ui) + c := state["config"].(config) ui.Say("Deleting temporary ssh key...") err := client.DestroyKey(s.keyId) + + curlstr := fmt.Sprintf("curl '%v/ssh_keys/%v/destroy?client_id=%v&api_key=%v'", + DIGITALOCEAN_API_URL, s.keyId, c.ClientID, c.APIKey) + if err != nil { log.Printf("Error cleaning up ssh key: %v", err.Error()) ui.Error(fmt.Sprintf( - "Error cleaning up ssh key. Please delete the key manually: %v", s.keyId)) + "Error cleaning up ssh key. Please delete the key manually: %v", curlstr)) } }