Class: Rubyipmi::Freeipmi::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyipmi/freeipmi/connection.rb

Constant Summary collapse

DRIVERS_MAP =
{
  'lan15' => 'LAN',
  'lan20' => 'LAN_2_0',
  'open'  => 'OPENIPMI'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, pass, host, opts) ⇒ Connection

Returns a new instance of Connection.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubyipmi/freeipmi/connection.rb', line 21

def initialize(user, pass, host, opts)
  @options = Rubyipmi::ObservableHash.new
  raise("Must provide a host to connect to") unless host
  @options["hostname"] = host
  # Credentials can also be stored in the freeipmi configuration file
  # So they are not required
  @options["username"] = user if user
  @options["password"] = pass if pass
  if opts.key?(:privilege)
    @options["privilege-level"] = opts[:privilege] # privilege type
  end
  # Note: rubyipmi should auto detect which driver to use so its unnecessary to specify the driver unless
  #       the user really wants to
  @options['driver-type'] = DRIVERS_MAP[opts[:driver]] unless DRIVERS_MAP[opts[:driver]].nil?
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/rubyipmi/freeipmi/connection.rb', line 13

def options
  @options
end

Instance Method Details

#bmcObject



52
53
54
# File 'lib/rubyipmi/freeipmi/connection.rb', line 52

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

#chassisObject



56
57
58
# File 'lib/rubyipmi/freeipmi/connection.rb', line 56

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

#connection_works?Boolean

test the connection to ensure we can at least make a single call

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/rubyipmi/freeipmi/connection.rb', line 38

def connection_works?
  ! (bmc.info.nil? || bmc.info.empty?)
rescue
  false
end

#fruObject



48
49
50
# File 'lib/rubyipmi/freeipmi/connection.rb', line 48

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

#get_diagObject



64
65
66
67
68
69
70
71
72
# File 'lib/rubyipmi/freeipmi/connection.rb', line 64

def get_diag
  data = {}
  data[:provider] = provider
  data[:frus]     = fru.getfrus
  data[:sensors]  = sensors.getsensors
  data[:bmc_info] = bmc.info
  data[:version]  = bmc.version
  data
end

#providerObject



44
45
46
# File 'lib/rubyipmi/freeipmi/connection.rb', line 44

def provider
  'freeipmi'
end

#sensorsObject



60
61
62
# File 'lib/rubyipmi/freeipmi/connection.rb', line 60

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