Class: HieraSimulator::Facts
- Inherits:
-
Object
- Object
- HieraSimulator::Facts
- Defined in:
- lib/hiera-simulator/facts.rb
Overview
Gather facts from the specified backend(s)
Class Method Summary collapse
-
.facts(config, node, stringify_facts = nil) ⇒ Object
Constructor.
- .format_errors(error_array) ⇒ Object
Class Method Details
.facts(config, node, stringify_facts = nil) ⇒ Object
Constructor
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hiera-simulator/facts.rb', line 6 def self.facts(config, node, stringify_facts = nil) override = {} override[:stringify_facts] = stringify_facts unless stringify_facts.nil? errors = [] backends = config.get(:backends, %w(FileSystem PuppetDB)) backends = ['FactFile'] unless config.get('fact_file', nil).nil? backends.each do |backend| begin obj = Module.const_get("HieraSimulator::FactSource::#{backend}").new(config, override) return obj.facts(node) rescue HieraSimulator::FactSourceError, HieraSimulator::FactLookupError => exc errors << { exception: exc, backend: backend } next end end raise "Unable to retrieve facts for #{node}:\n#{format_errors(errors)}" end |
.format_errors(error_array) ⇒ Object
24 25 26 |
# File 'lib/hiera-simulator/facts.rb', line 24 def self.format_errors(error_array) error_array.map { |x| "- #{x[:backend]}: #{x[:exception]}" }.join("\n") end |