From d912c8183dd922efc32e50a0f07697171438a943 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Fri, 20 Mar 2015 11:16:13 -0700 Subject: [PATCH] Validate overall success/failure of PUT --- lib/vmpooler/api/v1.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index c8e7d37..c0a5768 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -504,6 +504,8 @@ module Vmpooler if $redis.exists('vmpooler__vm__' + params[:hostname]) jdata = JSON.parse(request.body.read) + failure = false + jdata.each do |param, arg| case param when 'lifetime' @@ -511,23 +513,28 @@ module Vmpooler if arg > 0 $redis.hset('vmpooler__vm__' + params[:hostname], param, arg) - - status 200 - result['ok'] = true + else + failure = true end when 'tags' if arg.is_a?(Hash) arg.keys.each do |tag| $redis.hset('vmpooler__vm__' + params[:hostname], 'tag:' + tag, arg[tag]) end - - status 200 - result['ok'] = true + else + failure = true end end end end + if failure + status 400 + else + status 200 + result['ok'] = true + end + JSON.pretty_generate(result) end end