facter 4.0.50 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate_cli.rb +7 -0
  3. data/lib/facter.rb +90 -56
  4. data/lib/facter/config.rb +2 -0
  5. data/lib/facter/custom_facts/core/aggregate.rb +9 -0
  6. data/lib/facter/custom_facts/core/execution/base.rb +7 -3
  7. data/lib/facter/custom_facts/core/execution/popen3.rb +13 -1
  8. data/lib/facter/custom_facts/core/execution/posix.rb +2 -2
  9. data/lib/facter/custom_facts/core/execution/windows.rb +1 -1
  10. data/lib/facter/custom_facts/core/resolvable.rb +11 -0
  11. data/lib/facter/custom_facts/util/collection.rb +5 -0
  12. data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
  13. data/lib/facter/custom_facts/util/normalization.rb +7 -2
  14. data/lib/facter/custom_facts/util/resolution.rb +2 -0
  15. data/lib/facter/custom_facts/util/windows_root.rb +2 -1
  16. data/lib/facter/facts/aix/processors/cores.rb +16 -0
  17. data/lib/facter/facts/aix/processors/threads.rb +16 -0
  18. data/lib/facter/facts/amzn/lsbdistcodename.rb +16 -0
  19. data/lib/facter/facts/amzn/lsbdistdescription.rb +16 -0
  20. data/lib/facter/facts/amzn/lsbdistid.rb +16 -0
  21. data/lib/facter/facts/amzn/os/distro/codename.rb +24 -0
  22. data/lib/facter/facts/amzn/os/distro/description.rb +21 -0
  23. data/lib/facter/facts/amzn/os/distro/id.rb +21 -0
  24. data/lib/facter/facts/amzn/os/distro/release.rb +32 -0
  25. data/lib/facter/facts/freebsd/is_virtual.rb +1 -5
  26. data/lib/facter/facts/freebsd/virtual.rb +1 -2
  27. data/lib/facter/facts/linux/az_metadata.rb +23 -0
  28. data/lib/facter/facts/linux/cloud/provider.rb +20 -0
  29. data/lib/facter/facts/linux/dhcp_servers.rb +2 -2
  30. data/lib/facter/facts/linux/ec2_metadata.rb +1 -5
  31. data/lib/facter/facts/linux/ec2_userdata.rb +1 -5
  32. data/lib/facter/facts/linux/hypervisors/xen.rb +1 -4
  33. data/lib/facter/facts/linux/interfaces.rb +1 -1
  34. data/lib/facter/facts/linux/ipaddress6_interfaces.rb +1 -1
  35. data/lib/facter/facts/linux/ipaddress_interfaces.rb +1 -1
  36. data/lib/facter/facts/linux/is_virtual.rb +1 -5
  37. data/lib/facter/facts/linux/macaddress_interfaces.rb +1 -1
  38. data/lib/facter/facts/linux/mtu_interfaces.rb +1 -1
  39. data/lib/facter/facts/linux/netmask6_interfaces.rb +1 -1
  40. data/lib/facter/facts/linux/netmask_interfaces.rb +1 -1
  41. data/lib/facter/facts/linux/network6_interfaces.rb +1 -1
  42. data/lib/facter/facts/linux/network_interfaces.rb +1 -1
  43. data/lib/facter/facts/linux/networking/dhcp.rb +1 -1
  44. data/lib/facter/facts/linux/networking/domain.rb +1 -1
  45. data/lib/facter/facts/linux/networking/fqdn.rb +1 -1
  46. data/lib/facter/facts/linux/networking/hostname.rb +1 -1
  47. data/lib/facter/facts/linux/networking/interfaces.rb +1 -1
  48. data/lib/facter/facts/linux/networking/ip.rb +1 -1
  49. data/lib/facter/facts/linux/networking/ip6.rb +1 -1
  50. data/lib/facter/facts/linux/networking/mac.rb +1 -1
  51. data/lib/facter/facts/linux/networking/mtu.rb +1 -1
  52. data/lib/facter/facts/linux/networking/netmask.rb +1 -1
  53. data/lib/facter/facts/linux/networking/netmask6.rb +1 -1
  54. data/lib/facter/facts/linux/networking/network.rb +1 -1
  55. data/lib/facter/facts/linux/networking/network6.rb +1 -1
  56. data/lib/facter/facts/linux/networking/primary.rb +1 -1
  57. data/lib/facter/facts/linux/networking/scope6.rb +1 -1
  58. data/lib/facter/facts/linux/processors/cores.rb +16 -0
  59. data/lib/facter/facts/linux/processors/threads.rb +16 -0
  60. data/lib/facter/facts/linux/scope6_interfaces.rb +1 -1
  61. data/lib/facter/facts/linux/virtual.rb +1 -2
  62. data/lib/facter/facts/macosx/os/macosx/version.rb +15 -4
  63. data/lib/facter/facts/macosx/processors/cores.rb +16 -0
  64. data/lib/facter/facts/macosx/processors/threads.rb +16 -0
  65. data/lib/facter/facts/rhel/lsbdistcodename.rb +16 -0
  66. data/lib/facter/facts/rhel/lsbdistdescription.rb +16 -0
  67. data/lib/facter/facts/rhel/lsbdistid.rb +16 -0
  68. data/lib/facter/facts/rhel/os/distro/codename.rb +2 -4
  69. data/lib/facter/facts/rhel/os/distro/description.rb +2 -4
  70. data/lib/facter/facts/rhel/os/distro/id.rb +2 -4
  71. data/lib/facter/facts/rhel/os/distro/release.rb +13 -12
  72. data/lib/facter/facts/sles/lsbdistcodename.rb +16 -0
  73. data/lib/facter/facts/sles/lsbdistdescription.rb +16 -0
  74. data/lib/facter/facts/sles/lsbdistid.rb +16 -0
  75. data/lib/facter/facts/sles/os/distro/codename.rb +3 -4
  76. data/lib/facter/facts/sles/os/distro/description.rb +2 -5
  77. data/lib/facter/facts/sles/os/distro/id.rb +6 -5
  78. data/lib/facter/facts/sles/os/distro/release.rb +17 -12
  79. data/lib/facter/facts/solaris/hypervisors/ldom.rb +1 -1
  80. data/lib/facter/facts/solaris/hypervisors/zone.rb +1 -1
  81. data/lib/facter/facts/solaris/mountpoints.rb +1 -1
  82. data/lib/facter/facts/solaris/processors/cores.rb +16 -0
  83. data/lib/facter/facts/solaris/processors/threads.rb +16 -0
  84. data/lib/facter/facts/ubuntu/lsbdistrelease.rb +2 -2
  85. data/lib/facter/facts/windows/az_metadata.rb +23 -0
  86. data/lib/facter/facts/windows/cloud/provider.rb +21 -0
  87. data/lib/facter/facts/windows/ec2_metadata.rb +1 -1
  88. data/lib/facter/facts/windows/ec2_userdata.rb +1 -1
  89. data/lib/facter/facts/windows/gce.rb +1 -1
  90. data/lib/facter/facts/windows/hypervisors/hyperv.rb +1 -1
  91. data/lib/facter/facts/windows/hypervisors/kvm.rb +2 -1
  92. data/lib/facter/facts/windows/hypervisors/virtualbox.rb +2 -2
  93. data/lib/facter/facts/windows/hypervisors/vmware.rb +1 -1
  94. data/lib/facter/facts/windows/hypervisors/xen.rb +3 -1
  95. data/lib/facter/facts/windows/is_virtual.rb +15 -0
  96. data/lib/facter/facts/windows/{virtualization/is_virtual.rb → processors/cores.rb} +4 -4
  97. data/lib/facter/facts/windows/{virtualization/virtual.rb → processors/threads.rb} +4 -4
  98. data/lib/facter/facts/windows/virtual.rb +15 -0
  99. data/lib/facter/framework/cli/cli.rb +6 -8
  100. data/lib/facter/framework/config/config_reader.rb +2 -0
  101. data/lib/facter/framework/config/fact_groups.rb +25 -2
  102. data/lib/facter/framework/core/cache_manager.rb +7 -3
  103. data/lib/facter/framework/core/fact/external/external_fact_manager.rb +0 -1
  104. data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +41 -39
  105. data/lib/facter/framework/core/fact_filter.rb +5 -15
  106. data/lib/facter/framework/core/fact_loaders/external_fact_loader.rb +9 -6
  107. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +39 -37
  108. data/lib/facter/framework/core/fact_manager.rb +84 -14
  109. data/lib/facter/framework/core/file_loader.rb +1 -1
  110. data/lib/facter/framework/core/options.rb +1 -2
  111. data/lib/facter/framework/core/options/config_file_options.rb +7 -0
  112. data/lib/facter/framework/core/options/option_store.rb +12 -6
  113. data/lib/facter/framework/formatters/formatter_helper.rb +3 -5
  114. data/lib/facter/framework/logging/logger.rb +4 -4
  115. data/lib/facter/framework/parsers/query_parser.rb +5 -12
  116. data/lib/facter/models/fact_collection.rb +48 -5
  117. data/lib/facter/models/resolved_fact.rb +2 -3
  118. data/lib/facter/models/searched_fact.rb +2 -3
  119. data/lib/facter/resolvers/aix/ffi/ffi_helper.rb +1 -1
  120. data/lib/facter/resolvers/aix/processors.rb +4 -0
  121. data/lib/facter/resolvers/az.rb +39 -0
  122. data/lib/facter/resolvers/base_resolver.rb +2 -2
  123. data/lib/facter/resolvers/dmi_decode.rb +0 -1
  124. data/lib/facter/resolvers/linux/hostname.rb +126 -0
  125. data/lib/facter/resolvers/linux/networking.rb +124 -0
  126. data/lib/facter/resolvers/macosx/mountpoints.rb +14 -1
  127. data/lib/facter/resolvers/macosx/processor.rb +16 -1
  128. data/lib/facter/resolvers/mountpoints.rb +16 -8
  129. data/lib/facter/resolvers/networking.rb +3 -2
  130. data/lib/facter/resolvers/partitions.rb +1 -1
  131. data/lib/facter/resolvers/processors_lscpu.rb +44 -0
  132. data/lib/facter/resolvers/redhat_release.rb +28 -12
  133. data/lib/facter/resolvers/ruby.rb +1 -1
  134. data/lib/facter/resolvers/selinux.rb +5 -7
  135. data/lib/facter/resolvers/solaris/ffi/functions.rb +1 -1
  136. data/lib/facter/resolvers/solaris/ffi/structs.rb +12 -0
  137. data/lib/facter/resolvers/solaris/mountpoints.rb +22 -16
  138. data/lib/facter/resolvers/solaris/networking.rb +20 -5
  139. data/lib/facter/resolvers/solaris/processors.rb +7 -0
  140. data/lib/facter/resolvers/solaris/zone.rb +0 -1
  141. data/lib/facter/resolvers/windows/ffi/identity_ffi.rb +5 -0
  142. data/lib/facter/resolvers/windows/identity.rb +1 -6
  143. data/lib/facter/resolvers/windows/processors.rb +41 -4
  144. data/lib/facter/resolvers/windows/uptime.rb +3 -22
  145. data/lib/facter/resolvers/windows/virtualization.rb +46 -44
  146. data/lib/facter/resolvers/xen.rb +6 -1
  147. data/lib/facter/templates/man.erb +13 -5
  148. data/lib/facter/util/facts/posix/virtual_detector.rb +74 -0
  149. data/lib/facter/util/facts/unit_converter.rb +2 -2
  150. data/lib/facter/util/linux/dhcp.rb +86 -0
  151. data/lib/facter/util/linux/if_inet6.rb +73 -0
  152. data/lib/facter/util/linux/routing_table.rb +60 -0
  153. data/lib/facter/util/linux/socket_parser.rb +114 -0
  154. data/lib/facter/util/resolvers/ffi/hostname.rb +70 -0
  155. data/lib/facter/util/resolvers/http.rb +7 -1
  156. data/lib/facter/util/resolvers/networking/primary_interface.rb +11 -5
  157. data/lib/facter/util/utils.rb +18 -1
  158. data/lib/facter/version.rb +1 -1
  159. metadata +63 -13
  160. data/lib/facter/facts/linux/cloud.rb +0 -15
  161. data/lib/facter/framework/core/fact_augmenter.rb +0 -37
  162. data/lib/facter/resolvers/cloud.rb +0 -39
  163. data/lib/facter/resolvers/networking_linux.rb +0 -296
  164. data/lib/facter/util/facts/virtual_detector.rb +0 -90
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Linux
6
+ class Networking < BaseResolver
7
+ init_resolver
8
+
9
+ class << self
10
+ private
11
+
12
+ def post_resolve(fact_name, _options)
13
+ @fact_list.fetch(fact_name) { retrieve_network_info(fact_name) }
14
+
15
+ @fact_list[fact_name]
16
+ end
17
+
18
+ def retrieve_network_info(fact_name)
19
+ add_info_from_socket_reader
20
+ add_info_from_routing_table
21
+ retrieve_primary_interface
22
+ Facter::Util::Resolvers::Networking.expand_main_bindings(@fact_list)
23
+ add_flags
24
+ @fact_list[fact_name]
25
+ end
26
+
27
+ def add_info_from_socket_reader
28
+ @fact_list[:interfaces] = Facter::Util::Linux::SocketParser.retrieve_interfaces(log)
29
+ mtu_and_indexes = interfaces_mtu_and_index
30
+
31
+ @fact_list[:interfaces].keys.each do |interface_name|
32
+ mtu(interface_name, mtu_and_indexes)
33
+ dhcp(interface_name, mtu_and_indexes)
34
+
35
+ @log.debug("Found interface #{interface_name} with #{@fact_list[:interfaces][interface_name]}")
36
+ end
37
+ end
38
+
39
+ def interfaces_mtu_and_index
40
+ mtu_and_indexes = {}
41
+ output = Facter::Core::Execution.execute('ip link show', logger: log)
42
+ output.each_line do |line|
43
+ next unless line.include?('mtu')
44
+
45
+ parse_ip_command_line(line, mtu_and_indexes)
46
+ end
47
+ log.debug("Associated MTU and index in ip command: #{mtu_and_indexes}")
48
+ mtu_and_indexes
49
+ end
50
+
51
+ def parse_ip_command_line(line, mtu_and_indexes)
52
+ mtu = line.match(/mtu (\d+)/)&.captures&.first&.to_i
53
+ index_tokens = line.split(':')
54
+ index = index_tokens[0].strip
55
+ # vlans are displayed as <vlan_name>@<physical_interface>
56
+ name = index_tokens[1].split('@').first.strip
57
+ mtu_and_indexes[name] = { index: index, mtu: mtu }
58
+ end
59
+
60
+ def mtu(interface_name, mtu_and_indexes)
61
+ mtu = mtu_and_indexes.dig(interface_name, :mtu)
62
+ @fact_list[:interfaces][interface_name][:mtu] = mtu unless mtu.nil?
63
+ end
64
+
65
+ def dhcp(interface_name, mtu_and_indexes)
66
+ dhcp = Facter::Util::Linux::Dhcp.dhcp(interface_name, mtu_and_indexes.dig(interface_name, :index), log)
67
+ @fact_list[:interfaces][interface_name][:dhcp] = dhcp unless dhcp.nil?
68
+ end
69
+
70
+ def add_info_from_routing_table
71
+ routes4, routes6 = Facter::Util::Linux::RoutingTable.read_routing_table(log)
72
+ compare_ips(routes4, :bindings)
73
+ compare_ips(routes6, :bindings6)
74
+ end
75
+
76
+ def add_flags
77
+ flags = Facter::Util::Linux::IfInet6.read_flags
78
+ flags.each_pair do |iface, ips|
79
+ next unless @fact_list[:interfaces].key?(iface)
80
+
81
+ ips.each_pair do |ip, ip_flags|
82
+ next unless @fact_list[:interfaces][iface].key?(:bindings6)
83
+
84
+ @fact_list[:interfaces][iface][:bindings6].each do |binding|
85
+ next unless binding[:address] == ip
86
+
87
+ binding[:flags] = ip_flags
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ def compare_ips(routes, binding_key)
94
+ routes.each do |route|
95
+ next unless @fact_list[:interfaces].key?(route[:interface])
96
+
97
+ interface_data = @fact_list[:interfaces][route[:interface]]
98
+ add_binding_if_missing(interface_data, binding_key, route)
99
+ end
100
+ end
101
+
102
+ def add_binding_if_missing(interface_data, binding_key, route)
103
+ interface_binding = interface_data[binding_key]
104
+
105
+ if interface_binding.nil?
106
+ interface_data[binding_key] = [{ address: route[:ip] }]
107
+ elsif interface_binding.none? { |binding| binding[:address] == route[:ip] }
108
+ interface_binding << { address: route[:ip] }
109
+ end
110
+ end
111
+
112
+ def retrieve_primary_interface
113
+ primary_helper = Facter::Util::Resolvers::Networking::PrimaryInterface
114
+ primary_interface = primary_helper.read_from_proc_route
115
+ primary_interface ||= primary_helper.read_from_ip_route
116
+ primary_interface ||= primary_helper.find_in_interfaces(@fact_list[:interfaces])
117
+
118
+ @fact_list[:primary_interface] = primary_interface
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -21,7 +21,7 @@ module Facter
21
21
  device = fs.name
