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,361 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::Macro::ObjectInterface
5
+ #
6
+
7
+ module CORL
8
+ module Mixin
9
+ module Macro
10
+ module ObjectInterface
11
+
12
+ # requires Mixin::SubConfig
13
+ # requires Mixin::Settings
14
+
15
+ #-----------------------------------------------------------------------------
16
+ # Object collections
17
+
18
+ @@object_types = {}
19
+
20
+ #---
21
+
22
+ def object_collection(_type, _method_options = {})
23
+ _method_config = Config.ensure(_method_options)
24
+
25
+ _plural = _method_config.init(:plural, "#{_type}s").get(:plural)
26
+
27
+ unless _ensure_proc = _method_config.get(:ensure_proc, false)
28
+ _ensure_proc = Proc.new {|name, options = {}| options }
29
+ end
30
+ _delete_proc = _method_config.get(:delete_proc)
31
+ _search_proc = _method_config.get(:search_proc)
32
+
33
+ @@object_types[_type] = _method_config
34
+
35
+ logger.debug("Creating new object collection #{_type} with: #{_method_config.inspect}")
36
+
37
+ #---------------------------------------------------------------------------
38
+
39
+ object_utilities
40
+
41
+ #---------------------------------------------------------------------------
42
+
43
+ logger.debug("Defining object interface method: #{_type}_config")
44
+
45
+ define_method "#{_type}_config" do |name = nil|
46
+ Config.new( name ? get([ _plural, name ], {}) : get(_plural, {}) )
47
+ end
48
+
49
+ #---
50
+
51
+ logger.debug("Defining object interface method: #{_type}_setting")
52
+
53
+ define_method "#{_type}_setting" do |name, property, default = nil, format = false|
54
+ get([ _plural, name, property ], default, format)
55
+ end
56
+
57
+ #---
58
+
59
+ logger.debug("Defining object interface method: #{_plural}")
60
+
61
+ define_method "#{_plural}" do |reset = false|
62
+ send("init_#{_plural}") if reset || _get(_plural, {}).empty?
63
+ _get(_plural, {})
64
+ end
65
+
66
+ #---
67
+
68
+ logger.debug("Defining object interface method: init_#{_plural}")
69
+
70
+ define_method "init_#{_plural}" do
71
+ data = hash(_search_proc.call) if _search_proc
72
+ data = get_hash(_plural) unless data
73
+
74
+ logger.debug("Initializing object data: #{data.inspect}")
75
+
76
+ symbol_map(data).each do |name, options|
77
+ if name != :settings
78
+ options[:object_container] = myself
79
+
80
+ logger.debug("Initializing object: #{name}")
81
+
82
+ obj = _ensure_proc.call(name, options)
83
+ _set([ _plural, name ], obj)
84
+ end
85
+ end
86
+ end
87
+
88
+ #---
89
+
90
+ logger.debug("Defining object interface method: set_#{_plural}")
91
+
92
+ define_method "set_#{_plural}" do |data = {}|
93
+ data = Config.ensure(data).export
94
+
95
+ send("clear_#{_plural}")
96
+ set(_plural, data)
97
+
98
+ logger.debug("Setting #{_plural}")
99
+
100
+ data.each do |name, options|
101
+ options[:object_container] = myself
102
+
103
+ logger.debug("Setting #{_type} #{name}: #{options.inspect}")
104
+
105
+ obj = _ensure_proc.call(name, options)
106
+ _set([ _plural, name ], obj)
107
+ end
108
+ end
109
+
110
+ #---
111
+
112
+ logger.debug("Defining object interface method: #{_type}")
113
+
114
+ define_method "#{_type}" do |name, reset = false|
115
+ if reset || _get([ _plural, name ], nil).nil?
116
+ options = get([ _plural, name ], nil)
117
+
118
+ unless options.nil?
119
+ options[:object_container] = myself
120
+
121
+ logger.debug("Initializing object: #{name}")
122
+
123
+ obj = _ensure_proc.call(name, options)
124
+ _set([ _plural, name ], obj)
125
+ end
126
+ end
127
+ _get([ _plural, name ])
128
+ end
129
+
130
+ #---
131
+
132
+ logger.debug("Defining object interface method: set_#{_type}")
133
+
134
+ define_method "set_#{_type}" do |name, options = {}|
135
+ options = Config.ensure(options).export
136
+
137
+ set([ _plural, name ], options)
138
+
139
+ options[:object_container] = myself
140
+
141
+ logger.debug("Setting #{_type} #{_name}: #{options.inspect}")
142
+
143
+ obj = _ensure_proc.call(name, options)
144
+ _set([ _plural, name ], obj)
145
+ end
146
+
147
+ #---
148
+
149
+ logger.debug("Defining object interface method: set_#{_type}_setting")
150
+
151
+ define_method "set_#{_type}_setting" do |name, property, value = nil|
152
+ logger.debug("Setting #{name} property #{property} to #{value.inspect}")
153
+ set([ _plural, name, property ], value)
154
+ end
155
+
156
+ #---
157
+
158
+ logger.debug("Defining object interface method: delete_#{_type}")
159
+
160
+ define_method "delete_#{_type}" do |name|
161
+ obj = send(_type, name)
162
+
163
+ logger.debug("Deleting #{_type} #{name}")
164
+
165
+ delete([ _plural, name ])
166
+ _delete([ _plural, name ])
167
+
168
+ _delete_proc.call(obj) if _delete_proc && ! obj.nil?
169
+ end
170
+
171
+ #---
172
+
173
+ logger.debug("Defining object interface method: delete_#{_type}_setting")
174
+
175
+ define_method "delete_#{_type}_setting" do |name, property|
176
+ logger.debug("Deleting #{name} property: #{property}")
177
+
178
+ delete([ _plural, name, property ])
179
+ end
180
+
181
+ #---
182
+
183
+ logger.debug("Defining object interface method: clear_#{_plural}")
184
+
185
+ define_method "clear_#{_plural}" do
186
+ get(_plural).keys.each do |name|
187
+ logger.debug("Clearing #{_type} #{name}")
188
+
189
+ send("delete_#{_type}", name)
190
+ end
191
+ end
192
+
193
+ #---------------------------------------------------------------------------
194
+
195
+ logger.debug("Defining object interface method: search_#{_type}")
196
+
197
+ define_method "search_#{_type}" do |name, keys, default = '', format = false|
198
+ obj_config = send("#{_type}_config", name)
199
+ search_object(obj_config, keys, default, format)
200
+ end
201
+ end
202
+
203
+ #-----------------------------------------------------------------------------
204
+ # Utilities
205
+
206
+ def object_utilities
207
+
208
+ unless respond_to? :each_object_type
209
+ logger.debug("Defining object utility method: each_object_type")
210
+
211
+ define_method :each_object_type do |object_types = nil, filter_proc = nil, &code|
212
+ object_types = @@object_types.keys unless object_types
213
+ object_types = [ object_types ] unless object_types.is_a?(Array)
214
+
215
+ object_types.each do |type|
216
+ logger.debug("Processing object type: #{type}")
217
+
218
+ unless filter_proc && ! filter_proc.call(type, @@object_types[type])
219
+ plural = @@object_types[type][:plural]
220
+
221
+ logger.debug("Passing: #{@@object_types[type].inspect}")
222
+ code.call(type, plural, @@object_types[type])
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ #---
229
+
230
+ unless respond_to? :each_object
231
+ logger.debug("Defining object utility method: each_object")
232
+
233
+ define_method :each_object do |object_types = nil, &code|
234
+ each_object_type(object_types) do |type, plural, options|
235
+ logger.debug("Processing object type #{type}/#{plural} with: #{options.inspect}")
236
+
237
+ send(plural).each do |name, obj|
238
+ logger.debug("Processing object: #{name}")
239
+ code.call(type, name, obj)
240
+ end
241
+ end
242
+ end
243
+ end
244
+
245
+ #---
246
+
247
+ unless respond_to? :init_objects
248
+ logger.debug("Defining object utility method: init_objects")
249
+
250
+ define_method :init_objects do |object_types = nil, filter_proc = nil|
251
+ logger.debug("Initializing object collection")
252
+
253
+ each_object_type(object_types, filter_proc) do |type, plural, options|
254
+ send("init_#{plural}")
255
+ end
256
+ end
257
+ end
258
+
259
+ #---
260
+
261
+ unless respond_to? :clear_objects
262
+ logger.debug("Defining object utility method: clear_objects")
263
+
264
+ define_method :clear_objects do |object_types = nil, filter_proc = nil|
265
+ logger.debug("Clearing object collection")
266
+
267
+ each_object_type(object_types, filter_proc) do |type, plural, options|
268
+ send("clear_#{plural}")
269
+ end
270
+ end
271
+ end
272
+
273
+ #---------------------------------------------------------------------------
274
+
275
+ unless respond_to? :search_object
276
+ logger.debug("Defining object utility method: search_object")
277
+
278
+ define_method :search_object do |obj_config, keys, default = '', format = false|
279
+ obj_config = Marshal.load(Marshal.dump(obj_config))
280
+ value = obj_config.get(keys)
281
+
282
+ logger.debug("Searching object properties: #{obj_config.inspect}")
283
+
284
+ if ! value || value.is_a?(Hash)
285
+ settings = {}
286
+
287
+ keys = [ keys ] unless keys.is_a?(Array)
288
+ temp = keys.dup
289
+
290
+ logger.debug("Searching object keys: #{keys.inspect}")
291
+
292
+ logger.debug("Searching specialized settings")
293
+ until temp.empty? do
294
+ if obj_settings = obj_config.delete([ temp, :settings ])
295
+ array(obj_settings).each do |group_name|
296
+ if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
297
+ settings = Util::Data.merge([ group_settings.dup, settings ], true)
298
+ end
299
+ end
300
+ end
301
+ temp.pop
302
+ end
303
+
304
+ logger.debug("Specialized settings found: #{settings.inspect}")
305
+ logger.debug("Searching general settings")
306
+
307
+ if obj_settings = obj_config.delete(:settings)
308
+ array(obj_settings).each do |group_name|
309
+ if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
310
+ settings = Util::Data.merge([ group_settings, settings ], true)
311
+ end
312
+ end
313
+ end
314
+
315
+ logger.debug("Final settings found: #{settings.inspect}")
316
+
317
+ unless settings.empty?
318
+ final_config = Config.new(Util::Data.merge([ settings, obj_config.export ], true))
319
+ value = final_config.get(keys)
320
+
321
+ logger.debug("Final configuration: #{final_config.export.inspect}")
322
+ end
323
+
324
+ value = default if Util::Data.undef?(value)
325
+ end
326
+
327
+ logger.debug("Final value found (format: #{format.inspect}): #{value.inspect}")
328
+ filter(value, format)
329
+ end
330
+ end
331
+
332
+ #---------------------------------------------------------------------------
333
+ # Configuration loading saving
334
+
335
+ unless respond_to? :load
336
+ logger.debug("Defining object utility method: load")
337
+
338
+ define_method :load do |options = {}|
339
+ logger.debug("Loading configuration if possible")
340
+ if config.respond_to?(:load)
341
+ clear_objects
342
+ config.load(options)
343
+ end
344
+ end
345
+ end
346
+
347
+ #---
348
+
349
+ unless respond_to? :save
350
+ logger.debug("Defining object utility method: save")
351
+
352
+ define_method :save do |options = {}|
353
+ logger.debug("Saving configuration if possible")
354
+ config.save(options) if config.respond_to?(:save)
355
+ end
356
+ end
357
+ end
358
+ end
359
+ end
360
+ end
361
+ end