8a3479db80
This avoids an error thrown if the file is not available. Hint: the facter code is executed even if the module is not included on the catalog. Change-Id: Ie7a3dce6d42d3b2274bb5578862d677841e7bdc3
33 lines
878 B
Ruby
33 lines
878 B
Ruby
require 'facter'
|
|
if File.file?("/proc/bus/pci/devices")
|
|
drivers_details=File.read("/proc/bus/pci/devices")
|
|
drivers_lines=drivers_details.split("\n")
|
|
else
|
|
drivers_lines=Array.new
|
|
end
|
|
drivers=Hash.new
|
|
drivers_lines.each do |line|
|
|
line = line.gsub(/^\s+|\s+$/m, '').split(" ")
|
|
if line.length == 18
|
|
pci_embed = line[0]
|
|
driver = line[-1]
|
|
bus = pci_embed[0] + pci_embed[1]
|
|
dev = ((pci_embed[2].to_i(16) << 1) + (pci_embed[3].to_i(16) >> 3)).to_s(16).rjust(2,"0").upcase
|
|
fun = (pci_embed[3].to_i(16) & 7).to_s(16).upcase
|
|
pci = "0000:" + bus + ":" + dev + "." + fun
|
|
if not drivers.has_key?(driver)
|
|
drivers[driver] = Array.new
|
|
end
|
|
drivers[driver] << pci
|
|
end
|
|
end
|
|
|
|
drivers.each do |driver,pci_addr|
|
|
Facter.add("pci_address_driver_#{driver}") do
|
|
confine :kernel => :linux
|
|
setcode do
|
|
pci_addr.join(',')
|
|
end
|
|
end
|
|
end
|