Guest User

Untitled

a guest
Mar 16th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. require 'facter'
  2.  
  3. # We only want this to run for Linux boxes with a 2.6+ kernel version
  4. if Facter.value(:kernel) == 'Linux'
  5.  
  6. sysfs_block_directory = '/sys/block/'
  7.  
  8. blockdevices = []
  9.  
  10.  
  11. # This should prevent Linux boxes with < 2.6 kernels from running
  12. if File.exists?(sysfs_block_directory)
  13.  
  14. # Iterate over each file in the /sys/block directory and skip ones that do not have a device subdirectory
  15. Dir.entries(sysfs_block_directory).each do |device|
  16. sysfs_device_directory = sysfs_block_directory + device + "/device"
  17. next unless File.exist?(sysfs_device_directory)
  18.  
  19. # Add the device to the blockdevices list, which is returned as it's own fact later on
  20. blockdevices << device
  21.  
  22. sizefile = sysfs_block_directory + device + "/size"
  23.  
  24. if File.exist?(sizefile)
  25. Facter.add("#{device}_gb".to_sym) do
  26. confine :osfamily => 'RedHat'
  27. setcode { IO.read(sizefile).strip.to_i * 512 / 1073741824 }
  28. end
  29. end
  30.  
  31.  
  32. end
  33. end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment