lib/rundock/runner.rb in rundock-0.2.2 vs lib/rundock/runner.rb in rundock-0.2.3

- old
+ new

@@ -2,16 +2,18 @@ require 'open-uri' module Rundock class Runner ScenarioNotFoundError = Class.new(StandardError) + RUNDOCK_PLUGINS = %w(operation hook) class << self def run(options) Logger.debug 'Starting Rundoc:' runner = self.new(options) + runner.load_plugins runner.build(options) runner.run end end @@ -23,14 +25,10 @@ def run @scenario.run end - def run_tasks - @scenario.run - end - def build(options) if options[:scenario] || options[:hostgroup] if options[:scenario] && !FileTest.exist?(options[:scenario]) raise ScenarioNotFoundError, "'#{options[:scenario]}' scenario file is not found." elsif options[:hostgroup] && !FileTest.exist?(options[:hostgroup]) @@ -51,9 +49,33 @@ end end else # do rundock ssh @scenario = Rundock::Builder::ScenarioBuilder.new(options, nil).build + end + end + + def load_plugins + Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/plugin/**/*.rb").each do |f| + require f.gsub(/.rb$/, '') + end + + gems = [] + Gem::Specification.each do |gem| + gems << gem.name + end + gems.uniq! + + gems.each do |g| + RUNDOCK_PLUGINS.each do |plugin| + next if g !~ /^(rundock-plugin-#{plugin})-/ + next if Gem::Specification.find_by_path(g).nil? + Logger.debug("Loading rundock plugin: #{g}") + libdir = "#{Gem::Specification.find_by_path(g).full_gem_path}/lib/rundock/plugin/#{Regexp.last_match(0)}" + Dir.glob("#{libdir}/*.rb").each do |f| + require f.gsub(/.rb$/, '') + end + end end end end end