facter 4.0.38 → 4.0.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/bin/facter +3 -4
  3. data/lib/facter.rb +138 -27
  4. data/lib/facter/custom_facts/core/aggregate.rb +51 -17
  5. data/lib/facter/custom_facts/core/execution.rb +27 -35
  6. data/lib/facter/custom_facts/core/execution/base.rb +42 -6
  7. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  8. data/lib/facter/custom_facts/util/resolution.rb +40 -11
  9. data/lib/facter/facts/aix/disks.rb +1 -1
  10. data/lib/facter/facts/aix/kernel.rb +1 -1
  11. data/lib/facter/facts/aix/kernelmajversion.rb +1 -1
  12. data/lib/facter/facts/aix/kernelrelease.rb +1 -1
  13. data/lib/facter/facts/aix/kernelversion.rb +1 -1
  14. data/lib/facter/facts/aix/os/release.rb +1 -1
  15. data/lib/facter/facts/linux/cloud.rb +15 -0
  16. data/lib/facter/facts/linux/disks.rb +1 -1
  17. data/lib/facter/facts/linux/ec2_metadata.rb +5 -27
  18. data/lib/facter/facts/linux/ec2_userdata.rb +5 -27
  19. data/lib/facter/facts/linux/is_virtual.rb +7 -46
  20. data/lib/facter/facts/linux/virtual.rb +3 -58
  21. data/lib/facter/facts/solaris/disks.rb +1 -1
  22. data/lib/facter/facts/solaris/zones.rb +1 -1
  23. data/lib/facter/facts_utils/virtual_detector.rb +78 -0
  24. data/lib/facter/framework/cli/cli.rb +83 -36
  25. data/lib/facter/framework/cli/cli_launcher.rb +34 -38
  26. data/lib/facter/framework/config/fact_groups.rb +36 -2
  27. data/lib/facter/framework/core/cache_manager.rb +40 -23
  28. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +14 -11
  29. data/lib/facter/framework/core/options/config_file_options.rb +5 -3
  30. data/lib/facter/framework/core/options/option_store.rb +27 -10
  31. data/lib/facter/framework/logging/logger.rb +1 -5
  32. data/lib/facter/patches/sysfilesystem/sys/statvfs.rb +92 -0
  33. data/lib/facter/resolvers/aix/os_level.rb +27 -0
  34. data/lib/facter/resolvers/cloud.rb +39 -0
  35. data/lib/facter/resolvers/dmi_decode.rb +1 -0
  36. data/lib/facter/resolvers/dmi_resolver.rb +2 -2
  37. data/lib/facter/resolvers/memory_resolver.rb +12 -14
  38. data/lib/facter/resolvers/mountpoints_resolver.rb +5 -2
  39. data/lib/facter/resolvers/networking_linux_resolver.rb +10 -5
  40. data/lib/facter/resolvers/processors_resolver.rb +5 -1
  41. data/lib/facter/resolvers/solaris/mountpoints.rb +60 -0
  42. data/lib/facter/resolvers/solaris/networking.rb +1 -1
  43. data/lib/facter/resolvers/utils/filesystem_helper.rb +3 -1
  44. data/lib/facter/version.rb +1 -1
  45. metadata +8 -4
  46. data/lib/facter/resolvers/aix/os_level_resolver.rb +0 -25
  47. data/lib/facter/resolvers/os_level_resolver.rb +0 -28
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sys/filesystem'
4
+
5
+ module Sys
6
+ class Filesystem
7
+ module Structs
8
+ class Statvfs < FFI::Struct
9
+ # We must remove the instance variable layout defined by sys-filesystem, because setting
10
+ # it the second time will make FFI log a warning message.
11
+ remove_instance_variable(:@layout) if @layout
12
+
13
+ if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach/i
14
+ layout(
15
+ :f_bsize, :ulong,
16
+ :f_frsize, :ulong,
17
+ :f_blocks, :uint,
18
+ :f_bfree, :uint,
19
+ :f_bavail, :uint,
20
+ :f_files, :uint,
21
+ :f_ffree, :uint,
22
+ :f_favail, :uint,
23
+ :f_fsid, :ulong,
24
+ :f_flag, :ulong,
25
+ :f_namemax, :ulong
26
+ )
27
+ elsif RbConfig::CONFIG['host'] =~ /bsd/i
28
+ layout(
29
+ :f_bavail, :uint64,
30
+ :f_bfree, :uint64,
31
+ :f_blocks, :uint64,
32
+ :f_favail, :uint64,
33
+ :f_ffree, :uint64,
34
+ :f_files, :uint64,
35
+ :f_bsize, :ulong,
36
+ :f_flag, :ulong,
37
+ :f_frsize, :ulong,
38
+ :f_fsid, :ulong,
39
+ :f_namemax, :ulong
40
+ )
41
+ elsif RbConfig::CONFIG['host'] =~ /sunos|solaris/i
42
+ layout(
43
+ :f_bsize, :ulong,
44
+ :f_frsize, :ulong,
45
+ :f_blocks, :uint64_t,
46
+ :f_bfree, :uint64_t,
47
+ :f_bavail, :uint64_t,
48
+ :f_files, :uint64_t,
49
+ :f_ffree, :uint64_t,
50
+ :f_favail, :uint64_t,
51
+ :f_fsid, :ulong,
52
+ :f_basetype, [:char, 16],
53
+ :f_flag, :ulong,
54
+ :f_namemax, :ulong,
55
+ :f_fstr, [:char, 32],
56
+ :f_filler, [:ulong, 16]
57
+ )
58
+ elsif RbConfig::CONFIG['host'] =~ /i686/i
59
+ layout(
60
+ :f_bsize, :ulong,
61
+ :f_frsize, :ulong,
62
+ :f_blocks, :uint,
63
+ :f_bfree, :uint,
64
+ :f_bavail, :uint,
65
+ :f_files, :uint,
66
+ :f_ffree, :uint,
67
+ :f_favail, :uint,
68
+ :f_fsid, :ulong,
69
+ :f_flag, :ulong,
70
+ :f_namemax, :ulong,
71
+ :f_spare, [:int, 6]
72
+ )
73
+ else
74
+ layout(
75
+ :f_bsize, :ulong,
76
+ :f_frsize, :ulong,
77
+ :f_blocks, :uint64,
78
+ :f_bfree, :uint64,
79
+ :f_bavail, :uint64,
80
+ :f_files, :uint64,
81
+ :f_ffree, :uint64,
82
+ :f_favail, :uint64,
83
+ :f_fsid, :ulong,
84
+ :f_flag, :ulong,
85
+ :f_namemax, :ulong,
86
+ :f_spare, [:int, 6]
87
+ )
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Aix
6
+ class OsLevel < BaseResolver
7
+ @fact_list ||= {}
8
+
9
+ class << self
10
+ private
11
+
12
+ def post_resolve(fact_name)
13
+ @fact_list.fetch(fact_name) { read_oslevel(fact_name) }
14
+ end
15
+
16
+ def read_oslevel(fact_name)
17
+ output = Facter::Core::Execution.execute('/usr/bin/oslevel -s', logger: log)
18
+ @fact_list[:build] = output unless output.empty?
19
+ @fact_list[:kernel] = 'AIX'
20
+
21
+ @fact_list[fact_name]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ class Cloud < BaseResolver
6
+ # cloud_provider
7
+
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { detect_azure(fact_name) }
15
+ end
16
+
17
+ def detect_azure(fact_name)
18
+ search_dirs = %w[/var/lib/dhcp /var/lib/NetworkManager]
19
+ search_dirs.each do |path|
20
+ next if !File.readable?(path) || !File.directory?(path)
21
+
22
+ files = Dir.entries(path)
23
+ files.select! { |filename| filename =~ /^dhclient.*lease.*$/ }
24
+ files.each do |file|
25
+ path = File.join([path, file])
26
+ output = Util::FileHelper.safe_read(path)
27
+
28
+ if output.include?('option unknown-245') || output.include?('option 245')
29
+ @fact_list[:cloud_provider] = 'azure'
30
+ return @fact_list[fact_name]
31
+ end
32
+ end
33
+ end
34
+ nil
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -37,6 +37,7 @@ module Facter
37
37
  @fact_list[:virtualbox_version] = output.match(/vboxVer_(\S+)/)&.captures&.first
