facter 4.0.41 → 4.0.47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate.rb +32 -0
  3. data/lib/docs/template.erb +34 -0
  4. data/lib/facter.rb +110 -25
  5. data/lib/facter/config.rb +386 -0
  6. data/lib/facter/custom_facts/core/aggregate.rb +51 -17
  7. data/lib/facter/custom_facts/core/execution.rb +54 -38
  8. data/lib/facter/custom_facts/core/execution/base.rb +46 -40
  9. data/lib/facter/custom_facts/util/collection.rb +1 -2
  10. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  11. data/lib/facter/custom_facts/util/fact.rb +19 -2
  12. data/lib/facter/custom_facts/util/loader.rb +1 -1
  13. data/lib/facter/custom_facts/util/parser.rb +17 -3
  14. data/lib/facter/custom_facts/util/resolution.rb +41 -12
  15. data/lib/facter/facts/aix/interfaces.rb +1 -0
  16. data/lib/facter/facts/aix/memory/swap/available.rb +1 -1
  17. data/lib/facter/facts/aix/memory/swap/available_bytes.rb +1 -1
  18. data/lib/facter/facts/aix/memory/swap/total.rb +1 -1
  19. data/lib/facter/facts/aix/memory/swap/total_bytes.rb +1 -1
  20. data/lib/facter/facts/aix/memory/swap/used.rb +1 -1
  21. data/lib/facter/facts/aix/memory/system/available.rb +1 -1
  22. data/lib/facter/facts/aix/memory/system/available_bytes.rb +1 -1
  23. data/lib/facter/facts/aix/memory/system/total.rb +1 -1
  24. data/lib/facter/facts/aix/memory/system/total_bytes.rb +1 -1
  25. data/lib/facter/facts/aix/memory/system/used.rb +1 -1
  26. data/lib/facter/facts/aix/processors/speed.rb +1 -1
  27. data/lib/facter/facts/bsd/processors/speed.rb +1 -1
  28. data/lib/facter/facts/freebsd/is_virtual.rb +25 -0
  29. data/lib/facter/facts/freebsd/memory/swap/available.rb +1 -1
  30. data/lib/facter/facts/freebsd/memory/swap/available_bytes.rb +1 -1
  31. data/lib/facter/facts/freebsd/memory/swap/total.rb +1 -1
  32. data/lib/facter/facts/freebsd/memory/swap/total_bytes.rb +1 -1
  33. data/lib/facter/facts/freebsd/memory/swap/used.rb +1 -1
  34. data/lib/facter/facts/freebsd/memory/system/available.rb +1 -1
  35. data/lib/facter/facts/freebsd/memory/system/available_bytes.rb +1 -1
  36. data/lib/facter/facts/freebsd/memory/system/total.rb +1 -1
  37. data/lib/facter/facts/freebsd/memory/system/total_bytes.rb +1 -1
  38. data/lib/facter/facts/freebsd/memory/system/used.rb +1 -1
  39. data/lib/facter/facts/freebsd/processors/speed.rb +1 -1
  40. data/lib/facter/facts/freebsd/virtual.rb +22 -0
  41. data/lib/facter/facts/linux/dhcp_servers.rb +1 -0
  42. data/lib/facter/facts/linux/ec2_metadata.rb +1 -1
  43. data/lib/facter/facts/linux/ec2_userdata.rb +1 -1
  44. data/lib/facter/facts/linux/hypervisors/kvm.rb +1 -1
  45. data/lib/facter/facts/linux/hypervisors/xen.rb +1 -1
  46. data/lib/facter/facts/linux/interfaces.rb +1 -0
  47. data/lib/facter/facts/linux/is_virtual.rb +2 -2
  48. data/lib/facter/facts/linux/memory/swap/available.rb +1 -1
  49. data/lib/facter/facts/linux/memory/swap/available_bytes.rb +1 -1
  50. data/lib/facter/facts/linux/memory/swap/total.rb +1 -1
  51. data/lib/facter/facts/linux/memory/swap/total_bytes.rb +1 -1
  52. data/lib/facter/facts/linux/memory/swap/used.rb +1 -1
  53. data/lib/facter/facts/linux/memory/system/available.rb +1 -1
  54. data/lib/facter/facts/linux/memory/system/available_bytes.rb +1 -1
  55. data/lib/facter/facts/linux/memory/system/total.rb +1 -1
  56. data/lib/facter/facts/linux/memory/system/total_bytes.rb +1 -1
  57. data/lib/facter/facts/linux/memory/system/used.rb +1 -1
  58. data/lib/facter/facts/linux/processors/speed.rb +1 -1
  59. data/lib/facter/facts/linux/virtual.rb +1 -1
  60. data/lib/facter/facts/macosx/dhcp_servers.rb +1 -0
  61. data/lib/facter/facts/macosx/interfaces.rb +1 -0
  62. data/lib/facter/facts/macosx/memory/swap/available.rb +1 -1
  63. data/lib/facter/facts/macosx/memory/swap/available_bytes.rb +1 -1
  64. data/lib/facter/facts/macosx/memory/swap/total.rb +1 -1
  65. data/lib/facter/facts/macosx/memory/swap/total_bytes.rb +1 -1
  66. data/lib/facter/facts/macosx/memory/swap/used.rb +1 -1
  67. data/lib/facter/facts/macosx/memory/system/available.rb +1 -1
  68. data/lib/facter/facts/macosx/memory/system/available_bytes.rb +1 -1
  69. data/lib/facter/facts/macosx/memory/system/total.rb +1 -1
  70. data/lib/facter/facts/macosx/memory/system/total_bytes.rb +1 -1
  71. data/lib/facter/facts/macosx/memory/system/used.rb +1 -1
  72. data/lib/facter/facts/macosx/processors/speed.rb +1 -1
  73. data/lib/facter/facts/rhel/os/release.rb +1 -1
  74. data/lib/facter/facts/solaris/dhcp_servers.rb +1 -0
  75. data/lib/facter/facts/solaris/hypervisors/ldom.rb +3 -0
  76. data/lib/facter/facts/solaris/interfaces.rb +1 -0
  77. data/lib/facter/facts/solaris/is_virtual.rb +2 -2
  78. data/lib/facter/facts/solaris/ldom.rb +34 -4
  79. data/lib/facter/facts/solaris/memory/swap/available.rb +1 -1
  80. data/lib/facter/facts/solaris/memory/swap/available_bytes.rb +1 -1
  81. data/lib/facter/facts/solaris/memory/swap/total.rb +1 -1
  82. data/lib/facter/facts/solaris/memory/swap/total_bytes.rb +1 -1
  83. data/lib/facter/facts/solaris/memory/swap/used.rb +1 -1
  84. data/lib/facter/facts/solaris/memory/system/available.rb +1 -1
  85. data/lib/facter/facts/solaris/memory/system/available_bytes.rb +1 -1
  86. data/lib/facter/facts/solaris/memory/system/total.rb +1 -1
  87. data/lib/facter/facts/solaris/memory/system/total_bytes.rb +1 -1
  88. data/lib/facter/facts/solaris/memory/system/used.rb +1 -1
  89. data/lib/facter/facts/solaris/processors/speed.rb +1 -1
  90. data/lib/facter/facts/solaris/virtual.rb +1 -1
  91. data/lib/facter/facts/solaris/zones.rb +1 -1
  92. data/lib/facter/facts/windows/dhcp_servers.rb +1 -0
  93. data/lib/facter/facts/windows/interfaces.rb +1 -0
  94. data/lib/facter/facts/windows/memory/system/available.rb +1 -1
  95. data/lib/facter/facts/windows/memory/system/available_bytes.rb +1 -1
  96. data/lib/facter/facts/windows/memory/system/total.rb +1 -1
  97. data/lib/facter/facts/windows/memory/system/total_bytes.rb +1 -1
  98. data/lib/facter/facts/windows/memory/system/used.rb +1 -1
  99. data/lib/facter/facts/windows/os/release.rb +1 -1
  100. data/lib/facter/framework/benchmarking/timer.rb +4 -2
  101. data/lib/facter/framework/cli/cli.rb +20 -6
  102. data/lib/facter/framework/config/fact_groups.rb +10 -8
  103. data/lib/facter/framework/core/cache_manager.rb +79 -29
  104. data/lib/facter/framework/core/fact/internal/core_fact.rb +6 -1
  105. data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +38 -4
  106. data/lib/facter/framework/core/fact_augmenter.rb +1 -1
  107. data/lib/facter/framework/core/fact_loaders/external_fact_loader.rb +4 -2
  108. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +17 -1
  109. data/lib/facter/framework/core/fact_manager.rb +15 -3
  110. data/lib/facter/framework/core/file_loader.rb +6 -2
  111. data/lib/facter/framework/core/options/config_file_options.rb +16 -5
  112. data/lib/facter/framework/core/options/option_store.rb +40 -20
  113. data/lib/facter/framework/detector/os_hierarchy.rb +5 -9
  114. data/lib/facter/framework/logging/logger.rb +3 -3
  115. data/lib/facter/models/fact_collection.rb +11 -1
  116. data/lib/facter/models/loaded_fact.rb +2 -1
  117. data/lib/facter/resolvers/aio_agent_version.rb +2 -2
  118. data/lib/facter/resolvers/aix/architecture_resolver.rb +19 -4
  119. data/lib/facter/resolvers/aix/disks.rb +6 -5
  120. data/lib/facter/resolvers/aix/filesystem_resolver.rb +2 -2
  121. data/lib/facter/resolvers/aix/hardware_resolver.rb +4 -3
  122. data/lib/facter/resolvers/aix/load_averages_resolver.rb +2 -1
  123. data/lib/facter/resolvers/aix/memory.rb +4 -3
  124. data/lib/facter/resolvers/aix/mountpoints.rb +6 -5
  125. data/lib/facter/resolvers/aix/networking_resolver.rb +4 -3
  126. data/lib/facter/resolvers/aix/nim.rb +1 -1
  127. data/lib/facter/resolvers/aix/os_level.rb +2 -2
  128. data/lib/facter/resolvers/aix/partitions.rb +7 -6
  129. data/lib/facter/resolvers/aix/processors.rb +5 -4
  130. data/lib/facter/resolvers/aix/serialnumber.rb +2 -2
  131. data/lib/facter/resolvers/augeas_resolver.rb +8 -2
  132. data/lib/facter/resolvers/base_resolver.rb +14 -4
  133. data/lib/facter/resolvers/bsd/processors.rb +13 -8
  134. data/lib/facter/resolvers/cloud.rb +2 -2
  135. data/lib/facter/resolvers/containers.rb +5 -4
  136. data/lib/facter/resolvers/debian_version.rb +2 -2
  137. data/lib/facter/resolvers/disk_resolver.rb +17 -6
  138. data/lib/facter/resolvers/dmi_decode.rb +1 -1
  139. data/lib/facter/resolvers/dmi_resolver.rb +5 -4
  140. data/lib/facter/resolvers/ec2.rb +5 -2
  141. data/lib/facter/resolvers/eos_release_resolver.rb +2 -2
  142. data/lib/facter/resolvers/facterversion_resolver.rb +1 -1
  143. data/lib/facter/resolvers/filesystems_resolver.rb +5 -2
  144. data/lib/facter/resolvers/fips_enabled_resolver.rb +5 -2
  145. data/lib/facter/resolvers/freebsd/dmi_resolver.rb +1 -1
  146. data/lib/facter/resolvers/freebsd/freebsd_version_resolver.rb +9 -7
  147. data/lib/facter/resolvers/freebsd/geom_resolver.rb +15 -22
  148. data/lib/facter/resolvers/freebsd/processors.rb +13 -8
  149. data/lib/facter/resolvers/freebsd/swap_memory_resolver.rb +5 -3
  150. data/lib/facter/resolvers/freebsd/system_memory_resolver.rb +4 -2
  151. data/lib/facter/resolvers/freebsd/virtual_resolver.rb +45 -0
  152. data/lib/facter/resolvers/gce.rb +3 -2
  153. data/lib/facter/resolvers/hostname_resolver.rb +69 -21
  154. data/lib/facter/resolvers/identity_resolver.rb +2 -1
  155. data/lib/facter/resolvers/linux/docker_uptime.rb +3 -2
  156. data/lib/facter/resolvers/linux/load_averages.rb +3 -2
  157. data/lib/facter/resolvers/load_averages.rb +5 -3
  158. data/lib/facter/resolvers/lpar_resolver.rb +1 -1
  159. data/lib/facter/resolvers/lsb_release_resolver.rb +1 -1
  160. data/lib/facter/resolvers/lspci.rb +1 -1
  161. data/lib/facter/resolvers/macosx/dmi_resolver.rb +1 -1
  162. data/lib/facter/resolvers/macosx/filesystems_resolver.rb +1 -1
  163. data/lib/facter/resolvers/macosx/load_averages_resolver.rb +2 -1
  164. data/lib/facter/resolvers/macosx/mountpoints_resolver.rb +9 -8
  165. data/lib/facter/resolvers/macosx/processor_resolver.rb +2 -1
  166. data/lib/facter/resolvers/macosx/swap_memory_resolver.rb +2 -1
  167. data/lib/facter/resolvers/macosx/system_memory_resolver.rb +2 -1
  168. data/lib/facter/resolvers/macosx/system_profiler_resolver.rb +4 -6
  169. data/lib/facter/resolvers/memory_resolver.rb +16 -16
  170. data/lib/facter/resolvers/mountpoints_resolver.rb +56 -25
  171. data/lib/facter/resolvers/networking_linux_resolver.rb +188 -83
  172. data/lib/facter/resolvers/networking_resolver.rb +9 -6
  173. data/lib/facter/resolvers/open_vz.rb +2 -4
  174. data/lib/facter/resolvers/os_release_resolver.rb +2 -2
  175. data/lib/facter/resolvers/partitions.rb +67 -63
  176. data/lib/facter/resolvers/path_resolver.rb +1 -1
  177. data/lib/facter/resolvers/processors_resolver.rb +10 -3
  178. data/lib/facter/resolvers/redhat_release_resolver.rb +2 -2
  179. data/lib/facter/resolvers/ruby_resolver.rb +1 -1
  180. data/lib/facter/resolvers/selinux_resolver.rb +4 -4
  181. data/lib/facter/resolvers/solaris/disks.rb +2 -2
  182. data/lib/facter/resolvers/solaris/dmi.rb +3 -1
  183. data/lib/facter/resolvers/solaris/dmi_sparc.rb +1 -1
  184. data/lib/facter/resolvers/solaris/filesystems.rb +1 -1
  185. data/lib/facter/resolvers/solaris/ipaddress.rb +2 -1
  186. data/lib/facter/resolvers/solaris/ldom.rb +1 -3
  187. data/lib/facter/resolvers/solaris/memory.rb +4 -3
  188. data/lib/facter/resolvers/solaris/mountpoints.rb +61 -0
  189. data/lib/facter/resolvers/solaris/networking.rb +51 -44
  190. data/lib/facter/resolvers/solaris/os_release.rb +7 -5
  191. data/lib/facter/resolvers/solaris/processors.rb +2 -1
  192. data/lib/facter/resolvers/solaris/zone.rb +1 -1
  193. data/lib/facter/resolvers/solaris/zone_name.rb +1 -1
  194. data/lib/facter/resolvers/ssh_resolver.rb +11 -7
  195. data/lib/facter/resolvers/suse_release_resolver.rb +2 -2
  196. data/lib/facter/resolvers/sw_vers_resolver.rb +2 -2
  197. data/lib/facter/resolvers/timezone_resolver.rb +1 -1
  198. data/lib/facter/resolvers/uname_resolver.rb +1 -1
  199. data/lib/facter/resolvers/uptime_resolver.rb +3 -3
  200. data/lib/facter/resolvers/virt_what.rb +1 -1
  201. data/lib/facter/resolvers/vmware.rb +1 -1
  202. data/lib/facter/resolvers/windows/aio_agent_version.rb +2 -2
  203. data/lib/facter/resolvers/windows/dmi_bios_resolver.rb +2 -2
  204. data/lib/facter/resolvers/windows/dmi_computersystem_resolver.rb +2 -2
  205. data/lib/facter/resolvers/windows/fips_resolver.rb +2 -1
  206. data/lib/facter/resolvers/windows/hardware_architecture_resolver.rb +2 -1
  207. data/lib/facter/resolvers/windows/identity_resolver.rb +2 -1
  208. data/lib/facter/resolvers/windows/kernel_resolver.rb +3 -1
  209. data/lib/facter/resolvers/windows/memory_resolver.rb +7 -1
  210. data/lib/facter/resolvers/windows/netkvm_resolver.rb +2 -1
  211. data/lib/facter/resolvers/windows/networking_resolver.rb +5 -4
  212. data/lib/facter/resolvers/windows/processors_resolver.rb +3 -2
  213. data/lib/facter/resolvers/windows/product_release_resolver.rb +2 -1
  214. data/lib/facter/resolvers/windows/ssh.rb +5 -3
  215. data/lib/facter/resolvers/windows/system32_resolver.rb +3 -1
  216. data/lib/facter/resolvers/windows/uptime_resolver.rb +3 -2
  217. data/lib/facter/resolvers/windows/virtualization_resolver.rb +3 -2
  218. data/lib/facter/resolvers/windows/win_os_description_resolver.rb +4 -2
  219. data/lib/facter/resolvers/wpar_resolver.rb +1 -1
  220. data/lib/facter/resolvers/xen.rb +2 -2
  221. data/lib/facter/resolvers/zfs.rb +2 -1
  222. data/lib/facter/resolvers/zpool.rb +2 -1
  223. data/lib/facter/util/aix/info_extractor.rb +24 -0
  224. data/lib/facter/util/aix/odm_query.rb +46 -0
  225. data/lib/facter/util/api_debugger.rb +33 -29
  226. data/lib/facter/util/facts/facts_utils.rb +14 -0
  227. data/lib/facter/util/facts/unit_converter.rb +61 -0
  228. data/lib/facter/util/facts/uptime_parser.rb +128 -0
  229. data/lib/facter/util/facts/virtual_detector.rb +90 -0
  230. data/lib/facter/util/facts/windows_release_finder.rb +55 -0
  231. data/lib/facter/{resolvers/macosx/utils → util/macosx}/system_profile_executor.rb +1 -1
  232. data/lib/facter/util/resolvers/aws_token.rb +37 -0
  233. data/lib/facter/{resolvers/utils → util/resolvers}/ffi/load_averages.rb +2 -2
  234. data/lib/facter/util/resolvers/filesystem_helper.rb +47 -0
  235. data/lib/facter/util/resolvers/fingerprint.rb +15 -0
  236. data/lib/facter/{resolvers/utils → util/resolvers}/http.rb +17 -10
  237. data/lib/facter/util/resolvers/networking.rb +90 -0
  238. data/lib/facter/util/resolvers/networking/dhcp.rb +21 -0
  239. data/lib/facter/util/resolvers/networking/networking.rb +109 -0
  240. data/lib/facter/util/resolvers/networking/primary_interface.rb +82 -0
  241. data/lib/facter/util/resolvers/ssh.rb +17 -0
  242. data/lib/facter/util/resolvers/ssh_helper.rb +31 -0
  243. data/lib/facter/{resolvers/utils → util/resolvers}/uptime_helper.rb +2 -2
  244. data/lib/facter/{framework/utils → util}/utils.rb +0 -0
  245. data/lib/facter/util/windows/win32ole.rb +30 -0
  246. data/lib/facter/version.rb +1 -1
  247. metadata +33 -44
  248. data/lib/facter/fact_groups.conf +0 -308
  249. data/lib/facter/facts/aix/puppet_version.rb +0 -15
  250. data/lib/facter/facts/freebsd/puppet_version.rb +0 -15
  251. data/lib/facter/facts/linux/puppet_version.rb +0 -15
  252. data/lib/facter/facts/macosx/puppet_version.rb +0 -15
  253. data/lib/facter/facts/solaris/puppet_version.rb +0 -15
  254. data/lib/facter/facts/windows/puppet_version.rb +0 -15
  255. data/lib/facter/facts_utils/facts_utils.rb +0 -12
  256. data/lib/facter/facts_utils/unit_converter.rb +0 -59
  257. data/lib/facter/facts_utils/uptime_parser.rb +0 -124
  258. data/lib/facter/facts_utils/virtual_detector.rb +0 -78
  259. data/lib/facter/facts_utils/windows_release_finder.rb +0 -51
  260. data/lib/facter/os_hierarchy.json +0 -36
  261. data/lib/facter/resolvers/aix/utils/info_extractor.rb +0 -20
  262. data/lib/facter/resolvers/aix/utils/odm_query.rb +0 -42
  263. data/lib/facter/resolvers/puppet_version_resolver.rb +0 -26
  264. data/lib/facter/resolvers/utils/filesystem_helper.rb +0 -43
  265. data/lib/facter/resolvers/utils/fingerprint.rb +0 -11
  266. data/lib/facter/resolvers/utils/networking.rb +0 -86
  267. data/lib/facter/resolvers/utils/ssh.rb +0 -13
  268. data/lib/facter/resolvers/utils/ssh_helper.rb +0 -27
  269. data/lib/facter/resolvers/windows/utils/win32ole.rb +0 -24
