facter 4.0.37 → 4.0.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/bin/facter +3 -4
  3. data/lib/facter.rb +163 -23
  4. data/lib/facter/custom_facts/core/execution/base.rb +42 -6
  5. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  6. data/lib/facter/facts/aix/disks.rb +1 -1
  7. data/lib/facter/facts/aix/kernel.rb +1 -1
  8. data/lib/facter/facts/aix/kernelmajversion.rb +1 -1
  9. data/lib/facter/facts/aix/kernelrelease.rb +1 -1
  10. data/lib/facter/facts/aix/kernelversion.rb +1 -1
  11. data/lib/facter/facts/aix/os/release.rb +1 -1
  12. data/lib/facter/facts/linux/cloud.rb +15 -0
  13. data/lib/facter/facts/linux/disks.rb +1 -1
  14. data/lib/facter/facts/linux/ec2_metadata.rb +5 -27
  15. data/lib/facter/facts/linux/ec2_userdata.rb +5 -27
  16. data/lib/facter/facts/linux/is_virtual.rb +7 -46
  17. data/lib/facter/facts/linux/virtual.rb +3 -58
  18. data/lib/facter/facts/rhel/os/release.rb +2 -2
  19. data/lib/facter/facts/solaris/disks.rb +1 -1
  20. data/lib/facter/facts_utils/virtual_detector.rb +78 -0
  21. data/lib/facter/framework/cli/cli.rb +84 -36
  22. data/lib/facter/framework/cli/cli_launcher.rb +34 -38
  23. data/lib/facter/framework/config/fact_groups.rb +36 -2
  24. data/lib/facter/framework/core/cache_manager.rb +40 -23
  25. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +14 -11
  26. data/lib/facter/framework/core/options/config_file_options.rb +5 -3
  27. data/lib/facter/framework/core/options/option_store.rb +27 -10
  28. data/lib/facter/framework/logging/logger.rb +3 -11
  29. data/lib/facter/patches/sysfilesystem/sys/statvfs.rb +92 -0
  30. data/lib/facter/resolvers/aix/os_level.rb +27 -0
  31. data/lib/facter/resolvers/cloud.rb +39 -0
  32. data/lib/facter/resolvers/dmi_decode.rb +1 -0
  33. data/lib/facter/resolvers/memory_resolver.rb +12 -14
  34. data/lib/facter/resolvers/networking_linux_resolver.rb +0 -1
  35. data/lib/facter/resolvers/utils/filesystem_helper.rb +3 -1
  36. data/lib/facter/version.rb +1 -1
  37. metadata +7 -4
  38. data/lib/facter/resolvers/aix/os_level_resolver.rb +0 -25
  39. 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
@@ -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,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]
@@ -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.37' unless defined?(VERSION)
4
+ VERSION = '4.0.42' 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.37
4
+ version: 4.0.42
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-09 00:00:00.000000000 Z
11
+ date: 2020-10-07 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
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Facter
4
- module Resolvers
5
- class OsLevel < BaseResolver
6
- @fact_list ||= {}
7
-
8
- class << self
9
- private
10
-
11
- def post_resolve(fact_name)
12
- @fact_list.fetch(fact_name) { read_oslevel(fact_name) }
13
- end
14
-
15
- def read_oslevel(fact_name)
16
- output = Facter::Core::Execution.execute('/usr/bin/oslevel -s', logger: log)
17
- @fact_list[:build] = output
18
- @fact_list[:kernel] = 'AIX'
19
-
20
- @fact_list[fact_name]
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Facter
4
- module Resolvers
5
- class OsLevel < BaseResolver
6
- # build
7
-
8
- @fact_list ||= {}
9
-
10
- class << self
11
- private
12
-
13
- def post_resolve(fact_name)
14
- @fact_list.fetch(fact_name) { read_oslevel(fact_name) }
15
- end
16
-
17
- def read_oslevel(fact_name)
18
- output = Facter::Core::Execution.execute('/usr/bin/oslevel -s', logger: log)
19
-
20
- @fact_list[:build] = output unless output.empty?
21
- @fact_list[:kernel] = 'AIX'
22
-
23
- @fact_list[fact_name]
24
- end
25
- end
26
- end
27
- end
28
- end