diff --git a/support/ruby/consolr/lib/consolr.rb b/support/ruby/consolr/lib/consolr.rb index 9b460aa1f..0b448152c 100755 --- a/support/ruby/consolr/lib/consolr.rb +++ b/support/ruby/consolr/lib/consolr.rb @@ -5,7 +5,6 @@ require 'optparse' require 'yaml' -require 'consolr/runners/ipmitool' module Consolr class Console @@ -90,14 +89,35 @@ def start options abort("Please pass either the hostname OR the tag but not both.") end + runners = @config_params.fetch('runners', []).map {|runner| + begin + require "consolr/runners/#{runner}" + Consolr::Runners.const_get(runner.capitalize).new @config_params.fetch(runner, {}) + rescue NameError => e + puts "Could not load runner #{runner.capitalize}, skipping." + end + }.compact + + # Default to the ipmitool runner for backwards compatibility + if runners.empty? + require 'consolr/runners/ipmitool' + runners = [Consolr::Runners::Ipmitool.new(@config_params.fetch('ipmitool', {}))] + end # match assets like vm-67f5eh, zt-*, etc. nodes = options[:tag] ? (collins.find :tag => options[:tag]) : (collins.find :hostname => options[:hostname]) @node = nodes.length == 1 ? nodes.first : abort("Found #{nodes.length} assets, aborting.") - runner = Consolr::Runners::Ipmitool.new @config_params['ipmitool'] + # select the first runner that support the node + runner = runners.select {|runner| + runner.can_run? @node + }.first + + if runner.nil? + abort("No runners available for node #{@node.hostname} (#{@node.tag})") + end - if not runner.verify? @node + if not runner.verify @node abort("Cannot verify asset #{@node.hostname} (#{@node.tag})") end diff --git a/support/ruby/consolr/lib/consolr/runners/ipmitool.rb b/support/ruby/consolr/lib/consolr/runners/ipmitool.rb index 141bb2b1e..980fe4e16 100644 --- a/support/ruby/consolr/lib/consolr/runners/ipmitool.rb +++ b/support/ruby/consolr/lib/consolr/runners/ipmitool.rb @@ -4,10 +4,18 @@ module Consolr module Runners class Ipmitool < Runner def initialize config - @ipmitool = config['executable'] + @ipmitool = if config.empty? + '/usr/bin/ipmitool' + else + config + end end - def verify? node + def can_run? node + not (node.ipmi.address.empty? or node.ipmi.username.empty? or node.ipmi.password.empty?) + end + + def verify node Net::Ping::External.new(node.ipmi.address).ping? end @@ -16,11 +24,11 @@ def console node end def kick node - cmd 'sol dectivate', node + cmd 'sol deactivate', node end def identify node - cmd 'identify', node + cmd 'chassis identify', node end def sdr node