Commit e9fc9c02 authored by Arie Peterson's avatar Arie Peterson 🐚
Browse files

Do not detach a disk before deleting in the provisioner

parent c367c5a0
......@@ -55,39 +55,8 @@ type actionsJson struct {
Type string `json:"type"`
}
// Call the Cosmos2 API to detach the given disk image from whatever VPS it is
// currently attached to.
func (cc *CosmosClient) detachDiskImage(id string) bool {
actionsBody := actionsJson{
Type: "detach",
}
postData, _ := json.Marshal(actionsBody)
resp, err := cc.ApiCall("POST", "/disks/"+id+"/actions", postData)
if err != nil {
klog.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 {
klog.Warningf("Error reading Cosmos2 response: %v", err)
return false
}
klog.Warningf("Cosmos2 failed to detach disk: %d %s", resp.StatusCode, responseData)
return false
}
}
// Call the Cosmos2 API to first detach and then delete the given disk image.
// Call the Cosmos2 API to delete the given disk image.
func (cc *CosmosClient) DeleteDiskImage(id string) bool {
// First detach the disk. Cosmos2 doesn't like deleting disks that are
// still attached.
cc.detachDiskImage(id)
resp, err := cc.ApiCall("DELETE", "/disks/"+id, nil)
if err != nil {
klog.Warningf("Error performing API call to Cosmos2: %v", err)
......
Supports Markdown
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