@@ -3,20 +3,37 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class Mountpoints < BaseResolver
6
- include Facter::FilesystemHelper
7
- @fact_list ||= {}
6
+ include Facter::Util::Resolvers::FilesystemHelper
7
+
8
+ init_resolver
9
+
8
10
  @log = Facter::Log.new(self)
11
+
9
12
  class << self
10
13
  private
11
14
 
12
15
  def post_resolve(fact_name)
13
- @fact_list.fetch(fact_name) { read_mounts }
16
+ @fact_list.fetch(fact_name) { read_mounts(fact_name) }
14
17
  end
15
18
 
16
19
  def root_device
17
- cmdline = Util::FileHelper.safe_read('/proc/cmdline')
20
+ cmdline = Facter::Util::FileHelper.safe_read('/proc/cmdline')
18
21
  match = cmdline.match(/root=([^\s]+)/)
19
- match&.captures&.first
22
+ root = match&.captures&.first
23
+
24
+ if !root.nil? && root.include?('=')
25
+ # We are dealing with the PARTUUID of the partition. Need to extract partition path.
26
+ root_partition_path = convert_partuuid_to_path(root)
27
+ root = root_partition_path unless root_partition_path.nil?
28
+ end
29
+ root
30
+ end
31
+
32
+ def convert_partuuid_to_path(root)
33
+ blkid_content = Facter::Core::Execution.execute('blkid', logger: log)
34
+ partuuid = root.split('=').last
35
+ match = blkid_content.match(/(.+)#{partuuid}/)
36
+ match&.captures&.first&.split(':')&.first
20
37
  end
21
38
 
22
39
  def compute_device(device)
@@ -26,32 +43,46 @@ module Facter
26
43
  device
27
44
  end
28
45
 
29
- def read_mounts # rubocop:disable Metrics/AbcSize
46
+ def read_mounts(fact_name)
30
47
  mounts = []
31
- FilesystemHelper.read_mountpoints.each do |fs|
32
- device = compute_device(fs.name)
33
- filesystem = fs.mount_type
34
- path = fs.mount_point
35
- options = fs.options.split(',').map(&:strip)
48
+ Facter::Util::Resolvers::FilesystemHelper.read_mountpoints.each do |file_system|
49
+ mount = {}
50
+ get_mount_data(file_system, mount)
51
+
52
+ next if mount[:path] =~ %r{^/(proc|sys)} && mount[:filesystem] != 'tmpfs' || mount[:filesystem] == 'autofs'
53
+
54
+ get_mount_sizes(mount)
55
+ mounts << mount
56
+ end
36
57
 
37
- next if path =~ %r{^/(proc|sys)} && filesystem != 'tmpfs' || filesystem == 'autofs'
58
+ @fact_list[:mountpoints] = mounts
59
+ @fact_list[fact_name]
60
+ end
38
61
 
39
- stats = FilesystemHelper.read_mountpoint_stats(path)
40
- size_bytes = stats.bytes_total.abs
41
- available_bytes = stats.bytes_available.abs
62
+ def get_mount_data(file_system, mount)
63
+ mount[:device] = compute_device(file_system.name)
64
+ mount[:filesystem] = file_system.mount_type
65
+ mount[:path] = file_system.mount_point
66
+ mount[:options] = file_system.options.split(',').map(&:strip)
67
+ end
42
68
 
43
- used_bytes = stats.bytes_used.abs
44
- total_bytes = used_bytes + available_bytes
45
- capacity = FilesystemHelper.compute_capacity(used_bytes, total_bytes)
69
+ def get_mount_sizes(mount)
70
+ stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(mount[:path])
46
71
 
47
- size = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(size_bytes)
48
- available = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(available_bytes)
49
- used = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(used_bytes)
72
+ get_bytes_data(mount, stats)
50
73
 
51
- mounts << Hash[FilesystemHelper::MOUNT_KEYS.zip(FilesystemHelper::MOUNT_KEYS
52
- .map { |v| binding.local_variable_get(v) })]
53
- end
54
- @fact_list[:mountpoints] = mounts
74
+ total_bytes = mount[:used_bytes] + mount[:available_bytes]
75
+ mount[:capacity] = Facter::Util::Resolvers::FilesystemHelper.compute_capacity(mount[:used_bytes], total_bytes)
76
+
77
+ mount[:size] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:size_bytes])
78
+ mount[:available] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:available_bytes])
79
+ mount[:used] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:used_bytes])
80
+ end
81
+
82
+ def get_bytes_data(mount, stats)
83
+ mount[:size_bytes] = stats.bytes_total.abs
84
+ mount[:available_bytes] = stats.bytes_available.abs
85
+ mount[:used_bytes] = stats.bytes_used.abs
55
86
  end
56
87
  end
57
88
  end
@@ -3,8 +3,18 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class NetworkingLinux < BaseResolver
6
- @fact_list = {}
6
+ init_resolver
7
+
7
8
  DIRS = ['/var/lib/dhclient/', '/var/lib/dhcp/', '/var/lib/dhcp3/', '/var/lib/NetworkManager/', '/var/db/'].freeze
9
+ ROUTE_TYPES = %w[anycast
10
+ unicast
11
+ broadcast
12
+ local
13
+ nat
14
+ unreachable
15
+ prohibit
16
+ blackhole
17
+ throw].freeze
8
18
 
9
19
  class << self
10
20
  private
@@ -16,52 +26,188 @@ module Facter
16
26
  end
17
27
 
18
28
  def retrieve_network_info(fact_name)
19
- @fact_list ||= {}
20
-
21
- retrieve_interface_info
22
- retrieve_interfaces_mac_and_mtu
23
- retrieve_default_interface
24
- ::Resolvers::Utils::Networking.expand_main_bindings(@fact_list)
29
+ mtu_and_indexes = interfaces_mtu_and_index
30
+ retrieve_interface_info(mtu_and_indexes)
31
+ add_info_from_routing_table
32
+ retrieve_primary_interface
33
+ Facter::Util::Resolvers::Networking.expand_main_bindings(@fact_list)
25
34
  @fact_list[fact_name]
26
35
  end
27
36
 
28
- def retrieve_interfaces_mac_and_mtu
29
- @fact_list[:interfaces].map do |name, info|
30
- macaddress = Util::FileHelper.safe_read("/sys/class/net/#{name}/address", nil)
31
- info[:mac] = macaddress.strip if macaddress && !macaddress.include?('00:00:00:00:00:00')
32
- mtu = Util::FileHelper.safe_read("/sys/class/net/#{name}/mtu", nil)
33
- info[:mtu] = mtu.strip.to_i if mtu
37
+ def interfaces_mtu_and_index
38
+ mtu_and_indexes = {}
39
+ output = Facter::Core::Execution.execute("ip link show", logger: log)
40
+ output.each_line do |line|
41
+ next unless line.include?('mtu')
42
+
43
+ mtu = line.match(/mtu (\d+)/)&.captures&.first&.to_i
44
+ index_tokens = line.split(':')
45
+ index = index_tokens[0].strip
46
+ # vlans are displayed as <vlan_name>@<physical_interface>
47
+ name = index_tokens[1].split('@').first.strip
48
+ mtu_and_indexes[name] = [index, mtu]
34
49
  end
50
+ mtu_and_indexes
35
51
  end
36
52
 
37
- def retrieve_interface_info
38
- log.debug('retrieve_interface_info')
39
- output = Facter::Core::Execution.execute('ip -o address', logger: log)
40
- log.debug("ip -o address result is:\n#{output}")
41
-
53
+ def retrieve_interface_info(mtu_and_indexes)
54
+ require 'socket'
42
55
  interfaces = {}
56
+ Socket.getifaddrs.each do |interface|
57
+ interfaces[interface.name] = {} if interfaces[interface.name].nil?
58
+
59
+ if interfaces[interface.name][:mac].nil?
60
+ mac = extract_mac_address(interface)
61
+ interfaces[interface.name][:mac] = mac if mac
62
+ end
43
63
 
44
- output.each_line do |ip_line|
45
- ip_tokens = ip_line.split(' ')
64
+ if interfaces[interface.name][:mtu].nil?
65
+ mtu = mtu_and_indexes.dig(interface.name, 1)
66
+ interfaces[interface.name][:mtu] = mtu unless mtu.nil?
67
+ end
46
68
 
47
- log.debug("ip_tokens = #{ip_tokens}")
48
- log.debug("interfaces = #{interfaces}")
49
- fill_ip_v4_info!(ip_tokens, interfaces)
50
- fill_io_v6_info!(ip_tokens, interfaces)
51
- find_dhcp!(ip_tokens, interfaces)
69
+ if !interface.addr.nil? && !interface.netmask.nil?
70
+ begin
71
+ # ipv6 ips are retrieved as <ip>%<interface_name>
72
+ ip = interface.addr.ip_address.split('%').first if interface.addr.ip?
73
+ netmask = interface.netmask.ip_address
74
+ add_binding(interfaces, interface.name, ip, netmask, interface.addr.ipv4?)
75
+ rescue SocketError => e
76
+ end
77
+ end
78
+ find_dhcp!(interface.name, mtu_and_indexes, interfaces)
52
79
  end
53
80
 
54
81
  @fact_list[:interfaces] = interfaces
55
82
  end
56
83
 
57
- def find_dhcp!(tokens, network_info)
58
- interface_name = tokens[1]
59
- return if !network_info[interface_name] || network_info[interface_name][:dhcp]
84
+ def extract_mac_address(interface)
85
+ mac = get_bonded_interface_mac(interface.name)
86
+ begin
87
+ if mac.nil?
88
+ if Socket.const_defined? :PF_LINK
89
+ mac = interface.addr&.getnameinfo&.first #sometimes it returns localhost, ip but mac also
90
+ elsif Socket.const_defined? :PF_PACKET
91
+ return if interface.addr.nil? || interface.addr.inspect_sockaddr.nil?
92
+
93
+ mac = interface.addr&.inspect_sockaddr[/hwaddr=([\h:]+)/, 1]
94
+ end
95
+ end
96
+ rescue StandardError => e
97
+ log.debug("Could not read mac, got #{e}")
98
+ end
99
+ mac if !mac.nil? && mac != '00:00:00:00:00:00' && mac =~ /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/
100
+ end
101
+
102
+ def get_bonded_interface_mac(interface_name)
103
+ master = get_bond_master(interface_name)
104
+ return unless master
105
+
106
+ output = Facter::Util::FileHelper.safe_read("/proc/net/bonding/#{master}", nil)
107
+ return unless output
108
+
109
+ right_block = false
110
+ output.each_line do |line|
111
+ if line.strip == "Slave Interface: #{interface_name}"
112
+ right_block = true
113
+ elsif line.include? 'Slave Interface'
114
+ right_block = false
115
+ end
116
+ return Regexp.last_match(1) if right_block && line =~ /Permanent HW addr: (\S*)/
117
+ end
118
+ end
119
+
120
+ def get_bond_master(interface_name)
121
+ content = Facter::Core::Execution.execute("ip link show #{interface_name}", logger: log)
122
+ master = content.match(/master (\S*) /)
123
+ return master[1] if master
124
+
125
+ nil
126
+ end
127
+
128
+ def add_binding(interfaces, name, ip, netmask, ip_v4_type)
129
+ binding = Facter::Util::Resolvers::Networking.build_binding(ip, netmask)
130
+ return if binding.nil?
131
+
132
+ log.debug("Adding to interface #{name}, binding:\n#{binding}")
133
+ binding_key = ip_v4_type == true ? :bindings : :bindings6
134
+ interfaces[name][binding_key] = [] if interfaces[name][binding_key].nil?
135
+ interfaces[name][binding_key] << binding
136
+ end
137
+
138
+ def add_info_from_routing_table
139
+ routes4, routes6 = read_routing_table
140
+ compare_ips(routes4, :bindings)
141
+ compare_ips(routes6, :bindings6)
142
+ end
143
+
144
+
145
+ def read_routing_table
146
+ ipv4_output = Facter::Core::Execution.execute('ip route show', logger: log)
147
+ ipv6_output = Facter::Core::Execution.execute('ip -6 route show', logger: log)
148
+ routes4 = parse_routes(ipv4_output, 'ipv4')
149
+ routes6 = parse_routes(ipv6_output, 'ipv6')
150
+ [routes4, routes6]
151
+ end
152
+
153
+ def parse_routes(output, family)
154
+ routes = []
155
+ output.each_line do |line|
156
+ parts = line.split(' ').compact
157
+ next if parts.include?('linkdown')
158
+
159
+ route_type = parts[0]
160
+ parts.delete_at(0) if ROUTE_TYPES.include?(route_type)
161
+ next if family == 'ipv6' && !parts[0].include?(':')
162
+
163
+ route = construct_route(parts)
164
+ routes << route unless route[:ip].nil?
165
+ end
166
+ routes.uniq
167
+ end
168
+
169
+ def construct_route(parts)
170
+ route = {}
171
+ dev_index = parts.find_index { |elem| elem == 'dev' }
172
+ src_index = parts.find_index { |elem| elem == 'src' }
173
+ route[:interface] = parts[dev_index + 1] if dev_index
174
+ route[:ip] = parts[src_index + 1] if src_index
175
+ route
176
+ end
60
177
 
