1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<%
Puppet::Parser::Functions.autoloader.loadall
sched_home_dir = scope.lookupvar('buildsystem::var::scheduler::homedir')
conf = scope.lookupvar('buildsystem::var::youri::youri_conf')
conf_default = scope.lookupvar('buildsystem::var::youri::youri_conf_default')
distros = scope.lookupvar('buildsystem::var::distros::distros')
def line(text, indent)
res = ''
i = 0
while i < indent
res += ' '
i += 1
end
res += text + "\n"
end
def array_text(array, indent)
res = ''
array.each{|a|
res += line('- ' + a, indent)
}
return res
end
def hash_text(hash, indent)
res = ''
curindent = indent
hash.keys.sort.each{|key|
if hash[key].instance_of? Hash
res += line(key + ':', indent)
res += hash_text(hash[key], indent + 4)
elsif hash[key].instance_of? Array
res += line(key + ':', indent)
res += array_text(hash[key], indent + 4)
elsif hash[key].instance_of? String
res += line(key + ': ' + hash[key], indent)
end
}
return res
end
def class_hash(conf, conf_default)
res = {}
res['class'] = get_conf(conf, ['class']) == nil ?
conf_default['class'] : conf['class']
res['options'] = get_conf(conf_default, ['options']) == nil ? {} :
conf_default['options'].dup
if get_conf(conf, ['options']) != nil
res['options'].merge!(conf['options'])
end
return res
end
def get_conf(conf, path)
res = conf
path.each{|p|
if res == nil
return nil
end
res = res[p]
}
return res
end
def get_distros_conf(distros, conf_name, path)
res = {}
distros.keys.each{|distro|
t = get_conf(distros[distro], [ 'youri', conf_name ] + path)
if t != nil
res[distro] = t.dup
end
}
return res
end
def get_definitions(def_name, conf_name, conf, conf_default, distros)
res = {}
res[def_name] = {}
def_list = conf_default[conf_name][def_name].keys
def_list += get_conf(conf, [ conf_name, def_name ]) != nil ? \
conf[conf_name][def_name].keys : []
def_list.uniq.each{|d|
res[def_name][d] = class_hash(
get_conf(conf, [ conf_name, def_name, d ]),
get_conf(conf_default, [ conf_name, def_name, d ])
)
res[def_name][d]['options'].merge!(get_distros_conf(distros,
conf_name, [ def_name, d ]))
}
return res
end
%>
home: <%= @sched_home_dir %>
<%-
repository = {
'repository' => class_hash(get_conf(conf[conf_name],
['repository']),
conf_default[conf_name]['repository']),
}
distros.keys.each{|distro|
repository['repository']['options'][distro] = {
'arch' => distros[distro]['arch'].join(' '),
}
}
-%>
# repository declaration
<%= hash_text(@repository, 0) %>
<%-
targets = {
'targets' => get_distros_conf(distros, conf_name, [ 'targets' ]),
}
-%>
# targets definition
<%= hash_text(@targets, 0) %>
<%-
checks = get_definitions('checks', conf_name, conf, conf_default, distros)
-%>
# checks definition
<%= hash_text(@checks, 0) -%>
<%-
actions = get_definitions('actions', conf_name, conf, conf_default, distros)
-%>
# actions definitions
<%= hash_text(@actions, 0) -%>
<%-
posts = get_definitions('posts', conf_name, conf, conf_default, distros)
-%>
# posts definitions
<%= hash_text(@posts, 0) -%>
# vim:ft=yaml:et:sw=4
|