mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 02:18:41 -05:00
(QENG-3919) Naming fix, cosmetic cleanups
I mean, I presume all these commits are going to get squashed away on merge anyway.
This commit is contained in:
parent
67748e33b4
commit
2ea47a98be
1 changed files with 39 additions and 39 deletions
|
|
@ -96,6 +96,42 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def atomically_allocate_vms(payload)
|
||||||
|
return false unless payload and !payload.empty?
|
||||||
|
|
||||||
|
result = { 'ok' => false }
|
||||||
|
failed = false
|
||||||
|
vms = []
|
||||||
|
|
||||||
|
payload.each do |template, count|
|
||||||
|
count.to_i.times do |_i|
|
||||||
|
vm = fetch_single_vm(template)
|
||||||
|
if !vm
|
||||||
|
failed = true
|
||||||
|
break
|
||||||
|
else
|
||||||
|
vms << [ template, vm ]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if failed
|
||||||
|
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
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
get "#{api_prefix}/status/?" do
|
get "#{api_prefix}/status/?" do
|
||||||
content_type :json
|
content_type :json
|
||||||
|
|
||||||
|
|
@ -361,10 +397,10 @@ module Vmpooler
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
def payload_from_template(template)
|
def extract_templates_from_query_params(params)
|
||||||
payload = {}
|
payload = {}
|
||||||
|
|
||||||
params[:template].split('+').each do |template|
|
params.split('+').each do |template|
|
||||||
payload[template] ||= 0
|
payload[template] ||= 0
|
||||||
payload[template] += 1
|
payload[template] += 1
|
||||||
end
|
end
|
||||||
|
|
@ -372,44 +408,8 @@ module Vmpooler
|
||||||
payload
|
payload
|
||||||
end
|
end
|
||||||
|
|
||||||
def atomically_allocate_vms(payload)
|
|
||||||
return false unless payload and !payload.empty?
|
|
||||||
|
|
||||||
result = { 'ok' => false }
|
|
||||||
failed = false
|
|
||||||
vms = []
|
|
||||||
|
|
||||||
payload.each do |template, count|
|
|
||||||
count.to_i.times do |_i|
|
|
||||||
vm = fetch_single_vm(template)
|
|
||||||
if !vm
|
|
||||||
failed = true
|
|
||||||
break
|
|
||||||
else
|
|
||||||
vms << [ template, vm ]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if failed
|
|
||||||
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
|
|
||||||
|
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
post "#{api_prefix}/vm/:template/?" do
|
post "#{api_prefix}/vm/:template/?" do
|
||||||
payload = alias_deref(payload_from_template(params[:template]))
|
payload = alias_deref(extract_templates_from_query_params(params[:template]))
|
||||||
content_type :json
|
content_type :json
|
||||||
result = { 'ok' => false }
|
result = { 'ok' => false }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue