Skip to content

Commit

Permalink
Merge pull request jhoblitt#40 from negz/master
Browse files Browse the repository at this point in the history
Expose PD sizes, and support older MegaCli binaries.
  • Loading branch information
Joshua Hoblitt committed Feb 10, 2015
2 parents 8e003d1 + 18589cc commit 5a8d71c
Show file tree
Hide file tree
Showing 20 changed files with 643 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
25 changes: 25 additions & 0 deletions lib/facter/megaraid_physical_drives_size.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Facter.add(:megaraid_physical_drives_size) do
confine :kernel => 'Linux'

setcode do
megacli = Facter.value(:megacli)
megaraid_adapters = Facter.value(:megaraid_adapters)

if megacli.nil? ||
megaraid_adapters.nil? || (megaraid_adapters == 0)
next nil
end

# XXX there is no support for handling more than one adapter
sizes = []
list = Facter::Util::Resolution.exec("#{megacli} -PDList -aALL -NoLog")
next if list.nil?
list.each_line do |line|
if line =~ /Raw Size: ([\.\d]+ [A-Z]?B)/
sizes.push($1)
end
end

sizes.join(',')
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 5a8d71c

Please sign in to comment.