Skip to content

Commit

Permalink
Handle delete requests on transient SR
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed Oct 13, 2023
1 parent dc281d7 commit 5c1d0b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/server/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ def delete
service_id = document['DOCUMENT']['TEMPLATE']['BODY']['SERVICE_ID']
response = cclient.service_delete(service_id)
rc = response[0]
rb = response[1]

if rc == 404
cclient.logger.warning("Cannot find #{SR} Service")
elsif rc != 204
rb = response[1]
if rc != 204
if rc == 404
cclient.logger.warning("Cannot find #{SR} Service")
elsif rc == 500 && rb == 'Service cannot be undeployed in state: DEPLOYING'
rc = 423
rb = "#{SR} has not finished deployment"
end
return [rc, rb]
end

Expand Down
8 changes: 6 additions & 2 deletions src/server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DENIED = 'Permission denied'.freeze
NO_AUTH = 'Failed to authenticate in OpenNebula'.freeze
SR_NOT_FOUND = "#{SR} not found".freeze
NO_DELETE = "Failed to delete #{SR}".freeze

# Helper method to return JSON responses
def json_response(response_code, data)
Expand Down Expand Up @@ -232,8 +233,11 @@ def log_response(level, code, data, message)
when 403
log_response('error', rc, rb, DENIED)
halt rc, json_response(rc, rb)
when 423
log_response('error', rc, rb, NO_DELETE)
halt rc, json_response(rc, rb)
else
log_response('error', rc, rb, "Failed to delete #{SR}")
log_response('error', rc, rb, NO_DELETE)
halt 500, json_response(500, rb)
end
when 401
Expand All @@ -246,7 +250,7 @@ def log_response(level, code, data, message)
log_response('error', rc, rb, SR_NOT_FOUND)
halt rc, json_response(rc, rb)
else
log_response('error', rc, rb, "Failed to delete #{SR}")
log_response('error', rc, rb, NO_DELETE)
halt 500, json_response(500, rb)
end
end

0 comments on commit 5c1d0b7

Please sign in to comment.