coral_core 0.2.30 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -8
  3. data/Gemfile.lock +15 -86
  4. data/Rakefile +1 -3
  5. data/VERSION +1 -1
  6. data/coral_core.gemspec +12 -102
  7. metadata +18 -239
  8. data/lib/coral/command/shell.rb +0 -140
  9. data/lib/coral/machine/fog.rb +0 -215
  10. data/lib/coral/network/default.rb +0 -26
  11. data/lib/coral/node/rackspace.rb +0 -23
  12. data/lib/coral_core/config/collection.rb +0 -57
  13. data/lib/coral_core/config/options.rb +0 -70
  14. data/lib/coral_core/config/project.rb +0 -225
  15. data/lib/coral_core/config.rb +0 -329
  16. data/lib/coral_core/core.rb +0 -58
  17. data/lib/coral_core/event/puppet_event.rb +0 -98
  18. data/lib/coral_core/event/regexp_event.rb +0 -55
  19. data/lib/coral_core/event.rb +0 -170
  20. data/lib/coral_core/mixin/config_collection.rb +0 -52
  21. data/lib/coral_core/mixin/config_ops.rb +0 -51
  22. data/lib/coral_core/mixin/config_options.rb +0 -38
  23. data/lib/coral_core/mixin/lookup.rb +0 -211
  24. data/lib/coral_core/mixin/macro/object_interface.rb +0 -292
  25. data/lib/coral_core/mixin/macro/plugin_interface.rb +0 -277
  26. data/lib/coral_core/mixin/settings.rb +0 -46
  27. data/lib/coral_core/mixin/sub_config.rb +0 -208
  28. data/lib/coral_core/mod/hash.rb +0 -29
  29. data/lib/coral_core/mod/hiera_backend.rb +0 -63
  30. data/lib/coral_core/plugin/command.rb +0 -95
  31. data/lib/coral_core/plugin/machine.rb +0 -152
  32. data/lib/coral_core/plugin/network.rb +0 -24
  33. data/lib/coral_core/plugin/node.rb +0 -184
  34. data/lib/coral_core/plugin.rb +0 -261
  35. data/lib/coral_core/plugin_base.rb +0 -147
  36. data/lib/coral_core/repository.rb +0 -553
  37. data/lib/coral_core/resource.rb +0 -243
  38. data/lib/coral_core/template/environment.rb +0 -72
  39. data/lib/coral_core/template/json.rb +0 -13
  40. data/lib/coral_core/template/wrapper.rb +0 -13
  41. data/lib/coral_core/template/yaml.rb +0 -13
  42. data/lib/coral_core/template.rb +0 -92
  43. data/lib/coral_core/util/cli.rb +0 -293
  44. data/lib/coral_core/util/data.rb +0 -389
  45. data/lib/coral_core/util/disk.rb +0 -105
  46. data/lib/coral_core/util/git.rb +0 -40
  47. data/lib/coral_core/util/interface.rb +0 -190
  48. data/lib/coral_core/util/process.rb +0 -43
  49. data/lib/coral_core/util/shell.rb +0 -183
  50. data/lib/coral_core.rb +0 -375
  51. data/locales/en.yml +0 -8
  52. data/spec/coral_core/interface_spec.rb +0 -489
  53. data/spec/coral_mock_input.rb +0 -29
  54. data/spec/coral_test_kernel.rb +0 -22
  55. data/spec/spec_helper.rb +0 -15
@@ -1,293 +0,0 @@
1
- module Coral
2
- module Util
3
- module CLI
4
-
5
- #-------------------------------------------------------------------------
6
- # Utilities
7
-
8
- def self.message(name, default = nil)
9
- if default.nil?
10
- default = :none
11
- end
12
- return I18n.t(name.to_s, :default_value => default.to_s)
13
- end
14
-
15
- #-------------------------------------------------------------------------
16
- # Parser
17
-
18
- class Parser
19
-
20
- attr_accessor :parser
21
- attr_accessor :options
22
- attr_accessor :arguments
23
- attr_accessor :processed
24
-
25
- #---
26
-
27
- def initialize(args, banner = '', help = '')
28
-
29
- @parser = OptionParser.new
30
-
31
- self.options = {}
32
- self.arguments = {}
33
- self.processed = false
34
-
35
- @arg_settings = []
36
-
37
- self.banner = banner
38
- self.help = help
39
-
40
- yield(self) if block_given?
41
-
42
- parse_command(args)
43
- end
44
-
45
- #---
46
-
47
- def self.split(args, banner, separator = '')
48
- main_args = nil
49
- sub_command = nil
50
- sub_args = []
51
-
52
- args.each_index do |index|
53
- if !args[index].start_with?('-')
54
- main_args = args[0, index]
55
- sub_command = args[index]
56
- sub_args = args[index + 1, args.length - index + 1]
57
- break
58
- end
59
- end
60
-
61
- main_args = args.dup if main_args.nil?
62
- results = [ Parser.new(main_args, banner, separator) ]
63
-
64
- if sub_command
65
- results << [ sub_command, sub_args ]
66
- end
67
-
68
- return results.flatten
69
- end
70
-
71
- #---
72
-
73
- def banner=banner
74
- parser.banner = banner
75
- end
76
-
77
- #---
78
-
79
- def help=help
80
- if help.is_a?(Array)
81
- help.each do |line|
82
- parser.separator line
83
- end
84
- else
85
- parser.separator help
86
- end
87
- end
88
-
89
- #---
90
-
91
- def parse_command(args)
92
- args = args.dup
93
- error = false
94
-
95
- self.processed = false
96
-
97
- parser.on_tail('-h', '--help', CLI.message('coral.core.util.cli.options.help')) do
98
- puts parser.help.chomp
99
- options[:help] = true
100
- return
101
- end
102
-
103
- parser.parse!(args)
104
-
105
- @arg_settings.each_with_index do |settings, index|
106
- if index >= args.length
107
- value = nil
108
- else
109
- value = Util::Data.value(args[index])
110
- end
111
-
112
- if !value.nil? && settings.has_key?(:allowed)
113
- allowed = settings[:allowed]
114
- case allowed
115
- when Class
116
- unless value.is_a?(allowed)
117
- Coral.ui.error(CLI.message(settings[:message]))
118
- error = true
119
- end
120
- when Array
121
- unless allowed.include(value)
122
- Coral.ui.error(CLI.message(settings[:message]))
123
- error = true
124
- end
125
- end
126
- end
127
-
128
- if value.nil?
129
- if settings.has_key?(:default)
130
- value = settings[:default]
131
- else
132
- error = true
133
- end
134
- end
135
-
136
- if !value.nil? && settings.has_key?(:block)
137
- value = settings[:block].call(value)
138
- error = true if value.nil?
139
- end
140
-
141
- break if error
142
- self.arguments[settings[:name]] = value
143
- end
144
-
145
- if error
146
- Coral.ui.error(CLI.message('coral.util.cli.parse.error'))
147
- puts parser.help.chomp
148
- else
149
- self.processed = true
150
- end
151
-
152
- rescue OptionParser::InvalidOption
153
- raise Errors::CLIInvalidOptions, :help => parser.help.chomp
154
- end
155
-
156
- #---
157
-
158
- def option(name, default, option_str, allowed_values, message_id, config = {})
159
- config = Config.ensure(config)
160
- name = name.to_sym
161
- options[name] = config.get(name, default)
162
-
163
- message_name = name.to_s + '_message'
164
- message = CLI.message(message_id, options[name])
165
-
166
- option_str = Util::Data.array(option_str)
167
-
168
- if allowed_values
169
- parser.on(*option_str, allowed_values, config.get(message_name.to_sym, message)) do |value|
170
- value = yield(value) if block_given?
171
- options[name] = value unless value.nil?
172
- end
173
- else
174
- parser.on(*option_str, config.get(message_name.to_sym, message)) do |value|
175
- value = yield(value) if block_given?
176
- options[name] = value unless value.nil?
177
- end
178
- end
179
- end
180
-
181
- #---
182
-
183
- def arg(name, default, allowed_values, message_id, config = {}, &block)
184
- config = Config.ensure(config)
185
- name = name.to_sym
186
-
187
- message_name = name.to_s + '_message'
188
- message = CLI.message(message_id, arguments[name])
189
-
190
- settings = {
191
- :name => name,
192
- :default => config.get(name, default),
193
- :message => config.get(message_name.to_sym, message)
194
- }
195
- settings[:allowed] = allowed_values if allowed_values
196
- settings[:block] = block if block
197
-
198
- @arg_settings << settings
199
- end
200
-
201
- #---
202
-
203
- def option_bool(name, default, option_str, message_id, config = {})
204
- option(name, default, option_str, nil, message_id, config) do |value|
205
- value = Util::Data.value(value)
206
- if value == true || value == false
207
- block_given? ? yield(value) : value
208
- else
209
- nil
210
- end
211
- end
212
- end
213
-
214
- #---
215
-
216
- def arg_bool(name, default, message_id, config = {})
217
- arg(name, default, nil, message_id, config) do |value|
218
- value = Util::Data.value(value)
219
- if value == true || value == false
220
- block_given? ? yield(value) : value
221
- else
222
- nil
223
- end
224
- end
225
- end
226
-
227
- #---
228
-
229
- def option_int(name, default, option_str, message_id, config = {})
230
- option(name, default, option_str, Integer, message_id, config) do |value|
231
- block_given? ? yield(value) : value
232
- end
233
- end
234
-
235
- #---
236
-
237
- def arg_int(name, default, message_id, config = {})
238
- arg(name, default, Integer, message_id, config) do |value|
239
- block_given? ? yield(value) : value
240
- end
241
- end
242
-
243
- #---
244
-
245
- def option_float(name, default, option_str, message_id, config = {})
246
- option(name, default, option_str, Float, message_id, config) do |value|
247
- block_given? ? yield(value) : value
248
- end
249
- end
250
-
251
- #---
252
-
253
- def arg_float(name, default, message_id, config = {})
254
- arg(name, default, Float, message_id, config) do |value|
255
- block_given? ? yield(value) : value
256
- end
257
- end
258
-
259
- #---
260
-
261
- def option_str(name, default, option_str, message_id, config = {})
262
- option(name, default, option_str, nil, message_id, config) do |value|
263
- block_given? ? yield(value) : value
264
- end
265
- end
266
-
267
- #---
268
-
269
- def arg_str(name, default, message_id, config = {})
270
- arg(name, default, nil, message_id, config) do |value|
271
- block_given? ? yield(value) : value
272
- end
273
- end
274
-
275
- #---
276
-
277
- def option_array(name, default, option_str, message_id, config = {})
278
- option(name, default, option_str, Array, message_id, config) do |value|
279
- block_given? ? yield(value) : value
280
- end
281
- end
282
-
283
- #---
284
-
285
- def arg_array(name, default, message_id, config = {})
286
- arg(name, default, Array, message_id, config) do |value|
287
- block_given? ? yield(value) : value
288
- end
289
- end
290
- end
291
- end
292
- end
293
- end
@@ -1,389 +0,0 @@
1
-
2
- module Coral
3
- module Util
4
- class Data
5
-
6
- #-----------------------------------------------------------------------------
7
- # Type checking
8
-
9
- def self.undef?(value)
10
- if value.nil? ||
11
- (value.is_a?(Symbol) && value == :undef || value == :undefined) ||
12
- (value.is_a?(String) && value.match(/^\s*(undef|UNDEF|Undef|nil|NIL|Nil)\s*$/))
13
- return true
14
- end
15
- return false
16
- end
17
-
18
- #---
19
-
20
- def self.true?(value)
21
- if value == true ||
22
- (value.is_a?(String) && value.match(/^\s*(true|TRUE|True)\s*$/))
23
- return true
24
- end
25
- return false
26
- end
27
-
28
- #---
29
-
30
- def self.false?(value)
31
- if value == false ||
32
- (value.is_a?(String) && value.match(/^\s*(false|FALSE|False)\s*$/))
33
- return true
34
- end
35
- return false
36
- end
37
-
38
- #---
39
-
40
- def self.empty?(value)
41
- if undef?(value) || false?(value) || (value.respond_to?('empty?') && value.empty?)
42
- return true
43
- end
44
- return false
45
- end
46
-
47
- #---
48
-
49
- def self.exists?(data, keys, check_empty = false)
50
- keys = [ keys ] unless keys.is_a?(Array)
51
- keys.each do |key|
52
- return false unless data.is_a?(Hash) && data.has_key?(key)
53
- return false if check_empty && empty?(data[key])
54
- data = data[key]
55
- end
56
- return true
57
- end
58
-
59
- #-----------------------------------------------------------------------------
60
- # Translation
61
-
62
- def self.symbol_map(data)
63
- results = {}
64
- return data unless data
65
-
66
- case data
67
- when Hash
68
- data.each do |key, value|
69
- results[key.to_sym] = symbol_map(value)
70
- end
71
- else
72
- results = data
73
- end
74
- return results
75
- end
76
-
77
- #---
78
-
79
- def self.string_map(data)
80
- results = {}
81
- return data unless data
82
-
83
- case data
84
- when Hash
85
- data.each do |key, value|
86
- results[key.to_s] = string_map(value)
87
- end
88
- else
89
- results = data
90
- end
91
- return results
92
- end
93
-
94
- #---
95
-
96
- def self.parse_json(json_text)
97
- output = ''
98
- begin
99
- output = MultiJson.load(json_text)
100
-
101
- rescue Exception
102
- end
103
- return output
104
- end
105
-
106
- #---
107
-
108
- def self.to_json(data, pretty = true)
109
- output = ''
110
- begin
111
- output = MultiJson.dump(data, :pretty => pretty)
112
-
113
- rescue Exception
114
- end
115
- return output
116
- end
117
-
118
- #---
119
-
120
- def self.parse_yaml(yaml_text)
121
- output = ''
122
- begin
123
- output = YAML.load(yaml_text)
124
-
125
- rescue Exception
126
- end
127
- return output
128
- end
129
-
130
- #---
131
-
132
- def self.to_yaml(data)
133
- output = ''
134
- begin
135
- output = YAML.dump(data)
136
-
137
- rescue Exception
138
- end
139
- return output
140
- end
141
-
142
- #---
143
-
144
- def self.value(value)
145
- case value
146
- when String
147
- if undef?(value)
148
- value = nil
149
- elsif true?(value)
150
- value = true
151
- elsif false?(value)
152
- value = false
153
- end
154
-
155
- when Array
156
- value.each_with_index do |item, index|
157
- value[index] = value(item)
158
- end
159
-
160
- when Hash
161
- value.each do |key, data|
162
- value[key] = value(data)
163
- end
164
- end
165
- return value
166
- end
167
-
168
- #---
169
-
170
- def self.filter(data, method = false)
171
- if method && method.is_a?(Symbol) &&
172
- [ :array, :hash, :string, :symbol, :test ].include?(method.to_sym)
173
- return send(method, data)
174
- end
175
- return data
176
- end
177
-
178
- #---
179
-
180
- def self.array(data, default = [], split_string = false)
181
- result = default
182
- if data
183
- case data
184
- when Array
185
- result = data
186
- when String
187
- result = [ ( split_string ? data.split(/\s*,\s*/) : data ) ]
188
- else
189
- result = [ data ]
190
- end
191
- end
192
- return result
193
- end
194
-
195
- #---
196
-
197
- def self.hash(data, default = {})
198
- result = default
199
- if data
200
- case data
201
- when Hash
202
- result = data
203
- else
204
- result = {}
205
- end
206
- end
207
- return result
208
- end
209
-
210
- #---
211
-
212
- def self.string(data, default = '')
213
- result = default
214
- if data
215
- case data
216
- when String
217
- result = data
218
- else
219
- result = data.to_s
220
- end
221
- end
222
- return result
223
- end
224
-
225
- #---
226
-
227
- def self.symbol(data, default = :undefined)
228
- result = default
229
- if data
230
- case data
231
- when Symbol
232
- result = data
233
- when String
234
- result = data.to_sym
235
- else
236
- result = data.class.to_sym
237
- end
238
- end
239
- return result
240
- end
241
-
242
- #---
243
-
244
- def self.test(data)
245
- return false if Util::Data.empty?(data)
246
- return true
247
- end
248
-
249
- #-----------------------------------------------------------------------------
250
- # Operations
251
-
252
- def self.merge(data, force = true)
253
- value = data
254
-
255
- # Special case because this method is called from within Config.new so we
256
- # can not use Config.ensure, as that would cause an infinite loop.
257
- force = force.is_a?(Coral::Config) ? force.get(:force, true) : force
258
-
259
- if data.is_a?(Array)
260
- value = undef?(data[0]) ? nil : data.shift.clone
261
-
262
- data.each do |item|
263
- item = undef?(item) ? nil : item.clone
264
-
265
- case value
266
- when Hash
267
- begin
268
- require 'deep_merge'
269
- value = force ? value.deep_merge!(item) : value.deep_merge(item)
270
-
271
- rescue LoadError
272
- if item.is_a?(Hash) # Non recursive top level by default.
273
- value = value.merge(item)
274
- elsif force
275
- value = item
276
- end
277
- end
278
- when Array
279
- if item.is_a?(Array)
280
- value = value.concat(item).uniq
281
- elsif force
282
- value = item
283
- end
284
-
285
- else
286
- value = item if force || item.is_a?(String) || item.is_a?(Symbol)
287
- end
288
- end
289
- end
290
-
291
- return value
292
- end
293
-
294
- #---
295
-
296
- def self.interpolate(value, scope, options = {})
297
-
298
- pattern = ( options.has_key?(:pattern) ? options[:pattern] : '\$(\{)?([a-zA-Z0-9\_\-]+)(\})?' )
299
- group = ( options.has_key?(:var_group) ? options[:var_group] : 2 )
300
- flags = ( options.has_key?(:flags) ? options[:flags] : '' )
301
-
302
- if scope.is_a?(Hash)
303
- regexp = Regexp.new(pattern, flags.split(''))
304
-
305
- replace = lambda do |item|
306
- matches = item.match(regexp)
307
- result = nil
308
-
309
- #dbg(item, 'item')
310
- #dbg(matches, 'matches')
311
-
312
- unless matches.nil?
313
- replacement = scope.search(matches[group], options)
314
- result = item.gsub(matches[0], replacement) unless replacement.nil?
315
- end
316
- return result
317
- end
318
-
319
- case value
320
- when String
321
- #dbg(value, 'interpolate (string) -> init')
322
- while (temp = replace.call(value))
323
- #dbg(temp, 'interpolate (string) -> replacement')
324
- value = temp
325
- end
326
-
327
- when Hash
328
- #dbg(value, 'interpolate (hash) -> init')
329
- value.each do |key, data|
330
- #dbg(data, "interpolate (#{key}) -> data")
331
- value[key] = interpolate(data, scope, options)
332
- end
333
- end
334
- end
335
- #dbg(value, 'interpolate -> result')
336
- return value
337
- end
338
-
339
- #-----------------------------------------------------------------------------
340
- # Utilities
341
-
342
- def self.prefix(prefix, data)
343
- result = nil
344
-
345
- unless prefix.is_a?(String) && ! empty?(prefix)
346
- prefix = ''
347
- end
348
-
349
- case data
350
- when String, Symbol
351
- result = ( prefix.empty? ? data.to_s : prefix + '_' + data.to_s )
352
-
353
- when Array
354
- result = []
355
- data.each do |value|
356
- result << prefix(prefix, value)
357
- end
358
-
359
- when Hash
360
- result = {}
361
- data.each do |key, value|
362
- result[prefix(prefix, key)] = value
363
- end
364
- end
365
- return result
366
- end
367
-
368
- #---
369
-
370
- def self.ensure(test, success_value = nil, failure_value = nil)
371
- success_value = (success_value ? success_value : test)
372
- failure_value = (failure_value ? failure_value : nil)
373
-
374
- if empty?(test)
375
- value = failure_value
376
- else
377
- value = success_value
378
- end
379
- return value
380
- end
381
-
382
- #---
383
-
384
- def self.ensure_value(value, failure_value = nil)
385
- return self.ensure(value, nil, failure_value)
386
- end
387
- end
388
- end
389
- end