22
22
  filesystem = fs.mount_type
23
23
  path = fs.mount_point
24
- options = fs.options.split(',').map(&:strip).map { |o| o == 'rootfs' ? 'root' : o }
24
+ options = read_options(fs.options)
25
25
 
26
26
  mounts[path] = read_stats(path).tap do |hash|
27
27
  hash[:device] = device
@@ -53,6 +53,19 @@ module Facter
53
53
  used: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(used_bytes)
54
54
  }
55
55
  end
56
+
57
+ def read_options(options)
58
+ options_map = {
59
+ 'read-only' => 'readonly',
60
+ 'asynchronous' => 'async',
61
+ 'synchronous' => 'noasync',
62
+ 'quotas' => 'quota',
63
+ 'rootfs' => 'root',
64
+ 'defwrite' => 'deferwrites'
65
+ }
66
+
67
+ options.split(',').map(&:strip).map { |o| options_map.key?(o) ? options_map[o] : o }
68
+ end
56
69
  end
57
70
  end
58
71
  end
@@ -9,12 +9,17 @@ module Facter
9
9
  ITEMS = { logical_count: 'hw.logicalcpu_max',
10
10
  physical_count: 'hw.physicalcpu_max',
11
11
  brand: 'machdep.cpu.brand_string',
12
- speed: 'hw.cpufrequency_max' }.freeze
12
+ speed: 'hw.cpufrequency_max',
13
+ cores_per_socket: 'machdep.cpu.core_count',
14
+ threads_per_core: 'machdep.cpu.thread_count' }.freeze
15
+
13
16
  class << self
14
17
  # :logicalcount
15
18
  # :models
16
19
  # :physicalcount
17
20
  # :speed
21
+ # :cores_per_socket
22
+ # :threads_per_core
18
23
 
19
24
  private
20
25
 
@@ -33,6 +38,8 @@ module Facter
33
38
  build_physical_count(processors_data[1])
34
39
  build_models(processors_data[2])
35
40
  build_speed(processors_data[3])
41
+ build_cores_per_socket(processors_data[4])
42
+ build_threads_per_core(processors_data[5], processors_data[4])
36
43
  end
37
44
 
38
45
  def build_logical_count(count)
@@ -51,6 +58,14 @@ module Facter
51
58
  def build_speed(value)
52
59
  @fact_list[:speed] = value.split(': ')[1].to_i
53
60
  end
61
+
62
+ def build_cores_per_socket(count)
63
+ @fact_list[:cores_per_socket] = count.split(': ')[1].to_i
64
+ end
65
+
66
+ def build_threads_per_core(number_of_threads, number_of_cores)
67
+ @fact_list[:threads_per_core] = number_of_threads.split(': ')[1].to_i / number_of_cores.split(': ')[1].to_i
68
+ end
54
69
  end
55
70
  end
56
71
  end
@@ -67,10 +67,24 @@ module Facter
67
67
  end
68
68
 
69
69
  def get_mount_sizes(mount)
70
- stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(mount[:path])
70
+ begin
71
+ stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(mount[:path])
72
+ get_bytes_data(mount, stats)
73
+ rescue Sys::Filesystem::Error => e
74
+ @log.debug("Could not get stats for mountpoint #{mount[:path]}, got #{e}")
75
+ mount[:size_bytes] = mount[:available_bytes] = mount[:used_bytes] = 0
76
+ end
77
+
78
+ populate_mount(mount)
79
+ end
71
80
 
72
- get_bytes_data(mount, stats)
81
+ def get_bytes_data(mount, stats)
82
+ mount[:size_bytes] = stats.bytes_total.abs
83
+ mount[:available_bytes] = stats.bytes_available.abs
84
+ mount[:used_bytes] = stats.bytes_used.abs
85
+ end
73
86
 
87
+ def populate_mount(mount)
74
88
  total_bytes = mount[:used_bytes] + mount[:available_bytes]
75
89
  mount[:capacity] = Facter::Util::Resolvers::FilesystemHelper.compute_capacity(mount[:used_bytes], total_bytes)
76
90
 
@@ -78,12 +92,6 @@ module Facter
78
92
  mount[:available] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:available_bytes])
79
93
  mount[:used] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:used_bytes])
80
94
  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
86
- end
87
95
  end
88
96
  end
89
97
  end
@@ -42,7 +42,7 @@ module Facter
42
42
 
43
43
  def parse_interfaces_response(response)
44
44
  parsed_interfaces_data = {}
45
- interfaces_data = Hash[*response.split(/^([A-Za-z0-9_]+): /)[1..-1]]
45
+ interfaces_data = Hash[*response.split(/^([A-Za-z0-9_\.]+): /)[1..-1]]
46
46
 
47
47
  interfaces_data.each do |interface_name, raw_data|
48
48
  parsed_interface_data = {}
@@ -63,7 +63,8 @@ module Facter
63
63
  end
64
64
 
65
65
  def extract_mac(raw_data, parsed_interface_data)
66
- mac = raw_data.match(/(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/)&.captures&.first
66
+ mac = raw_data.match(/(?:ether|lladdr)\s+((?:\w?\w:){5}\w?\w)|(?:infiniband)\s+((?:\w?\w:){19}\w?\w)/)
67
+ &.captures&.compact&.first
67
68
  parsed_interface_data[:mac] = mac unless mac.nil?
68
69
  end
69
70
 
@@ -109,7 +109,7 @@ module Facter
109
109
 
110
110
  output = Facter::Core::Execution.execute("which #{command}", logger: log)
111
111
 
112
- blkid_and_lsblk[:command_exists_key] = !output.empty?
112
+ blkid_and_lsblk[command_exists_key] = !output.empty?
113
113
  end
114
114
 
115
115
  def execute_and_extract_blkid_info
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Linux
6
+ class Lscpu < BaseResolver
7
+ init_resolver
8
+
9
+ ITEMS = { threads_per_core: "-e 'Thread(s)'",
10
+ cores_per_socket: "-e 'Core(s)'" }.freeze
11
+
12
+ class << self
13
+ #:cores_per_socket
14
+ #:threads_per_core
15
+
16
+ private
17
+
18
+ def post_resolve(fact_name, _options)
19
+ @fact_list.fetch(fact_name) { read_cpuinfo(fact_name) }
20
+ end
21
+
22
+ def read_cpuinfo(fact_name)
23
+ lscpu_output = Facter::Core::Execution.execute("lscpu | grep #{ITEMS.values.join(' ')}", logger: log)
24
+ build_fact_list(lscpu_output.split("\n"))
25
+ @fact_list[fact_name]
26
+ end
27
+
28
+ def build_fact_list(processors_data)
29
+ build_threads_per_core(processors_data[0])
30
+ build_cores_per_socket(processors_data[1])
31
+ end
32
+
33
+ def build_threads_per_core(index)
34
+ @fact_list[:threads_per_core] = index.split(': ')[1].to_i
35
+ end
36
+
37
+ def build_cores_per_socket(index)
38
+ @fact_list[:cores_per_socket] = index.split(': ')[1].to_i
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -6,6 +6,8 @@ module Facter
6
6
  # :name
7
7
  # :version
8
8
  # :codename
9
+ # :description
10
+ # :distributor_id
9
11
 
10
12
  init_resolver
11
13
 
@@ -26,29 +28,43 @@ module Facter
26
28
  end
27
29
 
28
30
  def build_fact_list(output)
31
+ @fact_list[:description] = output.strip
29
32
  output_strings = output.split('release')
30
33
  output_strings.map!(&:strip)
31
- version_codename = output_strings[1].split(' ')
32
-
33
- @fact_list[:name] = name(output_strings[0])
34
- @fact_list[:version] = version_codename[0]&.strip
35
-
36
- codename = version_codename[1]&.strip
37
- @fact_list[:codename] = codename ? codename.gsub(/[()]/, '') : nil
38
34
 
35
+ @fact_list[:codename] = codename(output)
36
+ @fact_list[:distributor_id] = distributor_id(output_strings[0])
37
+ @fact_list[:name] = release_name(output_strings[0])
38
+ @fact_list[:version] = version(output_strings)
39
39
  @fact_list[:identifier] = identifier(@fact_list[:name])
40
40
  end
41
41
 
42
- def name(name)
43
- name.strip.split(' ')[0..1].join
42
+ def release_name(value)
43
+ value.split.reject { |el| el.casecmp('linux').zero? }[0..1].join
44
44
  end
45
45
 
46
- def identifier(name)
47
- identifier = name.strip.downcase
48
- identifier = 'rhel' if @fact_list[:name].strip.casecmp('Red Hat Enterprise Linux')
46
+ def identifier(value)
47
+ identifier = value.downcase
48
+ identifier = 'rhel' if @fact_list[:name].casecmp('Red Hat Enterprise Linux')
49
49
 
50
50
  identifier
51
51
  end
52
+
53
+ def codename(value)
54
+ matched_data = value.match(/.*release.*(\(.*\)).*/)
55
+ return unless matched_data
56
+
57
+ codename = (matched_data[1] || '').gsub(/\(|\)/, '')
58
+ codename.empty? ? nil : codename
59
+ end
60
+
61
+ def version(value)
62
+ value[1].split.first
63
+ end
64
+
65
+ def distributor_id(value)
66
+ value.split.reject { |el| el.casecmp('linux').zero? }.join
67
+ end
52
68
  end
53
69
  end
54
70
  end
@@ -13,7 +13,7 @@ module Facter
13
13
  end
14
14
 
15
15
  def retrieve_ruby_information(fact_name)
16
- @fact_list[:sitedir] = RbConfig::CONFIG['sitelibdir']
16
+ @fact_list[:sitedir] = RbConfig::CONFIG['sitelibdir'] if RbConfig::CONFIG['sitedir']
17
17
  @fact_list[:platform] = RUBY_PLATFORM
18
18
  @fact_list[:version] = RUBY_VERSION
19
19
  @fact_list[fact_name]
@@ -13,21 +13,21 @@ module Facter
13
13
  end
14
14
 
15
15
  def retrieve_facts(fact_name)
16
- mountpoint = read_mounts_file if @fact_list[:enabled].nil?
16
+ mountpoint = selinux_mountpoint
17
+
18
+ @fact_list[:enabled] = !mountpoint.empty? && read_selinux_config
17
19
  read_other_selinux_facts(mountpoint) if @fact_list[:enabled]
18
20
 
19
21
  @fact_list[fact_name]
20
22
  end
21
23
 
22
- def read_mounts_file
24
+ def selinux_mountpoint
23
25
  output = Facter::Core::Execution.execute('cat /proc/self/mounts', logger: log)
24
- @fact_list[:enabled] = false
25
26
  mountpoint = ''
26
27
 
27
28
  output.each_line do |line|
28
29
  next unless line =~ /selinuxfs/
29
30
 
30
- @fact_list[:enabled] = true
31
31
  mountpoint = line.split("\s")[1]
32
32
  break
33
33
  end
@@ -35,8 +35,6 @@ module Facter
35
35
  end
36
36
 
37
37
  def read_other_selinux_facts(mountpoint)
38
- return unless read_selinux_config
39
-
40
38
  enforce_file = "#{mountpoint}/enforce"
41
39
  policy_file = "#{mountpoint}/policyvers"
42
40
 
@@ -60,7 +58,7 @@ module Facter
60
58
  @fact_list[:config_policy] = line.split('=').last.strip if line =~ /^SELINUXTYPE=/
61
59
  end
62
60
 
63
- true unless file_lines.empty?
61
+ !file_lines.empty? ? true : false
64
62
  end
65
63
  end
66
64
  end
@@ -6,7 +6,7 @@ module Facter
6
6
  module FFI
7
7
  module Ioctl
8
8
  extend ::FFI::Library
9
- ffi_lib ::FFI::Library::LIBC, '/usr/lib/libsocket.so'
9
+ ffi_lib ::FFI::Library::LIBC, 'socket'
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
@@ -111,6 +111,18 @@ module Facter
111
111
  self[:sin_addr][:s_addr]
112
112
  end
113
113
  end
114
+
115
+ class In6Addr < ::FFI::Struct
116
+ layout :s_addr, [:uint32_t, 4]
117
+ end
118
+
119
+ class SockaddrIn6 < ::FFI::Struct
120
+ layout :sin6_family, :sa_family_t,
121
+ :sin6_port, :in_port_t,
122
+ :sin6_flowinfo, :uint32_t,
123
+ :sin6_addr, In6Addr,
124
+ :sin6_scope_id, :uint32_t
125
+ end
114
126
  end
115
127
  end
116
128
  end