38
38
  @fact_list[:virtualbox_revision] = output.match(/vboxRev_(\S+)/)&.captures&.first
39
39
  @fact_list[:vmware_version] = extract_vmware_version(output)
40
+ @fact_list[:vendor] = output.match(/Vendor: (\S+)/)&.captures&.first
40
41
 
41
42
  @fact_list[fact_name]
42
43
  end
@@ -36,9 +36,9 @@ module Facter
36
36
 
37
37
  file_content = Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
38
38
  if files.include?(fact_name.to_s) && file_content
39
- @fact_list[fact_name] = file_content.strip
39
+ file_content = file_content.strip
40
+ @fact_list[fact_name] = file_content unless file_content.empty?
40
41
  chassis_to_name(@fact_list[fact_name]) if fact_name == :chassis_type
41
-
42
42
  end
43
43
  @fact_list[fact_name]
44
44
  end
@@ -25,11 +25,21 @@ module Facter
25
25
 
26
26
  def read_system(output)
27
27
  @fact_list[:total] = kilobytes_to_bytes(output.match(/MemTotal:\s+(\d+)\s/)[1])
28
- @fact_list[:memfree] = kilobytes_to_bytes(output.match(/MemFree:\s+(\d+)\s/)[1])
29
- @fact_list[:used_bytes] = compute_used(@fact_list[:total], reclaimable_memory(output))
28
+ @fact_list[:memfree] = memfree(output)
29
+ @fact_list[:used_bytes] = compute_used(@fact_list[:total], @fact_list[:memfree])
30
30
  @fact_list[:capacity] = compute_capacity(@fact_list[:used_bytes], @fact_list[:total])
