corl 0.4.0 → 0.4.1

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 (122) hide show
  1. data/Gemfile +5 -10
  2. data/Gemfile.lock +13 -11
  3. data/README.rdoc +1 -1
  4. data/Rakefile +3 -3
  5. data/VERSION +1 -1
  6. data/bin/corl +2 -54
  7. data/bootstrap/bootstrap.sh +91 -0
  8. data/bootstrap/lib/shell/LICENSE.txt +674 -0
  9. data/bootstrap/lib/shell/command.sh +214 -0
  10. data/bootstrap/lib/shell/filesystem.sh +139 -0
  11. data/bootstrap/lib/shell/load.sh +73 -0
  12. data/bootstrap/lib/shell/os.sh +67 -0
  13. data/bootstrap/lib/shell/script.sh +160 -0
  14. data/bootstrap/lib/shell/starter.sh +64 -0
  15. data/bootstrap/lib/shell/validators.sh +50 -0
  16. data/bootstrap/os/ubuntu/00_base.sh +5 -0
  17. data/bootstrap/os/ubuntu/01_git.sh +5 -0
  18. data/bootstrap/os/ubuntu/05_ruby.sh +7 -0
  19. data/bootstrap/os/ubuntu/06_puppet.sh +38 -0
  20. data/bootstrap/os/ubuntu/10_corl.sh +9 -0
  21. data/corl.gemspec +61 -124
  22. data/lib/{corl → CORL}/action/bootstrap.rb +13 -7
  23. data/lib/CORL/action/exec.rb +39 -0
  24. data/lib/CORL/action/image.rb +31 -0
  25. data/lib/{corl → CORL}/action/images.rb +1 -1
  26. data/lib/CORL/action/lookup.rb +34 -0
  27. data/lib/{corl → CORL}/action/machines.rb +1 -1
  28. data/lib/CORL/action/provision.rb +31 -0
  29. data/lib/{corl → CORL}/action/seed.rb +3 -3
  30. data/lib/{corl → CORL}/action/spawn.rb +2 -2
  31. data/lib/CORL/action/start.rb +31 -0
  32. data/lib/CORL/action/stop.rb +31 -0
  33. data/lib/{corl → CORL}/configuration/file.rb +1 -1
  34. data/lib/{corl → CORL}/event/puppet.rb +1 -1
  35. data/lib/{corl → CORL}/extension/puppetloader.rb +1 -1
  36. data/lib/{corl → CORL}/machine/fog.rb +3 -3
  37. data/lib/{corl → CORL}/machine/physical.rb +2 -2
  38. data/lib/{corl → CORL}/network/default.rb +1 -1
  39. data/lib/{corl → CORL}/node/aws.rb +0 -4
  40. data/lib/{corl → CORL}/node/google.rb +0 -4
  41. data/lib/{corl → CORL}/node/local.rb +1 -1
  42. data/lib/{corl → CORL}/node/rackspace.rb +0 -4
  43. data/lib/{corl → CORL}/provisioner/puppetnode.rb +1 -14
  44. data/lib/{corl → CORL}/provisioner/puppetnode/resource.rb +0 -0
  45. data/lib/{corl → CORL}/provisioner/puppetnode/resource_group.rb +0 -0
  46. data/lib/{corl → CORL}/template/environment.rb +1 -1
  47. data/lib/core/facade.rb +49 -0
  48. data/lib/{corl_core → core}/mixin/action/keypair.rb +10 -10
  49. data/lib/{corl_core → core}/mixin/lookup.rb +0 -0
  50. data/lib/{corl_core → core}/mod/hiera_backend.rb +0 -0
  51. data/lib/{corl_core/mixin/action/node.rb → core/plugin/action.rb} +66 -33
  52. data/lib/{corl_core → core}/plugin/configuration.rb +2 -2
  53. data/lib/{corl/node → core/plugin}/fog.rb +5 -1
  54. data/lib/{corl_core → core}/plugin/machine.rb +2 -2
  55. data/lib/{corl_core → core}/plugin/network.rb +4 -4
  56. data/lib/{corl_core → core}/plugin/node.rb +11 -9
  57. data/lib/{corl_core → core}/plugin/provisioner.rb +2 -2
  58. data/lib/{corl_core → core}/util/ssh.rb +1 -1
  59. data/lib/corl.rb +53 -112
  60. data/lib/puppet/parser/functions/ensure.rb +0 -4
  61. data/locales/en.yml +55 -148
  62. metadata +84 -222
  63. data/lib/corl/action/add.rb +0 -69
  64. data/lib/corl/action/clone.rb +0 -40
  65. data/lib/corl/action/create.rb +0 -55
  66. data/lib/corl/action/exec.rb +0 -41
  67. data/lib/corl/action/extract.rb +0 -49
  68. data/lib/corl/action/image.rb +0 -30
  69. data/lib/corl/action/lookup.rb +0 -35
  70. data/lib/corl/action/provision.rb +0 -37
  71. data/lib/corl/action/remove.rb +0 -51
  72. data/lib/corl/action/save.rb +0 -53
  73. data/lib/corl/action/start.rb +0 -37
  74. data/lib/corl/action/stop.rb +0 -30
  75. data/lib/corl/action/update.rb +0 -37
  76. data/lib/corl/command/shell.rb +0 -164
  77. data/lib/corl/event/regex.rb +0 -52
  78. data/lib/corl/project/git.rb +0 -465
  79. data/lib/corl/project/github.rb +0 -108
  80. data/lib/corl/template/json.rb +0 -16
  81. data/lib/corl/template/wrapper.rb +0 -16
  82. data/lib/corl/template/yaml.rb +0 -16
  83. data/lib/corl/translator/json.rb +0 -27
  84. data/lib/corl/translator/yaml.rb +0 -27
  85. data/lib/corl_core/codes.rb +0 -107
  86. data/lib/corl_core/config.rb +0 -337
  87. data/lib/corl_core/config/collection.rb +0 -57
  88. data/lib/corl_core/config/options.rb +0 -70
  89. data/lib/corl_core/core.rb +0 -59
  90. data/lib/corl_core/corl.rb +0 -254
  91. data/lib/corl_core/errors.rb +0 -84
  92. data/lib/corl_core/facade.rb +0 -126
  93. data/lib/corl_core/gems.rb +0 -72
  94. data/lib/corl_core/manager.rb +0 -425
  95. data/lib/corl_core/mixin/action/commit.rb +0 -58
  96. data/lib/corl_core/mixin/action/project.rb +0 -53
  97. data/lib/corl_core/mixin/action/push.rb +0 -52
  98. data/lib/corl_core/mixin/config/collection.rb +0 -53
  99. data/lib/corl_core/mixin/config/ops.rb +0 -53
  100. data/lib/corl_core/mixin/config/options.rb +0 -39
  101. data/lib/corl_core/mixin/macro/object_interface.rb +0 -361
  102. data/lib/corl_core/mixin/macro/plugin_interface.rb +0 -380
  103. data/lib/corl_core/mixin/settings.rb +0 -46
  104. data/lib/corl_core/mixin/sub_config.rb +0 -148
  105. data/lib/corl_core/mod/hash.rb +0 -29
  106. data/lib/corl_core/plugin/action.rb +0 -381
  107. data/lib/corl_core/plugin/base.rb +0 -374
  108. data/lib/corl_core/plugin/command.rb +0 -98
  109. data/lib/corl_core/plugin/event.rb +0 -53
  110. data/lib/corl_core/plugin/extension.rb +0 -12
  111. data/lib/corl_core/plugin/project.rb +0 -927
  112. data/lib/corl_core/plugin/template.rb +0 -80
  113. data/lib/corl_core/plugin/translator.rb +0 -38
  114. data/lib/corl_core/util/cli.rb +0 -352
  115. data/lib/corl_core/util/data.rb +0 -404
  116. data/lib/corl_core/util/disk.rb +0 -114
  117. data/lib/corl_core/util/git.rb +0 -47
  118. data/lib/corl_core/util/interface.rb +0 -319
  119. data/lib/corl_core/util/liquid.rb +0 -17
  120. data/lib/corl_core/util/package.rb +0 -93
  121. data/lib/corl_core/util/shell.rb +0 -239
  122. data/spec/corl_core/interface_spec.rb +0 -489