61
- index = tokens[0].delete(':')
62
- dhcp = Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
63
- network_info[interface_name][:dhcp] = dhcp.match(/SERVER_ADDRESS=(.*)/)[1] if dhcp
64
- network_info[interface_name][:dhcp] ||= retrieve_from_other_directories(interface_name)
178
+ def compare_ips(routes, binding_key)
179
+ routes.each do |route|
180
+ # TODO we should simplify this
181
+ if @fact_list[:interfaces].key?(route[:interface])
182
+ if @fact_list[:interfaces][route[:interface]][binding_key].nil?
183
+ @fact_list[:interfaces][route[:interface]][binding_key] = [{ address: route[:ip] }]
184
+ elsif @fact_list[:interfaces][route[:interface]][binding_key].none? { |binding| binding[:address] == route[:ip] }
185
+ @fact_list[:interfaces][route[:interface]][binding_key] << { address: route[:ip] }
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ def find_dhcp!(interface_name, interface_indexes, interfaces)
192
+ return if !interfaces[interface_name] || interfaces[interface_name][:dhcp]
193
+
194
+ log.debug("Get DHCP for interface #{interface_name}")
195
+ unless interface_indexes[interface_name].nil?
196
+ index = interface_indexes[interface_name][0]
197
+ file_content = Facter::Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
198
+ dhcp = file_content.match(/SERVER_ADDRESS=(.*)/) if file_content
199
+ if dhcp
200
+ interfaces[interface_name][:dhcp] = dhcp[1]
201
+ else
202
+ alternate_dhcp = retrieve_from_other_directories(interface_name)
203
+ interfaces[interface_name][:dhcp] = alternate_dhcp if alternate_dhcp
204
+ end
205
+ end
206
+ return unless interfaces[interface_name][:dhcp].nil?
207
+
208
+ output = Facter::Core::Execution.execute("dhcpcd -U #{interface_name}", logger: log)
209
+ result = output.match(/dhcp_server_identifier='(.*)'/)&.captures&.first
210
+ interfaces[interface_name][:dhcp] = result if result
65
211
  end
66
212
 
67
213
  def retrieve_from_other_directories(interface_name)
@@ -72,10 +218,11 @@ module Facter
72
218
  next if lease_files.empty?
73
219
 
74
220
  lease_files.select do |file|
75
- content = Util::FileHelper.safe_read("#{dir}#{file}", nil)
221
+ content = Facter::Util::FileHelper.safe_read("#{dir}#{file}", nil)
76
222
  next unless content =~ /interface.*#{interface_name}/
77
223
 
