facter 4.5.1 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/bin/facter +1 -1
  3. data/lib/docs/generate.rb +1 -6
  4. data/lib/facter/custom_facts/core/directed_graph.rb +2 -4
  5. data/lib/facter/custom_facts/core/execution/base.rb +1 -1
  6. data/lib/facter/custom_facts/core/execution/posix.rb +6 -2
  7. data/lib/facter/custom_facts/core/execution/windows.rb +4 -1
  8. data/lib/facter/custom_facts/core/execution.rb +1 -1
  9. data/lib/facter/custom_facts/core/file_loader.rb +0 -4
  10. data/lib/facter/custom_facts/core/suitable.rb +1 -1
  11. data/lib/facter/custom_facts/util/collection.rb +2 -4
  12. data/lib/facter/custom_facts/util/confine.rb +4 -1
  13. data/lib/facter/custom_facts/util/fact.rb +1 -1
  14. data/lib/facter/custom_facts/util/loader.rb +2 -2
  15. data/lib/facter/custom_facts/util/resolution.rb +8 -4
  16. data/lib/facter/custom_facts/util/values.rb +1 -1
  17. data/lib/facter/facts/amzn/os/distro/release.rb +6 -1
  18. data/lib/facter/facts/amzn/os/release.rb +5 -0
  19. data/lib/facter/facts/linux/dmi/product/version.rb +19 -0
  20. data/lib/facter/facts/linux/kernelmajversion.rb +1 -1
  21. data/lib/facter/facts/macosx/is_virtual.rb +1 -1
  22. data/lib/facter/facts/macosx/virtual.rb +3 -3
  23. data/lib/facter/facts/mariner/os/release.rb +1 -1
  24. data/lib/facter/facts/photon/os/release.rb +1 -1
  25. data/lib/facter/facts/solaris/kernelmajversion.rb +1 -1
  26. data/lib/facter/facts/solaris/ldom.rb +1 -1
  27. data/lib/facter/facts/windows/hypervisors/kvm.rb +1 -1
  28. data/lib/facter/facts/windows/interfaces.rb +1 -1
  29. data/lib/facter/framework/benchmarking/timer.rb +2 -2
  30. data/lib/facter/framework/cli/cli.rb +6 -8
  31. data/lib/facter/framework/cli/cli_launcher.rb +1 -1
  32. data/lib/facter/framework/config/fact_groups.rb +1 -1
  33. data/lib/facter/framework/core/cache_manager.rb +5 -6
  34. data/lib/facter/framework/core/fact_loaders/class_discoverer.rb +4 -3
  35. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +1 -3
  36. data/lib/facter/framework/core/fact_manager.rb +4 -4
  37. data/lib/facter/framework/core/file_loader.rb +736 -733
  38. data/lib/facter/framework/core/options/config_file_options.rb +4 -6
  39. data/lib/facter/framework/formatters/hocon_fact_formatter.rb +3 -2
  40. data/lib/facter/framework/formatters/legacy_fact_formatter.rb +4 -4
  41. data/lib/facter/framework/logging/logger.rb +6 -6
  42. data/lib/facter/framework/logging/logger_helper.rb +10 -11
  43. data/lib/facter/framework/parsers/query_parser.rb +24 -20
  44. data/lib/facter/resolvers/aix/disks.rb +1 -1
  45. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  46. data/lib/facter/resolvers/aix/networking.rb +1 -1
  47. data/lib/facter/resolvers/aix/partitions.rb +2 -2
  48. data/lib/facter/resolvers/aix/serialnumber.rb +1 -1
  49. data/lib/facter/resolvers/amzn/os_release_rpm.rb +40 -0
  50. data/lib/facter/resolvers/dmi.rb +2 -1
  51. data/lib/facter/resolvers/fips_enabled.rb +1 -1
  52. data/lib/facter/resolvers/freebsd/dmi.rb +1 -1
  53. data/lib/facter/resolvers/freebsd/swap_memory.rb +1 -1
  54. data/lib/facter/resolvers/freebsd/system_memory.rb +15 -7
  55. data/lib/facter/resolvers/freebsd/virtual.rb +1 -1
  56. data/lib/facter/resolvers/linux/hostname.rb +1 -1
  57. data/lib/facter/resolvers/macosx/dmi.rb +1 -1
  58. data/lib/facter/resolvers/macosx/filesystems.rb +1 -1
  59. data/lib/facter/resolvers/memory.rb +1 -1
  60. data/lib/facter/resolvers/networking.rb +3 -3
  61. data/lib/facter/resolvers/os_release.rb +1 -1
  62. data/lib/facter/resolvers/partitions.rb +2 -2
  63. data/lib/facter/resolvers/processors_lscpu.rb +2 -2
  64. data/lib/facter/resolvers/solaris/ffi/ffi.rb +2 -2
  65. data/lib/facter/resolvers/solaris/ffi/functions.rb +2 -2
  66. data/lib/facter/resolvers/solaris/mountpoints.rb +1 -1
  67. data/lib/facter/resolvers/solaris/networking.rb +2 -2
  68. data/lib/facter/resolvers/solaris/os_release.rb +2 -2
  69. data/lib/facter/resolvers/uname.rb +10 -6
  70. data/lib/facter/resolvers/virt_what.rb +2 -1
  71. data/lib/facter/resolvers/windows/memory.rb +3 -2
  72. data/lib/facter/resolvers/windows/product_release.rb +7 -7
  73. data/lib/facter/resolvers/xen.rb +3 -1
  74. data/lib/facter/util/aix/info_extractor.rb +1 -1
  75. data/lib/facter/util/aix/odm_query.rb +1 -1
  76. data/lib/facter/util/api_debugger.rb +2 -2
  77. data/lib/facter/util/facts/facts_utils.rb +2 -1
  78. data/lib/facter/util/facts/posix/virtual_detector.rb +8 -5
  79. data/lib/facter/util/facts/unit_converter.rb +2 -2
  80. data/lib/facter/util/file_helper.rb +1 -2
  81. data/lib/facter/util/macosx/system_profile_executor.rb +3 -3
  82. data/lib/facter/util/resolvers/fingerprint.rb +1 -7
  83. data/lib/facter/util/resolvers/networking/networking.rb +4 -3
  84. data/lib/facter/util/resolvers/networking/primary_interface.rb +2 -0
  85. data/lib/facter/util/resolvers/ssh.rb +1 -9
  86. data/lib/facter/util/resolvers/ssh_helper.rb +2 -0
  87. data/lib/facter/util/utils.rb +2 -2
  88. data/lib/facter/version.rb +1 -1
  89. data/lib/facter.rb +7 -0
  90. metadata +11 -9
@@ -60,10 +60,8 @@ module Facter
60
60
  def augment_custom(file_global_conf)
61
61
  return unless file_global_conf
62
62
 
63
- if Options.cli?
64
- unless file_global_conf['no-custom-facts'].nil?
65
- @options[:no_custom_facts] = file_global_conf['no-custom-facts']
66
- end
63
+ if Options.cli? && !file_global_conf['no-custom-facts'].nil?
64
+ @options[:no_custom_facts] = file_global_conf['no-custom-facts']
67
65
  end
68
66
 
69
67
  @options[:custom_dir] = file_global_conf['custom-dir'] unless file_global_conf['custom-dir'].nil?
@@ -73,8 +71,8 @@ module Facter
73
71
  def augment_external(global_conf)
74
72
  return unless global_conf
75
73
 
76
- if Options.cli?
77
- @options[:no_external_facts] = global_conf['no-external-facts'] unless global_conf['no-external-facts'].nil?
74
+ if Options.cli? && !global_conf['no-external-facts'].nil?
75
+ @options[:no_external_facts] = global_conf['no-external-facts']
78
76
  end
79
77
 
80
78
  @options[:external_dir] = [global_conf['external-dir']].flatten unless global_conf['external-dir'].nil?
@@ -14,7 +14,8 @@ module Facter
14
14
 
15
15
  user_query = user_queries.first
16
16
  return format_for_no_query(resolved_facts) if user_query.empty?
17
- return format_for_single_user_query(user_queries.first, resolved_facts) unless user_query.empty?
17
+
18
+ format_for_single_user_query(user_queries.first, resolved_facts) unless user_query.empty?
18
19
  end
19
20
 
20
21
  private
@@ -39,7 +40,7 @@ module Facter
39
40
 
40
41
  return '' unless fact_value
41
42
 
42
- fact_value.class == Hash ? hash_to_hocon(fact_value) : fact_value
43
+ fact_value.instance_of?(Hash) ? hash_to_hocon(fact_value) : fact_value
43
44
  end
44
45
 
45
46
  def hash_to_hocon(fact_collection)
@@ -42,7 +42,7 @@ module Facter
42
42
  pretty_json = handle_newlines(pretty_json)
43
43
 
44
44
  @log.debug('Remove quotes from value if value is a string')
45
- pretty_json.gsub(/^(\S*) => \"(.*)\"/, '\1 => \2')
45
+ pretty_json.gsub(/^(\S*) => "(.*)"/, '\1 => \2')
46
46
  end
47
47
 
48
48
  def format_for_single_user_query(user_query, resolved_facts)
@@ -55,7 +55,7 @@ module Facter
55
55
  pretty_json = fact_value.nil? ? '' : hash_to_facter_format(fact_value)
56
56
 
57
57
  @log.debug('Remove quotes from value if it is a simple string')
58
- pretty_json.gsub(/^"(.*)\"/, '\1')
58
+ pretty_json.gsub(/^"(.*)"/, '\1')
59
59
  end
60
60
 
61
61
  def hash_to_facter_format(facts_hash)
@@ -66,7 +66,7 @@ module Facter
66
66
  pretty_json.gsub!(/":\s/, '" => ')
67
67
 
68
68
  @log.debug('Remove quotes from parent nodes')
69
- pretty_json.gsub!(/\"(.*)\"\ =>/, '\1 =>')
69
+ pretty_json.gsub!(/"(.*)"\ =>/, '\1 =>')
70
70
 
71
71
  @log.debug('Remove double backslashes from paths')
72
72
  pretty_json.gsub(/\\\\/, '\\')
@@ -95,7 +95,7 @@ module Facter
95
95
  # quotation marks that come after \ are not removed
96
96
  @log.debug('Remove unnecessary comma and quotation marks on root facts')
97
97
  output.split("\n")
98
- .map! { |line| /^[\s]+/.match?(line) ? line : line.gsub(/,$|(?<!\\)\"/, '').gsub('\\"', '"') }.join("\n")
98
+ .map! { |line| /^\s+/.match?(line) ? line : line.gsub(/,$|(?<!\\)"/, '').gsub('\\"', '"') }.join("\n")
99
99
  end
100
100
  end
101
101
  end
@@ -107,7 +107,7 @@ module Facter
107
107
  @@message_callback.call(:debug, msg)
108
108
  else
109
109
  msg = colorize(msg, CYAN) if Options[:color]
110
- @@logger.debug(@class_name + ' - ' + msg)
110
+ @@logger.debug("#{@class_name} - #{msg}")
111
111
  end
112
112
  end
113
113
 
@@ -128,7 +128,7 @@ module Facter
128
128
  @@message_callback.call(:info, msg)
129
129
  else
130
130
  msg = colorize(msg, GREEN) if Options[:color]
131
- @@logger.info(@class_name + ' - ' + msg)
131
+ @@logger.info("#{@class_name} - #{msg}")
132
132
  end
133
133
  end
134
134
 
@@ -137,7 +137,7 @@ module Facter
137
137
  @@message_callback.call(:warn, msg)
138
138
  else
139
139
  msg = colorize(msg, YELLOW) if Options[:color]
140
- @@logger.warn(@class_name + ' - ' + msg)
140
+ @@logger.warn("#{@class_name} - #{msg}")
141
141
  end
142
142
  end
143
143
 
@@ -149,20 +149,20 @@ module Facter
149
149
  warn(message_string)
150
150
  end
151
151
 
152
- def error(msg, colorize = false)
152
+ def error(msg, colorize = false) # rubocop:disable Style/OptionalBooleanParameter
153
153
  @@has_errors = true
154
154
 
155
155
  if @@message_callback && Options[:allow_external_loggers]
156
156
  @@message_callback.call(:error, msg)
157
157
  else
158
158
  msg = colorize(msg, RED) if colorize || Options[:color]
159
- @@logger.error(@class_name + ' - ' + msg)
159
+ @@logger.error("#{@class_name} - #{msg}")
160
160
  end
161
161
  end
162
162
 
163
163
  def log_exception(exception)
164
164
  msg = exception.message
165
- msg += "\n" + exception.backtrace.join("\n") if Options[:trace]
165
+ msg += "\n#{exception.backtrace.join("\n")}" if Options[:trace]
166
166
 
167
167
  error(msg, true)
168
168
  end
@@ -3,17 +3,16 @@
3
3
  class LoggerHelper
4
4
  class << self
5
5
  def determine_callers_name(sender_self)
6
- class_name = case sender_self
7
- when String
8
- sender_self
9
- when Class
10
- sender_self.name
11
- when Module
12
- sender_self.name
13
- else # when class is singleton
14
- sender_self.class.name
15
- end
16
- class_name
6
+ case sender_self
7
+ when String
8
+ sender_self
9
+ when Class
10
+ sender_self.name
11
+ when Module
12
+ sender_self.name
13
+ else # when class is singleton
14
+ sender_self.class.name
15
+ end
17
16
  end
18
17
  end
19
18
  end
@@ -18,18 +18,18 @@ module Facter
18
18
  # Because a root fact will always be resolved by a collection of child facts,
19
19
  # we can return one or more child facts for each parent.
20
20
  #
21
- # query - is the user input used to search for facts
22
- # loaded_fact - is a list with all facts for the current operating system
21
+ # @param query_list [Array] The list of facts to search for
22
+ # @param loaded_facts [Array] All of the fact definitions for the current operating system
23
23
  #
24
- # Returns a list of SearchedFact objects that resolve the users query.
25
- def parse(query_list, loaded_fact)
24
+ # @return [Array<SearchedFact>] a list of searchable facts that resolve the user's query
25
+ def parse(query_list, loaded_facts)
26
26
  matched_facts = []
27
27
  @query_list = query_list
28
28
 
29
- return no_user_query(loaded_fact) unless query_list.any?
29
+ return no_user_query(loaded_facts) unless query_list.any?
30
30
 
31
31
  query_list.each do |query|
32
- found_facts = search_for_facts(query, loaded_fact)
32
+ found_facts = search_for_facts(query, loaded_facts)
33
33
  matched_facts << found_facts
34
34
  end
35
35
 
@@ -44,15 +44,17 @@ module Facter
44
44
  searched_facts
45
45
  end
46
46
 
47
- def search_for_facts(query, loaded_fact_hash)
47
+ def search_for_facts(query, loaded_facts)
48
48
  resolvable_fact_list = []
49
49
  query = query.to_s
50
50
  query_tokens = query.end_with?('.*') ? [query] : query.split('.')
51
51
  size = query_tokens.size
52
52
 
53
+ # Try to match the most specific query_tokens to the least, returning the first match
53
54
  size.times do |i|
54
55
  query_token_range = 0..size - i - 1
55
- resolvable_fact_list = get_facts_matching_tokens(query_tokens, query_token_range, loaded_fact_hash)
56
+ query_fact = query_tokens[query_token_range].join('.')
57
+ resolvable_fact_list = get_facts_matching_tokens(query_tokens, query_fact, loaded_facts)
56
58
 
57
59
  return resolvable_fact_list if resolvable_fact_list.any?
58
60
  end
@@ -62,12 +64,10 @@ module Facter
62
64
  resolvable_fact_list
63
65
  end
64
66
 
65
- def get_facts_matching_tokens(query_tokens, query_token_range, loaded_fact_hash)
67
+ def get_facts_matching_tokens(query_tokens, query_fact, loaded_facts)
66
68
  resolvable_fact_list = []
67
69
 
68
- loaded_fact_hash.each do |loaded_fact|
69
- query_fact = query_tokens[query_token_range].join('.')
70
-
70
+ loaded_facts.each do |loaded_fact|
71
71
  next unless found_fact?(loaded_fact.name, query_fact)
72
72
 
73
73
  searched_fact = construct_loaded_fact(query_tokens, loaded_fact)
@@ -79,16 +79,20 @@ module Facter
79
79
  end
80
80
 
81
81
  def found_fact?(fact_name, query_fact)
82
+ # This is the case where the fact_name contains a wildcard like
83
+ # blockdevice_.*_model and we're querying for the legacy fact
84
+ # specifically using 'blockdevice_sba_model' and we don't want the query
85
+ # 'blockdevice.sba.model' to match
82
86
  fact_with_wildcard = fact_name.include?('.*') && !query_fact.include?('.')
83
87
 
84
- processed_equery_fact = query_fact.gsub('\\', '\\\\\\\\')
85
-
86
- return false if fact_with_wildcard && !query_fact.match("^#{fact_name}$")
87
-
88
- # Must escape metacharacters (like dots) to ensure the correct fact is found
89
- return false unless fact_with_wildcard || fact_name.match("^#{Regexp.escape(processed_equery_fact)}($|\\.)")
90
-
91
- true
88
+ if fact_with_wildcard
89
+ # fact_name contains wildcard, so we're intentially not escaping.
90
+ query_fact.match("^#{fact_name}$")
91
+ else
92
+ processed_equery_fact = query_fact.gsub('\\', '\\\\\\\\')
93
+ # Must escape metacharacters (like dots) to ensure the correct fact is found
94
+ fact_name.match("^#{Regexp.escape(processed_equery_fact)}($|\\.)")
95
+ end
92
96
  end
93
97
 
94
98
  def construct_loaded_fact(query_tokens, loaded_fact)
@@ -47,7 +47,7 @@ module Facter
47
47
  end
48
48
 
49
49
  def compute_size(size_hash)
50
- physical_partitions = size_hash['TOTAL PPs'].to_i + size_hash['FREE PPs'].to_i
50
+ physical_partitions = size_hash['TOTAL PPs'].to_i
51
51
  size_physical_partition = size_hash['PP SIZE']
52
52
  exp = if size_physical_partition[/mega/]
53
53
  Facter::Util::Aix::InfoExtractor::MEGABYTES_EXPONENT
@@ -77,7 +77,7 @@ module Facter
77
77
 
78
78
  family = FFI::AF_UNSPEC
79
79
 
80
- addresses.each do |_k, addr|
80
+ addresses.each_value do |addr|
81
81
  if family != FFI::AF_UNSPEC &&
82
82
  addr[:sa_family] != FFI::AF_UNSPEC &&
83
83
  family != addr[:sa_family]
@@ -47,7 +47,7 @@ module Facter
47
47
 
48
48
  info = line.split("\s")
49
49
  interface_name = info[0]
50
- mac = info[3][/^([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})$/]
50
+ mac = info[3][/^([0-9a-f]{1,2}[.:-]){5}([0-9a-f]{1,2})$/]
51
51
  if interfaces[interface_name]
52
52
  interfaces[interface_name][:mtu] = info[1].to_i
53
53
  interfaces[interface_name][:mac] = format_mac_address(mac) if mac
@@ -56,14 +56,14 @@ module Facter
56
56
  end
57
57
 
58
58
  def compute_size(info_hash)
59
- physical_partitions = info_hash['PPs'].to_i
59
+ logical_partitions = info_hash['LPs'].to_i
60
60
  size_physical_partition = info_hash['PP SIZE']
61
61
  exp = if size_physical_partition[/mega/]
62
62
  Facter::Util::Aix::InfoExtractor::MEGABYTES_EXPONENT
63
63
  else
64
64
  Facter::Util::Aix::InfoExtractor::GIGABYTES_EXPONENT
65
65
  end
66
- size_physical_partition.to_i * physical_partitions * exp
66
+ size_physical_partition.to_i * logical_partitions * exp
67
67
  end
68
68
  end
69
69
  end
@@ -22,7 +22,7 @@ module Facter
22
22
 
23
23
  result.each_line do |line|
24
24
  if line.include?('value')
25
- @fact_list[:serialnumber] = line.split('=')[1].strip.delete('\"')[6..-1]
25
+ @fact_list[:serialnumber] = line.split('=')[1].strip.delete('\"')[6..]
26
26
  break
27
27
  end
28
28
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Amzn
6
+ class OsReleaseRpm < BaseResolver
7
+ init_resolver
8
+
9
+ class << self
10
+ private
11
+
12
+ def post_resolve(fact_name, _options)
13
+ @fact_list.fetch(fact_name) { rpm_system_call(fact_name) }
14
+ end
15
+
16
+ def rpm_system_call(fact_name)
17
+ output = Facter::Core::Execution.execute(
18
+ 'rpm -q --qf \'%<NAME>s\n%<VERSION>s\n%<RELEASE>s\n%<VENDOR>s\' -f /etc/os-release',
19
+ logger: log
20
+ )
21
+ build_fact_list(output)
22
+
23
+ @fact_list[fact_name]
24
+ end
25
+
26
+ def build_fact_list(output)
27
+ rpm_results = output.split("\n")
28
+
29
+ return if rpm_results.empty?
30
+
31
+ @fact_list[:package],
32
+ @fact_list[:version],
33
+ @fact_list[:release],
34
+ @fact_list[:vendor] = rpm_results.map(&:strip)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -22,6 +22,7 @@ module Facter
22
22
  # :product_serial
23
23
  # :product_name
24
24
  # :product_uuid
25
+ # :product_version
25
26
 
26
27
  private
27
28
 
@@ -32,7 +33,7 @@ module Facter
32
33
  def read_facts(fact_name)
33
34
  files = %w[bios_date bios_vendor bios_version board_asset_tag board_vendor board_name
34
35
  board_serial chassis_asset_tag chassis_type sys_vendor product_name
35
- product_serial product_uuid]
36
+ product_serial product_uuid product_version]
36
37
  return unless File.directory?('/sys/class/dmi')
37
38
 
38
39
  file_content = Facter::Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
@@ -4,7 +4,7 @@ module Facter
4
4
  module Resolvers
5
5
  module Linux
6
6
  class FipsEnabled < BaseResolver
7
- #:fips_enabled
7
+ # :fips_enabled
8
8
 
9
9
  init_resolver
10
10
 
@@ -7,7 +7,7 @@ module Facter
7
7
  init_resolver
8
8
 
9
9
  class << self
10
- #:model
10
+ # :model
11
11
 
12
12
  private
13
13
 
@@ -15,7 +15,7 @@ module Facter
15
15
 
16
16
  def read_swap_memory(fact_name)
17
17
  output = Facter::Core::Execution.execute('swapinfo -k', logger: log)
18
- data = output.split("\n")[1..-1].map { |line| line.split(/\s+/) }
18
+ data = output.split("\n")[1..].map { |line| line.split(/\s+/) }
19
19
 
20
20
  unless data.empty?
21
21
  @fact_list[:total_bytes] = kilobytes_to_bytes(data.map { |line| line[1].to_i }.inject(:+))
@@ -15,25 +15,33 @@ module Facter
15
15
 
16
16
  def calculate_system_memory(fact_name)
17
17
  read_total_memory_in_bytes
18
- read_available_memory_in_bytes
18
+ read_used_memory_in_bytes
19
19
 
20
- @fact_list[:used_bytes] = @fact_list[:total_bytes] - @fact_list[:available_bytes]
20
+ @fact_list[:available_bytes] = @fact_list[:total_bytes] - @fact_list[:used_bytes]
21
21
  @fact_list[:capacity] = Facter::Util::Resolvers::FilesystemHelper
22
22
  .compute_capacity(@fact_list[:used_bytes], @fact_list[:total_bytes])
23
23
 
24
24
  @fact_list[fact_name]
25
25
  end
26
26
 
27
- def read_available_memory_in_bytes
28
- output = Facter::Core::Execution.execute('vmstat -H --libxo json', logger: log)
29
- data = JSON.parse(output)
30
- @fact_list[:available_bytes] = data['memory']['free-memory'] * 1024
27
+ def pagesize
28
+ @pagesize ||= Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_page_size')
29
+ end
30
+
31
+ def read_used_memory_in_bytes
32
+ require_relative 'ffi/ffi_helper'
33
+
34
+ @fact_list[:used_bytes] = pagesize * (
35
+ Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_active_count') +
36
+ Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_wire_count')
37
+ )
31
38
  end
32
39
 
33
40
  def read_total_memory_in_bytes
34
41
  require_relative 'ffi/ffi_helper'
35
42
 
36
- @fact_list[:total_bytes] = Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'hw.physmem')
43
+ @fact_list[:total_bytes] = pagesize *
44
+ Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_page_count')
37
45
  end
38
46
  end
39
47
  end
@@ -7,7 +7,7 @@ module Facter
7
7
  init_resolver
8
8
 
9
9
  class << self
10
- #:model
10
+ # :model
11
11
 
12
12
  VM_GUEST_SYSCTL_NAMES = {
13
13
  'hv' => 'hyperv',
@@ -50,7 +50,7 @@ module Facter
50
50
  end
51
51
 
52
52
  log.debug("Tried to retrieve hostname and got: #{output}")
53
- return output unless output&.empty?
53
+ output unless output&.empty?
54
54
  end
55
55
 
56
56
  def parse_fqdn(output)
@@ -7,7 +7,7 @@ module Facter
7
7
  init_resolver
8
8
 
9
9
  class << self
10
- #:model
10
+ # :model
11
11
 
12
12
  private
13
13
 
@@ -16,7 +16,7 @@ module Facter
16
16
 
17
17
  def read_filesystems(fact_name)
18
18
  output = Facter::Core::Execution.execute('mount', logger: log)
19
- filesystems = output.scan(/\(([a-z]+)\,*/).flatten
19
+ filesystems = output.scan(/\(([a-z]+),*/).flatten
20
20
  @fact_list[:macosx_filesystems] = filesystems.uniq.sort.join(',')
21
21
  @fact_list[fact_name]
22
22
  end
@@ -57,7 +57,7 @@ module Facter
57
57
  end
58
58
 
59
59
  def compute_capacity(used, total)
60
- format('%<computed_capacity>.2f', computed_capacity: (used / total.to_f * 100)) + '%'
60
+ "#{format('%<computed_capacity>.2f', computed_capacity: (used / total.to_f * 100))}%"
61
61
  end
62
62
 
63
63
  def compute_used(total, free)
@@ -39,12 +39,12 @@ module Facter
39
39
  # convert ip ranges into single ip. eg. 10.16.132.213 --> 10.16.132.213 is converted to 10.16.132.213
40
40
  # convert ip6 ranges into single ip. eg. 2001:db8:cafe::132:213 -->
41
41
  # 2001:db8:cafe::132:213 is converted to 2001:db8:cafe::132:213
42
- response.gsub!(/([\da-fA-F]+([\.:]+[\da-fA-F]+)*)\s+-->\s+[\da-fA-F]+([\.:]+[\da-fA-F]+)*/, '\\1')
42
+ response.gsub!(/([\da-fA-F]+([.:]+[\da-fA-F]+)*)\s+-->\s+[\da-fA-F]+([.:]+[\da-fA-F]+)*/, '\\1')
43
43
  end
44
44
 
45
45
  def parse_interfaces_response(response)
46
46
  parsed_interfaces_data = {}
47
- interfaces_data = Hash[*response.split(/^([A-Za-z0-9_\.]+): /)[1..-1]]
47
+ interfaces_data = Hash[*response.split(/^([A-Za-z0-9_.]+): /)[1..]]
48
48
 
49
49
  interfaces_data.each do |interface_name, raw_data|
50
50
  parsed_interface_data = {}
@@ -66,7 +66,7 @@ module Facter
66
66
 
67
67
  def extract_mac(raw_data, parsed_interface_data)
68
68
  mac = raw_data.match(/(?:ether|lladdr)\s+((?:\w?\w:){5}\w?\w)|(?:infiniband)\s+((?:\w?\w:){19}\w?\w)/)
69
- &.captures&.compact&.first
69
+ &.captures&.compact&.first
70
70
  parsed_interface_data[:mac] = mac unless mac.nil?
71
71
  end
72
72
 
@@ -110,7 +110,7 @@ module Facter
110
110
 
111
111
  def append_linux_to_os_name
112
112
  os_name = @fact_list[:name]
113
- @fact_list[:name] = os_name + 'Linux' if os_name.downcase.start_with?('virtuozzo')
113
+ @fact_list[:name] = "#{os_name}Linux" if os_name.downcase.start_with?('virtuozzo')
114
114
  end
115
115
  end
116
116
  end
@@ -112,9 +112,9 @@ module Facter
112
112
 
113
113
  def execute_and_extract_blkid_info
114
114
  stdout = Facter::Core::Execution.execute('blkid', logger: log)
115
- output_hash = Hash[*stdout.split(/^([^:]+):/)[1..-1]]
115
+ output_hash = Hash[*stdout.split(/^([^:]+):/)[1..]]
116
116
  output_hash.each do |key, value|
117
- output_hash[key] = Hash[*value.delete('"').chomp.rstrip.split(/ ([^= ]+)=/)[1..-1]]
117
+ output_hash[key] = Hash[*value.delete('"').chomp.rstrip.split(/ ([^= ]+)=/)[1..]]
118
118
  end
119
119
  end
120
120
 
@@ -10,8 +10,8 @@ module Facter
10
10
  cores_per_socket: "-e 'Core(s)'" }.freeze
11
11
 
12
12
  class << self
13
- #:cores_per_socket
14
- #:threads_per_core
13
+ # :cores_per_socket
14
+ # :threads_per_core
15
15
 
16
16
  private
17
17
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ffi'
4
- require_relative 'structs.rb'
5
- require_relative 'functions.rb'
4
+ require_relative 'structs'
5
+ require_relative 'functions'
6
6
 
7
7
  module Facter
8
8
  module Resolvers
@@ -10,7 +10,7 @@ module Facter
10
10
 
11
11
  attach_function :ioctl_base, :ioctl, %i[int int pointer], :int
12
12
  attach_function :open_socket, :socket, %i[int int int], :int
13
- attach_function :close_socket, :shutdown, %i[int int], :int
13
+ attach_function :close_socket, :close, %i[int], :int
14
14
  attach_function :inet_ntop, %i[int pointer pointer uint], :string
15
15
 
16
16
  def self.ioctl(call_const, pointer, address_family = AF_INET)
@@ -18,7 +18,7 @@ module Facter
18
18
  begin
19
19
  ioctl_base(fd, call_const, pointer)
20
20
  ensure
21
- Ioctl.close_socket(fd, 2)
21
+ Ioctl.close_socket(fd)
22
22
  end
23
23
  end
24
24
  end
@@ -23,7 +23,7 @@ module Facter
23
23
  end
24
24
  end
25
25
 
26
- def read_mounts(fact_name) # rubocop:disable Metrics/MethodLength
26
+ def read_mounts(fact_name)
27
27
  @mounts = []
28
28
  @auto_home_paths = []
29
29
  begin
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'ffi/ffi.rb'
3
+ require_relative 'ffi/ffi'
4
4
  module Facter
5
5
  module Resolvers
6
6
  module Solaris
@@ -79,7 +79,7 @@ module Facter
79
79
  ioctl = FFI::Ioctl.ioctl(FFI::SIOCGLIFMTU, lifreq, lifreq.ss_family)
80
80
 
81
81
  if ioctl == -1
82
- @log.error("Cold not read MTU, error code is #{::FFI::LastError.error}")
82
+ @log.error("Could not read MTU, error code is: #{::FFI::LastError.error}")
83
83
  return
84
84
  end
85
85
 
@@ -26,7 +26,7 @@ module Facter
26
26
 
27
27
  @fact_list[:major] = major
28
28
  @fact_list[:minor] = minor
29
- @fact_list[:full] = major == '10' ? major + '_u' + minor : major + '.' + minor
29
+ @fact_list[:full] = major == '10' ? "#{major}_u#{minor}" : "#{major}.#{minor}"
30
30
  break
31
31
  end
32
32
  @fact_list[fact_name]
@@ -36,7 +36,7 @@ module Facter
36
36
  result = text.match(regex_pattern)
37
37
  major, minor = result.captures if result
38
38
  minor = regex_pattern == /Solaris (\d+)/ ? '0' : minor
39
- return [major, minor] if major && minor
39
+ [major, minor] if major && minor
40
40
  end
41
41
  end
42
42
  end
@@ -28,12 +28,16 @@ module Facter
28
28
  def build_fact_list(output)
29
29
  uname_results = output.split("\n")
30
30
 
31
- @fact_list[:machine] = uname_results[0].strip
32
- @fact_list[:nodename] = uname_results[1].strip
33
- @fact_list[:processor] = uname_results[2].strip
34
- @fact_list[:kernelrelease] = uname_results[3].strip
35
- @fact_list[:kernelname] = uname_results[4].strip
36
- @fact_list[:kernelversion] = uname_results[5].strip
31
+ if !uname_results.empty?
32
+ @fact_list[:machine],
33
+ @fact_list[:nodename],
34
+ @fact_list[:processor],
35
+ @fact_list[:kernelrelease],
36
+ @fact_list[:kernelname],
37
+ @fact_list[:kernelversion] = uname_results.map(&:strip)
38
+ else
39
+ log.warn('Request to uname returned no output. Uname related facts are not populated.')
40
+ end
37
41
  end
38
42
  end
39
43
  end