coral_core 0.2.26 → 0.2.30

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 (46) hide show
  1. data/Gemfile +7 -2
  2. data/Gemfile.lock +84 -15
  3. data/VERSION +1 -1
  4. data/coral_core.gemspec +51 -16
  5. data/lib/{coral_core/command.rb → coral/command/shell.rb} +12 -116
  6. data/lib/coral/machine/fog.rb +215 -0
  7. data/lib/coral/network/default.rb +26 -0
  8. data/lib/coral/node/rackspace.rb +23 -0
  9. data/lib/coral_core.rb +249 -134
  10. data/lib/coral_core/config.rb +233 -275
  11. data/lib/coral_core/config/collection.rb +57 -0
  12. data/lib/coral_core/config/options.rb +70 -0
  13. data/lib/coral_core/config/project.rb +225 -0
  14. data/lib/coral_core/core.rb +19 -173
  15. data/lib/coral_core/event/puppet_event.rb +98 -0
  16. data/lib/coral_core/mixin/config_collection.rb +52 -0
  17. data/lib/coral_core/mixin/config_ops.rb +51 -0
  18. data/lib/coral_core/mixin/config_options.rb +38 -0
  19. data/lib/coral_core/mixin/lookup.rb +211 -0
  20. data/lib/coral_core/mixin/macro/object_interface.rb +292 -0
  21. data/lib/coral_core/mixin/macro/plugin_interface.rb +277 -0
  22. data/lib/coral_core/mixin/settings.rb +46 -0
  23. data/lib/coral_core/mixin/sub_config.rb +208 -0
  24. data/lib/coral_core/mod/hash.rb +29 -0
  25. data/lib/{hiera_backend.rb → coral_core/mod/hiera_backend.rb} +0 -0
  26. data/lib/coral_core/plugin.rb +261 -0
  27. data/lib/coral_core/plugin/command.rb +95 -0
  28. data/lib/coral_core/plugin/machine.rb +152 -0
  29. data/lib/coral_core/plugin/network.rb +24 -0
  30. data/lib/coral_core/plugin/node.rb +184 -0
  31. data/lib/coral_core/plugin_base.rb +147 -0
  32. data/lib/coral_core/repository.rb +471 -82
  33. data/lib/coral_core/util/cli.rb +293 -0
  34. data/lib/coral_core/util/data.rb +178 -8
  35. data/lib/coral_core/util/disk.rb +13 -0
  36. data/lib/coral_core/util/git.rb +35 -10
  37. data/lib/coral_core/{interface.rb → util/interface.rb} +31 -21
  38. data/lib/coral_core/util/process.rb +43 -0
  39. data/locales/en.yml +8 -0
  40. data/spec/coral_core/interface_spec.rb +45 -45
  41. metadata +109 -34
  42. data/.gitmodules +0 -12
  43. data/lib/coral_core/memory.rb +0 -226
  44. data/lib/coral_core/util/git/base.rb +0 -65
  45. data/lib/coral_core/util/git/lib.rb +0 -89
  46. data/lib/coral_core/util/git/remote.rb +0 -12
@@ -0,0 +1,292 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::Macro::ObjectInterface
5
+ #
6
+
7
+ module Coral
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
+ #---------------------------------------------------------------------------
36
+
37
+ object_utilities
38
+
39
+ #---
40
+
41
+ unless respond_to? :each_object!
42
+ define_method :each_object! do |object_types = nil|
43
+ each_object_type!(object_types) do |type, plural, options|
44
+ send(plural).each do |name, obj|
45
+ yield(type, name, obj)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ #---------------------------------------------------------------------------
52
+
53
+ define_method "#{_type}_config" do |name = nil|
54
+ Config.new( name ? get([ _plural, name ], {}) : get(_plural, {}) )
55
+ end
56
+
57
+ #---
58
+
59
+ define_method "#{_type}_setting" do |name, property, default = nil, format = false|
60
+ get([ _plural, name, property ], default, format)
61
+ end
62
+
63
+ #---
64
+
65
+ define_method "#{_plural}" do
66
+ _get(_plural, {})
67
+ end
68
+
69
+ #---
70
+
71
+ define_method "init_#{_plural}" do
72
+ data = hash(_search_proc.call) if _search_proc
73
+ data = get_hash(_plural) unless data
74
+
75
+ symbol_map(data).each do |name, options|
76
+ if name != :settings
77
+ options[:object_container] = self
78
+
79
+ obj = _ensure_proc.call(name, options)
80
+ _set([ _plural, name ], obj)
81
+ end
82
+ end
83
+ end
84
+
85
+ #---
86
+
87
+ define_method "set_#{_plural}" do |data = {}|
88
+ data = Config.ensure(data).export
89
+
90
+ send("clear_#{_plural}")
91
+ set(_plural, data)
92
+
93
+ data.each do |name, options|
94
+ options[:object_container] = self
95
+
96
+ obj = _ensure_proc.call(name, options)
97
+ _set([ _plural, name ], obj)
98
+ end
99
+ self
100
+ end
101
+
102
+ #---
103
+
104
+ define_method "#{_type}" do |name|
105
+ _get([ _plural, name ])
106
+ end
107
+
108
+ #---
109
+
110
+ define_method "set_#{_type}" do |name, options = {}|
111
+ options = Config.ensure(options).export
112
+
113
+ set([ _plural, name ], options)
114
+
115
+ options[:object_container] = self
116
+
117
+ obj = _ensure_proc.call(name, options)
118
+ _set([ _plural, name ], obj)
119
+ self
120
+ end
121
+
122
+ #---
123
+
124
+ define_method "set_#{_type}_setting" do |name, property, value = nil|
125
+ set([ _plural, name, property ], value)
126
+ self
127
+ end
128
+
129
+ #---
130
+
131
+ define_method "delete_#{_type}" do |name|
132
+ obj = send(_type, name)
133
+
134
+ delete([ _plural, name ])
135
+ _delete([ _plural, name ])
136
+
137
+ _delete_proc.call(obj) if _delete_proc
138
+ self
139
+ end
140
+
141
+ #---
142
+
143
+ define_method "delete_#{_type}_setting" do |name, property|
144
+ delete([ _plural, name, property ])
145
+ self
146
+ end
147
+
148
+ #---
149
+
150
+ define_method "clear_#{_plural}" do
151
+ _get(_plural).keys.each do |name|
152
+ send("delete_#{_type}", name)
153
+ end
154
+ self
155
+ end
156
+
157
+ #---------------------------------------------------------------------------
158
+
159
+ define_method "search_#{_type}" do |name, keys, default = '', format = false|
160
+ obj_config = send("#{_type}_config", name)
161
+ search_object(obj_config, keys, default, format)
162
+ end
163
+ end
164
+
165
+ #-----------------------------------------------------------------------------
166
+ # Utilities
167
+
168
+ def object_utilities
169
+
170
+ unless respond_to? :foreach_object_type!
171
+ define_method :foreach_object_type! do |object_types = nil, filter_proc = nil|
172
+ object_types = @@object_types.keys unless object_types
173
+ object_types = [ object_types ] unless object_types.is_a?(Array)
174
+
175
+ object_types.keys.each do |type|
176
+ unless filter_proc && ! filter_proc.call(type, @@object_types[type])
177
+ plural = @@object_types[type][:plural]
178
+ yield(type, plural, @@object_types[type])
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ #---
185
+
186
+ unless respond_to? :init_objects
187
+ define_method :init_objects do |object_types = nil, filter_proc = nil|
188
+ foreach_object_type!(object_types, filter_proc) do |type, plural, options|
189
+ send("init_#{plural}")
190
+ end
191
+ end
192
+ end
193
+
194
+ #---
195
+
196
+ unless respond_to? :clear_objects
197
+ define_method :clear_objects do |object_types = nil, filter_proc = nil|
198
+ foreach_object_type!(object_types, filter_proc) do |type, plural, options|
199
+ send("clear_#{plural}")
200
+ end
201
+ end
202
+ end
203
+
204
+ #---------------------------------------------------------------------------
205
+
206
+ unless respond_to? :search_object
207
+ define_method :search_object do |obj_config, keys, default = '', format = false|
208
+ obj_config = Marshal.load(Marshal.dump(obj_config))
209
+ value = obj_config.get(keys)
210
+
211
+ #dbg(obj_config, 'search object config')
212
+
213
+ if ! value || value.is_a?(Hash)
214
+ settings = {}
215
+
216
+ keys = [ keys ] unless keys.is_a?(Array)
217
+ temp = keys.dup
218
+
219
+ #dbg('specialized settings')
220
+
221
+ until temp.empty? do
222
+ #dbg(temp, 'temporary settings prefix')
223
+ if obj_settings = obj_config.delete([ temp, :settings ])
224
+ #dbg(obj_settings, 'object settings')
225
+ array(obj_settings).each do |group_name|
226
+ #dbg(group_name, 'group name')
227
+ if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
228
+ #dbg(group_settings, 'group settings')
229
+ settings = Util::Data.merge([ group_settings.dup, settings ], true)
230
+ end
231
+ end
232
+ end
233
+ temp.pop
234
+ end
235
+
236
+ #dbg(settings, 'specialized settings')
237
+
238
+ #dbg('general settings')
239
+
240
+ if obj_settings = obj_config.delete(:settings)
241
+ #dbg(obj_settings, 'object settings')
242
+ array(obj_settings).each do |group_name|
243
+ #dbg(group_name, 'group name')
244
+ if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
245
+ #dbg(group_settings, 'group settings')
246
+ settings = Util::Data.merge([ group_settings, settings ], true)
247
+ end
248
+ end
249
+ end
250
+
251
+ #dbg(settings, 'general settings')
252
+
253
+ unless settings.empty?
254
+ #dbg(obj_config, 'initial object config')
255
+ final_config = Config.new(Util::Data.merge([ settings, obj_config.export ], true))
256
+ value = final_config.get(keys)
257
+ #dbg(final_config, 'final object config')
258
+ end
259
+
260
+ value = default if Util::Data.undef?(value)
261
+ end
262
+ filter(value, format)
263
+ end
264
+ end
265
+
266
+ #---------------------------------------------------------------------------
267
+ # Configuration loading saving
268
+
269
+ unless respond_to? :load
270
+ define_method :load do |options = {}|
271
+ if config.respond_to?(:load)
272
+ clear_objects
273
+ config.load(options)
274
+ init_objects
275
+ end
276
+ self
277
+ end
278
+ end
279
+
280
+ #---
281
+
282
+ unless respond_to? :save
283
+ define_method :save do |options = {}|
284
+ config.save(options) if config.respond_to?(:save)
285
+ self
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end
@@ -0,0 +1,277 @@
1
+
2
+ # Should be included via extend
3
+ #
4
+ # extend Mixin::Macro::PluginInterface
5
+ #
6
+
7
+ coral_require(File.dirname(__FILE__), :object_interface)
8
+
9
+ #---
10
+
11
+ module Coral
12
+ module Mixin
13
+ module Macro
14
+ module PluginInterface
15
+
16
+ include Mixin::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
+ #---------------------------------------------------------------------------
33
+
34
+ object_utilities
35
+
36
+ #---
37
+
38
+ unless respond_to? :each_plugin!
39
+ define_method :each_plugin! do |plugin_types = nil, providers = nil|
40
+ providers = [ providers ] if providers && ! providers.is_a?(Array)
41
+
42
+ filter_proc = Proc.new {|type, config| config[:plugin] }
43
+ each_object_type!(plugin_types, filter_proc) do |type, plural, options|
44
+ send(plural).each do |provider, plugins|
45
+ unless providers && ! providers.include?(provider)
46
+ if plugins.is_a?(Hash)
47
+ plugins.each do |name, plugin|
48
+ yield(type, provider, plugin)
49
+ end
50
+ else
51
+ yield(type, provider, plugin)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ #---
60
+
61
+ define_method "each_#{_type}!" do |providers = nil|
62
+ each_plugin!(_type, providers) do |type, provider, plugin|
63
+ yield(type, provider, plugin)
64
+ end
65
+ end
66
+
67
+ #---------------------------------------------------------------------------
68
+
69
+ if _single_instance
70
+ define_method "#{_type}_config" do |provider|
71
+ Config.new(get([ _type, provider ], {}))
72
+ end
73
+
74
+ #---
75
+
76
+ define_method "#{_type}_setting" do |provider, property, default = nil, format = false|
77
+ get([ _type, provider, property ], default, format)
78
+ end
79
+
80
+ #---------------------------------------------------------------------------
81
+ else
82
+ define_method "#{_type}_config" do |provider, name = nil|
83
+ Config.new( name ? get([ _plural, provider, name ], {}) : get(_plural, provider, {}) )
84
+ end
85
+
86
+ #---
87
+
88
+ define_method "#{_type}_setting" do |provider, name, property, default = nil, format = false|
89
+ get([ _plural, provider, name, property ], default, format)
90
+ end
91
+ end
92
+
93
+ #---------------------------------------------------------------------------
94
+
95
+ define_method "#{_plural}" do |provider = nil|
96
+ ( provider ? _get([ _plural, provider ], {}) : _get(_plural, {}) )
97
+ end
98
+
99
+ #---
100
+
101
+ define_method "init_#{_plural}" do |providers = nil|
102
+ data = hash(_search_proc.call) if _search_proc
103
+ data = get_hash(_plural) unless data
104
+
105
+ providers = [ providers ] if providers && ! providers.is_a?(Array)
106
+
107
+ symbol_map(data).each do |provider, instance_settings|
108
+ if ! providers || providers.include?(provider)
109
+ if _single_instance
110
+ plugin = Coral.plugin(_plugin_type, provider, instance_settings)
111
+ plugin.plugin_parent = self
112
+
113
+ _set([ _plural, provider ], plugin)
114
+ else
115
+ instance_settings.each do |name, options|
116
+ if name != :settings
117
+ options[:name] = name
118
+ plugin = Coral.plugin(_plugin_type, provider, options)
119
+ plugin.plugin_parent = self
120
+
121
+ _set([ _plural, provider, name ], plugin)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ #---
130
+
131
+ define_method "set_#{_plural}" do |data = {}|
132
+ data = Config.ensure(data).export
133
+
134
+ send("clear_#{_plural}")
135
+ set(_plural, data)
136
+
137
+ data.each do |provider, instance_settings|
138
+ if _single_instance
139
+ plugin = Coral.plugin(_plugin_type, provider, instance_settings)
140
+ plugin.plugin_parent = self
141
+
142
+ _set([ _plural, provider ], plugin)
143
+ else
144
+ instance_settings.each do |name, options|
145
+ options[:name] = name
146
+ plugin = Coral.plugin(_plugin_type, provider, options)
147
+ plugin.plugin_parent = self
148
+
149
+ _set([ _plural, provider, name ], plugin)
150
+ end
151
+ end
152
+ end
153
+ self
154
+ end
155
+
156
+ #---
157
+
158
+ define_method "clear_#{_plural}" do
159
+ _get(_plural).keys.each do |name|
160
+ send("delete_#{_type}", name)
161
+ end
162
+ self
163
+ end
164
+
165
+ #---------------------------------------------------------------------------
166
+
167
+ if _single_instance
168
+ define_method "#{_type}" do |provider|
169
+ _get([ _plural, provider ])
170
+ end
171
+
172
+ #---
173
+
174
+ define_method "set_#{_type}" do |provider, options = {}|
175
+ options = Config.ensure(options).export
176
+
177
+ set([ _plural, provider ], options)
178
+
179
+ plugin = Coral.plugin(_plugin_type, provider, options)
180
+ plugin.plugin_parent = self
181
+
182
+ _set([ _plural, provider ], plugin)
183
+ self
184
+ end
185
+
186
+ #---
187
+
188
+ define_method "set_#{_type}_setting" do |provider, property, value = nil|
189
+ set([ _plural, provider, property ], value)
190
+ self
191
+ end
192
+
193
+ #---
194
+
195
+ define_method "delete_#{_type}" do |provider|
196
+ plugin = send(_type, provider)
197
+
198
+ delete([ _plural, provider ])
199
+ _delete([ _plural, provider ])
200
+
201
+ Coral.remove_plugin(plugin)
202
+ self
203
+ end
204
+
205
+ #---
206
+
207
+ define_method "delete_#{_type}_setting" do |provider, property|
208
+ delete([ _plural, provider, property ])
209
+ self
210
+ end
211
+
212
+ #---
213
+
214
+ define_method "search_#{_type}" do |provider, keys, default = '', format = false|
215
+ plugin_config = send("#{_type}_config", provider)
216
+ search_object(plugin_config, keys, default, format)
217
+ end
218
+
219
+ #---------------------------------------------------------------------------
220
+ else
221
+ define_method "#{_type}" do |provider, name|
222
+ _get([ _plural, provider, name ])
223
+ end
224
+
225
+ #---
226
+
227
+ define_method "set_#{_type}" do |provider, name, options = {}|
228
+ options = Config.ensure(options).export
229
+
230
+ set([ _plural, provider, name ], options)
231
+
232
+ options[:name] = name
233
+ plugin = Coral.plugin(_plugin_type, provider, options)
234
+ plugin.plugin_parent = self
235
+
236
+ _set([ _plural, provider, name ], plugin)
237
+ self
238
+ end
239
+
240
+ #---
241
+
242
+ define_method "set_#{_type}_setting" do |provider, name, property, value = nil|
243
+ set([ _plural, provider, name, property ], value)
244
+ self
245
+ end
246
+
247
+ #---
248
+
249
+ define_method "delete_#{_type}" do |provider, name|
250
+ plugin = send(_type, provider, name)
251
+
252
+ delete([ _plural, provider, name ])
253
+ _delete([ _plural, provider, name ])
254
+
255
+ Coral.remove_plugin(plugin)
256
+ self
257
+ end
258
+
259
+ #---
260
+
261
+ define_method "delete_#{_type}_setting" do |provider, name, property|
262
+ delete([ _plural, provider, name, property ])
263
+ self
264
+ end
265
+
266
+ #---
267
+
268
+ define_method "search_#{_type}" do |provider, name, keys, default = '', format = false|
269
+ plugin_config = send("#{_type}_config", provider, name)
270
+ search_object(plugin_config, keys, default, format)
271
+ end
272
+ end
273
+ end
274
+ end
275
+ end
276
+ end
277
+ end