mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 18:08:42 -05:00
Merge pull request #281 from mattkirby/pooler_109
(POOLER-109) Allow API to run independently
This commit is contained in:
commit
95d9c83479
13 changed files with 229 additions and 149 deletions
|
|
@ -4,8 +4,6 @@ module Vmpooler
|
|||
super
|
||||
end
|
||||
|
||||
set :environment, :production
|
||||
|
||||
not_found do
|
||||
content_type :json
|
||||
|
||||
|
|
@ -42,11 +40,10 @@ module Vmpooler
|
|||
use Vmpooler::API::Reroute
|
||||
use Vmpooler::API::V1
|
||||
|
||||
def configure(config, redis, metrics, environment = :production)
|
||||
def configure(config, redis, metrics)
|
||||
self.settings.set :config, config
|
||||
self.settings.set :redis, redis
|
||||
self.settings.set :metrics, metrics
|
||||
self.settings.set :environment, environment
|
||||
end
|
||||
|
||||
def execute!
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
module Vmpooler
|
||||
class Dashboard < Sinatra::Base
|
||||
|
||||
def config
|
||||
Vmpooler.config
|
||||
end
|
||||
|
||||
get '/dashboard/?' do
|
||||
erb :dashboard, locals: {
|
||||
site_name: $config[:config]['site_name'] || '<b>vmpooler</b>'
|
||||
site_name: ENV['SITE_NAME'] || config[:config]['site_name'] || '<b>vmpooler</b>'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,6 +32,31 @@ module Vmpooler
|
|||
$config
|
||||
end
|
||||
|
||||
# Place pool configuration in redis so an API instance can discover running pool configuration
|
||||
def load_pools_to_redis
|
||||
previously_configured_pools = $redis.smembers('vmpooler__pools')
|
||||
currently_configured_pools = []
|
||||
config[:pools].each do |pool|
|
||||
currently_configured_pools << pool['name']
|
||||
$redis.sadd('vmpooler__pools', pool['name'])
|
||||
pool_keys = pool.keys
|
||||
pool_keys.delete('alias')
|
||||
to_set = {}
|
||||
pool_keys.each do |k|
|
||||
to_set[k] = pool[k]
|
||||
end
|
||||
to_set['alias'] = pool['alias'].join(',') if to_set.has_key?('alias')
|
||||
$redis.hmset("vmpooler__pool__#{pool['name']}", to_set.to_a.flatten) unless to_set.empty?
|
||||
end
|
||||
previously_configured_pools.each do |pool|
|
||||
unless currently_configured_pools.include? pool
|
||||
$redis.srem('vmpooler__pools', pool)
|
||||
$redis.del("vmpooler__pool__#{pool}")
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
# Check the state of a VM
|
||||
def check_pending_vm(vm, pool, timeout, provider)
|
||||
Thread.new do
|
||||
|
|
@ -927,6 +952,9 @@ module Vmpooler
|
|||
end
|
||||
end
|
||||
|
||||
# Load running pool configuration into redis so API server can retrieve it
|
||||
load_pools_to_redis
|
||||
|
||||
# Get pool loop settings
|
||||
$config[:config] = {} if $config[:config].nil?
|
||||
check_loop_delay_min = $config[:config]['check_loop_delay_min'] || CHECK_LOOP_DELAY_MIN_DEFAULT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue