mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(QENG-1906) Refactor initialize to allow config passing
Prior to this commit, several pieces of vmpooler performed configuration and initialization steps within 'initialize'. This made it difficult to pass in mock objects for testing purposes. This commit performs a single configuration and passes the results to the various pieces of vmpooler.
This commit is contained in:
parent
34fd054a48
commit
1408f35867
7 changed files with 141 additions and 109 deletions
|
|
@ -1,24 +1,7 @@
|
|||
module Vmpooler
|
||||
class API < Sinatra::Base
|
||||
def initialize
|
||||
# Load the configuration file
|
||||
config_file = File.expand_path('vmpooler.yaml')
|
||||
$config = YAML.load_file(config_file)
|
||||
|
||||
$config[:uptime] = Time.now
|
||||
|
||||
# Set some defaults
|
||||
$config[:redis] ||= {}
|
||||
$config[:redis]['server'] ||= 'localhost'
|
||||
|
||||
if $config[:graphite]['server']
|
||||
$config[:graphite]['prefix'] ||= 'vmpooler'
|
||||
end
|
||||
|
||||
# Connect to Redis
|
||||
$redis = Redis.new(host: $config[:redis]['server'])
|
||||
|
||||
super()
|
||||
super
|
||||
end
|
||||
|
||||
set :environment, :production
|
||||
|
|
@ -51,8 +34,14 @@ module Vmpooler
|
|||
use Vmpooler::API::Reroute
|
||||
use Vmpooler::API::V1
|
||||
|
||||
Thread.new do
|
||||
run!
|
||||
def configure(config, redis, environment = :production)
|
||||
self.settings.set :config, config
|
||||
self.settings.set :redis, redis
|
||||
self.settings.set :environment, environment
|
||||
end
|
||||
|
||||
def execute!
|
||||
self.settings.run!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue