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,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Linux
5
+ class Cloud
6
+ FACT_NAME = 'cloud'
7
+
8
+ def call_the_resolver
9
+ cloud_provider = Facter::Resolvers::Cloud.resolve(:cloud_provider)
10
+
11
+ Facter::ResolvedFact.new(FACT_NAME, cloud_provider)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -25,7 +25,7 @@ module Facts
25
25
  def add_legacy_facts(disks, facts)
26
26
  disks.each do |disk_name, disk_info|
27
27
  facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_model", disk_info[:model], :legacy))
28
- facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes].to_s, :legacy))
28
+ facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes], :legacy))
29
29
  facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_vendor", disk_info[:vendor], :legacy))
30
30
  end
31
31
  end
@@ -5,6 +5,10 @@ module Facts
5
5
  class Ec2Metadata
6
6
  FACT_NAME = 'ec2_metadata'
7
7
 
8
+ def initialize
9
+ @virtual = Facter::VirtualDetector.new
10
+ end
11
+
8
12
  def call_the_resolver
9
13
  return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?
10
14
 
@@ -16,33 +20,7 @@ module Facts
16
20
  private
17
21
 
18
22
  def aws_hypervisors?
19
- virtual = check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
20
-
21
- virtual == 'kvm' || virtual =~ /xen/
22
- end
23
-
24
- def check_virt_what
25
- Facter::Resolvers::VirtWhat.resolve(:vm)
26
- end
27
-
28
- def check_xen
29
- Facter::Resolvers::Xen.resolve(:vm)
30
- end
31
-
32
- def check_product_name
33
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
34
- return unless product_name
35
-
36
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
37
- end
38
-
39
- def check_bios_vendor
40
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
41
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
42
- end
43
-
44
- def check_lspci
45
- Facter::Resolvers::Lspci.resolve(:vm)
23
+ @virtual.platform =~ /kvm|xen|aws/
46
24
  end
47
25
  end
48
26
  end
@@ -5,6 +5,10 @@ module Facts
5
5
  class Ec2Userdata
6
6
  FACT_NAME = 'ec2_userdata'
7
7
 
8
+ def initialize
9
+ @virtual = Facter::VirtualDetector.new
10
+ end
11
+
8
12
  def call_the_resolver
9
13
  return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?
10
14
 
@@ -16,33 +20,7 @@ module Facts
16
20
  private
17
21
 
18
22
  def aws_hypervisors?
19
- virtual = check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
20
-
21
- virtual == 'kvm' || virtual =~ /xen/
22
- end
23
-
24
- def check_virt_what
25
- Facter::Resolvers::VirtWhat.resolve(:vm)
26
- end
27
-
28
- def check_xen
29
- Facter::Resolvers::Xen.resolve(:vm)
30
- end
31
-
32
- def check_product_name
33
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
34
- return unless product_name
35
-
36
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
37
- end
38
-
39
- def check_bios_vendor
40
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
41
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
42
- end
43
-
44
- def check_lspci
45
- Facter::Resolvers::Lspci.resolve(:vm)
23
+ @virtual.platform =~ /kvm|xen|aws/
46
24
  end
47
25
  end
48
26
  end
@@ -5,59 +5,20 @@ module Facts
5
5
  class IsVirtual
6
6
  FACT_NAME = 'is_virtual'
7
7
 
8
- def call_the_resolver # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
9
- fact_value = check_docker_lxc || check_gce || retrieve_from_virt_what || check_vmware
10
- fact_value ||= check_open_vz || check_vserver || check_xen || check_other_facts || check_lspci || 'physical'
11
-
12
- Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value))
13
- end
14
-
15
- def check_gce
16
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
17
- 'gce' if bios_vendor&.include?('Google')
18
- end
19
-
20
- def check_docker_lxc
21
- Facter::Resolvers::Containers.resolve(:vm)
8
+ def initialize
9
+ @virtual = Facter::VirtualDetector.new
22
10
  end
23
11
 
24
- def check_vmware
25
- Facter::Resolvers::Vmware.resolve(:vm)
26
- end
12
+ def call_the_resolver
13
+ fact_value = @virtual.platform
27
14
 
28
- def retrieve_from_virt_what
29
- Facter::Resolvers::VirtWhat.resolve(:vm)
30
- end
31
-
32
- def check_open_vz
33
- Facter::Resolvers::OpenVz.resolve(:vm)
34
- end
35
-
36
- def check_vserver
37
- Facter::Resolvers::VirtWhat.resolve(:vserver)
38
- end
39
-
40
- def check_xen
41
- Facter::Resolvers::Xen.resolve(:vm)
42
- end
43
-
44
- def check_other_facts
45
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
46
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
47
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
48
- return unless product_name
49
-
50
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
51
-
52
- nil
15
+ Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value))
53
16
  end