31
31
  end
32
32
 
33
+ def memfree(output)
34
+ available = output.match(/MemAvailable:\s+(\d+)\s/)
35
+ return kilobytes_to_bytes(available[1]) if available
36
+
37
+ buffers = kilobytes_to_bytes(output.match(/Buffers:\s+(\d+)\s/)[1])
38
+ cached = kilobytes_to_bytes(output.match(/Cached:\s+(\d+)\s/)[1])
39
+ memfree = kilobytes_to_bytes(output.match(/MemFree:\s+(\d+)\s/)[1])
40
+ memfree + buffers + cached
41
+ end
42
+
33
43
  def read_swap(output)
34
44
  total = output.match(/SwapTotal:\s+(\d+)\s/)[1]
35
45
  return if total.to_i.zero?
@@ -44,18 +54,6 @@ module Facter
44
54
  quantity.to_i * 1024
45
55
  end
46
56
 
47
- def reclaimable_memory(output)
48
- buffers = kilobytes_to_bytes(output.match(/Buffers:\s+(\d+)\s/)[1])
49
- cached = kilobytes_to_bytes(output.match(/Cached:\s+(\d+)\s/)[1])
50
- s_reclaimable = output.match(/SReclaimable:\s+(\d+)\s/)
51
- s_reclaimable = if s_reclaimable
52
- kilobytes_to_bytes(s_reclaimable[1])
53
- else
54
- 0
55
- end
56
- @fact_list[:memfree] + buffers + cached + s_reclaimable
57
- end
58
-
59
57
  def compute_capacity(used, total)
60
58
  format('%<computed_capacity>.2f', computed_capacity: (used / total.to_f * 100)) + '%'
61
59
  end
@@ -10,7 +10,7 @@ module Facter
10
10
  private
11
11
 
12
12
  def post_resolve(fact_name)
13
- @fact_list.fetch(fact_name) { read_mounts }
13
+ @fact_list.fetch(fact_name) { read_mounts(fact_name) }
14
14
  end
15
15
 
16
16
  def root_device
@@ -26,7 +26,8 @@ module Facter
26
26
  device
27
27
  end
28
28
 
29
- def read_mounts # rubocop:disable Metrics/AbcSize
29
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
30
+ def read_mounts(fact_name)
30
31
  mounts = []
31
32
  FilesystemHelper.read_mountpoints.each do |fs|
32
33
  device = compute_device(fs.name)
@@ -52,7 +53,9 @@ module Facter
52
53
  .map { |v| binding.local_variable_get(v) })]
53
54
  end
54
55
  @fact_list[:mountpoints] = mounts
56
+ @fact_list[fact_name]
55
57
  end
58
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
56
59
  end
57
60
  end
58
61
  end
@@ -10,7 +10,6 @@ module Facter
10
10
  private
11
11
 
12
12
  def post_resolve(fact_name)
13
- log.debug('in networking_linux_resolver')
14
13
  @fact_list.fetch(fact_name) { retrieve_network_info(fact_name) }
15
14
 
16
15
  @fact_list[fact_name]
@@ -60,9 +59,14 @@ module Facter
60
59
  return if !network_info[interface_name] || network_info[interface_name][:dhcp]
61
60
 
62
61
  index = tokens[0].delete(':')
