]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/hardware/templates/default/ohai.rb.erb
Avoid exceptions on machines with bonded interfaces
[chef.git] / cookbooks / hardware / templates / default / ohai.rb.erb
index 1e7ca8713154bc88884ee8a3ca4e0d96b414a50a..132d5bcacdb015bb697a958a35958363d7562cf0 100644 (file)
@@ -5,12 +5,12 @@ Ohai.plugin(:Hardware) do
 
   def read_sysctl_link(file)
     File.basename(File.readlink(file))
-  rescue Errno::ENOENT
+  rescue Errno::ENOENT, Errno::ENOTDIR
   end
 
   def read_sysctl_file(file)
     IO.read(file).strip
-  rescue Errno::ENOENT, Errno::EINVAL
+  rescue Errno::ENOENT, Errno::ENOTDIR, Errno::EINVAL
   end
 
   def parse_memory_size(size)
@@ -180,7 +180,7 @@ Ohai.plugin(:Hardware) do
         end
       end
 
-      disk[:model].sub!(/-.*$/, "")
+      disk[:model].sub!(/-.*$/, "") if disk[:model]
     end
 
     disk
@@ -214,7 +214,7 @@ Ohai.plugin(:Hardware) do
   end
 
   def find_nvme_disks(devices)
-    Dir.glob("/sys/class/misc/nvme*") do |device|
+    Dir.glob("/sys/class/nvme/nvme*") do |device|
       controller = {
         :id => devices[:controllers].count,
         :pci_slot => File.basename(Pathname.new("#{device}/device").realpath),
@@ -232,7 +232,7 @@ Ohai.plugin(:Hardware) do
         end
       end
 
-      Dir.glob("#{device}/device/block/*").each do |block|
+      Dir.glob("#{device}/nvme*").each do |block|
         size = read_sysctl_file("#{block}/size").to_f / 2
 
         disk = {
@@ -358,6 +358,8 @@ Ohai.plugin(:Hardware) do
         controller[:device] = File.basename(device).sub(/^cciss(\d+)$/, "/dev/cciss/c\\1d0")
       elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:3:0/*:3:0:0/scsi_generic/sg*").first
         controller[:device] = "/dev/#{File.basename(device)}"
+      elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:1:0/*:1:0:0/scsi_generic/sg*").first
+        controller[:device] = "/dev/#{File.basename(device)}"
       end
     end
   end