54
17
 
55
- def check_lspci
56
- Facter::Resolvers::Lspci.resolve(:vm)
57
- end
18
+ private
58
19
 
59
20
  def check_if_virtual(found_vm)
60
- Facter::FactsUtils::PHYSICAL_HYPERVISORS.count(found_vm).zero?
21
+ Facter::FactsUtils::PHYSICAL_HYPERVISORS.count(found_vm).zero?.to_s
61
22
  end
62
23
  end
63
24
  end
@@ -7,71 +7,16 @@ module Facts
7
7
 
8
8
  def initialize
9
9
  @log = Facter::Log.new(self)
10
+ @virtual = Facter::VirtualDetector.new
10
11
  end
11
12
 
12
- def call_the_resolver # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
13
+ def call_the_resolver
13
14
  @log.debug('Linux Virtual Resolver')
14
-
15
- fact_value = check_docker_lxc || check_gce || retrieve_from_virt_what || check_vmware
16
- fact_value ||= check_open_vz || check_vserver || check_xen || check_other_facts || check_lspci || 'physical'
17
-
15
+ fact_value = @virtual.platform
18
16
  @log.debug("Fact value is: #{fact_value}")
19
17
 
20
18
  Facter::ResolvedFact.new(FACT_NAME, fact_value)
21
19
  end
22
-
23
- def check_gce
24
- @log.debug('Checking GCE')
25
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
26
- 'gce' if bios_vendor&.include?('Google')
27
- end
28
-
29
- def check_docker_lxc
30
- @log.debug('Checking Docker and LXC')
31
- Facter::Resolvers::Containers.resolve(:vm)
32
- end
33
-
34
- def check_vmware
35
- @log.debug('Checking VMware')
36
- Facter::Resolvers::Vmware.resolve(:vm)
37
- end
38
-
39
- def retrieve_from_virt_what
40
- @log.debug('Checking virtual_what')
41
- Facter::Resolvers::VirtWhat.resolve(:vm)
42
- end
43
-
44
- def check_open_vz
45
- @log.debug('Checking OpenVZ')
46
- Facter::Resolvers::OpenVz.resolve(:vm)
47
- end
48
-
49
- def check_vserver
50
- @log.debug('Checking VServer')
51
- Facter::Resolvers::VirtWhat.resolve(:vserver)
52
- end
53
-
54
- def check_xen
55
- @log.debug('Checking XEN')
56
- Facter::Resolvers::Xen.resolve(:vm)
57
- end
58
-
59
- def check_other_facts
60
- @log.debug('Checking others')
61
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
62
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
63
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
64
- return unless product_name
65
-
66
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
67
-
68
- nil
69
- end
70
-
71
- def check_lspci
72
- @log.debug('Checking lspci')
73
- Facter::Resolvers::Lspci.resolve(:vm)
74
- end
75
20
  end
76
21
  end
77
22
  end
@@ -18,8 +18,8 @@ module Facts
18
18
  end
19
19
 
20
20
  def determine_release_version
21
- version = Facter::Resolvers::OsRelease.resolve(:version_id)
22
- version ||= Facter::Resolvers::RedHatRelease.resolve(:version)
21
+ version = Facter::Resolvers::RedHatRelease.resolve(:version)
22
+ version ||= Facter::Resolvers::OsRelease.resolve(:version_id)
23
23
 
24
24
  return unless version
25
25
 
@@ -24,7 +24,7 @@ module Facts
24
24
 
25
25
  def add_legacy_facts(disks, facts)
26
26
  disks.each do |disk_name, disk_info|
27
- facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes].to_s, :legacy))
27
+ facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes], :legacy))
28
28
  facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_vendor", disk_info[:vendor], :legacy))
29
29
  end
30
30
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ class VirtualDetector
5
+ def initialize
6
+ @log = Facter::Log.new(self)
7
+ end
8
+
9
+ def platform # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
10
+ fact_value = check_docker_lxc || check_dmi || check_gce || retrieve_from_virt_what || check_vmware
11
+ fact_value ||= check_open_vz || check_vserver || check_xen || check_other_facts || check_lspci || 'physical'
12
+
13
+ fact_value
14
+ end
15
+
16
+ def check_docker_lxc
17
+ @log.debug('Checking Docker and LXC')
18
+ Facter::Resolvers::Containers.resolve(:vm)
19
+ end
20
+
21
+ def check_dmi
22
+ @log.debug('Checking DMI')
23
+ vendor = Facter::Resolvers::DmiDecode.resolve(:vendor)
24
+ @log.debug("dmi detected vendor: #{vendor}")
25
+ return 'aws' if vendor =~ /Amazon/
26
+
27
+ 'xen' if vendor =~ /Xen/
28
+ end
29
+
30
+ def check_gce
31
+ @log.debug('Checking GCE')
32
+ bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
33
+ 'gce' if bios_vendor&.include?('Google')
34
+ end
35
+
36
+ def check_vmware
37
+ @log.debug('Checking VMware')
38
+ Facter::Resolvers::Vmware.resolve(:vm)
39
+ end
40
+
41
+ def retrieve_from_virt_what
42
+ @log.debug('Checking virtual_what')
43
+ Facter::Resolvers::VirtWhat.resolve(:vm)
44
+ end
45
+
46
+ def check_open_vz
47
+ @log.debug('Checking OpenVZ')
48
+ Facter::Resolvers::OpenVz.resolve(:vm)
49
+ end
50
+
51
+ def check_vserver
52
+ @log.debug('Checking VServer')
53
+ Facter::Resolvers::VirtWhat.resolve(:vserver)
54
+ end
55
+
56
+ def check_xen
57
+ @log.debug('Checking XEN')
58
+ Facter::Resolvers::Xen.resolve(:vm)
59
+ end
60
+
61
+ def check_other_facts
62
+ @log.debug('Checking others')
63
+ product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
64
+ bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
65
+ return 'kvm' if bios_vendor&.include?('Amazon EC2')
66
+ return unless product_name
67
+
68
+ Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
69
+
70
+ nil
71
+ end
72
+
73
+ def check_lspci
74
+ @log.debug('Checking lspci')
75
+ Facter::Resolvers::Lspci.resolve(:vm)
76
+ end
77
+ end
78
+ end
@@ -1,14 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'thor'
5
+
4
6
  module Facter
5
7
  class Cli < Thor
6
- check_unknown_options!
7
-
8
8
  class_option :color,
9
9
  type: :boolean,
10
10
  desc: 'Enable color output.'
11
11
 
12
+ class_option :no_color,
13
+ type: :boolean,
14
+ desc: 'Disable color output.'
15
+
12
16
  class_option :config,
13
17
  aliases: '-c',
14
18
  type: :string,
@@ -29,17 +33,6 @@ module Facter
29
33
  repeatable: true,
30
34
  desc: 'A directory to use for external facts.'
31
35
 
32
- class_option :help,
33
- hide: true,
34
- aliases: '-h',
35
- type: :boolean,
36
- desc: 'Print this help message.'
37
-
38
- class_option :man,
39
- hide: true,
40
- type: :boolean,
41
- desc: 'Display manual.'
42
-
43
36
  class_option :hocon,
44
37
  type: :boolean,
45
38
  desc: 'Output in Hocon format.'
@@ -49,36 +42,28 @@ module Facter
49
42
  type: :boolean,
50
43
  desc: 'Output in JSON format.'
51
44
 
52
- class_option :list_block_groups,
53
- type: :boolean,
54
- desc: 'List the names of all blockable fact groups.'
55
-
56
- class_option :list_cache_groups,
57
- type: :boolean,
58
- desc: 'List the names of all cacheable fact groups.'
59
-
60
45
  class_option :log_level,
61
46
  aliases: '-l',
62
47
  type: :string,
63
48
  desc: 'Set logging level. Supported levels are: none, trace, debug, info, warn, error, and fatal.'
64
49
 
65
- class_option :block,
50
+ class_option :no_block,
66
51
  type: :boolean,
67
52
  desc: 'Disable fact blocking.'
68
53
 
69
- class_option :cache,
54
+ class_option :no_cache,
70
55
  type: :boolean,
71
56
  desc: 'Disable loading and refreshing facts from the cache'
72
57
 
73
- class_option :custom_facts,
58
+ class_option :no_custom_facts,
74
59
  type: :boolean,
75
60
  desc: 'Disable custom facts.'
76
61
 
77
- class_option :external_facts,
62
+ class_option :no_external_facts,
78
63
  type: :boolean,
79
64
  desc: 'Disable external facts.'
80
65
 
81
- class_option :ruby,
66
+ class_option :no_ruby,
82
67
  type: :boolean,
83
68
  desc: 'Disable loading Ruby, facts requiring Ruby, and custom facts.'
84
69
 
@@ -103,17 +88,12 @@ module Facter
103
88
  type: :boolean,
104
89
  desc: 'Enable more aggressive error reporting.'
105
90
 
106
- class_option :puppet,
107
- type: :boolean,
108
- aliases: '-p',
109
- desc: 'Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
110
-
111
91
  class_option :timing,
112
92
  type: :boolean,
113
93
  aliases: '-t',
114
94
  desc: 'Show how much time it took to resolve each fact'
115
95
 
116
- desc '--man', 'Manual', hide: true
96
+ desc '--man', 'Display manual.', hide: true
117
97
  map ['--man'] => :man
118
98
  def man(*args)
119
99
  require 'erb'
@@ -126,7 +106,6 @@ module Facter
126
106
  end
127
107
 
128
108
  desc 'query', 'Default method', hide: true
129
- desc '[options] [query] [query] [...]', ''
130
109
  def query(*args)
131
110
  output, status = Facter.to_user_output(@options, *args)
132
111
  puts output
@@ -135,13 +114,21 @@ module Facter
135
114
  exit status
136
115
  end
137
116
 
117
+ desc 'arg_parser', 'Parse arguments', hide: true
118
+ def arg_parser(*args)
119
+ # ignore unknown options
120
+ args.reject! { |arg| arg.start_with?('-') }
121
+
122
+ Facter.values(@options, args)
123
+ end
124
+
138
125
  desc '--version, -v', 'Print the version', hide: true
139
126
  map ['--version', '-v'] => :version
140
- def version
127
+ def version(*_args)
141
128
  puts Facter::VERSION
142
129
  end
143
130
 
144
- desc '--list-block-groups', 'List block groups', hide: true
131
+ desc '--list-block-groups', 'List block groups'
145
132
  map ['--list-block-groups'] => :list_block_groups
146
133
  def list_block_groups(*args)
147
134
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
@@ -153,7 +140,7 @@ module Facter
153
140
  puts block_groups
154
141
  end
155
142
 
156
- desc '--list-cache-groups', 'List cache groups', hide: true
143
+ desc '--list-cache-groups', 'List cache groups'
157
144
  map ['--list-cache-groups'] => :list_cache_groups
158
145
  def list_cache_groups(*args)
159
146
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
@@ -165,6 +152,67 @@ module Facter
165
152
  puts cache_groups
166
153
  end
167
154
 
155
+ desc '--puppet, -p', '(NOT SUPPORTED)Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
156
+ map ['--puppet', '-p'] => :puppet
157
+ def puppet(*_args)
158
+ puts '`facter --puppet` and `facter -p` are no longer supported, use `puppet facts show` instead'
159
+ end
160
+
161
+ desc 'help', 'Help for all arguments'
162
+ def help(*args)
163
+ help_string = +''
164
+ help_string << help_header(args)
165
+ help_string << add_class_options_to_help
166
+ help_string << add_commands_to_help
167
+
168
+ puts help_string
169
+ end
170
+
171
+ no_commands do
172
+ def help_header(_args)
173
+ path = File.join(File.dirname(__FILE__), '../../')
174
+
175
+ Util::FileHelper.safe_read("#{path}fixtures/facter_help_header")
176
+ end
177
+
178
+ IGNORE_OPTIONS = %w[log_level color no_color].freeze
179
+
180
+ def add_class_options_to_help
181
+ help_class_options = +''
182
+ class_options = Cli.class_options
183
+ class_options.each do |class_option|
184
+ option = class_option[1]
185
+ next if option.hide
186
+
187
+ help_class_options << build_option(option.name, option.aliases, option.description)
188
+ end
189
+
190
+ help_class_options
191
+ end
192
+
193
+ def add_commands_to_help
194
+ help_command_options = +''
195
+ Cli.commands
196
+ .select { |_k, command_class| command_class.instance_of?(Thor::Command) }
197
+ .each do |_k, command|
198
+ help_command_options << build_option(command['name'], [], command['description'])
199
+ end
200
+
201
+ help_command_options
202
+ end
203
+
204
+ def build_option(name, aliases, description)
205
+ help_option = +''
206
+ help_option << aliases.join(',').rjust(10)
207
+ help_option << ' '
208
+ help_option << "[--#{name}]".ljust(30)
209
+ help_option << " #{description}"
210
+ help_option << "\n"
211
+
212
+ help_option
213
+ end
214
+ end
215
+
168
216
  def self.exit_on_failure?
169
217
  true
170
218
  end