Commit b30f3f6e authored by Arie Peterson's avatar Arie Peterson

Improve handling of Cosmos2 errors in provisioner

parent 4eb51afc
......@@ -3,6 +3,7 @@ package ghost
import (
"encoding/json"
"errors"
"io/ioutil"
"github.com/golang/glog"
)
......@@ -33,6 +34,14 @@ func (cc *CosmosClient) CreateDiskImage(specs *Specs) (*DiskImage, error) {
if err != nil {
return nil, err
}
if resp.StatusCode >= 400 {
responseData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = errors.New("Cosmos2 could not create the new disk image: " + string(responseData))
return nil, err
}
var diskResponse diskResponse
json.NewDecoder(resp.Body).Decode(&diskResponse)
diskImage := diskResponse.DiskImage
......@@ -55,14 +64,19 @@ func (cc *CosmosClient) detachDiskImage(id string) bool {
resp, err := cc.ApiCall("POST", "/disks/"+id+"/actions", postData)
if err != nil {
glog.Warningf("Error when detaching disk: %v", err)
glog.Warningf("Error performing API call to Cosmos2: %v", err)
return false
}
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
return true
} else {
glog.Warningf("Error when detaching disk: %d", resp.StatusCode)
responseData, err := ioutil.ReadAll(resp.Body)
if err != nil {
glog.Warningf("Error reading Cosmos2 response: %v", err)
return false
}
glog.Warningf("Cosmos2 failed to detach disk: %d %s", resp.StatusCode, responseData)
return false
}
}
......@@ -75,13 +89,19 @@ func (cc *CosmosClient) DeleteDiskImage(id string) bool {
resp, err := cc.ApiCall("DELETE", "/disks/"+id, nil)
if err != nil {
glog.Warningf("Error when deleting disk: %v", err)
glog.Warningf("Error performing API call to Cosmos2: %v", err)
return false
}
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
return true
} else {
responseData, err := ioutil.ReadAll(resp.Body)
if err != nil {
glog.Warningf("Error reading Cosmos2 response: %v", err)
return false
}
glog.Warningf("Cosmos2 failed to delete disk: %d %s", resp.StatusCode, responseData)
glog.Warningf("Error when deleting disk: %d", resp.StatusCode)
return false
}
......@@ -105,6 +125,14 @@ func (cc *CosmosClient) GetInstanceData() (*string, error) {
if err != nil {
glog.Fatalf("Could not get instance data: %v", err)
}
if resp.StatusCode >= 400 {
responseData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = errors.New("Cosmos2 could not get use the instance data: " + string(responseData))
return nil, err
}
var instanceResponse InstanceResponse
err = json.NewDecoder(resp.Body).Decode(&instanceResponse)
......
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