corl 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +14 -6
- data/README.rdoc +4 -4
- data/VERSION +1 -1
- data/corl.gemspec +3 -2
- data/lib/CORL/action/keypair.rb +56 -0
- data/lib/CORL/action/provision.rb +4 -3
- data/lib/CORL/provisioner/puppetnode.rb +104 -77
- data/lib/core/mixin/action/keypair.rb +1 -1
- data/lib/core/mixin/lookup.rb +56 -5
- data/lib/core/mod/hiera_backend.rb +37 -54
- data/lib/core/plugin/provisioner.rb +13 -14
- data/lib/core/util/puppet.rb +62 -13
- data/lib/core/util/puppet/resource_group.rb +1 -5
- data/lib/facter/custom_facts.rb +14 -1
- data/lib/puppet/indirector/corl.rb +24 -11
- data/lib/puppet/indirector/data_binding/corl.rb +1 -1
- data/lib/puppet/parser/functions/corl_include.rb +21 -10
- data/lib/puppet/parser/functions/corl_initialize.rb +10 -0
- data/lib/puppet/parser/functions/corl_resources.rb +17 -9
- data/lib/puppet/parser/functions/global_array.rb +8 -7
- data/lib/puppet/parser/functions/global_hash.rb +8 -7
- data/lib/puppet/parser/functions/global_param.rb +8 -7
- data/lib/puppet/parser/functions/interpolate.rb +28 -2
- data/lib/puppet/parser/functions/module_array.rb +16 -12
- data/lib/puppet/parser/functions/module_hash.rb +16 -12
- data/lib/puppet/parser/functions/module_options.rb +3 -1
- data/lib/puppet/parser/functions/module_param.rb +16 -12
- data/lib/puppet/parser/functions/render.rb +33 -8
- data/locales/en.yml +8 -2
- metadata +25 -24
@@ -1,63 +1,46 @@
|
|
1
|
-
begin
|
2
|
-
require 'hiera/backend'
|
3
1
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# use case might be in Puppet where a Puppet module declares
|
16
|
-
# default data using in-module data while users can override
|
17
|
-
# using JSON/YAML etc. By layering the backends and putting
|
18
|
-
# the Puppet one last you can override module author data
|
19
|
-
# easily.
|
20
|
-
#
|
21
|
-
# Backend instances are cached so if you need to connect to any
|
22
|
-
# databases then do so in your constructor, future calls to your
|
23
|
-
# backend will not create new instances
|
24
|
-
def lookup(key, default, scope, order_override, resolution_type)
|
25
|
-
@backends ||= {}
|
26
|
-
answer = nil
|
2
|
+
class Hiera
|
3
|
+
module Backend
|
4
|
+
class << self
|
5
|
+
#
|
6
|
+
# NOTE: This function is overridden so we can collect accumulated hiera
|
7
|
+
# parameters and their values on a particular provisioning run for reporting
|
8
|
+
# purposes.
|
9
|
+
#
|
10
|
+
def lookup(key, default, scope, order_override, resolution_type)
|
11
|
+
@backends ||= {}
|
12
|
+
answer = nil
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
14
|
+
Config[:backends].each do |backend|
|
15
|
+
if constants.include?("#{backend.capitalize}_backend") || constants.include?("#{backend.capitalize}_backend".to_sym)
|
16
|
+
@backends[backend] ||= Backend.const_get("#{backend.capitalize}_backend").new
|
17
|
+
new_answer = @backends[backend].lookup(key, scope, order_override, resolution_type)
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
19
|
+
if not new_answer.nil?
|
20
|
+
case resolution_type
|
21
|
+
when :array
|
22
|
+
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
23
|
+
answer ||= []
|
24
|
+
answer << new_answer
|
25
|
+
when :hash
|
26
|
+
raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
27
|
+
answer ||= {}
|
28
|
+
answer = merge_answer(new_answer,answer)
|
29
|
+
else
|
30
|
+
answer = new_answer
|
31
|
+
break
|
48
32
|
end
|
49
33
|
end
|
50
|
-
|
51
|
-
answer = resolve_answer(answer, resolution_type) unless answer.nil?
|
52
|
-
answer = parse_string(default, scope) if answer.nil? and default.is_a?(String)
|
53
|
-
|
54
|
-
answer = default if answer.nil?
|
55
|
-
|
56
|
-
CORL::Config.set_property(key, answer) # This is why we override this function!!
|
57
|
-
return answer
|
58
34
|
end
|
59
35
|
end
|
60
|
-
end
|
61
36
|
|
62
|
-
|
37
|
+
answer = resolve_answer(answer, resolution_type) unless answer.nil?
|
38
|
+
answer = parse_string(default, scope) if answer.nil? and default.is_a?(String)
|
39
|
+
answer = default if answer.nil?
|
40
|
+
|
41
|
+
CORL::Config.set_property(key, answer) # This is why we override this function!!
|
42
|
+
return answer
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
63
46
|
end
|
@@ -225,24 +225,23 @@ class Provisioner < CORL.plugin_class(:base)
|
|
225
225
|
|
226
226
|
def lookup(property, default = nil, options = {})
|
227
227
|
# Implement in providers
|
228
|
+
nil
|
228
229
|
end
|
229
|
-
|
230
|
-
#--
|
231
|
-
|
232
|
-
def import(files, options = {})
|
233
|
-
# Implement in providers
|
234
|
-
end
|
235
|
-
|
236
|
-
#---
|
237
|
-
|
238
|
-
def include(resource_name, properties = {}, options = {})
|
239
|
-
# Implement in providers
|
240
|
-
end
|
241
|
-
|
230
|
+
|
242
231
|
#---
|
243
232
|
|
244
233
|
def provision(profiles, options = {})
|
245
|
-
|
234
|
+
config = Config.ensure(options)
|
235
|
+
|
236
|
+
use_colors = Util::Console.use_colors
|
237
|
+
Util::Console.use_colors = config.get(:color, true)
|
238
|
+
|
239
|
+
success = yield(config) if block_given?
|
240
|
+
Config.save_properties(Config.get_options(:corl_log)) if success
|
241
|
+
success
|
242
|
+
|
243
|
+
ensure
|
244
|
+
Util::Console.use_colors = use_colors
|
246
245
|
end
|
247
246
|
|
248
247
|
#-----------------------------------------------------------------------------
|
data/lib/core/util/puppet.rb
CHANGED
@@ -92,6 +92,13 @@ module Puppet
|
|
92
92
|
return unless puppet_scope
|
93
93
|
|
94
94
|
info = type_info(type_name, options)
|
95
|
+
|
96
|
+
if config.get(:debug, false)
|
97
|
+
CORL.ui.info("\n", { :prefix => false })
|
98
|
+
CORL.ui_group(Util::Console.purple(info[:name])) do |ui|
|
99
|
+
ui.info("-----------------------------------------------------")
|
100
|
+
end
|
101
|
+
end
|
95
102
|
ResourceGroup.new(info, defaults).add(resources, config)
|
96
103
|
end
|
97
104
|
|
@@ -107,15 +114,19 @@ module Puppet
|
|
107
114
|
type = type_info(type, config)
|
108
115
|
end
|
109
116
|
|
117
|
+
display_name = puppet_scope.parent_module_name ? puppet_scope.parent_module_name : 'toplevel'
|
118
|
+
|
110
119
|
case type[:type]
|
111
120
|
when :type, :define
|
112
|
-
CORL.ui_group(
|
113
|
-
|
121
|
+
CORL.ui_group(Util::Console.cyan(display_name)) do |ui|
|
122
|
+
rendered_title = Util::Console.blue(title)
|
123
|
+
ui.info("Adding #{type[:name]} #{rendered_title}")
|
114
124
|
end
|
115
125
|
add_definition(type, title, properties, config)
|
116
126
|
when :class
|
117
|
-
CORL.ui_group(
|
118
|
-
|
127
|
+
CORL.ui_group(Util::Console.cyan(display_name)) do |ui|
|
128
|
+
rendered_title = Util::Console.blue(title)
|
129
|
+
ui.info("Adding class #{rendered_title}")
|
119
130
|
end
|
120
131
|
add_class(title, properties, config)
|
121
132
|
end
|
@@ -131,7 +142,7 @@ module Puppet
|
|
131
142
|
klass = puppet_scope.find_hostclass(title)
|
132
143
|
return unless klass
|
133
144
|
|
134
|
-
|
145
|
+
debug_resource(config, title, properties)
|
135
146
|
klass.ensure_in_catalog(puppet_scope, properties)
|
136
147
|
puppet_scope.catalog.add_class(title)
|
137
148
|
end
|
@@ -140,7 +151,7 @@ module Puppet
|
|
140
151
|
#---
|
141
152
|
|
142
153
|
def self.add_definition(type, title, properties, options = {})
|
143
|
-
config
|
154
|
+
config = Config.ensure(options)
|
144
155
|
|
145
156
|
puppet_scope = config.get(:puppet_scope, nil)
|
146
157
|
return unless puppet_scope
|
@@ -153,14 +164,16 @@ module Puppet
|
|
153
164
|
|
154
165
|
namevar = namevar(type[:name], title).to_sym
|
155
166
|
resource_name = properties.has_key?(namevar) ? properties[namevar] : title
|
167
|
+
properties = { :name => resource_name }.merge(properties)
|
156
168
|
|
157
|
-
|
169
|
+
properties.each do |key, value|
|
158
170
|
resource.set_parameter(key, value)
|
159
171
|
end
|
160
172
|
if type[:type] == :define
|
161
173
|
type[:resource].instantiate_resource(puppet_scope, resource)
|
162
174
|
end
|
163
|
-
|
175
|
+
|
176
|
+
debug_resource(config, title, properties)
|
164
177
|
puppet_scope.compiler.add_resource(puppet_scope, resource)
|
165
178
|
end
|
166
179
|
|
@@ -188,6 +201,8 @@ module Puppet
|
|
188
201
|
puppet_scope = config.get(:puppet_scope, nil)
|
189
202
|
return false unless puppet_scope
|
190
203
|
|
204
|
+
display_name = puppet_scope.parent_module_name ? puppet_scope.parent_module_name : 'toplevel'
|
205
|
+
|
191
206
|
if resource_name.is_a?(Array)
|
192
207
|
resource_name = resource_name.flatten
|
193
208
|
else
|
@@ -198,10 +213,23 @@ module Puppet
|
|
198
213
|
classes = Config.lookup(name, nil, config)
|
199
214
|
if classes.is_a?(Array)
|
200
215
|
classes.each do |klass|
|
216
|
+
CORL.ui_group(Util::Console.cyan(display_name)) do |ui|
|
217
|
+
ui.info("Including class #{klass}")
|
218
|
+
end
|
201
219
|
class_data[klass] = properties
|
202
220
|
end
|
203
|
-
|
204
|
-
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
if config.get(:debug, false)
|
225
|
+
CORL.ui.info("\n", { :prefix => false })
|
226
|
+
CORL.ui_group(Util::Console.cyan("#{display_name} include")) do |ui|
|
227
|
+
ui.info("-----------------------------------------------------")
|
228
|
+
|
229
|
+
dump = Util::Console.green(Util::Data.to_json(class_data, true))
|
230
|
+
|
231
|
+
ui.info(":\n#{dump}")
|
232
|
+
ui.info("\n", { :prefix => false })
|
205
233
|
end
|
206
234
|
end
|
207
235
|
|
@@ -237,7 +265,11 @@ module Puppet
|
|
237
265
|
base_names = base_names.reverse if reverse_lookup
|
238
266
|
|
239
267
|
base_names.each do |base|
|
240
|
-
|
268
|
+
search_property_name = "#{base}::#{property}"
|
269
|
+
|
270
|
+
value = puppet_scope.lookupvar("::#{search_property_name}")
|
271
|
+
Config.debug_lookup(config, search_property_name, value, "Puppet override lookup")
|
272
|
+
|
241
273
|
break unless Util::Data.undef?(value)
|
242
274
|
end
|
243
275
|
end
|
@@ -245,12 +277,16 @@ module Puppet
|
|
245
277
|
components = property.to_s.split('::')
|
246
278
|
|
247
279
|
if components.length > 1
|
248
|
-
components
|
249
|
-
|
280
|
+
components += [ 'default', components.pop ]
|
281
|
+
search_property_name = components.flatten.join('::')
|
282
|
+
|
283
|
+
value = puppet_scope.lookupvar("::#{search_property_name}")
|
284
|
+
Config.debug_lookup(config, search_property_name, value, "Puppet default lookup")
|
250
285
|
end
|
251
286
|
end
|
252
287
|
if Util::Data.undef?(value) && search_name
|
253
288
|
value = puppet_scope.lookupvar("::#{property}")
|
289
|
+
Config.debug_lookup(config, property, value, "Puppet name lookup")
|
254
290
|
end
|
255
291
|
|
256
292
|
::Puppet::Util::Log.level = log_level
|
@@ -297,6 +333,19 @@ module Puppet
|
|
297
333
|
else
|
298
334
|
'name'
|
299
335
|
end
|
336
|
+
end
|
337
|
+
|
338
|
+
#---
|
339
|
+
|
340
|
+
def self.debug_resource(config, title, properties)
|
341
|
+
if config.get(:debug, false)
|
342
|
+
CORL.ui_group(Util::Console.cyan(title.to_s)) do |ui|
|
343
|
+
dump = Util::Console.green(Util::Data.to_json(properties, true))
|
344
|
+
|
345
|
+
ui.info(":\n#{dump}")
|
346
|
+
ui.info("\n", { :prefix => false })
|
347
|
+
end
|
348
|
+
end
|
300
349
|
end
|
301
350
|
end
|
302
351
|
end
|
@@ -75,16 +75,12 @@ class ResourceGroup < Core
|
|
75
75
|
#---
|
76
76
|
|
77
77
|
def add(resources, options = {})
|
78
|
-
config = Config.ensure(options)
|
79
|
-
|
80
|
-
dbg(resources, 'before')
|
81
|
-
dbg(default, 'defaults')
|
78
|
+
config = Config.ensure(options)
|
82
79
|
resources = normalize(info[:name], resources, config)
|
83
80
|
|
84
81
|
unless Data.empty?(resources)
|
85
82
|
collection = self.resources
|
86
83
|
resources.each do |title, resource|
|
87
|
-
dbg(resource.export, "#{info[:type]} #{info[:name]}: #{title}")
|
88
84
|
Puppet.add_resource(info, title, resource.export, config)
|
89
85
|
collection[title] = resource
|
90
86
|
end
|
data/lib/facter/custom_facts.rb
CHANGED
@@ -9,7 +9,20 @@ begin
|
|
9
9
|
network = CORL.network(CORL.sha1(network_config), network_config, :default)
|
10
10
|
|
11
11
|
if network && node = network.local_node
|
12
|
-
|
12
|
+
Facter.add(:corl_provider) do
|
13
|
+
setcode do
|
14
|
+
node.plugin_provider
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
corl_facts = CORL::Util::Data.merge([ {
|
19
|
+
:corl_identity => "test",
|
20
|
+
:corl_stage => "maintain",
|
21
|
+
:corl_type => "core",
|
22
|
+
:corl_environment => "development"
|
23
|
+
}, node[:facts] ])
|
24
|
+
|
25
|
+
CORL::Util::Data.hash(corl_facts).each do |name, value|
|
13
26
|
Facter.add(name) do
|
14
27
|
confine :kernel => :linux # TODO: Extend this to work with more systems
|
15
28
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
|
2
2
|
require 'puppet/indirector/terminus'
|
3
3
|
|
4
|
-
class Puppet::Indirector::
|
4
|
+
class Puppet::Indirector::Corl < Puppet::Indirector::Terminus
|
5
5
|
|
6
6
|
def initialize(*args)
|
7
|
-
unless CORL::Config.
|
7
|
+
unless CORL::Config.config_initialized?
|
8
8
|
raise "CORL terminus not supported without the CORL library"
|
9
9
|
end
|
10
10
|
super
|
@@ -13,15 +13,28 @@ class Puppet::Indirector::CORL < Puppet::Indirector::Terminus
|
|
13
13
|
#---
|
14
14
|
|
15
15
|
def find(request)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
:
|
23
|
-
:
|
24
|
-
|
16
|
+
puppet_scope = request.options[:variables]
|
17
|
+
module_name = nil
|
18
|
+
module_name = puppet_scope.source.module_name if puppet_scope.source
|
19
|
+
contexts = [ :param, :data_binding, request.key ]
|
20
|
+
|
21
|
+
default_options = {
|
22
|
+
:provisioner => :puppetnode,
|
23
|
+
:hiera_scope => puppet_scope,
|
24
|
+
:puppet_scope => puppet_scope,
|
25
|
+
:search => 'core::default',
|
26
|
+
:search_name => false,
|
27
|
+
:force => true,
|
28
|
+
:merge => true,
|
29
|
+
:undefined_value => :undef
|
30
|
+
}
|
31
|
+
|
32
|
+
if module_name
|
33
|
+
config = CORL::Config.init({}, contexts, module_name, default_options)
|
34
|
+
else
|
35
|
+
config = CORL::Config.init_flat({}, contexts, default_options)
|
36
|
+
end
|
37
|
+
|
25
38
|
value = CORL::Config.lookup(request.key, nil, config)
|
26
39
|
end
|
27
40
|
end
|
@@ -23,17 +23,28 @@ If no value is found in the defined sources, it does not include any classes.
|
|
23
23
|
raise(Puppet::ParseError, "corl_include(): Define at least the variable name " +
|
24
24
|
"given (#{args.size} for 1)") if args.size < 1
|
25
25
|
|
26
|
-
var_name
|
27
|
-
parameters
|
28
|
-
options
|
26
|
+
var_name = args[0]
|
27
|
+
parameters = ( args.size > 1 ? args[1] : {} )
|
28
|
+
options = ( args.size > 2 ? args[2] : {} )
|
29
|
+
|
30
|
+
module_name = parent_module_name
|
31
|
+
contexts = [ :include, var_name ]
|
32
|
+
|
33
|
+
default_options = {
|
34
|
+
:hiera_scope => self,
|
35
|
+
:puppet_scope => self,
|
36
|
+
:search => 'core::default',
|
37
|
+
:force => true,
|
38
|
+
:merge => true,
|
39
|
+
:undefined_value => :undef
|
40
|
+
}
|
41
|
+
|
42
|
+
if module_name
|
43
|
+
config = CORL::Config.init(options, contexts, module_name, default_options)
|
44
|
+
else
|
45
|
+
config = CORL::Config.init_flat(options, contexts, default_options)
|
46
|
+
end
|
29
47
|
|
30
|
-
config = CORL::Config.init_flat(options, [ :include ], {
|
31
|
-
:hiera_scope => self,
|
32
|
-
:puppet_scope => self,
|
33
|
-
:search => 'core::default',
|
34
|
-
:force => true,
|
35
|
-
:merge => true
|
36
|
-
})
|
37
48
|
CORL::Util::Puppet.include(var_name, parameters, config)
|
38
49
|
end
|
39
50
|
end
|
@@ -9,7 +9,17 @@ This function initializes the CORL plugin system through Puppet.
|
|
9
9
|
EOS
|
10
10
|
) do |args|
|
11
11
|
CORL.run do
|
12
|
+
# Register all Nucleon plugins defined by Puppet modules.
|
12
13
|
CORL::Util::Puppet.register_plugins({ :puppet_scope => self })
|
14
|
+
|
15
|
+
# Make sure defaults are evaluated first!
|
16
|
+
if compiler.node.classes.is_a?(Hash)
|
17
|
+
compiler.node.classes.each do |name, parameters|
|
18
|
+
if name.match(/::default:?/)
|
19
|
+
compiler.evaluate_classes({ name => parameters }, self, false)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
13
23
|
end
|
14
24
|
end
|
15
25
|
end
|