@@ -1,29 +0,0 @@
1
-
2
- #-------------------------------------------------------------------------------
3
- # Hash data type alterations
4
-
5
- class Hash
6
- def search(search_key, options = {})
7
- config = CORL::Config.ensure(options)
8
- value = nil
9
-
10
- recurse = config.get(:recurse, false)
11
- recurse_level = config.get(:recurse_level, -1)
12
-
13
- self.each do |key, data|
14
- if key == search_key
15
- value = data
16
-
17
- elsif data.is_a?(Hash) &&
18
- recurse && (recurse_level == -1 || recurse_level > 0)
19
-
20
- recurse_level -= 1 unless recurse_level == -1
21
- value = value.search(search_key,
22
- CORL::Config.new(config).set(:recurse_level, recurse_level)
23
- )
24
- end
25
- break unless value.nil?
26
- end
27
- return value
28
- end
29
- end
@@ -1,381 +0,0 @@
1
-
2
- module CORL
3
- module Plugin
4
- class Action < Base
5
-
6
- include Mixin::Action::Node
7
-
8
- #-----------------------------------------------------------------------------
9
- # Default option interface
10
-
11
- class Option
12
- def initialize(provider, name, type, default, locale = nil, &validator)
13
- @provider = provider
14
- @name = name
15
- @type = type
16
- @default = default
17
- @locale = locale.nil? ? "corl.actions.#{provider}.options.#{name}" : locale
18
- @validator = validator if validator
19
- end
20
-
21
- #---
22
-
23
- attr_reader :provider, :name, :type
24
- attr_accessor :default, :locale, :validator
25
-
26
- #---
27
-
28
- def validate(value, node, network)
29
- success = true
30
- if @validator
31
- success = @validator.call(value, node, network)
32
- end
33
- success
34
- end
35
- end
36
-
37
- #-----------------------------------------------------------------------------
38
- # Action plugin interface
39
-
40
- def self.exec_safe(provider, options)
41
- action_result = nil
42
-
43
- begin
44
- logger = CORL.logger
45
-
46
- logger.debug("Running corl action #{provider} with #{options.inspect}")
47
- action = CORL.action(provider, options)
48
- exit_status = action.execute
49
- action_result = action.result
50
-
51
- rescue Exception => error
52
- logger.error("Corl action #{provider} experienced an error:")
53
- logger.error(error.inspect)
54
- logger.error(error.message)
55
- logger.error(CORL::Util::Data.to_yaml(error.backtrace))
56
-
57
- CORL.ui.error(error.message, { :prefix => false }) if error.message
58
-
59
- exit_status = error.status_code if error.respond_to?(:status_code)
60
- end
61
-
62
- CORL.remove_plugin(action) if action
63
-
64
- exit_status = CORL.code.unknown_status unless exit_status.is_a?(Integer)
65
- { :status => exit_status, :result => action_result }
66
- end
67
-
68
- def self.exec(provider, options, quiet = true)
69
- exec_safe(provider, { :settings => Config.ensure(options), :quiet => quiet })
70
- end
71
-
72
- def self.exec_cli(provider, args, quiet = false)
73
- results = exec_safe(provider, { :args => args, :quiet => quiet })
74
- results[:status]
75
- end
76
-
77
- #---
78
-
79
- def normalize
80
- args = array(delete(:args, []))
81
-
82
- @action_interface = Util::Liquid.new do |method, method_args|
83
- options = {}
84
- options = method_args[0] if method_args.length > 0
85
-
86
- quiet = true
87
- quiet = method_args[1] if method_args.length > 1
88
-
89
- myself.class.exec(method, options, quiet)
90
- end
91
-
92
- set(:config, Config.new)
93
-
94
- if get(:settings, nil)
95
- # Internal processing
96
- configure
97
- set(:processed, true)
98
- set(:settings, Config.ensure(get(:settings)))
99
-
100
- CORL.log_level = settings[:log_level] if settings.has_key?(:log_level)
101
- else
102
- # External processing
103
- set(:settings, Config.new)
104
- configure
105
- parse_base(args)
106
- end
107
- end
108
-
109
- #-----------------------------------------------------------------------------
110
- # Checks
111
-
112
- def processed?
113
- get(:processed, false)
114
- end
115
-
116
- #-----------------------------------------------------------------------------
117
- # Property accessor / modifiers
118
-
119
- def config
120
- get(:config)
121
- end
122
-
123
- #---
124
-
125
- def config_subset(names)
126
- Util::Data.subset(config, names)
127
- end
128
-
129
- #---
130
-
131
- def settings
132
- get(:settings)
133
- end
134
-
135
- #---
136
-
137
- def register(name, type, default, locale = nil)
138
- name = name.to_sym
139
-
140
- if block_given?
141
- option = Option.new(plugin_provider, name, type, default, locale) do |value, success|
142
- yield(value, success)
143
- end
144
- else
145
- option = Option.new(plugin_provider, name, type, default, locale)
146
- end
147
-
148
- config[name] = option
149
- settings[name] = option.default if settings[name].nil?
150
- end
151
-
152
- #---
153
-
154
- def remove(names)
155
- Util::Data.rm_keys(config, names)
156
- Util::Data.rm_keys(settings, names)
157
- end
158
-
159
- #---
160
-
161
- def ignore
162
- []
163
- end
164
-
165
- def options
166
- config.keys - arguments - ignore
167
- end
168
-
169
- def arguments
170
- []
171
- end
172
-
173
- #---
174
-
175
- def configure
176
- node_config
177
- yield if block_given?
178
-
179
- usage = "corl #{plugin_provider} "
180
- arguments.each do |arg|
181
- arg_config = config[arg.to_sym]
182
-
183
- if arg_config.type == :array
184
- usage << "<#{arg}> ..."
185
- else
186
- usage << "<#{arg}> "
187
- end
188
- end
189
- myself.usage = usage
190
- myself
191
- end
192
-
193
- #---
194
-
195
- def usage=usage
196
- set(:usage, usage)
197
- end
198
-
199
- def usage
200
- get(:usage, '')
201
- end
202
-
203
- #---
204
-
205
- def help
206
- return @parser.help if @parser
207
- usage
208
- end
209
-
210
- #---
211
-
212
- def result=result
213
- set(:result, result)
214
- end
215
-
216
- def result
217
- get(:result, nil)
218
- end
219
-
220
- #-----------------------------------------------------------------------------
221
- # Operations
222
-
223
- def parse_base(args)
224
- logger.info("Parsing action #{plugin_provider} with: #{args.inspect}")
225
-
226
- @parser = Util::CLI::Parser.new(args, usage) do |parser|
227
- parse(parser)
228
- extension(:parse, { :parser => parser, :config => config })
229
- end
230
-
231
- if @parser
232
- if @parser.processed
233
- set(:processed, true)
234
- settings.import(Util::Data.merge([ @parser.options, @parser.arguments ], true))
235
- logger.debug("Parse successful: #{export.inspect}")
236
-
237
- elsif @parser.options[:help] && ! quiet?
238
- puts I18n.t('corl.core.exec.help.usage') + ': ' + help + "\n"
239
-
240
- else
241
- if @parser.options[:help]
242
- logger.debug("Help wanted but running in silent mode")
243
- else
244
- logger.warn("Parse failed for unknown reasons")
245
- end
246
- end
247
- end
248
- end
249
-
250
- #---
251
-
252
- def parse(parser)
253
-
254
- generate = lambda do |format, name|
255
- formats = [ :option, :arg ]
256
- types = [ :bool, :int, :float, :str, :array ]
257
- name = name.to_sym
258
-
259
- if config.export.has_key?(name) && formats.include?(format.to_sym)
260
- option_config = config[name]
261
- type = option_config.type
262
- default = option_config.default
263
- locale = option_config.locale
264
-
265
- if types.include?(type.to_sym)
266
- value_label = "#{type.to_s.upcase}"
267
-
268
- if type == :bool
269
- parser.send("option_#{type}", name, default, "--[no-]#{name}", locale)
270
- elsif format == :arg
271
- parser.send("#{format}_#{type}", name, default, locale)
272
- else
273
- if type == :array
274
- parser.send("option_#{type}", name, default, "--#{name} #{value_label},...", locale)
275
- else
276
- parser.send("option_#{type}", name, default, "--#{name} #{value_label}", locale)
277
- end
278
- end
279
- end
280
- end
281
- end
282
-
283
- #---
284
-
285
- options.each do |name|
286
- generate.call(:option, name)
287
- end
288
-
289
- arguments.each do |name|
290
- generate.call(:arg, name)
291
- end
292
- end
293
-
294
- #---
295
-
296
- def validate(node, network)
297
- # TODO: Add extension hooks and logging
298
-
299
- # Validate all of the configurations
300
- success = true
301
- config.export.each do |name, option|
302
- success = false unless option.validate(settings[name], node, network)
303
- end
304
- if success
305
- # Check for missing arguments (in case of internal execution mode)
306
- arguments.each do |name|
307
- if settings[name.to_sym].nil?
308
- warn('corl.core.exec.errors.missing_argument', { :name => name })
309
- success = false
310
- end
311
- end
312
- end
313
- if ignore.include?(:nodes)
314
- settings[:nodes] = []
315
- end
316
- success
317
- end
318
-
319
- #---
320
-
321
- def execute
322
- logger.info("Executing action #{plugin_provider}")
323
-
324
- myself.status = code.success
325
- myself.result = nil
326
-
327
- if processed?
328
- node_exec do |node, network|
329
- hook_config = { :node => node, :network => network }
330
-
331
- begin
332
- yield(node, network) if block_given? && extension_check(:exec_init, hook_config)
333
- myself.status = extension_set(:exec_exit, status, hook_config)
334
- ensure
335
- cleanup
336
- end
337
- end
338
- else
339
- if @parser.options[:help]
340
- myself.status = code.help_wanted
341
- else
342
- myself.status = code.action_unprocessed
343
- end
344
- end
345
-
346
- myself.status = code.unknown_status unless status.is_a?(Integer)
347
-
348
- if processed? && status != code.success
349
- logger.warn("Execution failed for #{plugin_provider} with status #{status}: #{export.inspect}")
350
- alert(Codes.render_index(status))
351
- end
352
-
353
- status
354
- end
355
-
356
- #---
357
-
358
- def run
359
- @action_interface
360
- end
361
-
362
- #---
363
-
364
- def cleanup
365
- logger.info("Running cleanup for action #{plugin_provider}")
366
-
367
- yield if block_given?
368
-
369
- # Nothing to do right now
370
- extension(:cleanup)
371
- end
372
-
373
- #-----------------------------------------------------------------------------
374
- # Output
375
-
376
- def render_options
377
- settings
378
- end
379
- end
380
- end
381
- end
@@ -1,374 +0,0 @@
1
-
2
- module CORL
3
- module Plugin
4
- class Base < Core
5
-
6
- include Mixin::Lookup
7
-
8
- #---
9
-
10
- # All Plugin classes should directly or indirectly extend Base
11
-
12
- def initialize(type, provider, options)
13
- config = Util::Data.clean(Config.ensure(options))
14
- name = Util::Data.ensure_value(config.delete(:plugin_name), config.delete(:name, provider))
15
- @quiet = config.delete(:quiet, false)
16
-
17
- set_meta(config.delete(:meta, Config.new))
18
-
19
- # No logging statements aove this line!!
20
- super(config.import({ :logger => "#{plugin_type}->#{plugin_provider}" }))
21
- myself.plugin_name = name
22
-
23
- logger.debug("Set #{plugin_type} plugin #{plugin_name} meta data: #{meta.inspect}")
24
- logger.debug("Normalizing #{plugin_type} plugin #{plugin_name}")
25
- normalize
26
- end
27
-
28
- #---
29
-
30
- def method_missing(method, *args, &block)
31
- return nil
32
- end
33
-
34
- #-----------------------------------------------------------------------------
35
- # Checks
36
-
37
- def initialized?(options = {})
38
- return true
39
- end
40
-
41
- #---
42
-
43
- def quiet?
44
- @quiet
45
- end
46
-
47
- #-----------------------------------------------------------------------------
48
- # Property accessor / modifiers
49
-
50
- def myself
51
- return current_actor if respond_to?(:current_actor) # Celluloid enhanced plugin
52
- self
53
- end
54
- alias_method :me, :myself
55
-
56
- #---
57
-
58
- def quiet=quiet
59
- @quiet = quiet
60
- end
61
-
62
- #---
63
-
64
- def meta
65
- return @meta
66
- end
67
-
68
- #---
69
-
70
- def set_meta(meta)
71
- @meta = Config.ensure(meta)
72
- end
73
-
74
- #---
75
-
76
- def plugin_name
77
- return meta.get(:name)
78
- end
79
- alias_method :name, :plugin_name
80
-
81
- def plugin_name=plugin_name
82
- meta.set(:name, string(plugin_name))
83
- end
84
- alias_method :name=, :plugin_name=
85
-
86
- #---
87
-
88
- def plugin_type
89
- return meta.get(:type)
90
- end
91
-
92
- #---
93
-
94
- def plugin_provider
95
- return meta.get(:provider)
96
- end
97
-
98
- #---
99
-
100
- def plugin_directory
101
- return meta.get(:directory)
102
- end
103
-
104
- #---
105
-
106
- def plugin_file
107
- return meta.get(:file)
108
- end
109
-
110
- #---
111
-
112
- def plugin_instance_name
113
- return meta.get(:instance_name)
114
- end
115
-
116
- #---
117
-
118
- def plugin_parent=parent
119
- meta.set(:parent, parent) if parent.is_a?(CORL::Plugin::Base)
120
- end
121
-
122
- def plugin_parent
123
- return meta.get(:parent)
124
- end
125
-
126
- #-----------------------------------------------------------------------------
127
- # Status codes
128
-
129
- def code
130
- CORL.code
131
- end
132
-
133
- def codes(*codes)
134
- CORL.codes(*codes)
135
- end
136
-
137
- #---
138
-
139
- def status=status
140
- meta.set(:status, status)
141
- end
142
-
143
- def status
144
- meta.get(:status, code.unknown_status)
145
- end
146
-
147
- #-----------------------------------------------------------------------------
148
- # Plugin operations
149
-
150
- def normalize
151
- end
152
-
153
- #-----------------------------------------------------------------------------
154
- # Extensions
155
-
156
- def hook_method(hook)
157
- "#{plugin_type}_#{plugin_provider}_#{hook}"
158
- end
159
-
160
- #---
161
-
162
- def extension(hook, options = {})
163
- method = hook_method(hook)
164
-
165
- logger.debug("Executing plugin hook #{hook} (#{method})")
166
-
167
- return Manager.connection.exec(method, Config.ensure(options).defaults({ :extension_type => :base }).import({ :plugin => myself })) do |op, results|
168
- results = yield(op, results) if block_given?
169
- results
170
- end
171
- end
172
-
173
- #---
174
-
175
- def extended_config(type, options = {})
176
- config = Config.ensure(options)
177
-
178
- logger.debug("Generating #{type} extended configuration from: #{config.export.inspect}")
179
-
180
- extension("#{type}_config", Config.new(config.export).import({ :extension_type => :config })) do |op, results|
181
- if op == :reduce
182
- results.each do |provider, result|
183
- config.defaults(result)
184
- end
185
- nil
186
- else
187
- hash(results)
188
- end
189
- end
190
- config.delete(:extension_type)
191
-
192
- logger.debug("Final extended configuration: #{config.export.inspect}")
193
- config
194
- end
195
-
196
- #---
197
-
198
- def extension_check(hook, options = {})
199
- config = Config.ensure(options)
200
-
201
- logger.debug("Checking extension #{plugin_provider} #{hook} given: #{config.export.inspect}")
202
-
203
- success = extension(hook, config.import({ :extension_type => :check })) do |op, results|
204
- if op == :reduce
205
- ! results.values.include?(false)
206
- else
207
- results ? true : false
208
- end
209
- end
210
-
211
- success = success.nil? || success ? true : false
212
-
213
- logger.debug("Extension #{plugin_provider} #{hook} check result: #{success.inspect}")
214
- success
215
- end
216
-
217
- #---
218
-
219
- def extension_set(hook, value, options = {})
220
- config = Config.ensure(options)
221
-
222
- logger.debug("Setting extension #{plugin_provider} #{hook} value given: #{value.inspect}")
223
-
224
- extension(hook, config.import({ :value => value, :extension_type => :set })) do |op, results|
225
- if op == :process
226
- value = results unless results.nil?
227
- end
228
- end
229
-
230
- logger.debug("Extension #{plugin_provider} #{hook} set value to: #{value.inspect}")
231
- value
232
- end
233
-
234
- #---
235
-
236
- def extension_collect(hook, options = {})
237
- config = Config.ensure(options)
238
- values = []
239
-
240
- logger.debug("Collecting extension #{plugin_provider} #{hook} values")
241
-
242
- extension(hook, config.import({ :extension_type => :add })) do |op, results|
243
- if op == :process
244
- values << results unless results.nil?
245
- end
246
- end
247
-
248
- logger.debug("Extension #{plugin_provider} #{hook} collected values: #{values.inspect}")
249
- values
250
- end
251
-
252
- #-----------------------------------------------------------------------------
253
- # Output
254
-
255
- def render_options
256
- export
257
- end
258
- protected :render_options
259
-
260
- #---
261
-
262
- def render(display, options = {})
263
- ui.info(display.strip, options) unless quiet? || display.strip.empty?
264
- end
265
-
266
- #---
267
-
268
- def info(name, options = {})
269
- ui.info(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet?
270
- end
271
-
272
- #---
273
-
274
- def alert(display, options = {})
275
- ui.warn(display.strip, options) unless quiet? || display.strip.empty?
276
- end
277
-
278
- #---
279
-
280
- def warn(name, options = {})
281
- ui.warn(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet?
282
- end
283
-
284
- #---
285
-
286
- def error(name, options = {})
287
- ui.error(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet?
288
- end
289
-
290
- #---
291
-
292
- def success(name, options = {})
293
- ui.success(I18n.t(name, Util::Data.merge([ Config.ensure(render_options).export, options ], true))) unless quiet?
294
- end
295
-
296
- #-----------------------------------------------------------------------------
297
- # Utilities
298
-
299
- def self.build_info(type, data)
300
- plugins = []
301
-
302
- if data.is_a?(Hash)
303
- data = [ data ]
304
- end
305
-
306
- logger.debug("Building plugin list of #{type} from data: #{data.inspect}")
307
-
308
- if data.is_a?(Array)
309
- data.each do |info|
310
- unless Util::Data.empty?(info)
311
- info = translate(info)
312
-
313
- if Util::Data.empty?(info[:provider])
314
- info[:provider] = Manager.connection.type_default(type)
315
- end
316
-
317
- logger.debug("Translated plugin info: #{info.inspect}")
318
-
319
- plugins << info
320
- end
321
- end
322
- end
323
- return plugins
324
- end
325
-
326
- #---
327
-
328
- def self.translate(data)
329
- logger.debug("Translating data to internal plugin structure: #{data.inspect}")
330
- return ( data.is_a?(Hash) ? symbol_map(data) : {} )
331
- end
332
-
333
- #---
334
-
335
- def self.init_plugin_collection
336
- logger.debug("Initializing plugin collection interface at #{Time.now}")
337
-
338
- include Celluloid
339
- include Mixin::Settings
340
- include Mixin::SubConfig
341
-
342
- extend Mixin::Macro::PluginInterface
343
- end
344
-
345
- #---
346
-
347
- def safe_exec(return_result = true)
348
- begin
349
- result = yield
350
- return result if return_result
351
- return true
352
-
353
- rescue Exception => e
354
- logger.error(e.inspect)
355
- logger.error(e.message)
356
-
357
- ui.error(e.message, { :prefix => false }) if e.message
358
- end
359
- return false
360
- end
361
-
362
- #---
363
-
364
- def admin_exec
365
- if CORL.admin?
366
- yield if block_given?
367
- else
368
- ui.warn("The #{plugin_provider} action must be run as a machine administrator")
369
- myself.status = code.access_denied
370
- end
371
- end
372
- end
373
- end
374
- end