63
- dhcp = Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
64
- network_info[interface_name][:dhcp] = dhcp.match(/SERVER_ADDRESS=(.*)/)[1] if dhcp
65
- network_info[interface_name][:dhcp] ||= retrieve_from_other_directories(interface_name)
62
+ file_content = Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
63
+ dhcp = file_content.match(/SERVER_ADDRESS=(.*)/) if file_content
64
+ if dhcp
65
+ network_info[interface_name][:dhcp] = dhcp[1]
66
+ else
67
+ alternate_dhcp = retrieve_from_other_directories(interface_name)
68
+ network_info[interface_name][:dhcp] = alternate_dhcp if alternate_dhcp
69
+ end
66
70
  end
67
71
 
68
72
  def retrieve_from_other_directories(interface_name)
@@ -76,7 +80,8 @@ module Facter
76
80
  content = Util::FileHelper.safe_read("#{dir}#{file}", nil)
77
81
  next unless content =~ /interface.*#{interface_name}/
78
82
 
79
- return content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)[1]
83
+ dhcp = content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)
84
+ return dhcp[1] if dhcp
80
85
  end
81
86
  end
82
87
  return unless File.readable?('/var/lib/NetworkManager/')
@@ -60,7 +60,11 @@ module Facter
60
60
  def physical_devices_count
61
61
  Dir.entries('/sys/devices/system/cpu')
62
62
  .select { |dir| dir =~ /cpu[0-9]+$/ }
63
- .count { |dir| File.exist?("/sys/devices/system/cpu/#{dir}/topology/physical_package_id") }
63
+ .select { |dir| File.exist?("/sys/devices/system/cpu/#{dir}/topology/physical_package_id") }
64
+ .map do |dir|
65
+ Util::FileHelper.safe_read("/sys/devices/system/cpu/#{dir}/topology/physical_package_id").strip
66
+ end
67
+ .uniq.count
64
68
  end
65
69
 
66
70
  def build_speed(tokens)
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class Mountpoints < BaseResolver
7
+ include Facter::FilesystemHelper
8
+ @fact_list ||= {}
9
+ @log = Facter::Log.new(self)
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { read_mounts(fact_name) }
15
+ end
16
+
17
+ def root_device
18
+ cmdline = Util::FileHelper.safe_read('/proc/cmdline')
19
+ match = cmdline.match(/root=([^\s]+)/)
20
+ match&.captures&.first
21
+ end
22
+
23
+ def compute_device(device)
24
+ # If the "root" device, lookup the actual device from the kernel options
25
+ # This is done because not all systems symlink /dev/root
26
+ device = root_device if device == '/dev/root'
27
+ device
28
+ end
29
+
30
+ def read_mounts(fact_name) # rubocop:disable Metrics/AbcSize
31
+ mounts = []
32
+ FilesystemHelper.read_mountpoints.each do |fs|
33
+ device = compute_device(fs.name)
34
+ filesystem = fs.mount_type
35
+ path = fs.mount_point
36
+ options = fs.options.split(',').map(&:strip)
37
+
38
+ stats = FilesystemHelper.read_mountpoint_stats(path)
39
+ size_bytes = stats.bytes_total.abs
40
+ available_bytes = stats.bytes_available.abs
41
+
42
+ used_bytes = stats.bytes_used.abs
43
+ total_bytes = used_bytes + available_bytes
44
+ capacity = FilesystemHelper.compute_capacity(used_bytes, total_bytes)
45
+
46
+ size = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(size_bytes)
47
+ available = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(available_bytes)
48
+ used = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(used_bytes)
49
+
50
+ mounts << Hash[FilesystemHelper::MOUNT_KEYS.zip(FilesystemHelper::MOUNT_KEYS
51
+ .map { |v| binding.local_variable_get(v) })]
52
+ end
53
+ @fact_list[:mountpoints] = mounts
54
+ @fact_list[fact_name]
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -66,7 +66,7 @@ module Facter
66
66
 
67
67
  @log.debug("Error! #{::FFI::LastError.error}") if ioctl == -1
68
68
 
69
- @interfaces[lifreq.name][:mtu] = lifreq[:lifr_lifru][:lifru_metric]
69
+ @interfaces[lifreq.name][:mtu] ||= lifreq[:lifr_lifru][:lifru_metric]
70
70
  end
71
71
 
72
72
  def load_netmask(lifreq)
@@ -7,7 +7,9 @@ module Facter
7
7
  size_bytes used used_bytes capacity].freeze
