facter 4.0.51 → 4.0.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docs/generate_cli.rb +7 -0
  3. data/lib/facter.rb +57 -44
  4. data/lib/facter/custom_facts/core/aggregate.rb +9 -0
  5. data/lib/facter/custom_facts/core/resolvable.rb +11 -0
  6. data/lib/facter/custom_facts/util/resolution.rb +2 -0
  7. data/lib/facter/facts/amzn/lsbdistcodename.rb +16 -0
  8. data/lib/facter/facts/amzn/lsbdistdescription.rb +16 -0
  9. data/lib/facter/facts/amzn/lsbdistid.rb +16 -0
  10. data/lib/facter/facts/amzn/os/distro/codename.rb +24 -0
  11. data/lib/facter/facts/amzn/os/distro/description.rb +21 -0
  12. data/lib/facter/facts/amzn/os/distro/id.rb +21 -0
  13. data/lib/facter/facts/amzn/os/distro/release.rb +32 -0
  14. data/lib/facter/facts/linux/az_metadata.rb +27 -0
  15. data/lib/facter/facts/linux/cloud/provider.rb +17 -0
  16. data/lib/facter/facts/linux/dhcp_servers.rb +2 -2
  17. data/lib/facter/facts/linux/interfaces.rb +1 -1
  18. data/lib/facter/facts/linux/ipaddress6_interfaces.rb +1 -1
  19. data/lib/facter/facts/linux/ipaddress_interfaces.rb +1 -1
  20. data/lib/facter/facts/linux/macaddress_interfaces.rb +1 -1
  21. data/lib/facter/facts/linux/mtu_interfaces.rb +1 -1
  22. data/lib/facter/facts/linux/netmask6_interfaces.rb +1 -1
  23. data/lib/facter/facts/linux/netmask_interfaces.rb +1 -1
  24. data/lib/facter/facts/linux/network6_interfaces.rb +1 -1
  25. data/lib/facter/facts/linux/network_interfaces.rb +1 -1
  26. data/lib/facter/facts/linux/networking/dhcp.rb +1 -1
  27. data/lib/facter/facts/linux/networking/domain.rb +1 -1
  28. data/lib/facter/facts/linux/networking/fqdn.rb +1 -1
  29. data/lib/facter/facts/linux/networking/hostname.rb +1 -1
  30. data/lib/facter/facts/linux/networking/interfaces.rb +1 -1
  31. data/lib/facter/facts/linux/networking/ip.rb +1 -1
  32. data/lib/facter/facts/linux/networking/ip6.rb +1 -1
  33. data/lib/facter/facts/linux/networking/mac.rb +1 -1
  34. data/lib/facter/facts/linux/networking/mtu.rb +1 -1
  35. data/lib/facter/facts/linux/networking/netmask.rb +1 -1
  36. data/lib/facter/facts/linux/networking/netmask6.rb +1 -1
  37. data/lib/facter/facts/linux/networking/network.rb +1 -1
  38. data/lib/facter/facts/linux/networking/network6.rb +1 -1
  39. data/lib/facter/facts/linux/networking/primary.rb +1 -1
  40. data/lib/facter/facts/linux/networking/scope6.rb +1 -1
  41. data/lib/facter/facts/linux/scope6_interfaces.rb +1 -1
  42. data/lib/facter/facts/rhel/lsbdistcodename.rb +16 -0
  43. data/lib/facter/facts/rhel/lsbdistdescription.rb +16 -0
  44. data/lib/facter/facts/rhel/lsbdistid.rb +16 -0
  45. data/lib/facter/facts/rhel/os/distro/codename.rb +2 -4
  46. data/lib/facter/facts/rhel/os/distro/description.rb +2 -4
  47. data/lib/facter/facts/rhel/os/distro/id.rb +2 -4
  48. data/lib/facter/facts/rhel/os/distro/release.rb +13 -12
  49. data/lib/facter/facts/sles/lsbdistcodename.rb +16 -0
  50. data/lib/facter/facts/sles/lsbdistdescription.rb +16 -0
  51. data/lib/facter/facts/sles/lsbdistid.rb +16 -0
  52. data/lib/facter/facts/sles/os/distro/codename.rb +3 -4
  53. data/lib/facter/facts/sles/os/distro/description.rb +2 -5
  54. data/lib/facter/facts/sles/os/distro/id.rb +6 -5
  55. data/lib/facter/facts/sles/os/distro/release.rb +17 -12
  56. data/lib/facter/facts/ubuntu/lsbdistrelease.rb +2 -2
  57. data/lib/facter/facts/windows/az_metadata.rb +27 -0
  58. data/lib/facter/facts/windows/cloud/provider.rb +17 -0
  59. data/lib/facter/framework/cli/cli.rb +5 -5
  60. data/lib/facter/framework/config/config_reader.rb +2 -0
  61. data/lib/facter/framework/config/fact_groups.rb +25 -2
  62. data/lib/facter/framework/core/cache_manager.rb +5 -1
  63. data/lib/facter/framework/core/fact_filter.rb +3 -3
  64. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +0 -1
  65. data/lib/facter/framework/core/fact_manager.rb +5 -3
  66. data/lib/facter/framework/core/options.rb +1 -2
  67. data/lib/facter/framework/core/options/option_store.rb +1 -3
  68. data/lib/facter/framework/parsers/query_parser.rb +13 -6
  69. data/lib/facter/resolvers/az.rb +39 -0
  70. data/lib/facter/resolvers/linux/hostname.rb +115 -0
  71. data/lib/facter/resolvers/linux/networking.rb +106 -0
  72. data/lib/facter/resolvers/redhat_release.rb +28 -12
  73. data/lib/facter/resolvers/solaris/ffi/functions.rb +1 -1
  74. data/lib/facter/templates/man.erb +8 -0
  75. data/lib/facter/util/linux/dhcp.rb +86 -0
  76. data/lib/facter/util/linux/routing_table.rb +60 -0
  77. data/lib/facter/util/linux/socket_parser.rb +114 -0
  78. data/lib/facter/util/resolvers/ffi/hostname.rb +70 -0
  79. data/lib/facter/version.rb +1 -1
  80. metadata +29 -7
  81. data/lib/facter/facts/linux/cloud.rb +0 -15
  82. data/lib/facter/resolvers/cloud.rb +0 -39
  83. data/lib/facter/resolvers/networking_linux.rb +0 -296
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db03b26f8336c77d444ced6b4d073a927b529e6272ef0ba65eafc69af0e66060
4
- data.tar.gz: a07adb46289f6315764d40a3f21c967de22c187fe9070177959a02c82bd1da6a
3
+ metadata.gz: 778d4d972d3e950f98d4fd8dbd4100e7b2a0c168369949b234d7088ddeba539f
4
+ data.tar.gz: 50303cfdfcf434c38d3d9539c35362f190dd84b82a8f85227d804a876b5a4ce3
5
5
  SHA512:
6
- metadata.gz: 1cf1b38ac9c4e67b93e73474afa8f134132f0afd90d9cb5e45a4ced0c2cca3874ca581d1e6dd59ea154eb57e7ffc423a2a0c9aa1d36bdd04501648499dc30c3f
7
- data.tar.gz: 0567b4d6940087e0c0d273392b103bd507fe6f15adbcaa826d783db1eda0c512582da10031400a0360b76fa397150101e925b4f814b394bdc478b615a1d1c1d0
6
+ metadata.gz: 38f84ef3e3699e3bed3b348ae07562f9423121011659ef9ebac4395a157eb06bd110a64e7481f82331e8f65e908936df826c630f57f879ba79686bee0878ac5a
7
+ data.tar.gz: bf2a8b2d1d1e23a0d0ba22f21d2b8e228bc238f2eededc1ab4474dff9e0d5f13094ec2c5990f24916a563b28fd75bfa2d745bd728d2f6cda9b31283116d9df34
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'facter/framework/cli/cli_launcher'
4
+
5
+ cli = Facter::Cli.new([])
6
+
7
+ puts cli.man
data/lib/facter.rb CHANGED
@@ -27,23 +27,32 @@ module Facter
27
27
  require 'facter/framework/cli/cli_launcher'
28
28
 
29
29
  args = args_as_string.split(' ')
30
-
31
30
  Facter::OptionsValidator.validate(args)
