Created
July 17, 2020 14:29
-
-
Save micah/09a6198c2ac9f6c29bbe3faf1de2d9bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case Facter.value(:operatingsystem) | |
when /Debian|Ubuntu/i | |
lspci = "/usr/bin/lspci" | |
when /RedHat|CentOS|Fedora|Scientific|SLES/i | |
lspci = "/sbin/lspci" | |
else | |
lspci = "" | |
end | |
# We can't do this if we don't know the location of lspci | |
if !lspci.empty? and FileTest.exists?(lspci) | |
# Create a hash of ALL PCI devices, the key is the PCI slot ID. | |
# { SLOT_ID => { ATTRIBUTE => VALUE }, ... } | |
slot="" | |
# after the following loop, devices will contain ALL PCI devices and the info returned from lspci | |
devices = {} | |
%x{#{lspci} -v -mm -D -n}.each_line do |line| | |
if not line =~ /^$/ # We don't need to parse empty lines | |
splitted = line.split(/\t/) | |
# lspci has a nice syntax: | |
# ATTRIBUTE:\tVALUE | |
# We use this to fill our hash | |
if splitted[0] =~ /^Slot:$/ | |
slot=splitted[1].chomp | |
devices[slot] = {} | |
else | |
# The chop is needed to strip the ':' from the string | |
devices[slot][splitted[0].chop] = splitted[1].chomp | |
end | |
end | |
end | |
device = "" | |
devices.each_key do |a| | |
case devices[a].fetch("Vendor") | |
when /^8086/ | |
case devices[a].fetch("Device") | |
when /^153a|^1096/ | |
device=Dir.entries("/sys/bus/pci/devices/#{slot}/net").select {|f| !File.directory? f}[0] | |
puts device | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment