Ensure pool sizes and templates are synced

This commit adds a step to sync pool sizes and templates when interacting with the configuration API. Without this change a pool size change is not reflected by the API loaded configuration until the change is made again via the API, and this registers as a new change.
This commit is contained in:
kirby@puppetlabs.com 2018-05-24 14:12:44 -07:00
parent 3b97afe076
commit 17956294ca
2 changed files with 51 additions and 24 deletions

View file

@ -125,6 +125,7 @@ module Vmpooler
pool_index = pool_index(pools)
pools_updated = 0
sync_pool_sizes
payload.each do |poolname, size|
unless pools[pool_index[poolname]]['size'] == size.to_i
@ -144,6 +145,7 @@ module Vmpooler
pool_index = pool_index(pools)
pools_updated = 0
sync_pool_templates
payload.each do |poolname, template|
unless pools[pool_index[poolname]]['template'] == template
@ -158,6 +160,34 @@ module Vmpooler
result
end
def sync_pool_templates
pool_index = pool_index(pools)
template_configs = backend.hgetall('vmpooler__config__template')
unless template_configs.nil?
template_configs.each do |poolname, template|
if pool_index.include? poolname
unless pools[pool_index[poolname]]['template'] == template
pools[pool_index[poolname]]['template'] = template
end
end
end
end
end
def sync_pool_sizes
pool_index = pool_index(pools)
poolsize_configs = backend.hgetall('vmpooler__config__poolsize')
unless poolsize_configs.nil?
poolsize_configs.each do |poolname, size|
if pool_index.include? poolname
unless pools[pool_index[poolname]]['size'] == size.to_i
pools[pool_index[poolname]]['size'] == size.to_i
end
end
end
end
end
# Provide run-time statistics
#
# Example:
@ -234,6 +264,8 @@ module Vmpooler
}
}
sync_pool_sizes
result[:capacity] = get_capacity_metrics(pools, backend) unless views and not views.include?("capacity")
result[:queue] = get_queue_metrics(pools, backend) unless views and not views.include?("queue")
result[:clone] = get_task_metrics(backend, 'clone', Date.today.to_s) unless views and not views.include?("clone")
@ -864,6 +896,9 @@ module Vmpooler
status 404
if pools
sync_pool_sizes
sync_pool_templates
result = {
pool_configuration: pools,
status: {