corl 0.4.0

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.
Files changed (132) hide show
  1. data/.document +5 -0
  2. data/.gitmodules +4 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +123 -0
  5. data/LICENSE.txt +674 -0
  6. data/README.rdoc +27 -0
  7. data/Rakefile +78 -0
  8. data/VERSION +1 -0
  9. data/bin/corl +55 -0
  10. data/corl.gemspec +228 -0
  11. data/lib/corl/action/add.rb +69 -0
  12. data/lib/corl/action/bootstrap.rb +83 -0
  13. data/lib/corl/action/clone.rb +40 -0
  14. data/lib/corl/action/create.rb +55 -0
  15. data/lib/corl/action/exec.rb +41 -0
  16. data/lib/corl/action/extract.rb +49 -0
  17. data/lib/corl/action/image.rb +30 -0
  18. data/lib/corl/action/images.rb +55 -0
  19. data/lib/corl/action/lookup.rb +35 -0
  20. data/lib/corl/action/machines.rb +51 -0
  21. data/lib/corl/action/provision.rb +37 -0
  22. data/lib/corl/action/remove.rb +51 -0
  23. data/lib/corl/action/save.rb +53 -0
  24. data/lib/corl/action/seed.rb +115 -0
  25. data/lib/corl/action/spawn.rb +75 -0
  26. data/lib/corl/action/start.rb +37 -0
  27. data/lib/corl/action/stop.rb +30 -0
  28. data/lib/corl/action/update.rb +37 -0
  29. data/lib/corl/command/shell.rb +164 -0
  30. data/lib/corl/configuration/file.rb +386 -0
  31. data/lib/corl/event/puppet.rb +90 -0
  32. data/lib/corl/event/regex.rb +52 -0
  33. data/lib/corl/extension/puppetloader.rb +24 -0
  34. data/lib/corl/machine/fog.rb +310 -0
  35. data/lib/corl/machine/physical.rb +161 -0
  36. data/lib/corl/network/default.rb +26 -0
  37. data/lib/corl/node/aws.rb +90 -0
  38. data/lib/corl/node/fog.rb +198 -0
  39. data/lib/corl/node/google.rb +115 -0
  40. data/lib/corl/node/local.rb +26 -0
  41. data/lib/corl/node/rackspace.rb +89 -0
  42. data/lib/corl/project/git.rb +465 -0
  43. data/lib/corl/project/github.rb +108 -0
  44. data/lib/corl/provisioner/puppetnode/resource.rb +245 -0
  45. data/lib/corl/provisioner/puppetnode/resource_group.rb +205 -0
  46. data/lib/corl/provisioner/puppetnode.rb +407 -0
  47. data/lib/corl/template/environment.rb +73 -0
  48. data/lib/corl/template/json.rb +16 -0
  49. data/lib/corl/template/wrapper.rb +16 -0
  50. data/lib/corl/template/yaml.rb +16 -0
  51. data/lib/corl/translator/json.rb +27 -0
  52. data/lib/corl/translator/yaml.rb +27 -0
  53. data/lib/corl.rb +173 -0
  54. data/lib/corl_core/codes.rb +107 -0
  55. data/lib/corl_core/config/collection.rb +57 -0
  56. data/lib/corl_core/config/options.rb +70 -0
  57. data/lib/corl_core/config.rb +337 -0
  58. data/lib/corl_core/core.rb +59 -0
  59. data/lib/corl_core/corl.rb +254 -0
  60. data/lib/corl_core/errors.rb +84 -0
  61. data/lib/corl_core/facade.rb +126 -0
  62. data/lib/corl_core/gems.rb +72 -0
  63. data/lib/corl_core/manager.rb +425 -0
  64. data/lib/corl_core/mixin/action/commit.rb +58 -0
  65. data/lib/corl_core/mixin/action/keypair.rb +105 -0
  66. data/lib/corl_core/mixin/action/node.rb +129 -0
  67. data/lib/corl_core/mixin/action/project.rb +53 -0
  68. data/lib/corl_core/mixin/action/push.rb +52 -0
  69. data/lib/corl_core/mixin/config/collection.rb +53 -0
  70. data/lib/corl_core/mixin/config/ops.rb +53 -0
  71. data/lib/corl_core/mixin/config/options.rb +39 -0
  72. data/lib/corl_core/mixin/lookup.rb +196 -0
  73. data/lib/corl_core/mixin/macro/object_interface.rb +361 -0
  74. data/lib/corl_core/mixin/macro/plugin_interface.rb +380 -0
  75. data/lib/corl_core/mixin/settings.rb +46 -0
  76. data/lib/corl_core/mixin/sub_config.rb +148 -0
  77. data/lib/corl_core/mod/hash.rb +29 -0
  78. data/lib/corl_core/mod/hiera_backend.rb +63 -0
  79. data/lib/corl_core/plugin/action.rb +381 -0
  80. data/lib/corl_core/plugin/base.rb +374 -0
  81. data/lib/corl_core/plugin/command.rb +98 -0
  82. data/lib/corl_core/plugin/configuration.rb +177 -0
  83. data/lib/corl_core/plugin/event.rb +53 -0
  84. data/lib/corl_core/plugin/extension.rb +12 -0
  85. data/lib/corl_core/plugin/machine.rb +266 -0
  86. data/lib/corl_core/plugin/network.rb +359 -0
  87. data/lib/corl_core/plugin/node.rb +904 -0
  88. data/lib/corl_core/plugin/project.rb +927 -0
  89. data/lib/corl_core/plugin/provisioner.rb +51 -0
  90. data/lib/corl_core/plugin/template.rb +80 -0
  91. data/lib/corl_core/plugin/translator.rb +38 -0
  92. data/lib/corl_core/util/cli.rb +352 -0
  93. data/lib/corl_core/util/data.rb +404 -0
  94. data/lib/corl_core/util/disk.rb +114 -0
  95. data/lib/corl_core/util/git.rb +47 -0
  96. data/lib/corl_core/util/interface.rb +319 -0
  97. data/lib/corl_core/util/liquid.rb +17 -0
  98. data/lib/corl_core/util/package.rb +93 -0
  99. data/lib/corl_core/util/shell.rb +239 -0
  100. data/lib/corl_core/util/ssh.rb +286 -0
  101. data/lib/facter/corl_config_ready.rb +13 -0
  102. data/lib/facter/corl_exists.rb +15 -0
  103. data/lib/facter/corl_network.rb +17 -0
  104. data/lib/hiera/corl_logger.rb +18 -0
  105. data/lib/puppet/indirector/corl.rb +27 -0
  106. data/lib/puppet/indirector/data_binding/corl.rb +6 -0
  107. data/lib/puppet/parser/functions/config_initialized.rb +26 -0
  108. data/lib/puppet/parser/functions/corl_include.rb +44 -0
  109. data/lib/puppet/parser/functions/corl_resources.rb +58 -0
  110. data/lib/puppet/parser/functions/deep_merge.rb +21 -0
  111. data/lib/puppet/parser/functions/ensure.rb +29 -0
  112. data/lib/puppet/parser/functions/file_exists.rb +19 -0
  113. data/lib/puppet/parser/functions/global_array.rb +35 -0
  114. data/lib/puppet/parser/functions/global_hash.rb +35 -0
  115. data/lib/puppet/parser/functions/global_options.rb +23 -0
  116. data/lib/puppet/parser/functions/global_param.rb +43 -0
  117. data/lib/puppet/parser/functions/interpolate.rb +26 -0
  118. data/lib/puppet/parser/functions/is_false.rb +21 -0
  119. data/lib/puppet/parser/functions/is_true.rb +21 -0
  120. data/lib/puppet/parser/functions/module_array.rb +38 -0
  121. data/lib/puppet/parser/functions/module_hash.rb +38 -0
  122. data/lib/puppet/parser/functions/module_options.rb +23 -0
  123. data/lib/puppet/parser/functions/module_param.rb +48 -0
  124. data/lib/puppet/parser/functions/name.rb +21 -0
  125. data/lib/puppet/parser/functions/render.rb +33 -0
  126. data/lib/puppet/parser/functions/value.rb +21 -0
  127. data/locales/en.yml +232 -0
  128. data/spec/corl_core/interface_spec.rb +489 -0
  129. data/spec/corl_mock_input.rb +29 -0
  130. data/spec/corl_test_kernel.rb +22 -0
  131. data/spec/spec_helper.rb +15 -0
  132. metadata +406 -0