78
- return content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)[1]
224
+ dhcp = content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)
225
+ return dhcp[1] if dhcp
79
226
  end
80
227
  end
81
228
  return unless File.readable?('/var/lib/NetworkManager/')
@@ -88,7 +235,7 @@ module Facter
88
235
  lease_file = files.find { |file| file =~ /internal.*#{interface_name}\.lease/ }
89
236
  return unless lease_file
90
237
 
91
- dhcp = Util::FileHelper.safe_read("/var/lib/NetworkManager/#{lease_file}", nil)
238
+ dhcp = Facter::Util::FileHelper.safe_read("/var/lib/NetworkManager/#{lease_file}", nil)
92
239
 
93
240
  return unless dhcp
94
241
 
@@ -96,57 +243,15 @@ module Facter
96
243
  dhcp[1] if dhcp
97
244
  end
98
245
 
99
- def fill_ip_v4_info!(ip_tokens, network_info)
100
- log.debug('fill_ip_v4_info!')
101
- return unless ip_tokens[2].casecmp('inet').zero?
102
-
103
- interface_name, ip4_address, ip4_mask_length = retrieve_name_and_ip_info(ip_tokens)
104
-
105
- log.debug("interface_name = #{interface_name}\n" \
106
- "ip4_address = #{ip4_address}\n" \
107
- "ip4_mask_length = #{ip4_mask_length}")
108
-
109
- binding = ::Resolvers::Utils::Networking.build_binding(ip4_address, ip4_mask_length)
110
- build_network_info_structure!(network_info, interface_name, :bindings)
246
+ def retrieve_primary_interface
247
+ primary_helper = Facter::Util::Resolvers::Networking::PrimaryInterface
248
+ primary_interface = primary_helper.read_from_proc_route
249
+ primary_interface ||= primary_helper.read_from_ip_route
250
+ primary_interface ||= primary_helper.find_in_interfaces(@fact_list[:interfaces])
111
251
 
112
- network_info[interface_name][:bindings] << binding
252
+ @fact_list[:primary_interface] = primary_interface
113
253
  end
114
254
 
115
- def retrieve_name_and_ip_info(tokens)
116
- interface_name = tokens[1]
117
- ip_info = tokens[3].split('/')
118
- ip_address = ip_info[0]
119
- ip_mask_length = ip_info[1]
120
-
121
- [interface_name, ip_address, ip_mask_length]
122
- end
123
-
124
- def fill_io_v6_info!(ip_tokens, network_info)
125
- return unless ip_tokens[2].casecmp('inet6').zero?
126
-
127
- interface_name, ip6_address, ip6_mask_length = retrieve_name_and_ip_info(ip_tokens)
128
-
129
- binding = ::Resolvers::Utils::Networking.build_binding(ip6_address, ip6_mask_length)
130
-
131
- build_network_info_structure!(network_info, interface_name, :bindings6)
132
-
133
- network_info[interface_name][:scope6] ||= ip_tokens[5]
134
- network_info[interface_name][:bindings6] << binding
135
- end
136
-
137
- def retrieve_default_interface
138
- output = Facter::Core::Execution.execute('ip route get 1', logger: log)
139
-
140
- ip_route_tokens = output.each_line.first.strip.split(' ')
141
- default_interface = ip_route_tokens[4]
142
-
143
- @fact_list[:primary_interface] = default_interface
144
- end
145
-
146
- def build_network_info_structure!(network_info, interface_name, binding)
147
- network_info[interface_name] = {} unless network_info.dig(interface_name)
148
- network_info[interface_name][binding] = [] unless network_info.dig(interface_name, binding)
149
- end
150
255
  end
151
256
  end
152
257
  end
@@ -3,7 +3,7 @@
3
3
  module Facter
4
4
  module Resolvers
5
5
  class Networking < BaseResolver
6
- @fact_list ||= {}
6
+ init_resolver
7
7
 
8
8
  class << self
9
9
  private
@@ -13,16 +13,19 @@ module Facter
13
13
  end
14
14
 
15
15
  def read_facts(fact_name)
16
- primary_interface
17
16
  interfaces_data
18
- ::Resolvers::Utils::Networking.expand_main_bindings(@fact_list)
17
+ primary_interface
18
+ Facter::Util::Resolvers::Networking.expand_main_bindings(@fact_list)
19
19
  @fact_list[fact_name]
20
20
  end
21
21
 
22
22
  def primary_interface
23
- result = Facter::Core::Execution.execute('route -n get default', logger: log)
23
+ primary_helper = Facter::Util::Resolvers::Networking::PrimaryInterface
24
+ primary_interface ||= primary_helper.read_from_route
25
+
26
+ primary_interface ||= primary_helper.find_in_interfaces(@fact_list[:interfaces])
24
27
 
25
- @fact_list[:primary_interface] = result.match(/interface: (.+)/)&.captures&.first
28
+ @fact_list[:primary_interface] = primary_interface
26
29
  end
27
30
 
28
31
  def interfaces_data
@@ -95,7 +98,7 @@ module Facter
95
98
  def create_bindings(ips, masks)
96
99
  bindings = []
97
100
  ips.zip(masks).each do |ip, mask|
98
- bindings << ::Resolvers::Utils::Networking.build_binding(ip, mask)
101
+ bindings << Facter::Util::Resolvers::Networking.build_binding(ip, mask)
99
102
  end
100
103
  bindings
101
104
  end