patch-lib_facter_util_partitions_openbsd_rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. $OpenBSD: patch-lib_facter_util_partitions_openbsd_rb,v 1.5 2015/09/01 07:23:35 jasper Exp $
  2. Cache df/mount output to prevent running these programs 3 times for every partition found.
  3. https://github.com/puppetlabs/facter/pull/1119
  4. --- lib/facter/util/partitions/openbsd.rb.orig Tue May 19 18:41:15 2015
  5. +++ lib/facter/util/partitions/openbsd.rb Mon Aug 31 19:03:46 2015
  6. @@ -1,9 +1,26 @@
  7. module Facter::Util::Partitions
  8. module OpenBSD
  9. + @df_output = nil
  10. + @mount_output = nil
  11. +
  12. def self.list
  13. - Facter::Core::Execution.exec('df').scan(/\/dev\/(\S+)/).flatten
  14. + @df_output ||= run_df
  15. + @df_output.scan(/\/dev\/(\S+)/).flatten
  16. end
  17. + def self.flushable?
  18. + true
  19. + end
  20. +
  21. + def self.flush!
  22. + @df_output = nil
  23. + @mount_output = nil
  24. + end
  25. +
  26. + def self.flushed?
  27. + !@df_output
  28. + end
  29. +
  30. # On OpenBSD partitions don't have a UUID; disks have DUID but that's not
  31. # compatible.
  32. def self.uuid(partition)
  33. @@ -22,19 +39,29 @@ module Facter::Util::Partitions
  34. def self.filesystem(partition)
  35. scan_mount(/\/dev\/#{partition}\son\s\S+\stype\s(\S+)/)
  36. end
  37. -
  38. +
  39. # On OpenBSD there are no labels for partitions
  40. def self.label(partition)
  41. nil
  42. end
  43. private
  44. + def self.run_mount
  45. + Facter::Core::Execution.exec('mount')
  46. + end
  47. +
  48. + def self.run_df
  49. + Facter::Core::Execution.exec('df -k')
  50. + end
  51. +
  52. def self.scan_mount(scan_regex)
  53. - Facter::Core::Execution.exec('mount').scan(scan_regex).flatten.first
  54. + @mount_output ||= run_mount
  55. + @mount_output.scan(scan_regex).flatten.first
  56. end
  57. def self.scan_df(scan_regex)
  58. - Facter::Core::Execution.exec('df -k').scan(scan_regex).flatten.first
  59. + @df_output ||= run_df
  60. + @df_output.scan(scan_regex).flatten.first
  61. end
  62. end
  63. end