@@ -0,0 +1,380 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::Macro::PluginInterface
5
+ #
6
+
7
+ corl_require(File.dirname(__FILE__), :object_interface)
8
+
9
+ #---
10
+
11
+ module CORL
12
+ module Mixin
13
+ module Macro
14
+ module PluginInterface
15
+
16
+ include Macro::ObjectInterface
17
+
18
+ #-----------------------------------------------------------------------------
19
+ # Plugin collections
20
+
21
+ def plugin_collection(_type, _method_options = {})
22
+ _method_config = Config.ensure(_method_options)
23
+ _method_config.set(:plugin, true)
24
+
25
+ _plural = _method_config.init(:plural, "#{_type}s").get(:plural)
26
+ _search_proc = _method_config.get(:search_proc)
27
+ _single_instance = _method_config.get(:single_instance, false)
28
+ _plugin_type = _method_config.get(:plugin_type, _type)
29
+
30
+ @@object_types[_type] = _method_config
31
+
32
+ logger.debug("Creating new plugin collection #{_type} with: #{_method_config.inspect}")
33
+
34
+ #---------------------------------------------------------------------------
35
+
36
+ object_utilities
37
+
38
+ #---
39
+
40
+ unless respond_to? :each_plugin
41
+ logger.debug("Defining plugin interface method: each_plugin")
42
+
43
+ define_method :each_plugin do |plugin_types = nil, providers = nil, &code|
44
+ providers = [ providers ] if providers && ! providers.is_a?(Array)
45
+
46
+ filter_proc = Proc.new {|type, config| config[:plugin] }
47
+ each_object_type(plugin_types, filter_proc) do |type, plural, options|
48
+ logger.debug("Processing plugin type #{type}/#{plural} with: #{options.inspect}")
49
+
50
+ send(plural).each do |provider, plugins|
51
+ logger.debug("Processing plugin provider: #{provider}")
52
+
53
+ unless providers && ! providers.include?(provider)
54
+ if plugins.is_a?(Hash)
55
+ plugins.each do |name, plugin|
56
+ logger.debug("Processing plugin: #{name}")
57
+ code.call(type, provider, name, plugin)
58
+ end
59
+ else
60
+ logger.debug("Processing plugin: #{plugin.name}")
61
+ code.call(type, provider, plugin.name, plugin)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ #---
70
+
71
+ logger.debug("Defining plugin interface method: each_#{_type}")
72
+
73
+ define_method "each_#{_type}" do |providers = nil, &code|
74
+ each_plugin(_type, providers) do |type, provider, name, plugin|
75
+ code.call(provider, name, plugin)
76
+ end
77
+ end
78
+
79
+ #---------------------------------------------------------------------------
80
+
81
+ logger.debug("Defining plugin interface method: #{_plural}")
82
+
83
+ define_method "#{_plural}" do |provider = nil, reset = false|
84
+ keys = ( provider ? [ _plural, provider ] : _plural )
85
+ send("init_#{_plural}", provider) if reset || _get(keys, {}).empty?
86
+ _get(keys, {})
87
+ end
88
+
89
+ #---
90
+
91
+ logger.debug("Defining plugin interface method: init_#{_plural}")
92
+
93
+ define_method "init_#{_plural}" do |providers = nil|
94
+ data = hash(_search_proc.call) if _search_proc
95
+ data = get_hash(_plural) unless data
96
+
97
+ providers = [ providers ] if providers && ! providers.is_a?(Array)
98
+
99
+ logger.debug("Initializing #{_plugin_type} plugin data: #{data.inspect}")
100
+ logger.debug("Providers: #{providers.inspect}")
101
+
102
+ symbol_map(data).each do |provider, instance_settings|
103
+ if ! providers || providers.include?(provider)
104
+ if _single_instance
105
+ logger.debug("Initializing single instance plugin: #{instance_settings.inspect}")
106
+
107
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(instance_settings).import({ :meta => { :parent => myself } }))
108
+
109
+ _set([ _plural, provider ], plugin)
110
+ else
111
+ instance_settings.each do |name, options|
112
+ if name != :settings
113
+ logger.debug("Initializing plugin #{_plugin_type} #{name}: #{options.inspect}")
114
+
115
+ options[:name] = name
116
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
117
+
118
+ _set([ _plural, provider, name ], plugin)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ #---
127
+
128
+ logger.debug("Defining plugin interface method: set_#{_plural}")
129
+
130
+ define_method "set_#{_plural}" do |data = {}|
131
+ data = Config.ensure(data).export
132
+
133
+ send("clear_#{_plural}")
134
+ set(_plural, data)
135
+
136
+ logger.debug("Setting #{_plural}")
137
+
138
+ data.each do |provider, instance_settings|
139
+ if _single_instance
140
+ logger.debug("Setting single #{_plugin_type} #{provider}: #{instance_settings.inspect}")
141
+
142
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(instance_settings).import({ :meta => { :parent => myself } }))
143
+
144
+ _set([ _plural, provider ], plugin)
145
+ else
146
+ instance_settings.each do |name, options|
147
+ logger.debug("Setting #{_plugin_type} #{provider} #{name}: #{options.inspect}")
148
+
149
+ options[:name] = name
150
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
151
+
152
+ _set([ _plural, provider, name ], plugin)
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ #---
159
+
160
+ logger.debug("Defining plugin interface method: clear_#{_plural}")
161
+
162
+ define_method "clear_#{_plural}" do
163
+ get(_plural).keys.each do |provider|
164
+ logger.debug("Clearing #{_type} #{provider}")
165
+
166
+ if _single_instance
167
+ send("delete_#{_type}", provider)
168
+ else
169
+ get_hash([ _plural, provider ]).keys.each do |name|
170
+ send("delete_#{_type}", provider, name)
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ #---------------------------------------------------------------------------
177
+
178
+ if _single_instance
179
+ logger.debug("Defining single instance plugin interface method: #{_type}_config")
180
+
181
+ define_method "#{_type}_config" do |provider = nil|
182
+ keys = [ _plural ]
183
+ keys << provider unless provider.nil?
184
+ Config.new(get(keys, {}))
185
+ end
186
+
187
+ #---
188
+
189
+ logger.debug("Defining single instance plugin interface method: #{_type}_setting")
190
+
191
+ define_method "#{_type}_setting" do |provider, property, default = nil, format = false|
192
+ get([ _plural, provider, property ], default, format)
193
+ end
194
+
195
+ #---
196
+
197
+ logger.debug("Defining single instance plugin interface method: #{_type}")
198
+
199
+ define_method "#{_type}" do |provider, reset = false|
200
+ if reset || _get([ _plural, provider ], nil).nil?
201
+ options = get([ _plural, provider ], nil)
202
+
203
+ unless options.nil?
204
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
205
+
206
+ logger.debug("Initializing plugin #{_plugin_type} #{provider}: #{options.inspect}")
207
+
208
+ _set([ _plural, provider ], plugin)
209
+ end
210
+ end
211
+ _get([ _plural, provider ])
212
+ end
213
+
214
+ #---
215
+
216
+ logger.debug("Defining single instance plugin interface method: set_#{_type}")
217
+
218
+ define_method "set_#{_type}" do |provider, options = {}|
219
+ options = Config.ensure(options).export
220
+
221
+ set([ _plural, provider ], options)
222
+
223
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
224
+
225
+ logger.debug("Setting single #{_plugin_type} #{provider}: #{options.inspect}")
226
+
227
+ _set([ _plural, provider ], plugin)
228
+ plugin
229
+ end
230
+
231
+ #---
232
+
233
+ logger.debug("Defining single instance plugin interface method: set_#{_type}_setting")
234
+
235
+ define_method "set_#{_type}_setting" do |provider, property, value = nil|
236
+ logger.debug("Setting single #{provider} property #{property} to #{value.inspect}")
237
+ set([ _plural, provider, property ], value)
238
+ end
239
+
240
+ #---
241
+
242
+ logger.debug("Defining single instance plugin interface method: delete_#{_type}")
243
+
244
+ define_method "delete_#{_type}" do |provider|
245
+ plugin = send(_type, provider)
246
+
247
+ logger.debug("Deleting single #{_type} #{provider}")
248
+
249
+ delete([ _plural, provider ])
250
+ _delete([ _plural, provider ])
251
+
252
+ CORL.remove_plugin(plugin) unless plugin.nil?
253
+ end
254
+
255
+ #---
256
+
257
+ logger.debug("Defining single instance plugin interface method: delete_#{_type}_setting")
258
+
259
+ define_method "delete_#{_type}_setting" do |provider, property|
260
+ logger.debug("Deleting single #{provider} property: #{property}")
261
+ delete([ _plural, provider, property ])
262
+ end
263
+
264
+ #---
265
+
266
+ logger.debug("Defining single instance plugin interface method: search_#{_type}")
267
+
268
+ define_method "search_#{_type}" do |provider, keys, default = '', format = false|
269
+ plugin_config = send("#{_type}_config", provider)
270
+ logger.debug("Searching single #{_type} #{provider}: #{plugin_config.inspect}")
271
+
272
+ search_object(plugin_config, keys, default, format)
273
+ end
274
+
275
+ #---------------------------------------------------------------------------
276
+ else
277
+ logger.debug("Defining multi instance plugin interface method: #{_type}_config")
278
+
279
+ define_method "#{_type}_config" do |provider = nil, name = nil|
280
+ keys = [ _plural ]
281
+ keys << provider unless provider.nil?
282
+ keys << name unless name.nil?
283
+ Config.new(get(keys, {}))
284
+ end
285
+
286
+ #---
287
+
288
+ logger.debug("Defining multi instance plugin interface method: #{_type}_setting")
289
+
290
+ define_method "#{_type}_setting" do |provider, name, property, default = nil, format = false|
291
+ get([ _plural, provider, name, property ], default, format)
292
+ end
293
+
294
+ #---
295
+
296
+ logger.debug("Defining multi instance plugin interface method: #{_type}")
297
+
298
+ define_method "#{_type}" do |provider, name|
299
+ if reset || _get([ _plural, provider, name ], nil).nil?
300
+ options = get([ _plural, provider, name ], nil)
301
+
302
+ unless options.nil?
303
+ options[:name] = name
304
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
305
+
306
+ logger.debug("Initializing plugin #{_plugin_type} #{provider}: #{options.inspect}")
307
+
308
+ _set([ _plural, provider, name ], plugin)
309
+ end
310
+ end
311
+ _get([ _plural, provider, name ])
312
+ end
313
+
314
+ #---
315
+
316
+ logger.debug("Defining multi instance plugin interface method: set_#{_type}")
317
+
318
+ define_method "set_#{_type}" do |provider, name, options = {}|
319
+ options = Config.ensure(options).export
320
+
321
+ set([ _plural, provider, name ], options)
322
+
323
+ options[:name] = name
324
+ plugin = CORL.plugin(_plugin_type, provider, Config.ensure(options).import({ :meta => { :parent => myself } }))
325
+
326
+ logger.debug("Setting #{_plugin_type} #{provider} #{name}: #{options.inspect}")
327
+
328
+ _set([ _plural, provider, name ], plugin)
329
+ plugin
330
+ end
331
+
332
+ #---
333
+
334
+ logger.debug("Defining multi instance plugin interface method: set_#{_type}_setting")
335
+
336
+ define_method "set_#{_type}_setting" do |provider, name, property, value = nil|
337
+ logger.debug("Setting #{provider} #{name} property #{property} to #{value.inspect}")
338
+ set([ _plural, provider, name, property ], value)
339
+ end
340
+
341
+ #---
342
+
343
+ logger.debug("Defining multi instance plugin interface method: delete_#{_type}")
344
+
345
+ define_method "delete_#{_type}" do |provider, name|
346
+ plugin = send(_type, provider, name)
347
+
348
+ logger.debug("Deleting #{_type} #{provider} #{name}")
349
+
350
+ delete([ _plural, provider, name ])
351
+ _delete([ _plural, provider, name ])
352
+
353
+ CORL.remove_plugin(plugin) unless plugin.nil?
354
+ end
355
+
356
+ #---
357
+
358
+ logger.debug("Defining multi instance plugin interface method: delete_#{_type}_setting")
359
+
360
+ define_method "delete_#{_type}_setting" do |provider, name, property|
361
+ logger.debug("Deleting #{provider} #{name} property: #{property}")
362
+ delete([ _plural, provider, name, property ])
363
+ end
364
+
365
+ #---
366
+
367
+ logger.debug("Defining multi instance plugin interface method: search_#{_type}")
368
+
369
+ define_method "search_#{_type}" do |provider, name, keys, default = '', format = false|
370
+ plugin_config = send("#{_type}_config", provider, name)
371
+ logger.debug("Searching #{_type} #{provider} #{name}: #{plugin_config.inspect}")
372
+
373
+ search_object(plugin_config, keys, default, format)
374
+ end
375
+ end
376
+ end
377
+ end
378
+ end
379
+ end
380
+ end
@@ -0,0 +1,46 @@
1
+
2
+ # Should be included via include
3
+ #
4
+ # include Mixin::Settings
5
+ #
6
+
7
+ module CORL
8
+ module Mixin
9
+ module Settings
10
+
11
+ def settings(name)
12
+ return get_hash([ :settings, name ])
13
+ end
14
+
15
+ #---
16
+
17
+ def set_settings(name, settings = {})
18
+ return set([ :settings, name ], settings)
19
+ end
20
+
21
+ #---
22
+
23
+ def delete_settings(name)
24
+ return delete([ :settings, name ])
25
+ end
26
+
27
+ #---
28
+
29
+ def setting(name, key, default = '', format = false)
30
+ return get([ :settings, name, key ], default, format)
31
+ end
32
+
33
+ #---
34
+
35
+ def set_setting(name, key, value = '')
36
+ return set([ :settings, name, key ], value)
37
+ end
38
+
39
+ #---
40
+
41
+ def delete_setting(name, key)
42
+ return delete([ :settings, name, key ])
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,148 @@
1
+
2
+ # Should be included via include
3
+ #
4
+ # include Mixin::SubConfig
5
+ #
6
+
7
+ module CORL
8
+ module Mixin
9
+ module SubConfig
10
+
11
+ #-----------------------------------------------------------------------------
12
+ # Initialization
13
+
14
+ def init_subconfig(reset = false)
15
+ return if @subconfig_initialized && ! reset
16
+
17
+ unless @config
18
+ @config = Config.new
19
+ end
20
+
21
+ @subconfig_initialized = true
22
+ end
23
+ protected :init_subconfig
24
+
25
+ #-----------------------------------------------------------------------------
26
+ # Propety accessors / modifiers
27
+
28
+ def config
29
+ return @config
30
+ end
31
+
32
+ #---
33
+
34
+ def config=config
35
+ @config = config
36
+ end
37
+
38
+ #-----------------------------------------------------------------------------
39
+
40
+ def _get(keys, default = nil, format = false)
41
+ return fetch(@properties, array(keys).flatten, default, format)
42
+ end
43
+ protected :_get
44
+
45
+ #---
46
+
47
+ def get(keys, default = nil, format = false)
48
+ init_subconfig
49
+ return config.get(keys, default, format)
50
+ end
51
+
52
+ #---
53
+
54
+ def _init(keys, default = nil)
55
+ return _set(keys, _get(keys, default))
56
+ end
57
+ protected :_init
58
+
59
+ #---
60
+
61
+ def _set(keys, value = '')
62
+ modify(@properties, array(keys).flatten, value)
63
+ end
64
+ protected :_set
65
+
66
+ #---
67
+
68
+ def set(keys, value = '')
69
+ init_subconfig
70
+ config.set(keys, value)
71
+ end
72
+
73
+ #---
74
+
75
+ def _delete(keys, default = nil)
76
+ existing = modify(@properties, array(keys).flatten, nil)
77
+ return existing[:value] if existing[:value]
78
+ return default
79
+ end
80
+ protected :_delete
81
+
82
+ #---
83
+
84
+ def delete(keys, default = nil)
85
+ init_subconfig
86
+ config.delete(keys, default)
87
+ end
88
+
89
+ #---
90
+
91
+ def _clear
92
+ @properties = {}
93
+ end
94
+ protected :_clear
95
+
96
+ #---
97
+
98
+ def clear
99
+ init_subconfig
100
+ config.clear
101
+ end
102
+
103
+ #-----------------------------------------------------------------------------
104
+ # Import / Export
105
+
106
+ def _import(properties, options = {})
107
+ return import_base(properties, options)
108
+ end
109
+ protected :_import
110
+
111
+ #---
112
+
113
+ def import(properties, options = {})
114
+ init_subconfig
115
+ config.import(properties, options)
116
+ end
117
+
118
+ #---
119
+
120
+ def _defaults(defaults, options = {})
121
+ config = new(options).set(:import_type, :default)
122
+ return import_base(defaults, config)
123
+ end
124
+ protected :_defaults
125
+
126
+ #---
127
+
128
+ def defaults(defaults, options = {})
129
+ init_subconfig
130
+ config.defaults(defaults, options)
131
+ end
132
+
133
+ #---
134
+
135
+ def _export
136
+ return @properties
137
+ end
138
+ protected :_export
139
+
140
+ #---
141
+
142
+ def export
143
+ init_subconfig
144
+ return config.export
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,29 @@
1
+
2
+ #-------------------------------------------------------------------------------
3
+ # Hash data type alterations
4
+
5
+ class Hash
6
+ def search(search_key, options = {})
7
+ config = CORL::Config.ensure(options)
8
+ value = nil
9
+
10
+ recurse = config.get(:recurse, false)
11
+ recurse_level = config.get(:recurse_level, -1)
12
+
13
+ self.each do |key, data|
14
+ if key == search_key
15
+ value = data
16
+
17
+ elsif data.is_a?(Hash) &&
18
+ recurse && (recurse_level == -1 || recurse_level > 0)
19
+
20
+ recurse_level -= 1 unless recurse_level == -1
21
+ value = value.search(search_key,
22
+ CORL::Config.new(config).set(:recurse_level, recurse_level)
23
+ )
24
+ end
25
+ break unless value.nil?
26
+ end
27
+ return value
28
+ end
29
+ end
@@ -0,0 +1,63 @@
1
+ begin
2
+ require 'hiera/backend'
3
+
4
+ class Hiera
5
+ module Backend
6
+ #
7
+ # NOTE: This function is overridden so we can collect accumulated hiera
8
+ # parameters and their values on a particular puppet run for reporting
9
+ # purposes.
10
+ #
11
+ # Calls out to all configured backends in the order they
12
+ # were specified. The first one to answer will win.
13
+ #
14
+ # This lets you declare multiple backends, a possible
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
27
+
28
+ Config[:backends].each do |backend|
29
+ if constants.include?("#{backend.capitalize}_backend") || constants.include?("#{backend.capitalize}_backend".to_sym)
30
+ @backends[backend] ||= Backend.const_get("#{backend.capitalize}_backend").new
31
+ new_answer = @backends[backend].lookup(key, scope, order_override, resolution_type)
32
+
33
+ if not new_answer.nil?
34
+ case resolution_type
35
+ when :array
36
+ raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
37
+ answer ||= []
38
+ answer << new_answer
39
+ when :hash
40
+ raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
41
+ answer ||= {}
42
+ answer = merge_answer(new_answer,answer)
43
+ else
44
+ answer = new_answer
45
+ break
46
+ end
47
+ end
48
+ end
49
+ 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
+ end
59
+ end
60
+ end
61
+
62
+ rescue LoadError
63
+ end