Class: OS::Puppet::Fencing::FacterAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/fencing/facter_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(puppet_nodes_dir = '/var/lib/puppet/yaml/facts') ⇒ FacterAdapter

Returns a new instance of FacterAdapter.



10
11
12
# File 'lib/fencing/facter_adapter.rb', line 10

def initialize(puppet_nodes_dir = '/var/lib/puppet/yaml/facts')
	@node_dir = puppet_nodes_dir
end

Instance Method Details

#find_node_def(node_name) ⇒ Object



23
24
25
26
27
28
# File 'lib/fencing/facter_adapter.rb', line 23

def find_node_def(node_name)
	Dir.foreach(@node_dir) do | file |
		return File.join(@node_dir, file) if file.start_with?(node_name)
	end
	raise "Cannot find node #{node_name}"
end

#lookup(node_name, fact_name) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/fencing/facter_adapter.rb', line 14

def lookup(node_name, fact_name)
node_def = find_node_def(node_name)
node = YAML.load_file(node_def)
fact_list = node.to_data_hash
fact_result = fact_list['values'][fact_name]
raise "Fact #{fact_name} not found on node #{node_name}" if fact_result == nil
fact_result
end