mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
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:
parent
3b97afe076
commit
17956294ca
2 changed files with 51 additions and 24 deletions
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -18,24 +18,25 @@ describe Vmpooler::API::V1 do
|
|||
Vmpooler::API
|
||||
end
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
pool_names: [ 'pool1', 'pool2', 'poolone' ]
|
||||
}
|
||||
}
|
||||
|
||||
describe '/config/pooltemplate' do
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
pool_names: [ 'pool1', 'pool2', 'poolone' ]
|
||||
}
|
||||
}
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
|
|
@ -170,15 +171,6 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe 'GET /config' do
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:config) {
|
||||
{
|
||||
config: {},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
it 'returns pool configuration when set' do
|
||||
get "#{prefix}/config"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue