Skip to content

Commit

Permalink
Support ancient versions of MegaCli
Browse files Browse the repository at this point in the history
At around version 8.02.16 some arguments to MegaCli changed. This change
attempts to determine whether MegaCli is modern (8.02.16 or newer) or
legacy (everything else). Facts affected by the changed arguments are
gated using a confine statement.

This change also handles cases where the MegaCli binary is lowercase (megacli).
  • Loading branch information
Nic Cope committed Feb 3, 2015
1 parent b3cf2b8 commit 18589cc
Show file tree
Hide file tree
Showing 18 changed files with 540 additions and 67 deletions.
10 changes: 9 additions & 1 deletion lib/facter/megacli.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Facter.add(:megacli) do
confine :kernel => :linux

megacli_binaries = ['MegaCli', 'megacli']

setcode do
Facter::Util::Resolution.which('MegaCli')
path = nil
megacli_binaries.each do |bin|
path = Facter::Util::Resolution.which(bin)
next if path.nil?
break
end
path
end
end
21 changes: 21 additions & 0 deletions lib/facter/megacli_legacy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'semver'

# Legacy versions of MegaCLI require different arguments to determine certain
# software and firmware versions.
Facter.add(:megacli_legacy) do
megacli = Facter.value(:megacli)
megacli_version = Facter.value(:megacli_version)

setcode do
next if megacli.nil?
next if megacli_version.nil?

# Modern version assumed from changelog at
# http://www.lsi.com/downloads/Public/RAID%20Controllers/RAID%20Controllers%20Common%20Files/Linux%20MegaCLI%208.07.10.txt
actual_version = SemVer.new(megacli_version)
modern_version = SemVer.new('8.02.16')

actual_version < modern_version

end
end
16 changes: 13 additions & 3 deletions lib/facter/megacli_version.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
Facter.add(:megacli_version) do
megacli = Facter.value(:megacli)
version_commands = ["#{megacli} -Version -Cli -aALL -NoLog",
"#{megacli} -v -aALL -NoLog"]

setcode do
unless megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Cli -aALL -NoLog")
next if megacli.nil?

version = nil
# This is a bit hacky, but we need to try different commands to ascertain
# the version of the megacli binary.
version_commands.each do |cmd|
output = Facter::Util::Resolution.exec(cmd)
next if output.nil?
m = output.match(/MegaCLI SAS RAID Management Tool Ver ([\d\.]+)/)
next if m.nil?
next unless m.size == 2
m[1]
version = m[1]
break
end
version
end
end
31 changes: 24 additions & 7 deletions lib/facter/megaraid_fw_package_build.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
Facter.add(:megaraid_fw_package_build) do
confine :megacli_legacy => false

megacli = Facter.value(:megacli)
setcode do
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/F[wW] Package Build\s*:\s*([\d\.\-]+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end


Facter.add(:megaraid_fw_package_build) do
confine :megacli_legacy => true

megacli = Facter.value(:megacli)
setcode do
unless megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/Fw Package Build : ([\d\.\-]+)\s*$/)
next unless m.size == 2
m[1]
end
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog")
next if output.nil?
m = output.match(/F[wW] Package Build\s*:\s*([\d\.\-]+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end
31 changes: 24 additions & 7 deletions lib/facter/megaraid_fw_version.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
Facter.add(:megaraid_fw_version) do
confine :megacli_legacy => false

megacli = Facter.value(:megacli)
setcode do
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/FW Version\s*:\s*([\d\.\-]+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end


Facter.add(:megaraid_fw_version) do
confine :megacli_legacy => true

megacli = Facter.value(:megacli)
setcode do
unless megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/FW Version : ([\d\.\-]+)\s*$/)
next unless m.size == 2
m[1]
end
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog")
next if output.nil?
m = output.match(/FW Version\s*:\s*([\d\.\-]+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end
31 changes: 24 additions & 7 deletions lib/facter/megaraid_product_name.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
Facter.add(:megaraid_product_name) do
confine :megacli_legacy => false

megacli = Facter.value(:megacli)
setcode do
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/Product Name\s*:\s*(.+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end


Facter.add(:megaraid_product_name) do
confine :megacli_legacy => true

megacli = Facter.value(:megacli)
setcode do
unless megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/Product Name : (.+)\s*$/)
next unless m.size == 2
m[1]
end
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog")
next if output.nil?
m = output.match(/Product Name\s*:\s*(.+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end
32 changes: 24 additions & 8 deletions lib/facter/megaraid_serial.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
Facter.add(:megaraid_serial) do
confine :megacli_legacy => false

megacli = Facter.value(:megacli)
setcode do
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/Serial No\s*:\s*(\S+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end


Facter.add(:megaraid_serial) do
confine :megacli_legacy => true

megacli = Facter.value(:megacli)
setcode do
unless megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog")
next if output.nil?
m = output.match(/Serial No : (\S+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
next if megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog")
next if output.nil?
m = output.match(/Serial No\s*:\s*(\S+)\s*$/)
next if m.nil?
next unless m.size == 2
m[1]
end
end
2 changes: 1 addition & 1 deletion lib/facter/megaraid_virtual_drives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
devices.each do |dev|
vendor = Facter.value("blockdevice_#{dev}_vendor")
case vendor
when 'LSI', 'SMC'
when 'LSI', 'SMC', 'DELL'
vds << dev
end
end
Expand Down
Loading

0 comments on commit 18589cc

Please sign in to comment.