Sha256: a9038a5b06bfbce81f9617f0bc7600be52913f8457984fefe8d926f032515730

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require 'rubyipmi/ipmitool/errorcodes'
require 'rubyipmi/observablehash'
require 'rubyipmi/commands/basecommand'
require 'rubyipmi/ipmitool/commands/basecommand'

Dir[File.dirname(__FILE__) + '/commands/*.rb'].each do |file|
  require file
end

module Rubyipmi
  module Ipmitool

    class Connection

      attr_accessor :options, :debug


      def initialize(user, pass, host, opts)
        @debug = opts[:debug]
        @options = Rubyipmi::ObservableHash.new
        raise("Must provide a host to connect to") unless host
        @options["H"] = host
        # Credentials can also be stored in the freeipmi configuration file
        # So they are not required
        @options["U"] = user if user
        @options["P"] = pass if pass
        if opts.has_key?(:privilege)
          @options["L"] = opts[:privilege]
        end
        # Note: rubyipmi should auto detect which driver to use so its unnecessary to specify the driver unless
        #  the user really wants to.
        @options['I'] = drivers_map[opts[:driver]] unless drivers_map[opts[:driver]].nil?
      end

      def drivers_map
        {
          'lan15' => 'lan',
          'lan20' => 'lanplus',
          'open'  => 'open'
        }
      end

      def fru
        @fru ||= Rubyipmi::Ipmitool::Fru.new(@options)
      end

      def provider
        'ipmitool'
      end

      def bmc
        @bmc ||= Rubyipmi::Ipmitool::Bmc.new(@options)
      end

      def sensors
        @sensors ||= Rubyipmi::Ipmitool::Sensors.new(@options)
      end

      def chassis
        @chassis ||= Rubyipmi::Ipmitool::Chassis.new(@options)
      end

      def get_diag
        data = {}
        data['provider'] = provider
        if @fru
          data['frus'] = @fru.getfrus
        end
        if @sensors
          data['sensors'] = @sensors.getsensors
        end
        if @bmc
          data['bmc_info'] = @bmc.info
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubyipmi-0.8.1 lib/rubyipmi/ipmitool/connection.rb