32
31
  processed_arguments = CliLauncher.prepare_arguments(args, nil)
33
-
34
32
  cli = Facter::Cli.new([], processed_arguments)
35
-
36
- if cli.args.include?(:version)
37
- cli.invoke(:version, [])
38
- elsif cli.args.include?('--list-cache-groups')
39
- cli.invoke(:list_cache_groups, [])
40
- elsif cli.args.include?('--list-block-groups')
41
- cli.invoke(:list_block_groups, [])
42
- else
43
- cli.invoke(:arg_parser)
33
+ cli_options = cli.options.dup
34
+
35
+ # config file options
36
+ config_file = cli_options.delete(:config)
37
+ if config_file
38
+ Facter::OptionStore.set(:config, config_file)
39
+ Facter::ConfigFileOptions.init(config_file)
40
+ Facter::Options.store(ConfigFileOptions.get)
44
41
  end
42
+
43
+ # user provided options
44
+ cli_options[:show_legacy] ||= false
45
+ Facter::Options.store(cli_options)
46
+
47
+ queried_facts(cli.args)
45
48
  end
46
49
 
50
+ # Method used by cli to set puppet paths
51
+ # in order to retrieve puppet custom and external facts
52
+ #
53
+ # @return nil
54
+ #
55
+ # @api private
47
56
  def puppet_facts
48
57
  require 'puppet'
49
58
 
@@ -110,10 +119,10 @@ module Facter
110
119
  nil
111
120
  end
112
121
 
113
- # Gets the value for a core fact, external or custom facts are
114
- # not returned with this call. Returns `nil` if no such fact exists.
122
+ # Retrieves the value of a core fact. External or custom facts are
123
+ # not returned with this call. Returns `nil` if no such fact exists.
115
124
  #
116
- # @return [FactCollection] hash with fact names and values
125
+ # @return [FactCollection] A hash with fact names and values
117
126
  #
118
127
  # @api private
119
128
  def core_value(user_query)
@@ -198,14 +207,29 @@ module Facter
198
207
  Facter::Options[:debug] = debug_bool
199
208
  end
200
209
 
210
+ # Enable sequential resolving of facts
211
+ #
212
+ # @return [bool]
213
+ #
214
+ # @api public
201
215
  def enable_sequential
202
216
  Facter::Options[:sequential] = true
203
217
  end
204
218
 
219
+ # Disable sequential resolving of facts
220
+ #
221
+ # @return [bool]
222
+ #
223
+ # @api public
205
224
  def disable_sequential
206
225
  Facter::Options[:sequential] = false
207
226
  end
208
227
 
228
+ # Check if facts are resolved sequentially or not
229
+ #
230
+ # @return [bool]
231
+ #
232
+ # @api public
209
233
  def sequential?
210
234
  Facter::Options[:sequential]
211
235
  end
@@ -343,10 +367,10 @@ module Facter
343
367
  Options.custom_dir
344
368
  end
345
369
 
346
- # Gets a hash mapping fact names to their values
347
- # The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).
370
+ # Retrieves a fact's value. Returns `nil` if no such fact exists.
348
371
  #
349
- # @return [FactCollection] hash with fact names and values
372
+ # @param user_query [String] the fact name
373
+ # @return [String] the value of the fact, or nil if no fact is found
350
374
  #
351
375
  # @api public
352
376
  def to_hash
@@ -390,29 +414,6 @@ module Facter
390
414
  @already_searched[user_query]&.value
391
415
  end
392
416
 
393
- # Gets the values for multiple facts.
394
- #
395
- # @param options [Hash] parameters for the fact - attributes
396
- # of {Facter::Util::Fact} and {Facter::Util::Resolution} can be
397
- # supplied here
398
- # @param user_queries [Array] the fact names
399
- #
400
- # @return [FactCollection] hash with fact names and values
401
- #
402
- # @api public
403
- def values(options, user_queries)
404
- init_cli_options(options, user_queries)
405
- log_blocked_facts
406
- resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
407
- resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
408
-
409
- if user_queries.count.zero?
410
- Facter::FactCollection.new.build_fact_collection!(resolved_facts)
411
- else
412
- FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
413
- end
414
- end
415
-
416
417
  # Returns Facter version
417
418
  #
418
419
  # @return [String] Current version
@@ -428,7 +429,7 @@ module Facter
428
429
  #
429
430
  # @api private
430
431
  def to_user_output(cli_options, *args)
431
- init_cli_options(cli_options, args)
432
+ init_cli_options(cli_options)
432
433
  logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
433
434
  logger.debug("Facter version: #{Facter::VERSION}")
434
435
  log_blocked_facts
@@ -454,7 +455,7 @@ module Facter
454
455
  nil
455
456
  end
456
457
 
457
- # Returns a list with the names of all solved facts
458
+ # Returns a list with the names of all resolved facts
458
459
  # @return [Array] the list with all the fact names
459
460
  #
460
461
  # @api public
@@ -490,6 +491,18 @@ module Facter
490
491
 
491
492
  private
492
493
 
494
+ def queried_facts(user_query)
495
+ log_blocked_facts
496
+ resolved_facts = Facter::FactManager.instance.resolve_facts(user_query)
497
+ resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
498
+
499
+ if user_query.count.zero?
500
+ Facter::FactCollection.new.build_fact_collection!(resolved_facts)
501
+ else
502
+ FormatterHelper.retrieve_facts_to_display_for_user_query(user_query, resolved_facts)
503
+ end
504
+ end
505
+
493
506
  def resolve_facts_for_user_query(user_query)
494
507
  resolved_facts = Facter::FactManager.instance.resolve_facts(user_query)
495
508
  user_querie = resolved_facts.uniq(&:user_query).map(&:user_query).first
@@ -516,9 +529,9 @@ module Facter
516
529
  @logger ||= Log.new(self)
517
530
  end
518
531
 
519
- def init_cli_options(options, args)
532
+ def init_cli_options(options)
520
533
  options = options.map { |(k, v)| [k.to_sym, v] }.to_h
521
- Facter::Options.init_from_cli(options, args)
534
+ Facter::Options.init_from_cli(options)
522
535
  end
523
536
 
524
537
  def add_fact_to_searched_facts(user_query, value)
@@ -53,6 +53,15 @@ module Facter
53
53
  # @api private
54
54
  attr_reader :fact
55
55
 
56
+ # Create a new aggregated resolution mechanism.
57
+ #
58
+ # @param name [String] The name of the resolution.
59
+ # @param fact [Facter::Fact] The fact to which this
60
+ # resolution will be added.
61
+ #
62
+ # @return [Facter::Util::Resolution] The created resolution
63
+ #
64
+ # @api private
56
65
  def initialize(name, fact)
57
66
  @name = name
58
67
  @fact = fact
@@ -59,6 +59,17 @@ module LegacyFacter
59
59
  @on_flush_block&.call
60
60
  end
61
61
 
62
+ # Resolves the fact's value or loggs an error if the value
63
+ # couldn't be resolved.
64
+ #
65
+ # @raise Facter::ResolveCustomFactError if an error was raised
66
+ # (except Timeout::Error or Narmalization::NarmalizationError
67
+ # in which case an error message is logged and the execution
68
+ # isn't suspended).
69
+ #
70
+ # @return value (hash, string, int, array, etc) or nil
71
+ #
72
+ # @api private
62
73
  def value
63
74
  result = nil
64
75
 
@@ -56,6 +56,8 @@ module Facter
56
56
  # Create a new resolution mechanism.
57
57
  #
58
58
  # @param name [String] The name of the resolution.
59
+ # @param fact [Facter::Fact] The fact to which this
60
+ # resolution will be added.
59
61
  #
60
62
  # @return [Facter::Util::Resolution] The created resolution
61
63
  #
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Amzn
5
+ class Lsbdistcodename
6
+ FACT_NAME = 'lsbdistcodename'
7
+ TYPE = :legacy
8
+
9
+ def call_the_resolver
10
+ fact_value = Facter::Resolvers::LsbRelease.resolve(:codename)
11
+
12
+ Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Amzn
5
+ class Lsbdistdescription
6
+ FACT_NAME = 'lsbdistdescription'
7
+ TYPE = :legacy
8
+
9
+ def call_the_resolver
10
+ fact_value = Facter::Resolvers::LsbRelease.resolve(:description)
11
+
12
+ Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Amzn
5
+ class Lsbdistid
6
+ FACT_NAME = 'lsbdistid'
7
+ TYPE = :legacy
8
+
9
+ def call_the_resolver
10
+ fact_value = Facter::Resolvers::LsbRelease.resolve(:distributor_id)
11
+
12
+ Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Amzn
5
+ module Os
6
+ module Distro
7
+ class Codename
8
+ FACT_NAME = 'os.distro.codename'
9
+
10
+ def call_the_resolver
11
+ fact_value = Facter::Resolvers::SpecificReleaseFile.resolve(
12
+ :release, release_file: '/etc/system-release'
13
+ ).match(/.*release.*(\(.*\)).*/)
14
+
15
+ fact_value = fact_value[1].gsub(/\(|\)/, '') if fact_value
16
+ fact_value ||= 'n/a'
17
+
18
+ Facter::ResolvedFact.new(FACT_NAME, fact_value)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Amzn
5
+ module Os
6
+ module Distro
7
+ class Description
8
+ FACT_NAME = 'os.distro.description'
9
+
10
+ def call_the_resolver
11
+ fact_value = Facter::Resolvers::SpecificReleaseFile.resolve(
12
+ :release, release_file: '/etc/system-release'
13
+ )
14
+
15
+ Facter::ResolvedFact.new(FACT_NAME, fact_value)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Amzn
5
+ module Os
6
+ module Distro
7
+ class Id
8
+ FACT_NAME = 'os.distro.id'
9
+
10
+ def call_the_resolver
11
+ fact_value = Facter::Resolvers::SpecificReleaseFile.resolve(
12
+ :release, release_file: '/etc/system-release'
13
+ ).split('release')[0].split.reject { |el| el.casecmp('linux').zero? }.join
14
+
15
+ Facter::ResolvedFact.new(FACT_NAME, fact_value)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Amzn
5
+ module Os
6
+ module Distro
7
+ class Release
8
+ FACT_NAME = 'os.distro.release'
9
+ ALIASES = %w[lsbdistrelease lsbmajdistrelease lsbminordistrelease].freeze
10
+
11
+ def call_the_resolver
12
+ version = determine_release_version
13
+
14
+ return Facter::ResolvedFact.new(FACT_NAME, nil) unless version
15
+
16
+ [Facter::ResolvedFact.new(FACT_NAME, version),
17
+ Facter::ResolvedFact.new(ALIASES[0], version['full'], :legacy),
18
+ Facter::ResolvedFact.new(ALIASES[1], version['major'], :legacy),
19
+ Facter::ResolvedFact.new(ALIASES[2], version['minor'], :legacy)]
20
+ end
21
+
22
+ def determine_release_version
23
+ version = Facter::Resolvers::ReleaseFromFirstLine.resolve(:release, release_file: '/etc/system-release')
24
+ version ||= Facter::Resolvers::OsRelease.resolve(:version_id)
25
+
26
+ Facter::Util::Facts.release_hash_from_string(version)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Linux
5
+ class AzMetadata
6
+ FACT_NAME = 'az_metadata'
7
+
8
+ def initialize
9
+ @virtual = Facter::Util::Facts::VirtualDetector.new
10
+ end
11
+
12
+ def call_the_resolver
13
+ return Facter::ResolvedFact.new(FACT_NAME, nil) unless azure_hypervisor?
14
+
15
+ fact_value = Facter::Resolvers::Az.resolve(:metadata)
16
+
17
+ Facter::ResolvedFact.new(FACT_NAME, fact_value&.empty? ? nil : fact_value)
18
+ end
19
+
20
+ private
21
+
22
+ def azure_hypervisor?
23
+ @virtual.platform == 'hyperv'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facts
4
+ module Linux
5
+ module Cloud
6
+ class Provider
7
+ FACT_NAME = 'cloud.provider'
8
+
9
+ def call_the_resolver
10
+ az_metadata = Facter::Resolvers::Az.resolve(:metadata)
11
+
12
+ Facter::ResolvedFact.new(FACT_NAME, az_metadata&.empty? ? nil : 'azure')
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end