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,489 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ module CORL
5
+
6
+ describe Util::Interface do
7
+
8
+ #---------------------------------------------------------------------------
9
+ # UI functionality
10
+
11
+ describe "#say" do
12
+
13
+ #-------------------------------------------------------------------------
14
+ # Delegation
15
+
16
+ it "can delegate to another class that contains this method" do
17
+ output = double('output')
18
+ output.should_receive(:puts).with('message')
19
+
20
+ ui = Util::Interface.new({
21
+ :output => output,
22
+ :printer => :puts,
23
+ })
24
+ Util::Interface.new({ :ui_delegate => ui }).say(:info, 'message')
25
+ end
26
+
27
+ #-------------------------------------------------------------------------
28
+ # Output formats
29
+
30
+ it "prints a message with default options" do
31
+ output1 = double('output1')
32
+ output1.should_receive(:puts).with('message')
33
+
34
+ Util::Interface.new({ :output => output1 }).say(:info, 'message')
35
+
36
+ output2 = double('output2')
37
+ output2.should_receive(:puts).with('[component] message')
38
+
39
+ Util::Interface.new({
40
+ :resource => 'component',
41
+ :output => output2,
42
+ }).say(:info, 'message')
43
+ end
44
+
45
+ #---
46
+
47
+ it "prints a message with and without newlines included" do
48
+ output1 = double('output1')
49
+ output1.should_receive(:puts).with('message')
50
+
51
+ test = Util::Interface.new({ :output => output1 })
52
+ test.say(:info, 'message', { :new_line => true })
53
+
54
+ output2 = double('output2')
55
+ output2.should_receive(:print).with('message')
56
+
57
+ test = Util::Interface.new({ :output => output2 })
58
+ test.say(:info, 'message', { :new_line => false })
59
+ end
60
+
61
+ #---
62
+
63
+ it "routes message to output and error channels based on type given" do
64
+ [:info, :warn, :success].each do |type|
65
+ output = double('output')
66
+ output.should_receive(:puts).with('message')
67
+
68
+ Util::Interface.new({
69
+ :output => output,
70
+ :printer => :puts,
71
+ :color => false,
72
+ }).say(type, 'message')
73
+ end
74
+
75
+ error = double('error')
76
+ error.should_receive(:puts).with('message')
77
+
78
+ Util::Interface.new({
79
+ :error => error,
80
+ :printer => :puts,
81
+ :color => false,
82
+ }).say(:error, 'message')
83
+ end
84
+
85
+ #---
86
+
87
+ it "routes message to output and error channels based on channel given" do
88
+ [:info, :warn, :success].each do |type|
89
+ output = double('output')
90
+ output.should_receive(:puts).with('message')
91
+
92
+ Util::Interface.new({
93
+ :output => output,
94
+ :printer => :puts,
95
+ }).say(:info, 'message', { :channel => type })
96
+ end
97
+
98
+ error = double('error')
99
+ error.should_receive(:puts).with('message')
100
+
101
+ Util::Interface.new({
102
+ :error => error,
103
+ :printer => :puts,
104
+ :color => false,
105
+ }).say(:info, 'message', { :channel => :error })
106
+ end
107
+ end
108
+
109
+ #---
110
+
111
+ describe "#ask" do
112
+
113
+ #-------------------------------------------------------------------------
114
+ # Delegation
115
+
116
+ it "can delegate to another class that contains this method"
117
+
118
+ #-------------------------------------------------------------------------
119
+ # Input
120
+
121
+ it "displays a prompt and returns user feedback"
122
+ end
123
+
124
+ #---
125
+
126
+ describe "#info" do
127
+
128
+ #-------------------------------------------------------------------------
129
+ # Delegation
130
+
131
+ it "can delegate to another class that contains this method" do
132
+ output = double('output')
133
+ output.should_receive(:puts).with('message')
134
+
135
+ ui = Util::Interface.new({
136
+ :output => output,
137
+ :printer => :puts,
138
+ })
139
+ Util::Interface.new({ :ui_delegate => ui }).info('message')
140
+ end
141
+
142
+ #-------------------------------------------------------------------------
143
+ # Printing
144
+
145
+ it "prints an uncolored information message" do
146
+ output = double('output')
147
+ output.should_receive(:puts).with('message')
148
+
149
+ Util::Interface.new({
150
+ :output => output,
151
+ :printer => :puts,
152
+ }).info('message')
153
+ end
154
+ end
155
+
156
+ #---
157
+
158
+ describe "#warn" do
159
+
160
+ #-------------------------------------------------------------------------
161
+ # Delegation
162
+
163
+ it "can delegate to another class that contains this method" do
164
+ output = double('output')
165
+ output.should_receive(:puts).with('message')
166
+
167
+ ui = Util::Interface.new({
168
+ :output => output,
169
+ :printer => :puts,
170
+ :color => false,
171
+ })
172
+ Util::Interface.new({ :ui_delegate => ui }).warn('message')
173
+ end
174
+
175
+ #-------------------------------------------------------------------------
176
+ # Printing
177
+
178
+ it "prints an uncolored warning message" do
179
+ output = double('output')
180
+ output.should_receive(:puts).with('message')
181
+
182
+ Util::Interface.new({
183
+ :output => output,
184
+ :printer => :puts,
185
+ :color => false,
186
+ }).warn('message')
187
+ end
188
+
189
+ #---
190
+
191
+ it "prints a colored warning message" do
192
+ output = double('output')
193
+ output.should_receive(:print).with(/^\e\[33mmessage\e\[0m$/)
194
+
195
+ Util::Interface.new({
196
+ :output => output,
197
+ :color => true,
198
+ }).warn('message', { :new_line => false })
199
+ end
200
+ end
201
+
202
+ #---
203
+
204
+ describe "#error" do
205
+
206
+ #-------------------------------------------------------------------------
207
+ # Delegation
208
+
209
+ it "can delegate to another class that contains this method" do
210
+ error = double('error')
211
+ error.should_receive(:puts).with('message')
212
+
213
+ ui = Util::Interface.new({
214
+ :error => error,
215
+ :printer => :puts,
216
+ :color => false,
217
+ })
218
+ Util::Interface.new({ :ui_delegate => ui }).error('message')
219
+ end
220
+
221
+ #-------------------------------------------------------------------------
222
+ # Printing
223
+
224
+ it "prints an uncolored error message" do
225
+ error = double('error')
226
+ error.should_receive(:puts).with('message')
227
+
228
+ Util::Interface.new({
229
+ :error => error,
230
+ :printer => :puts,
231
+ :color => false,
232
+ }).error('message')
233
+ end
234
+
235
+ #---
236
+
237
+ it "prints a colored error message" do
238
+ error = double('error')
239
+ error.should_receive(:print).with(/^\e\[31mmessage\e\[0m$/)
240
+
241
+ Util::Interface.new({
242
+ :error => error,
243
+ :color => true,
244
+ }).error('message', { :new_line => false })
245
+ end
246
+ end
247
+
248
+ #---
249
+
250
+ describe "#success" do
251
+
252
+ #-------------------------------------------------------------------------
253
+ # Delegation
254
+
255
+ it "can delegate to another class that contains this method" do
256
+ output = double('output')
257
+ output.should_receive(:puts).with('message')
258
+
259
+ ui = Util::Interface.new({
260
+ :output => output,
261
+ :printer => :puts,
262
+ :color => false,
263
+ })
264
+ Util::Interface.new({ :ui_delegate => ui }).success('message')
265
+ end
266
+
267
+ #-------------------------------------------------------------------------
268
+ # Printing
269
+
270
+ it "prints an uncolored success message" do
271
+ output = double('output')
272
+ output.should_receive(:puts).with('message')
273
+
274
+ Util::Interface.new({
275
+ :output => output,
276
+ :printer => :puts,
277
+ :color => false,
278
+ }).success('message')
279
+ end
280
+
281
+ #---
282
+
283
+ it "prints a colored success message" do
284
+ output = double('output')
285
+ output.should_receive(:print).with(/^\e\[32mmessage\e\[0m$/)
286
+
287
+ Util::Interface.new({
288
+ :output => output,
289
+ :color => true,
290
+ }).success('message', { :new_line => false })
291
+ end
292
+ end
293
+
294
+ #---------------------------------------------------------------------------
295
+ # Utilities
296
+
297
+ describe "#format_message" do
298
+
299
+ #-------------------------------------------------------------------------
300
+ # Delegation
301
+
302
+ it "can delegate to another class that contains this method" do
303
+ message = Util::Interface.new({
304
+ :ui_delegate => Util::Interface.new('delegate')
305
+ }).format_message(:info, 'message', { :prefix => true })
306
+
307
+ message.should == '[delegate] message'
308
+ end
309
+
310
+ #-------------------------------------------------------------------------
311
+ # Prefix specifications
312
+
313
+ it "returns without a prefix because no resource" do
314
+ message = Util::Interface.new.format_message(:info, 'message', { :prefix => true })
315
+ message.should == 'message'
316
+ end
317
+
318
+ #---
319
+
320
+ it "returns without a prefix because prefix is false" do
321
+ message = Util::Interface.new('component').format_message(:info, 'message', { :prefix => false })
322
+ message.should == 'message'
323
+ end
324
+
325
+ #---
326
+
327
+ it "returns without a prefix because no prefix option given" do
328
+ message = Util::Interface.new('component').format_message(:info, 'message')
329
+ message.should == 'message'
330
+ end
331
+
332
+ #---
333
+
334
+ it "returns with a prefix if resource and prefix option given" do
335
+ message = Util::Interface.new('component').format_message(:info, 'message', { :prefix => true })
336
+ message.should == '[component] message'
337
+ end
338
+
339
+ #-------------------------------------------------------------------------
340
+ # Color specifications
341
+
342
+ it "formats a error message in red if color enabled" do
343
+ message = Util::Interface.new({
344
+ :resource => 'component',
345
+ :color => true,
346
+ }).format_message(:error, 'message')
347
+ message.should match(/^\e\[31mmessage\e\[0m$/)
348
+ end
349
+
350
+ #---
351
+
352
+ it "formats a warning message in yellow if color enabled" do
353
+ message = Util::Interface.new({
354
+ :resource => 'component',
355
+ :color => true,
356
+ }).format_message(:warn, 'message')
357
+ message.should match(/^\e\[33mmessage\e\[0m$/)
358
+ end
359
+
360
+ #---
361
+
362
+ it "formats a success message in green if color enabled" do
363
+ message = Util::Interface.new({
364
+ :resource => 'component',
365
+ :color => true,
366
+ }).format_message(:success, 'message')
367
+ message.should match(/^\e\[32mmessage\e\[0m$/)
368
+ end
369
+ end
370
+
371
+ #---------------------------------------------------------------------------
372
+
373
+ describe "#safe_puts" do
374
+
375
+ #-------------------------------------------------------------------------
376
+ # Delegation
377
+
378
+ it "can delegate to another class that contains this method" do
379
+ output = double('output')
380
+ output.should_receive(:puts).with('message')
381
+
382
+ ui = Util::Interface.new({
383
+ :output => output,
384
+ :printer => :puts,
385
+ })
386
+ Util::Interface.new({ :ui_delegate => ui }).safe_puts('message')
387
+ end
388
+
389
+ #-------------------------------------------------------------------------
390
+ # Instance configuration
391
+
392
+ it "prints an empty string unless message given" do
393
+ output = double('output')
394
+ output.should_receive(:puts).with('')
395
+
396
+ Util::Interface.new({
397
+ :output => output,
398
+ :printer => :puts,
399
+ }).safe_puts()
400
+ end
401
+
402
+ #---
403
+
404
+ it "prints to different output channels if they are given" do
405
+ output1 = double('output1')
406
+ output1.should_receive(:puts).with('message')
407
+
408
+ test = Util::Interface.new({
409
+ :output => output1,
410
+ :printer => :puts,
411
+ })
412
+ test.safe_puts('message')
413
+
414
+ output2 = double('output2')
415
+ output2.should_receive(:puts).with('message')
416
+
417
+ test.output = output2
418
+ test.safe_puts('message')
419
+ end
420
+
421
+ #---
422
+
423
+ it "prints with puts if puts printer option given" do
424
+ output = double('output')
425
+ output.should_receive(:puts).with('message')
426
+
427
+ Util::Interface.new({
428
+ :output => output,
429
+ :printer => :puts,
430
+ }).safe_puts('message')
431
+ end
432
+
433
+ #---
434
+
435
+ it "prints with print if print printer option given" do
436
+ output = double('output')
437
+ output.should_receive(:print).with('message')
438
+
439
+ Util::Interface.new({
440
+ :output => output,
441
+ :printer => :print,
442
+ }).safe_puts('message')
443
+ end
444
+
445
+ #-------------------------------------------------------------------------
446
+ # Method configuration
447
+
448
+ it "can override the instance output channel" do
449
+ output1 = double('output1')
450
+ output1.should_not_receive(:puts).with('message')
451
+
452
+ output2 = double('output2')
453
+ output2.should_receive(:puts).with('message')
454
+
455
+ Util::Interface.new({
456
+ :output => output1,
457
+ :printer => :puts,
458
+ }).safe_puts('message', { :channel => output2 })
459
+ end
460
+
461
+ #---
462
+
463
+ it "can override the instance printer handler" do
464
+ output = double('output')
465
+ output.should_not_receive(:puts).with('message')
466
+ output.should_receive(:print).with('message')
467
+
468
+ Util::Interface.new({
469
+ :output => output,
470
+ :printer => :puts,
471
+ }).safe_puts('message', { :printer => :print })
472
+ end
473
+ end
474
+
475
+ #---------------------------------------------------------------------------
476
+
477
+ describe "#check_delegate" do
478
+
479
+ it "returns false if no delegate exists" do
480
+ Util::Interface.new.check_delegate('safe_puts').should be_false
481
+ end
482
+ it "returns true if a delegate exists and it implements given method" do
483
+ test = Util::Interface.new({ :ui_delegate => Util::Interface.new })
484
+ test.check_delegate('safe_puts').should be_true
485
+ test.check_delegate('nonexistent').should be_false
486
+ end
487
+ end
488
+ end
489
+ end
@@ -0,0 +1,29 @@
1
+
2
+ class MockInput
3
+
4
+ #-----------------------------------------------------------------------------
5
+ # Constructor / Destructor
6
+
7
+ def initialize(strings)
8
+ if strings.is_a?(String)
9
+ strings = [ strings ]
10
+ end
11
+ @strings = strings
12
+ end
13
+
14
+ #---
15
+
16
+ def self.with(strings)
17
+ $stdin = self.new(strings)
18
+ yield
19
+ ensure
20
+ $stdin = STDIN
21
+ end
22
+
23
+ #-----------------------------------------------------------------------------
24
+ # Accessors / Modifiers
25
+
26
+ def gets
27
+ return @strings.shift
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+
2
+ module Kernel
3
+
4
+ #-----------------------------------------------------------------------------
5
+ # Utilities
6
+
7
+ def capture
8
+ out = StringIO.new
9
+ $stdout = out
10
+
11
+ error = StringIO.new
12
+ $stderr = error
13
+
14
+ # Go do stuff!
15
+ yield
16
+ return out, error
17
+
18
+ ensure
19
+ $stdout = STDOUT
20
+ $stderr = STDERR
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+
2
+ require 'rspec'
3
+ require 'stringio'
4
+ require 'corl'
5
+
6
+ require 'corl_test_kernel'
7
+ require 'corl_mock_input'
8
+
9
+ #-------------------------------------------------------------------------------
10
+
11
+ RSpec.configure do |config|
12
+ config.mock_framework = :rspec
13
+ config.color_enabled = true
14
+ config.formatter = 'documentation'
15
+ end