Sha256: deb48bf2c0e87b56ab648bab5c13cc4cd06a0f0f0ddb2f10a7245d08300577a3

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

require 'consolr/runners/runner'

module Consolr
  module Runners
    class Ipmitool < Runner
      def initialize config
        @ipmitool = if config.empty?
                      '/usr/bin/ipmitool'
                    else
                      config
                    end
      end

      def can_run? node
        begin
          not (node.ipmi.address.empty? or node.ipmi.username.empty? or node.ipmi.password.empty?)
        rescue
          false
        end
      end

      def verify node
        Net::Ping::External.new(node.ipmi.address).ping?
      end

      def console node
        cmd 'sol activate', node
      end

      def kick node
        cmd 'sol deactivate', node
      end

      def identify node
        cmd 'chassis identify', node
      end

      def sdr node
        cmd 'sdr elist all', node
      end

      def log_list node
        cmd 'sel list', node
      end

      def log_clear node
        cmd 'sel clear', node
      end

      def on node
        cmd 'power on', node
      end

      def off node
        cmd 'power off', node
      end

      def soft_off node
        cmd 'power soft', node
      end

      def reboot node
        cmd 'power cycle', node
      end

      def soft_reboot node
        cmd 'power reset', node
      end

      def status node
        cmd 'power status', node
      end

      def sensors node
        cmd 'sensor list', node
      end

      def sol_info node
        cmd 'session info active', node
      end

      private
      def cmd action, node
        system("#{@ipmitool} -I lanplus -H #{node.ipmi.address} -U #{node.ipmi.username} -P #{node.ipmi.password} #{action}")
        return $?.exitstatus == 0 ? "SUCCESS" : "FAILED"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
consolr-1.1.5 lib/consolr/runners/ipmitool.rb
consolr-1.1.4 lib/consolr/runners/ipmitool.rb
consolr-1.1.3 lib/consolr/runners/ipmitool.rb
consolr-1.1.2 lib/consolr/runners/ipmitool.rb