mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 02:18:41 -05:00
(QENG-3919) Bring query params version in line with JSON post version
Not clear to me why these had to be implemented so differently.
This commit is contained in:
parent
c0cf772281
commit
0e66d35199
1 changed files with 38 additions and 27 deletions
|
|
@ -348,12 +348,12 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
post "#{api_prefix}/vm/?" do
|
post "#{api_prefix}/vm/?" do
|
||||||
|
jdata = alias_deref(JSON.parse(request.body.read))
|
||||||
|
|
||||||
content_type :json
|
content_type :json
|
||||||
result = { 'ok' => false }
|
result = { 'ok' => false }
|
||||||
|
|
||||||
jdata = alias_deref(JSON.parse(request.body.read))
|
if jdata and !jdata.empty?
|
||||||
|
|
||||||
if not jdata.nil? and not jdata.empty?
|
|
||||||
failed = false
|
failed = false
|
||||||
vms = []
|
vms = []
|
||||||
|
|
||||||
|
|
@ -389,43 +389,54 @@ module Vmpooler
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
post "#{api_prefix}/vm/:template/?" do
|
def payload_from_template(template)
|
||||||
content_type :json
|
|
||||||
|
|
||||||
result = { 'ok' => false }
|
|
||||||
payload = {}
|
payload = {}
|
||||||
|
|
||||||
params[:template].split('+').each do |template|
|
params[:template].split('+').each do |template|
|
||||||
payload[template] ||= 0
|
payload[template] ||= 0
|
||||||
payload[template] = payload[template] + 1
|
payload[template] += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
payload = alias_deref(payload)
|
payload
|
||||||
|
end
|
||||||
|
|
||||||
if not payload.nil? and not payload.empty?
|
post "#{api_prefix}/vm/:template/?" do
|
||||||
available = 1
|
payload = alias_deref(payload_from_template(params[:template]))
|
||||||
else
|
|
||||||
status 404
|
|
||||||
end
|
|
||||||
|
|
||||||
payload.each do |key, val|
|
content_type :json
|
||||||
if backend.scard('vmpooler__ready__' + key).to_i < val.to_i
|
result = { 'ok' => false }
|
||||||
available = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if (available == 1)
|
if payload and !payload.empty?
|
||||||
result['ok'] = true
|
failed = false
|
||||||
|
vms = []
|
||||||
|
|
||||||
payload.each do |key, val|
|
payload.each do |template, count|
|
||||||
val.to_i.times do |_i|
|
count.to_i.times do |_i|
|
||||||
result = checkout_vm(key, result)
|
vm = fetch_single_vm(template)
|
||||||
|
if !vm
|
||||||
|
failed = true
|
||||||
|
break
|
||||||
|
else
|
||||||
|
vms << [ template, vm ]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if result['ok'] && config['domain']
|
if failed
|
||||||
result['domain'] = config['domain']
|
vms.each do |(template, vm)|
|
||||||
|
return_single_vm(template, vm)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
vms.each do |(template, vm)|
|
||||||
|
account_for_starting_vm(template, vm)
|
||||||
|
update_result_hosts(result, template, vm)
|
||||||
|
end
|
||||||
|
|
||||||
|
result['ok'] = true
|
||||||
|
result['domain'] = config['domain'] if config['domain']
|
||||||
|
end
|
||||||
|
else
|
||||||
|
status 404
|
||||||
end
|
end
|
||||||
|
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue