Skip to content

Commit

Permalink
ipmitool_fru: Add new fact to show to information from ipmtool fru
Browse files Browse the repository at this point in the history
This CR adds a new structured fact called ipmitool with two keys fru and
mc_info.  fru is new data from ipmitool fru print.  mc_info is the
current ipmi_mc_info  fact.  I have updated the ipmi_mc_info fact so
that it uses this new structured fact.

The new fact will look like the following:

```
{
  fru => {
    fru_device_description => "OEM fru (ID 17)",
    board_mfg_date => "Tue Mar  3 21:43:00 2015",
    board_mfg => "DELL",
    board_product => "PowerEdge R220",
    board_serial => "*********",
    board_part_number => "0DRXF5A04",
    product_manufacturer => "DELL",
    product_name => "Test",
    product_extra => "*********"
  },
  mc_info => {
    IPMI_Puppet_Service_Recommend => "running",
    Device ID => "32",
    Device Revision => "1",
    Firmware Revision => "2.65",
    IPMI Version => "2.0",
    Manufacturer ID => "674",
    Manufacturer Name => "DELL Inc",
    Product ID => "256 (0x0100)",
    Product Name => "Unknown (0x100)",
    Device Available => "yes",
    Provides Device SDRs => "yes"
  }
}
```

We are able to use commands like the following:
set the board_product with:
* sudo ipmitool fru edit 0 field b 1

And the product_name with:
* sudo ipmitool fru edit 0 field p 1
  • Loading branch information
b4ldr committed Feb 13, 2024
1 parent b994667 commit 26449ea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
36 changes: 36 additions & 0 deletions lib/facter/ipmitool.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

Facter.add(:ipmitool, :type => :aggregate) do

Check failure on line 4 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/HashSyntax: Use the new Ruby 1.9 hash syntax. (https://rubystyle.guide#hash-literals)
# https://puppet.com/docs/puppet/latest/fact_overview.html
confine kernel: 'Linux'
confine is_virtual: false
confine do
Facter::Util::Resolution.which('ipmitool')
end

chunk(:fru) do
retval = {fru: {}}

Check failure on line 13 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceInsideHashLiteralBraces: Space inside { missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 13 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceInsideHashLiteralBraces: Space inside } missing. (https://rubystyle.guide#spaces-braces)
ipmitool_output = Facter::Util::Resolution.exec('ipmitool fru print 2>/dev/null')
ipmitool_output.each_line do |line|
next unless line.include?(':')

Check failure on line 16 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
info = line.split(':', 2)
next if info[1].strip.empty?

Check failure on line 18 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
key = info[0].strip.tr("\s", "_").downcase

Check failure on line 19 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://rubystyle.guide#consistent-string-literals)
retval[:fru][key] = info[1].strip
end
retval
end

chunk(:mc_info) do
retval = {mc_info: {'IPMI_Puppet_Service_Recommend' => 'stopped'}}

Check failure on line 26 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceInsideHashLiteralBraces: Space inside { missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 26 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceInsideHashLiteralBraces: Space inside { missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 26 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceInsideHashLiteralBraces: Space inside } missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 26 in lib/facter/ipmitool.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceInsideHashLiteralBraces: Space inside } missing. (https://rubystyle.guide#spaces-braces)
ipmitool_output = Facter::Util::Resolution.exec('ipmitool mc info 2>/dev/null')

ipmitool_output.each_line do |line|
info = line.split(':')
retval[:mc_info][info[0].strip] = info[1].strip if info.length == 2 && (info[1].strip != '')
end
retval[:mc_info]['IPMI_Puppet_Service_Recommend'] = 'running' if retval[:mc_info].fetch('Device Available', 'no') == 'yes'
retval
end
end
16 changes: 1 addition & 15 deletions lib/facter/ipmitool_mc_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,7 @@
Facter.add(:ipmitool_mc_info) do
# https://puppet.com/docs/puppet/latest/fact_overview.html
confine kernel: 'Linux'

retval = {}
retval['IPMI_Puppet_Service_Recommend'] = 'stopped'

if Facter::Util::Resolution.which('ipmitool')
ipmitool_output = Facter::Util::Resolution.exec('ipmitool mc info 2>/dev/null')

ipmitool_output.each_line do |line|
info = line.split(':')
retval[info[0].strip] = info[1].strip if info.length == 2 && (info[1].strip != '')
end
retval['IPMI_Puppet_Service_Recommend'] = 'running' if retval.fetch('Device Available', 'no') == 'yes'
end

setcode do
retval
Facter.value('ipmitool')[:mc_info]
end
end

0 comments on commit 26449ea

Please sign in to comment.