8
8
  class << self
9
9
  def read_mountpoints
10
- require 'sys/filesystem'
10
+ # TODO: this require must be replaced with "require 'sys/filesystem'" when a new release of
11
+ # djberg96/sys-filesystem gem is available
12
+ require_relative '../../patches/sysfilesystem/sys/statvfs.rb'
11
13
  force_utf(Sys::Filesystem.mounts)
12
14
  end
13
15
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.0.38' unless defined?(VERSION)
4
+ VERSION = '4.0.43' unless defined?(VERSION)
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.38
4
+ version: 4.0.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-16 00:00:00.000000000 Z
11
+ date: 2020-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -385,6 +385,7 @@ files:
385
385
  - lib/facter/facts/freebsd/zpool_version.rb
386
386
  - lib/facter/facts/linux/aio_agent_version.rb
387
387
  - lib/facter/facts/linux/augeas/version.rb
388
+ - lib/facter/facts/linux/cloud.rb
388
389
  - lib/facter/facts/linux/dhcp_servers.rb
389
390
  - lib/facter/facts/linux/disks.rb
390
391
  - lib/facter/facts/linux/dmi/bios/release_date.rb
@@ -813,6 +814,7 @@ files:
813
814
  - lib/facter/facts_utils/facts_utils.rb
814
815
  - lib/facter/facts_utils/unit_converter.rb
815
816
  - lib/facter/facts_utils/uptime_parser.rb
817
+ - lib/facter/facts_utils/virtual_detector.rb
816
818
  - lib/facter/facts_utils/windows_release_finder.rb
817
819
  - lib/facter/framework/benchmarking/timer.rb
818
820
  - lib/facter/framework/cli/cli.rb
@@ -853,6 +855,7 @@ files:
853
855
  - lib/facter/models/resolved_fact.rb
854
856
  - lib/facter/models/searched_fact.rb
855
857
  - lib/facter/os_hierarchy.json
858
+ - lib/facter/patches/sysfilesystem/sys/statvfs.rb
856
859
  - lib/facter/resolvers/aio_agent_version.rb
857
860
  - lib/facter/resolvers/aix/architecture_resolver.rb
858
861
  - lib/facter/resolvers/aix/disks.rb
@@ -864,7 +867,7 @@ files:
864
867
  - lib/facter/resolvers/aix/mountpoints.rb
865
868
  - lib/facter/resolvers/aix/networking_resolver.rb
866
869
  - lib/facter/resolvers/aix/nim.rb
867
- - lib/facter/resolvers/aix/os_level_resolver.rb
870
+ - lib/facter/resolvers/aix/os_level.rb
868
871
  - lib/facter/resolvers/aix/partitions.rb
869
872
  - lib/facter/resolvers/aix/processors.rb
870
873
  - lib/facter/resolvers/aix/serialnumber.rb
@@ -874,6 +877,7 @@ files:
874
877
  - lib/facter/resolvers/base_resolver.rb
875
878
  - lib/facter/resolvers/bsd/ffi/ffi_helper.rb
876
879
  - lib/facter/resolvers/bsd/processors.rb
880
+ - lib/facter/resolvers/cloud.rb
877
881
  - lib/facter/resolvers/containers.rb
878
882
  - lib/facter/resolvers/debian_version.rb
879
883
  - lib/facter/resolvers/disk_resolver.rb
@@ -914,7 +918,6 @@ files:
914
918
  - lib/facter/resolvers/networking_linux_resolver.rb
915
919
  - lib/facter/resolvers/networking_resolver.rb
916
920
  - lib/facter/resolvers/open_vz.rb
917
- - lib/facter/resolvers/os_level_resolver.rb
918
921
  - lib/facter/resolvers/os_release_resolver.rb
919
922
  - lib/facter/resolvers/partitions.rb
920
923
  - lib/facter/resolvers/path_resolver.rb
@@ -933,6 +936,7 @@ files:
933
936
  - lib/facter/resolvers/solaris/ipaddress.rb
934
937
  - lib/facter/resolvers/solaris/ldom.rb
935
938
  - lib/facter/resolvers/solaris/memory.rb
939
+ - lib/facter/resolvers/solaris/mountpoints.rb
936
940
  - lib/facter/resolvers/solaris/networking.rb
937
941
  - lib/facter/resolvers/solaris/os_release.rb
938
942
  - lib/facter/resolvers/solaris/processors.rb