Commit 9b3404b6 authored by Arie Peterson's avatar Arie Peterson 🐚
Browse files

Check Cosmos2 api call error status in driver

parent 4f2c6521
......@@ -82,6 +82,13 @@ ghostAction() {
# Record the complete body from the HTTP response in the log.
debug "output: "
debug $(jq '.' <<<"$response")
errorOccurred=$(jq '."error"' <<<"$response")
if [ "$errorOccurred" = "true" ]
errorMessage=$(jq '."message"' <<<"$response")
debug "The Cosmos2 api call returned an error: $errorMessage"
return 1
# Store the `disk_slot` field of the output in a variable for later use.
diskSlot=$(jq '."disk_slot"' <<<"$response")
......@@ -98,9 +105,17 @@ domount() {
# which disk to detach; also
# 2. even if we could detach directly after unmount, there might be an error
# during detach, which we need to be able to recover from.
ghostAction "detach" "$apiToken" "$diskID"
if ! ghostAction "detach" "$apiToken" "$diskID"
output "{\"status\":\"Failure\"}"
exit 1
# Now tell Cosmos2 to attach the disk to the right VPS.
ghostAction "attach" "$apiToken" "$diskID" "$vpsID"
if ! ghostAction "attach" "$apiToken" "$diskID" "$vpsID"
output "{\"status\":\"Failure\"}"
exit 1
debug "disk_slot: $diskSlot"
# Convert numeric disk slot index to device letter, so
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