mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 18:08:42 -05:00
(POOLER-123) Improve PUT vm endpoint error messaging
Prior to this commit the PUT vm endpoint didn't give any useful information about why a user's request failed. This commit updates PUT to output a more helpful set of error messages in the `failure` key that gets returned in the JSON response.
This commit is contained in:
parent
ac17284a61
commit
da48517750
1 changed files with 16 additions and 14 deletions
|
|
@ -875,7 +875,7 @@ module Vmpooler
|
||||||
status 404
|
status 404
|
||||||
result = { 'ok' => false }
|
result = { 'ok' => false }
|
||||||
|
|
||||||
failure = false
|
failure = []
|
||||||
|
|
||||||
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
||||||
|
|
||||||
|
|
@ -896,36 +896,38 @@ module Vmpooler
|
||||||
max_lifetime_upper_limit = config[:max_lifetime_upper_limit]
|
max_lifetime_upper_limit = config[:max_lifetime_upper_limit]
|
||||||
if max_lifetime_upper_limit
|
if max_lifetime_upper_limit
|
||||||
max_lifetime_upper_limit = max_lifetime_upper_limit.to_i
|
max_lifetime_upper_limit = max_lifetime_upper_limit.to_i
|
||||||
unless arg.to_i < max_lifetime_upper_limit
|
if arg.to_i >= max_lifetime_upper_limit
|
||||||
failure = true
|
failure.push("You provided a lifetime (#{arg}) that exceeds the configured maximum of #{max_lifetime_upper_limit}.")
|
||||||
end
|
else
|
||||||
# also make sure we do not extend past max_lifetime_upper_limit
|
# also make sure we do not extend past max_lifetime_upper_limit
|
||||||
rdata = backend.hgetall('vmpooler__vm__' + params[:hostname])
|
rdata = backend.hgetall('vmpooler__vm__' + params[:hostname])
|
||||||
running = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
running = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
||||||
unless running + arg.to_i < max_lifetime_upper_limit
|
unless running + arg.to_i < max_lifetime_upper_limit
|
||||||
failure = true
|
failure.push("You provided a lifetime (#{arg}) that will extend the current lifetime past the configured maximum of #{max_lifetime_upper_limit}.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# validate lifetime is within boundaries
|
# validate lifetime is within boundaries
|
||||||
unless arg.to_i > 0
|
unless arg.to_i > 0
|
||||||
failure = true
|
failure.push("You provided a lifetime (#{arg}) but you must provide a positive number.")
|
||||||
end
|
end
|
||||||
when 'tags'
|
when 'tags'
|
||||||
unless arg.is_a?(Hash)
|
unless arg.is_a?(Hash)
|
||||||
failure = true
|
failure.push("You provided tags (#{arg}) as something other than a hash.")
|
||||||
end
|
end
|
||||||
|
|
||||||
if config['allowed_tags']
|
if config['allowed_tags']
|
||||||
failure = true if not (arg.keys - config['allowed_tags']).empty?
|
failure.push("You provided unsuppored tags (#{arg}).") if not (arg.keys - config['allowed_tags']).empty?
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
failure = true
|
failure.push("Unknown argument #{arg}.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if failure
|
if failure.size > 0
|
||||||
status 400
|
status 400
|
||||||
|
result['failure'] = failure
|
||||||
else
|
else
|
||||||
jdata.each do |param, arg|
|
jdata.each do |param, arg|
|
||||||
case param
|
case param
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue