corl 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,404 @@
1
+
2
+ module CORL
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
+ if keys.is_a?(String) || keys.is_a?(Symbol)
51
+ keys = [ keys ]
52
+ end
53
+ key = keys.shift.to_sym
54
+
55
+ if data.has_key?(key)
56
+ value = data[key]
57
+
58
+ if keys.empty?
59
+ return false if check_empty && empty?(value)
60
+ return true
61
+ else
62
+ return exists?(data[key], keys)
63
+ end
64
+ end
65
+ return false
66
+ end
67
+
68
+ #-----------------------------------------------------------------------------
69
+ # Translation
70
+
71
+ def self.symbol_map(data)
72
+ results = {}
73
+ return data unless data
74
+
75
+ case data
76
+ when Hash
77
+ data.each do |key, value|
78
+ results[key.to_sym] = symbol_map(value)
79
+ end
80
+ else
81
+ results = data
82
+ end
83
+ return results
84
+ end
85
+
86
+ #---
87
+
88
+ def self.string_map(data)
89
+ results = {}
90
+ return data unless data
91
+
92
+ case data
93
+ when Hash
94
+ data.each do |key, value|
95
+ results[key.to_s] = string_map(value)
96
+ end
97
+ else
98
+ results = data
99
+ end
100
+ return results
101
+ end
102
+
103
+ #---
104
+
105
+ def self.parse_json(json_text)
106
+ return MultiJson.load(json_text)
107
+ end
108
+
109
+ #---
110
+
111
+ def self.to_json(data, pretty = true)
112
+ return MultiJson.dump(data, :pretty => pretty)
113
+ end
114
+
115
+ #---
116
+
117
+ def self.parse_yaml(yaml_text)
118
+ return YAML.load(yaml_text)
119
+ end
120
+
121
+ #---
122
+
123
+ def self.to_yaml(data)
124
+ return YAML.dump(data)
125
+ end
126
+
127
+ #---
128
+
129
+ def self.value(value)
130
+ case value
131
+ when String
132
+ if undef?(value)
133
+ value = nil
134
+ elsif true?(value)
135
+ value = true
136
+ elsif false?(value)
137
+ value = false
138
+ end
139
+
140
+ when Array
141
+ value.each_with_index do |item, index|
142
+ value[index] = value(item)
143
+ end
144
+
145
+ when Hash
146
+ value.each do |key, data|
147
+ value[key] = value(data)
148
+ end
149
+ end
150
+ return value
151
+ end
152
+
153
+ #---
154
+
155
+ def self.filter(data, method = false)
156
+ if method && method.is_a?(Symbol) &&
157
+ [ :array, :hash, :string, :symbol, :test ].include?(method.to_sym)
158
+ return send(method, data)
159
+ end
160
+ return data
161
+ end
162
+
163
+ #---
164
+
165
+ def self.array(data, default = [], split_string = false)
166
+ result = default
167
+ if data
168
+ case data
169
+ when Array
170
+ result = data
171
+ when String
172
+ result = [ ( split_string ? data.split(/\s*,\s*/) : data ) ]
173
+ else
174
+ result = [ data ]
175
+ end
176
+ end
177
+ return result
178
+ end
179
+
180
+ #---
181
+
182
+ def self.hash(data, default = {})
183
+ result = default
184
+ if data
185
+ case data
186
+ when Hash
187
+ result = data
188
+ else
189
+ result = {}
190
+ end
191
+ end
192
+ return result
193
+ end
194
+
195
+ #---
196
+
197
+ def self.string(data, default = '')
198
+ result = default
199
+ if data
200
+ case data
201
+ when String
202
+ result = data
203
+ else
204
+ result = data.to_s
205
+ end
206
+ end
207
+ return result
208
+ end
209
+
210
+ #---
211
+
212
+ def self.symbol(data, default = :undefined)
213
+ result = default
214
+ if data
215
+ case data
216
+ when Symbol
217
+ result = data
218
+ when String
219
+ result = data.to_sym
220
+ else
221
+ result = data.class.to_sym
222
+ end
223
+ end
224
+ return result
225
+ end
226
+
227
+ #---
228
+
229
+ def self.test(data)
230
+ return false if Util::Data.empty?(data)
231
+ return true
232
+ end
233
+
234
+ #-----------------------------------------------------------------------------
235
+ # Operations
236
+
237
+ def self.clean(data)
238
+ data.keys.each do |key|
239
+ data.delete(key) if data[key].nil?
240
+ end
241
+ data
242
+ end
243
+
244
+ #---
245
+
246
+ def self.merge(data, force = true)
247
+ value = data
248
+
249
+ # Special case because this method is called from within Config.new so we
250
+ # can not use Config.ensure, as that would cause an infinite loop.
251
+ force = force.is_a?(CORL::Config) ? force.get(:force, true) : force
252
+
253
+ if data.is_a?(Array)
254
+ value = undef?(data[0]) ? nil : data.shift.clone
255
+
256
+ data.each do |item|
257
+ item = undef?(item) ? nil : item.clone
258
+
259
+ case value
260
+ when Hash
261
+ begin
262
+ require 'deep_merge'
263
+ value = force ? value.deep_merge!(item) : value.deep_merge(item)
264
+
265
+ rescue LoadError
266
+ if item.is_a?(Hash) # Non recursive top level by default.
267
+ value = value.merge(item)
268
+ elsif force
269
+ value = item
270
+ end
271
+ end
272
+ when Array
273
+ if item.is_a?(Array)
274
+ value = value.concat(item).uniq
275
+ elsif force
276
+ value = item
277
+ end
278
+
279
+ else
280
+ value = item if force || item.is_a?(String) || item.is_a?(Symbol)
281
+ end
282
+ end
283
+ end
284
+
285
+ return value
286
+ end
287
+
288
+ #---
289
+
290
+ def self.interpolate(value, scope, options = {})
291
+
292
+ pattern = ( options.has_key?(:pattern) ? options[:pattern] : '\$(\{)?([a-zA-Z0-9\_\-]+)(\})?' )
293
+ group = ( options.has_key?(:var_group) ? options[:var_group] : 2 )
294
+ flags = ( options.has_key?(:flags) ? options[:flags] : '' )
295
+
296
+ if scope.is_a?(Hash)
297
+ regexp = Regexp.new(pattern, flags.split(''))
298
+
299
+ replace = lambda do |item|
300
+ matches = item.match(regexp)
301
+ result = nil
302
+
303
+ #dbg(item, 'item')
304
+ #dbg(matches, 'matches')
305
+
306
+ unless matches.nil?
307
+ replacement = scope.search(matches[group], options)
308
+ result = item.gsub(matches[0], replacement) unless replacement.nil?
309
+ end
310
+ return result
311
+ end
312
+
313
+ case value
314
+ when String
315
+ #dbg(value, 'interpolate (string) -> init')
316
+ while (temp = replace.call(value))
317
+ #dbg(temp, 'interpolate (string) -> replacement')
318
+ value = temp
319
+ end
320
+
321
+ when Hash
322
+ #dbg(value, 'interpolate (hash) -> init')
323
+ value.each do |key, data|
324
+ #dbg(data, "interpolate (#{key}) -> data")
325
+ value[key] = interpolate(data, scope, options)
326
+ end
327
+ end
328
+ end
329
+ #dbg(value, 'interpolate -> result')
330
+ return value
331
+ end
332
+
333
+ #---
334
+
335
+ def self.rm_keys(data, keys)
336
+ keys = [ keys ] unless keys.is_a?(Array)
337
+ keys.each do |key|
338
+ data.delete(key)
339
+ end
340
+ data
341
+ end
342
+
343
+ #---
344
+
345
+ def self.subset(data, keys)
346
+ keys = [ keys ] unless keys.is_a?(Array)
347
+ new_data = {}
348
+ keys.each do |key|
349
+ new_data[key] = data[key] if data.has_key?(key)
350
+ end
351
+ new_data
352
+ end
353
+
354
+ #-----------------------------------------------------------------------------
355
+ # Utilities
356
+
357
+ def self.prefix(prefix, data)
358
+ result = nil
359
+
360
+ unless prefix.is_a?(String) && ! empty?(prefix)
361
+ prefix = ''
362
+ end
363
+
364
+ case data
365
+ when String, Symbol
366
+ result = ( prefix.empty? ? data.to_s : prefix + '_' + data.to_s )
367
+
368
+ when Array
369
+ result = []
370
+ data.each do |value|
371
+ result << prefix(prefix, value)
372
+ end
373
+
374
+ when Hash
375
+ result = {}
376
+ data.each do |key, value|
377
+ result[prefix(prefix, key)] = value
378
+ end
379
+ end
380
+ return result
381
+ end
382
+
383
+ #---
384
+
385
+ def self.ensure(test, success_value = nil, failure_value = nil)
386
+ success_value = (success_value ? success_value : test)
387
+ failure_value = (failure_value ? failure_value : nil)
388
+
389
+ if empty?(test)
390
+ value = failure_value
391
+ else
392
+ value = success_value
393
+ end
394
+ return value
395
+ end
396
+
397
+ #---
398
+
399
+ def self.ensure_value(value, failure_value = nil)
400
+ return self.ensure(value, nil, failure_value)
401
+ end
402
+ end
403
+ end
404
+ end
@@ -0,0 +1,114 @@
1
+
2
+ module CORL
3
+ module Util
4
+ class Disk
5
+
6
+ #-----------------------------------------------------------------------------
7
+ # Properties
8
+
9
+ @@files = {}
10
+
11
+ @@separator = false
12
+ @@description = ''
13
+
14
+ #-----------------------------------------------------------------------------
15
+ # Utilities
16
+
17
+ def self.exists?(file)
18
+ return ::File.exists?(::File.expand_path(file))
19
+ end
20
+
21
+ #---
22
+
23
+ def self.filename(file_name)
24
+ return ( file_name.is_a?(Array) ? file_name.join(::File::SEPARATOR) : file_name.to_s )
25
+ end
26
+
27
+ #---
28
+
29
+ def self.open(file_name, options = {}, reset = false)
30
+ mode = options[:mode].to_s
31
+
32
+ @@separator = ( options[:separator] ? options[:separator] : false )
33
+ @@description = ( options[:description] ? options[:description] : '' )
34
+
35
+ if @@files.has_key?(file_name) && ! reset
36
+ reset = true if ! mode.empty? && mode != @@files[file_name][:mode]
37
+ end
38
+
39
+ if ! @@files.has_key?(file_name) || ! @@files[file_name][:file] || reset
40
+ @@files[file_name][:file].close if @@files[file_name] && @@files[file_name][:file]
41
+ unless mode.empty? || ( mode == 'r' && ! ::File.exists?(file_name) )
42
+ @@files[file_name] = {
43
+ :file => ::File.open(file_name, mode),
44
+ :mode => mode,
45
+ }
46
+ end
47
+ end
48
+ return nil unless @@files[file_name]
49
+ return @@files[file_name][:file]
50
+ end
51
+
52
+ #---
53
+
54
+ def self.read(file_name, options = {})
55
+ options[:mode] = ( options[:mode] ? options[:mode] : 'r' )
56
+ file = open(file_name, options)
57
+
58
+ if file
59
+ file.pos = 0 if options[:mode] == 'r'
60
+ return file.read
61
+ end
62
+ return nil
63
+ end
64
+
65
+ #---
66
+
67
+ def self.write(file_name, data, options = {})
68
+ options[:mode] = ( options[:mode] ? options[:mode] : 'w' )
69
+ file = open(file_name, options)
70
+
71
+ if file
72
+ file.pos = 0 if options[:mode] == 'w'
73
+ success = file.write(data)
74
+ file.flush
75
+ return success
76
+ end
77
+ return nil
78
+ end
79
+
80
+ #---
81
+
82
+ def self.delete(file_path)
83
+ return ::File.delete(file_path)
84
+ end
85
+
86
+ #---
87
+
88
+ def self.log(data, options = {})
89
+ reset = ( options[:file_name] || options[:mode] )
90
+ file = open(( options[:file_name] ? options[:file_name] : 'log.txt' ), options, reset)
91
+ if file
92
+ file.write("--------------------------------------\n") if @@separator
93
+ file.write("#{@@description}\n") if @@description
94
+ file.write("#{data}\n")
95
+ end
96
+ end
97
+
98
+ #---
99
+
100
+ def self.close(file_names = [])
101
+ file_names = @@files.keys unless file_names && ! file_names.empty?
102
+
103
+ unless file_names.is_a?(Array)
104
+ file_names = [ file_names ]
105
+ end
106
+
107
+ file_names.each do |file_name|
108
+ @@files[file_name][:file].close if @@files[file_name] && @@files[file_name][:file]
109
+ @@files.delete(file_name)
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,47 @@
1
+ module CORL
2
+ module Util
3
+ class Git < ::Grit::Repo
4
+
5
+ #-----------------------------------------------------------------------------
6
+ # Constructor / Destructor
7
+
8
+ def initialize(path, options = {})
9
+ epath = File.expand_path(path)
10
+ git_dir = File.join(epath, '.git')
11
+
12
+ @bare = (options[:is_bare] ? true : false)
13
+
14
+ Grit.debug = true if CORL.log_level == :debug
15
+
16
+ if File.exist?(git_dir)
17
+ self.working_dir = epath
18
+
19
+ if File.directory?(git_dir)
20
+ self.path = git_dir
21
+ else
22
+ git_dir = Util::Disk.read(git_dir)
23
+ unless git_dir.nil?
24
+ git_dir = git_dir.gsub(/^gitdir\:\s*/, '').strip
25
+ self.path = git_dir if File.directory?(git_dir)
26
+ end
27
+ end
28
+
29
+ elsif File.directory?(epath) && (options[:is_bare] || (epath =~ /\.git$/ && File.exist?(File.join(epath, 'HEAD'))))
30
+ self.path = epath
31
+ @bare = true
32
+
33
+ else
34
+ self.path = git_dir
35
+ end
36
+
37
+ self.git = ::Grit::Git.new(self.path)
38
+ self.git.work_tree = epath
39
+
40
+ #unless File.directory?(epath) && self.git.exist?
41
+ # FileUtils.mkdir_p(epath) unless File.directory?(epath)
42
+ # self.git.init({ :bare => @bare })
43
+ #end
44
+ end
45
+ end
46
+ end
47
+ end