Class: HieraSimulator::FactSource::PuppetDB

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera-simulator/fact_source/puppetdb.rb

Overview

Retrieve facts from PuppetDB. This object is a connection to a PuppetDB instance.

Instance Method Summary collapse

Constructor Details

#initialize(config, override = {}) ⇒ PuppetDB

Constructor

Parameters:

Raises:



10
11
12
13
14
15
16
17
# File 'lib/hiera-simulator/fact_source/puppetdb.rb', line 10

def initialize(config, override = {})
  @puppetdb_url = override.fetch(:puppetdb_url, config.get('puppetdb_url', nil))
  raise HieraSimulator::FactSourceError, 'No PuppetDB URL was found in hiera-simulator configuration' if @puppetdb_url.nil?
  @puppetdb_api_version = override.fetch(:puppetdb_api_version, config.get('puppetdb_api_version', 3))
  @httparty_timeout = override.fetch(:timeout, config.get('timeout', 10))
  @mock_puppetdb = override.fetch(:mock_puppetdb, config.get('mock_puppetdb', nil))
  @stringify_facts = determine_stringify_facts(override, config)
end

Instance Method Details

#facts(node) ⇒ Hash

Get facts for a node

Parameters:

  • node (String)

    Node FQDN as it should exist in PuppetDB

Returns:

  • (Hash)

    Facts from the node in question

Raises:



22
23
24
25
26
27
# File 'lib/hiera-simulator/fact_source/puppetdb.rb', line 22

def facts(node)
  return facts_v3(node) if @puppetdb_api_version == 3
  return facts_v4(node) if @puppetdb_api_version == 4
  message = "HieraSimulator does not know how to handle PuppetDB API version #{@puppetdb_api_version}"
  raise HieraSimulator::FactSourceError, message
end