mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Allow an external Redis server to be specified
This commit is contained in:
parent
ac52d0df3e
commit
b6f4b735e8
2 changed files with 17 additions and 11 deletions
|
|
@ -18,6 +18,7 @@ $config = YAML.load_file(config_file)
|
||||||
|
|
||||||
pools = $config[:pools]
|
pools = $config[:pools]
|
||||||
vsphere = $config[:vsphere]
|
vsphere = $config[:vsphere]
|
||||||
|
redis = $config[:redis]
|
||||||
|
|
||||||
# Load logger library
|
# Load logger library
|
||||||
$logger = Logger.new $config[:config]['logfile']
|
$logger = Logger.new $config[:config]['logfile']
|
||||||
|
|
@ -31,9 +32,10 @@ end
|
||||||
# Set some defaults
|
# Set some defaults
|
||||||
$config[:config]['task_limit'] ||= 10
|
$config[:config]['task_limit'] ||= 10
|
||||||
$config[:config]['vm_lifetime'] ||= 24
|
$config[:config]['vm_lifetime'] ||= 24
|
||||||
|
$config[:redis]['server'] ||= 'localhost'
|
||||||
|
|
||||||
# Connect to Redis
|
# Connect to Redis
|
||||||
$redis = Redis.new
|
$redis = Redis.new(:host => $config[:redis]['server'])
|
||||||
|
|
||||||
# vSphere object
|
# vSphere object
|
||||||
$vsphere = {}
|
$vsphere = {}
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,24 @@ Dir.chdir(File.dirname(__FILE__))
|
||||||
|
|
||||||
# Load the configuration file
|
# Load the configuration file
|
||||||
config_file = File.expand_path('vmware-host-pooler.yaml')
|
config_file = File.expand_path('vmware-host-pooler.yaml')
|
||||||
config = YAML.load_file(config_file)
|
$config = YAML.load_file(config_file)
|
||||||
|
|
||||||
pools = config[:pools]
|
pools = $config[:pools]
|
||||||
|
redis = $config[:redis]
|
||||||
|
|
||||||
# Load logger library
|
# Load logger library
|
||||||
$logger = Logger.new config[:config]['logfile']
|
$logger = Logger.new $config[:config]['logfile']
|
||||||
|
|
||||||
|
# Set some defaults
|
||||||
|
$config[:redis]['server'] ||= 'localhost'
|
||||||
|
|
||||||
# Connect to Redis
|
# Connect to Redis
|
||||||
$redis = Redis.new
|
$redis = Redis.new(:host => $config[:redis]['server'])
|
||||||
|
|
||||||
# Sinatra!
|
# Sinatra!
|
||||||
get '/' do
|
get '/' do
|
||||||
erb :dashboard, locals: {
|
erb :dashboard, locals: {
|
||||||
site_name: config[:config]['site_name'] || '<b>vmware-host-pooler</b>',
|
site_name: $config[:config]['site_name'] || '<b>vmware-host-pooler</b>',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -42,7 +46,7 @@ get '/dashboard/stats/vcloud/numbers' do
|
||||||
result['running'] = 0
|
result['running'] = 0
|
||||||
result['completed'] = 0
|
result['completed'] = 0
|
||||||
|
|
||||||
config[:pools].each do |pool|
|
$config[:pools].each do |pool|
|
||||||
result['pending'] += $redis.scard( 'vmware_host_pool__pending__' + pool['name'] )
|
result['pending'] += $redis.scard( 'vmware_host_pool__pending__' + pool['name'] )
|
||||||
result['ready'] += $redis.scard( 'vmware_host_pool__ready__' + pool['name'] )
|
result['ready'] += $redis.scard( 'vmware_host_pool__ready__' + pool['name'] )
|
||||||
result['running'] += $redis.scard( 'vmware_host_pool__running__' + pool['name'] )
|
result['running'] += $redis.scard( 'vmware_host_pool__running__' + pool['name'] )
|
||||||
|
|
@ -61,18 +65,18 @@ end
|
||||||
get '/dashboard/stats/vcloud/pool' do
|
get '/dashboard/stats/vcloud/pool' do
|
||||||
result = Hash.new
|
result = Hash.new
|
||||||
|
|
||||||
config[:pools].each do |pool|
|
$config[:pools].each do |pool|
|
||||||
result[pool['name']] ||= Hash.new
|
result[pool['name']] ||= Hash.new
|
||||||
result[pool['name']]['size'] = pool['size']
|
result[pool['name']]['size'] = pool['size']
|
||||||
result[pool['name']]['ready'] = $redis.scard( 'vmware_host_pool__ready__' + pool['name'] )
|
result[pool['name']]['ready'] = $redis.scard( 'vmware_host_pool__ready__' + pool['name'] )
|
||||||
end
|
end
|
||||||
|
|
||||||
if ( params[:history] )
|
if ( params[:history] )
|
||||||
if ( config[:config]['graphite'] )
|
if ( $config[:config]['graphite'] )
|
||||||
history ||= Hash.new
|
history ||= Hash.new
|
||||||
|
|
||||||
begin
|
begin
|
||||||
buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.ready.*&from=-1hour&format=json' ).read
|
buffer = open( 'http://'+$config[:config]['graphite']+'/render?target=vcloud.ready.*&from=-1hour&format=json' ).read
|
||||||
history = JSON.parse( buffer )
|
history = JSON.parse( buffer )
|
||||||
|
|
||||||
history.each do |pool|
|
history.each do |pool|
|
||||||
|
|
@ -99,7 +103,7 @@ get '/dashboard/stats/vcloud/pool' do
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
config[:pools].each do |pool|
|
$config[:pools].each do |pool|
|
||||||
result[pool['name']] ||= Hash.new
|
result[pool['name']] ||= Hash.new
|
||||||
result[pool['name']]['history'] = [ $redis.scard( 'vmware_host_pool__ready__' + pool['name'] ) ]
|
result[pool['name']]['history'] = [ $redis.scard( 'vmware_host_pool__ready__' + pool['name'] ) ]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue