Class: Hieracles::Node
Instance Attribute Summary collapse
Instance Method Summary
collapse
#parse
Methods included from Utils
#deep_merge!, #deep_sort, #max_key_length, #sym_keys, #to_deep_hash, #to_shallow_hash
Constructor Details
#initialize(fqdn, options) ⇒ Node
Returns a new instance of Node.
12
13
14
15
16
17
18
19
20
|
# File 'lib/hieracles/node.rb', line 12
def initialize(fqdn, options)
Config.load(options)
@hiera = Hieracles::Hiera.new
@hiera_params = { fqdn: fqdn }.
merge(get_hiera_params(fqdn)).
merge(Config.scope).
merge(Config.)
@fqdn = fqdn
end
|
Instance Attribute Details
#hiera ⇒ Object
Returns the value of attribute hiera.
10
11
12
|
# File 'lib/hieracles/node.rb', line 10
def hiera
@hiera
end
|
#hiera_params ⇒ Object
Returns the value of attribute hiera_params.
10
11
12
|
# File 'lib/hieracles/node.rb', line 10
def hiera_params
@hiera_params
end
|
Instance Method Details
#add_modules(line, modules) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/hieracles/node.rb', line 106
def add_modules(line, modules)
if /^\s*include\s*([-_:a-zA-Z0-9]*)\s*/.match(line)
mod = $1
mainmod = mod[/^[^:]*/]
if Dir.exists? modulepath(mainmod)
modules[mod] = File.join(Config.modulepath, mainmod)
else
modules[mod] = nil
end
end
modules
end
|
#classfiles ⇒ Object
96
97
98
99
100
|
# File 'lib/hieracles/node.rb', line 96
def classfiles
@hiera_params[:classes].map do |cl|
format(Config.path('classpath'), cl)
end
end
|
#files(without_common = true) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/hieracles/node.rb', line 31
def files(without_common = true)
@__files ||= @hiera.hierarchy.reduce([]) do |a, f|
file = parse("#{f}.yaml", @hiera_params, Config.interactive)
if file &&
File.exist?(File.join(@hiera.datapath, file)) &&
(!without_common ||
!file[/common/])
a << File.join(@hiera.datadir, file)
end
a
end
end
|
#get_hiera_params(fqdn) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/hieracles/node.rb', line 22
def get_hiera_params(fqdn)
if File.exist?(File.join(Config.path('encpath'), "#{fqdn}.yaml"))
load = YAML.load_file(File.join(Config.path('encpath'), "#{fqdn}.yaml"))
sym_keys(load['parameters']).merge({ classes: load['classes']})
else
raise "Node not found"
end
end
|
#info ⇒ Object
92
93
94
|
# File 'lib/hieracles/node.rb', line 92
def info
@hiera_params
end
|
#modulepath(path) ⇒ Object
102
103
104
|
# File 'lib/hieracles/node.rb', line 102
def modulepath(path)
File.join(Config.path('modulepath'), path)
end
|
#modules ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/hieracles/node.rb', line 76
def modules
modules = {}
classfiles.each do |c|
if File.exist?(c)
f = File.open(c, "r")
f.each_line do |line|
modules = add_modules(line, modules)
end
f.close
else
raise "Class file #{c} not found."
end
end
modules
end
|
#params(without_common = true) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/hieracles/node.rb', line 48
def params(without_common = true)
params = {}
files(without_common).each do |f|
data = YAML.load_file(File.join(Config.basepath, f))
if data
s = to_shallow_hash(data)
s.each do |k,v|
params[k] ||= []
params[k] << { value: v, file: f}
end
end
end
params.sort
end
|
#params_tree(without_common = true) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/hieracles/node.rb', line 64
def params_tree(without_common = true)
params = {}
paths(without_common).each do |f|
data = YAML.load_file(f)
if data
deep_merge!(params, data)
end
end
deep_sort(params)
end
|
#paths(without_common = true) ⇒ Object
44
45
46
|
# File 'lib/hieracles/node.rb', line 44
def paths(without_common = true)
files(without_common).map { |p| File.join(Config.basepath, p) }
end
|