mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Clean up Redis VM objects after redis['data_ttl']
This commit is contained in:
parent
48a9ef0dfd
commit
7b97e58e0f
5 changed files with 47 additions and 3 deletions
|
|
@ -11,7 +11,7 @@ module Vmpooler
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
%w( api graphite logger pool_manager vsphere_helper ).each do |lib|
|
%w( api graphite janitor logger pool_manager vsphere_helper ).each do |lib|
|
||||||
begin
|
begin
|
||||||
require "vmpooler/#{lib}"
|
require "vmpooler/#{lib}"
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
||||||
39
lib/vmpooler/janitor.rb
Normal file
39
lib/vmpooler/janitor.rb
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
module Vmpooler
|
||||||
|
class Janitor
|
||||||
|
def initialize
|
||||||
|
# Load the configuration file
|
||||||
|
config_file = File.expand_path('vmpooler.yaml')
|
||||||
|
$config = YAML.load_file(config_file)
|
||||||
|
|
||||||
|
# Set some defaults
|
||||||
|
$config[:redis] ||= {}
|
||||||
|
$config[:redis]['server'] ||= 'localhost'
|
||||||
|
$config[:redis]['data_ttl'] ||= 168
|
||||||
|
|
||||||
|
# Load logger library
|
||||||
|
$logger = Vmpooler::Logger.new $config[:config]['logfile']
|
||||||
|
|
||||||
|
# Connect to Redis
|
||||||
|
$redis = Redis.new(host: $config[:redis]['server'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute!
|
||||||
|
|
||||||
|
loop do
|
||||||
|
$redis.keys('vmpooler__vm__*').each do |key|
|
||||||
|
data = $redis.hgetall(key);
|
||||||
|
|
||||||
|
if data['destroy']
|
||||||
|
lifetime = (Time.now - Time.parse(data['destroy'])) / 60 / 60
|
||||||
|
|
||||||
|
if lifetime > $config[:redis]['data_ttl']
|
||||||
|
$redis.del(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sleep(600)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -11,8 +11,8 @@ module Vmpooler
|
||||||
$config[:config]['task_limit'] ||= 10
|
$config[:config]['task_limit'] ||= 10
|
||||||
$config[:config]['vm_checktime'] ||= 15
|
$config[:config]['vm_checktime'] ||= 15
|
||||||
$config[:config]['vm_lifetime'] ||= 24
|
$config[:config]['vm_lifetime'] ||= 24
|
||||||
$config[:redis] ||= {}
|
$config[:redis] ||= {}
|
||||||
$config[:redis]['server'] ||= 'localhost'
|
$config[:redis]['server'] ||= 'localhost'
|
||||||
|
|
||||||
# Load logger library
|
# Load logger library
|
||||||
$logger = Vmpooler::Logger.new $config[:config]['logfile']
|
$logger = Vmpooler::Logger.new $config[:config]['logfile']
|
||||||
|
|
|
||||||
1
vmpooler
1
vmpooler
|
|
@ -6,6 +6,7 @@ require 'rubygems' unless defined?(Gem)
|
||||||
require 'lib/vmpooler'
|
require 'lib/vmpooler'
|
||||||
|
|
||||||
Thread.new { Vmpooler::API.new.execute! }
|
Thread.new { Vmpooler::API.new.execute! }
|
||||||
|
Thread.new { Vmpooler::Janitor.new.execute! }
|
||||||
Thread.new { Vmpooler::PoolManager.new.execute! }
|
Thread.new { Vmpooler::PoolManager.new.execute! }
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@
|
||||||
# - password
|
# - password
|
||||||
# The password used to authenticate Redis.
|
# The password used to authenticate Redis.
|
||||||
# (optional)
|
# (optional)
|
||||||
|
#
|
||||||
|
# - data_ttl
|
||||||
|
# How long (in hours) to retain metadata in Redis after VM destruction.
|
||||||
|
# (optional; default: '168')
|
||||||
|
|
||||||
# Example:
|
# Example:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue