mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(POOLER-193) Mark checked out VM as active
This change sets a VM as running in redis as soon as it is checked out. Without this change when allocated several instances it is possible for a machine that has been allocated for a checkout, but not yet marked as active, to be identified as running when it should not be, which was added in POOLER-191. Without this change a machine may be destroyed during checkout by pool_manager if there are several instances being allocated. Additionally, redis multi is added for vm checkout operations to minimize the round trips to redis during a checkout operation. Without this addition each VM checkout causes several redis interactions.
This commit is contained in:
parent
a3cfe7749e
commit
cfd6a5f991
1 changed files with 20 additions and 13 deletions
|
|
@ -163,26 +163,31 @@ module Vmpooler
|
|||
end
|
||||
|
||||
def return_vm_to_ready_state(template, vm)
|
||||
backend.multi
|
||||
backend.srem("vmpooler__migrating__#{template}", vm)
|
||||
backend.hdel("vmpooler__active__#{template}", vm)
|
||||
backend.hdel("vmpooler__vm__#{vm}", 'checkout', 'token:token', 'token:user')
|
||||
backend.smove("vmpooler__running__#{template}", "vmpooler__ready__#{template}", vm)
|
||||
backend.exec
|
||||
end
|
||||
|
||||
def account_for_starting_vm(template, vm)
|
||||
user = backend.hget("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'user')
|
||||
has_token_result = has_token?
|
||||
backend.multi
|
||||
backend.sadd("vmpooler__migrating__#{template}", vm)
|
||||
backend.hset("vmpooler__active__#{template}", vm, Time.now)
|
||||
backend.hset("vmpooler__vm__#{vm}", 'checkout', Time.now)
|
||||
|
||||
if Vmpooler::API.settings.config[:auth] and has_token?
|
||||
validate_token(backend)
|
||||
|
||||
if Vmpooler::API.settings.config[:auth] and has_token_result
|
||||
backend.hset("vmpooler__vm__#{vm}", 'token:token', request.env['HTTP_X_AUTH_TOKEN'])
|
||||
backend.hset("vmpooler__vm__#{vm}", 'token:user',
|
||||
backend.hget("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'user')
|
||||
)
|
||||
backend.hset("vmpooler__vm__#{vm}", 'token:user', user)
|
||||
|
||||
if config['vm_lifetime_auth'].to_i > 0
|
||||
backend.hset("vmpooler__vm__#{vm}", 'lifetime', config['vm_lifetime_auth'].to_i)
|
||||
end
|
||||
end
|
||||
backend.exec
|
||||
end
|
||||
|
||||
def update_result_hosts(result, template, vm)
|
||||
|
|
@ -200,16 +205,19 @@ module Vmpooler
|
|||
failed = false
|
||||
vms = []
|
||||
|
||||
validate_token(backend) if Vmpooler::API.settings.config[:auth] and has_token?
|
||||
|
||||
payload.each do |requested, count|
|
||||
count.to_i.times do |_i|
|
||||
vmname, vmpool, vmtemplate = fetch_single_vm(requested)
|
||||
if !vmname
|
||||
if vmname
|
||||
account_for_starting_vm(vmpool, vmname)
|
||||
vms << [vmpool, vmname, vmtemplate]
|
||||
metrics.increment("checkout.success.#{vmtemplate}")
|
||||
else
|
||||
failed = true
|
||||
metrics.increment("checkout.empty.#{requested}")
|
||||
break
|
||||
else
|
||||
vms << [vmpool, vmname, vmtemplate]
|
||||
metrics.increment("checkout.success.#{vmpool}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -220,8 +228,7 @@ module Vmpooler
|
|||
end
|
||||
status 503
|
||||
else
|
||||
vms.each do |(vmpool, vmname, vmtemplate)|
|
||||
account_for_starting_vm(vmpool, vmname)
|
||||
vms.each do |(_vmpool, vmname, vmtemplate)|
|
||||
update_result_hosts(result, vmtemplate, vmname)
|
||||
end
|
||||
|
||||
|
|
@ -1094,7 +1101,7 @@ module Vmpooler
|
|||
result[params[:hostname]]['lifetime'] = (rdata['lifetime'] || config['vm_lifetime']).to_i
|
||||
|
||||
if rdata['destroy']
|
||||
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
||||
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2) if rdata['checkout']
|
||||
result[params[:hostname]]['state'] = 'destroyed'
|
||||
elsif rdata['checkout']
|
||||
result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue