mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 18:08:42 -05:00
(POOLER-123) Implement a max TTL
Before this change, we could checkout a vm and set the lifetime to a very high number which would esssentially keep the vm running forever. Now implementing a config setting max_lifetime_upper_limit which enforces a maximum lifetime in hours both for initial checkout and extending a running vm
This commit is contained in:
parent
86dbc783ef
commit
ac17284a61
4 changed files with 63 additions and 1 deletions
|
|
@ -892,6 +892,22 @@ module Vmpooler
|
|||
when 'lifetime'
|
||||
need_token! if Vmpooler::API.settings.config[:auth]
|
||||
|
||||
# in hours, defaults to one week
|
||||
max_lifetime_upper_limit = config[:max_lifetime_upper_limit]
|
||||
if max_lifetime_upper_limit
|
||||
max_lifetime_upper_limit = max_lifetime_upper_limit.to_i
|
||||
unless arg.to_i < max_lifetime_upper_limit
|
||||
failure = true
|
||||
end
|
||||
# also make sure we do not extend past max_lifetime_upper_limit
|
||||
rdata = backend.hgetall('vmpooler__vm__' + params[:hostname])
|
||||
running = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
||||
unless running + arg.to_i < max_lifetime_upper_limit
|
||||
failure = true
|
||||
end
|
||||
end
|
||||
|
||||
# validate lifetime is within boundaries
|
||||
unless arg.to_i > 0
|
||||
failure = true
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue