end
def pci_devices
+ devices = {}
device = nil
- IO.popen(["lspci", "-Dkvmm"]).each_with_object(Mash.new) do |line, devices|
+ IO.popen(["lspci", "-Dkvmm"]).each do |line|
if line =~ /^Slot:\s+((\h{4}):(\h{2}):(\h{2}).(\h))\s*$/
device = {
:slot => Regexp.last_match(1),
device = nil
end
end
+
+ IO.popen(["lspci", "-Dkvmmn"]).each do |line|
+ if line =~ /^Slot:\s+((\h{4}):(\h{2}):(\h{2}).(\h))\s*$/
+ device = devices[Regexp.last_match(1)]
+ elsif device && line =~ /^([A-Z]+):\s+(.*)\s*$/i
+ case Regexp.last_match(1)
+ when "Class" then device[:class_id] = Regexp.last_match(2)
+ when "Vendor" then device[:vendor_id] = Regexp.last_match(2)
+ when "Device" then device[:device_id] = Regexp.last_match(2)
+ when "SVendor" then device[:subsystem_vendor_id] = Regexp.last_match(2)
+ when "SDevice" then device[:subsystem_device_id] = Regexp.last_match(2)
+ end
+ elsif device && line =~ /^\s*$/
+ device = nil
+ end
+ end
+
+ devices
end
def network_devices
devices[:disks] << disk
controller[:disks] << disk[:id]
array[:disks] << disk[:id]
- elsif disk && line =~ /^ (\S[^:]+):\s+(\S.*\S)\s*$/
+ elsif disk && line =~ /^ (\S[^:]+):\s+(.*\S)\s*$/
case Regexp.last_match(1)
when "Interface Type" then disk[:interface] = Regexp.last_match(2)
when "Size" then disk[:size] = Regexp.last_match(2)
when "Serial Number" then disk[:serial_number] = Regexp.last_match(2)
when "Model" then disk[:model] = Regexp.last_match(2)
end
- elsif array && line =~ /^ (\S[^:]+):\s+(\S.*\S)\s*$/
+ elsif array && line =~ /^ (\S[^:]+):\s+(.*\S)\s*$/
case Regexp.last_match(1)
when "Size" then array[:size] = Regexp.last_match(2)
when "Fault Tolerance" then array[:raid_level] = Regexp.last_match(2)
end
end
+ def psu_devices
+ device = nil
+
+ IO.popen(["dmidecode", "-t", "39"]).each_with_object([]) do |line, devices|
+ if line =~ /^System Power Supply\s*$/
+ device = {}
+ elsif device && line =~ /^\s+([A-Z ]+):\s+(.*)\s*$/i
+ device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2).strip
+ elsif device && line =~ /^\s*$/
+ devices << device
+ device = nil
+ end
+ end
+ end
+
+ def mc_device
+ device = {}
+
+ IO.popen(["ipmitool", "mc", "info"]).each_with_object([]) do |line, devices|
+ if line =~ /(Product [A-Z ]+[A-Z])\s*:\s+(.*\S)\s+\(.*\)\s*$/i
+ device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2)
+ elsif line =~ /([A-Z ]+[A-Z])\s*:\s+(.*\S)\s*$/i
+ device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2)
+ end
+ end
+
+ IO.popen(["ipmitool", "mc", "guid"]).each_with_object([]) do |line, devices|
+ if line =~ /^System GUID\s*:\s+(\S+)\s*$/
+ device[:system_guid] = Regexp.last_match(1)
+ end
+ end
+
+ device
+ end
+
collect_data(:default) do
hardware Mash.new
hardware[:network] = network_devices
hardware[:memory] = memory_devices
hardware[:disk] = disk_devices
+ hardware[:psu] = psu_devices
+ hardware[:mc] = mc_device
end
end