corl 0.5.4 → 0.5.5

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.
@@ -2,24 +2,24 @@
2
2
  module CORL
3
3
  module Util
4
4
  module Puppet
5
-
5
+
6
6
  def self.logger
7
7
  CORL.logger
8
8
  end
9
-
9
+
10
10
  #-----------------------------------------------------------------------------
11
11
  # Plugins
12
-
12
+
13
13
  @@register = {}
14
-
14
+
15
15
  #---
16
-
16
+
17
17
  def self.register_plugins(options = {})
18
18
  config = Config.ensure(options)
19
-
19
+
20
20
  puppet_scope = config.get(:puppet_scope, nil)
21
21
  return unless puppet_scope
22
-
22
+
23
23
  each_module(config) do |mod|
24
24
  unless @@register.has_key?(mod.path)
25
25
  lib_dir = File.join(mod.path, 'lib')
@@ -31,91 +31,91 @@ module Puppet
31
31
  end
32
32
  end
33
33
  end
34
-
34
+
35
35
  #-----------------------------------------------------------------------------
36
36
  # Resources
37
-
37
+
38
38
  def self.type_info(type_name, options = {})
39
39
  config = Config.ensure(options)
40
40
  reset = config.get(:reset, false)
41
-
41
+
42
42
  puppet_scope = config.get(:puppet_scope, nil)
43
43
  return nil unless puppet_scope
44
-
44
+
45
45
  type_name = type_name.to_s.downcase
46
46
  type_info = config.get(:type_info, {})
47
-
48
- if reset || ! type_info.has_key?(type_name)
49
- resource_type = nil
47
+
48
+ if reset || ! type_info.has_key?(type_name)
49
+ resource_type = nil
50
50
  type_exported, type_virtual = false
51
-
51
+
52
52
  if type_name.start_with?('@@')
53
53
  type_name = type_name[2..-1]
54
54
  type_exported = true
55
-
55
+
56
56
  elsif type_name.start_with?('@')
57
57
  type_name = type_name[1..-1]
58
58
  type_virtual = true
59
59
  end
60
-
60
+
61
61
  if type_name == 'class'
62
62
  resource_type = :class
63
63
  else
64
64
  if resource = ::Puppet::Type.type(type_name.to_sym)
65
65
  resource_type = :type
66
-
66
+
67
67
  elsif resource = puppet_scope.find_definition(type_name)
68
68
  resource_type = :define
69
69
  end
70
70
  end
71
-
71
+
72
72
  type_info[type_name] = {
73
- :name => type_name,
74
- :type => resource_type,
75
- :resource => resource,
76
- :exported => type_exported,
77
- :virtual => type_virtual
73
+ :name => type_name,
74
+ :type => resource_type,
75
+ :resource => resource,
76
+ :exported => type_exported,
77
+ :virtual => type_virtual
78
78
  }
79
79
  config.set(:type_info, type_info)
80
80
  end
81
-
82
- type_info[type_name]
81
+
82
+ type_info[type_name]
83
83
  end
84
-
84
+
85
85
  #-----------------------------------------------------------------------------
86
86
  # Catalog alterations
87
-
87
+
88
88
  def self.add(type_name, resources, defaults = {}, options = {})
89
89
  config = Config.ensure(options)
90
-
91
- puppet_scope = config.get(:puppet_scope, nil)
90
+
91
+ puppet_scope = config.get(:puppet_scope, nil)
92
92
  return unless puppet_scope
93
-
93
+
94
94
  info = type_info(type_name, options)
95
-
95
+
96
96
  if config.get(:debug, false)
97
97
  CORL.ui.info("\n", { :prefix => false })
98
98
  CORL.ui_group(Util::Console.purple(info[:name])) do |ui|
99
99
  ui.info("-----------------------------------------------------")
100
100
  end
101
- end
101
+ end
102
102
  ResourceGroup.new(info, defaults).add(resources, config)
103
103
  end
104
-
104
+
105
105
  #---
106
-
106
+
107
107
  def self.add_resource(type, title, properties, options = {})
108
108
  config = Config.ensure(options)
109
-
110
- puppet_scope = config.get(:puppet_scope, nil)
109
+
110
+ puppet_scope = config.get(:puppet_scope, nil)
111
111
  return unless puppet_scope
112
-
112
+
113
113
  if type.is_a?(String)
114
114
  type = type_info(type, config)
115
115
  end
116
-
116
+
117
117
  display_name = puppet_scope.parent_module_name ? puppet_scope.parent_module_name : 'toplevel'
118
-
118
+
119
119
  case type[:type]
120
120
  when :type, :define
121
121
  CORL.ui_group(Util::Console.cyan(display_name)) do |ui|
@@ -135,82 +135,82 @@ module Puppet
135
135
  end
136
136
 
137
137
  #---
138
-
138
+
139
139
  def self.add_class(title, properties, options = {})
140
- config = Config.ensure(options)
140
+ config = Config.ensure(options)
141
141
  puppet_scope = config.get(:puppet_scope, nil)
142
-
142
+
143
143
  if puppet_scope
144
144
  klass = puppet_scope.find_hostclass(title)
145
145
  return unless klass
146
-
146
+
147
147
  debug_resource(config, title, properties)
148
148
  klass.ensure_in_catalog(puppet_scope, properties)
149
149
  puppet_scope.catalog.add_class(title)
150
- end
150
+ end
151
151
  end
152
-
152
+
153
153
  #---
154
-
154
+
155
155
  def self.add_definition(type, title, properties, options = {})
156
156
  config = Config.ensure(options)
157
-
158
- puppet_scope = config.get(:puppet_scope, nil)
157
+
158
+ puppet_scope = config.get(:puppet_scope, nil)
159
159
  return unless puppet_scope
160
-
160
+
161
161
  type = type_info(type, config) if type.is_a?(String)
162
-
162
+
163
163
  resource = ::Puppet::Parser::Resource.new(type[:name], title, :scope => puppet_scope, :source => type[:resource])
164
164
  resource.virtual = type[:virtual]
165
165
  resource.exported = type[:exported]
166
-
166
+
167
167
  namevar = namevar(type[:name], title).to_sym
168
168
  resource_name = properties.has_key?(namevar) ? properties[namevar] : title
169
169
  properties = { :name => resource_name }.merge(properties)
170
-
170
+
171
171
  properties.each do |key, value|
172
172
  resource.set_parameter(key, value)
173
173
  end
174
174
  if type[:type] == :define
175
175
  type[:resource].instantiate_resource(puppet_scope, resource)
176
176
  end
177
-
177
+
178
178
  debug_resource(config, title, properties)
179
179
  puppet_scope.compiler.add_resource(puppet_scope, resource)
180
180
  end
181
-
181
+
182
182
  #--
183
-
183
+
184
184
  def self.import(files, options = {})
185
- config = Config.ensure(options)
186
-
187
- puppet_scope = config.get(:puppet_scope, nil)
185
+ config = Config.ensure(options)
186
+
187
+ puppet_scope = config.get(:puppet_scope, nil)
188
188
  return unless puppet_scope
189
-
189
+
190
190
  if types = puppet_scope.environment.known_resource_types
191
191
  Util::Data.array(files).each do |file|
192
192
  types.loader.import(file, config.get(:puppet_import_base, nil))
193
193
  end
194
194
  end
195
195
  end
196
-
196
+
197
197
  #---
198
-
198
+
199
199
  def self.include(resource_name, properties = {}, options = {})
200
200
  config = Config.ensure(options)
201
201
  class_data = {}
202
-
202
+
203
203
  puppet_scope = config.get(:puppet_scope, nil)
204
204
  return false unless puppet_scope
205
-
205
+
206
206
  display_name = puppet_scope.parent_module_name ? puppet_scope.parent_module_name : 'toplevel'
207
-
207
+
208
208
  if resource_name.is_a?(Array)
209
209
  resource_name = resource_name.flatten
210
210
  else
211
211
  resource_name = [ resource_name ]
212
212
  end
213
-
213
+
214
214
  resource_name.each do |name|
215
215
  classes = Config.lookup(name, nil, config)
216
216
  if classes.is_a?(Array)
@@ -224,19 +224,19 @@ module Puppet
224
224
  end
225
225
  end
226
226
  end
227
-
228
- if config.get(:debug, false)
227
+
228
+ if config.get(:debug, false)
229
229
  CORL.ui.info("\n", { :prefix => false })
230
230
  CORL.ui_group(Util::Console.cyan("#{display_name} include")) do |ui|
231
231
  ui.info("-----------------------------------------------------")
232
-
233
- dump = Util::Console.green(Util::Data.to_json(class_data, true))
234
-
232
+
233
+ dump = Util::Console.green(Util::Data.to_json(class_data, true))
234
+
235
235
  ui.info(":\n#{dump}")
236
- ui.info("\n", { :prefix => false })
236
+ ui.info("\n", { :prefix => false })
237
237
  end
238
238
  end
239
-
239
+
240
240
  klasses = puppet_scope.compiler.evaluate_classes(class_data, puppet_scope, false)
241
241
  missing = class_data.keys.find_all do |klass|
242
242
  ! klasses.include?(klass)
@@ -244,46 +244,46 @@ module Puppet
244
244
  return false unless missing.empty?
245
245
  true
246
246
  end
247
-
247
+
248
248
  #-----------------------------------------------------------------------------
249
249
  # Lookup
250
-
250
+
251
251
  def self.lookup(property, default = nil, options = {})
252
252
  config = Config.ensure(options)
253
253
  value = nil
254
-
255
- puppet_scope = config.get(:puppet_scope, nil)
256
- base_names = config.get(:search, nil)
254
+
255
+ puppet_scope = config.get(:puppet_scope, nil)
256
+ base_names = config.get(:search, nil)
257
257
  search_name = config.get(:search_name, true)
258
258
  reverse_lookup = config.get(:reverse_lookup, true)
259
-
259
+
260
260
  return default unless puppet_scope
261
-
261
+
262
262
  log_level = ::Puppet::Util::Log.level
263
263
  ::Puppet::Util::Log.level = :err # Don't want failed parameter lookup warnings here.
264
-
264
+
265
265
  if base_names
266
266
  if base_names.is_a?(String)
267
267
  base_names = [ base_names ]
268
268
  end
269
269
  base_names = base_names.reverse if reverse_lookup
270
-
270
+
271
271
  base_names.each do |base|
272
272
  search_property_name = "#{base}::#{property}"
273
-
273
+
274
274
  value = puppet_scope.lookupvar("::#{search_property_name}")
275
275
  Config.debug_lookup(config, search_property_name, value, "Puppet override lookup")
276
-
277
- break unless value.nil?
276
+
277
+ break unless value.nil?
278
278
  end
279
279
  end
280
280
  if value.nil?
281
281
  components = property.to_s.split('::')
282
-
282
+
283
283
  if components.length > 1
284
284
  components += [ 'default', components.pop ]
285
285
  search_property_name = components.flatten.join('::')
286
-
286
+
287
287
  value = puppet_scope.lookupvar("::#{search_property_name}")
288
288
  Config.debug_lookup(config, search_property_name, value, "Puppet default lookup")
289
289
  end
@@ -292,65 +292,65 @@ module Puppet
292
292
  value = puppet_scope.lookupvar("::#{property}")
293
293
  Config.debug_lookup(config, property, value, "Puppet name lookup")
294
294
  end
295
-
295
+
296
296
  ::Puppet::Util::Log.level = log_level
297
- value
297
+ value
298
298
  end
299
-
299
+
300
300
  #-----------------------------------------------------------------------------
301
301
  # Utilities
302
-
302
+
303
303
  def self.each_module(options = {}, &code)
304
304
  config = Config.ensure(options)
305
305
  values = []
306
-
307
- puppet_scope = config.get(:puppet_scope, nil)
306
+
307
+ puppet_scope = config.get(:puppet_scope, nil)
308
308
  return nil unless puppet_scope
309
-
309
+
310
310
  puppet_scope.compiler.environment.modules.each do |mod|
311
311
  values << code.call(mod)
312
312
  end
313
313
  values
314
314
  end
315
-
315
+
316
316
  #---
317
-
317
+
318
318
  def self.to_name(name)
319
319
  Util::Data.value(name).to_s.gsub(/[\/\\\-\.]/, '_')
320
320
  end
321
-
321
+
322
322
  #---
323
-
323
+
324
324
  def self.type_name(value)
325
325
  return :main if value == :main
326
326
  return "Class" if value == "" or value.nil? or value.to_s.downcase == "component"
327
327
  value.to_s.split("::").collect { |s| s.capitalize }.join("::")
328
328
  end
329
-
329
+
330
330
  #---
331
-
331
+
332
332
  def self.namevar(type_name, resource_name)
333
333
  resource = ::Puppet::Resource.new(type_name.sub(/^\@?\@/, ''), resource_name)
334
-
334
+
335
335
  if resource.builtin_type? and type = resource.resource_type and type.key_attributes.length == 1
336
336
  type.key_attributes.first.to_s
337
337
  else
338
338
  'name'
339
339
  end
340
340
  end
341
-
341
+
342
342
  #---
343
-
343
+
344
344
  def self.debug_resource(config, title, properties)
345
345
  if config.get(:debug, false)
346
346
  CORL.ui_group(Util::Console.cyan(title.to_s)) do |ui|
347
- dump = Util::Console.green(Util::Data.to_json(properties, true))
348
-
347
+ dump = Util::Console.green(Util::Data.to_json(properties, true))
348
+
349
349
  ui.info(":\n#{dump}")
350
- ui.info("\n", { :prefix => false })
350
+ ui.info("\n", { :prefix => false })
351
351
  end
352
352
  end
353
- end
353
+ end
354
354
  end
355
355
  end
356
356
  end
@@ -11,67 +11,80 @@ class CORL < ::Vagrant.plugin("2", :config)
11
11
  super
12
12
  @network = UNSET_VALUE
13
13
  @node = UNSET_VALUE
14
-
14
+
15
15
  @force_updates = false
16
16
  @user_home = UNSET_VALUE
17
17
  @user_home_env_var = UNSET_VALUE
18
-
18
+
19
19
  @root_user = UNSET_VALUE
20
20
  @root_home = UNSET_VALUE
21
-
21
+
22
22
  @bootstrap = UNSET_VALUE
23
23
  @bootstrap_path = UNSET_VALUE
24
24
  @bootstrap_glob = UNSET_VALUE
25
25
  @bootstrap_init = UNSET_VALUE
26
+ @bootstrap_scripts = UNSET_VALUE
27
+ @reboot = true
28
+ @dev_build = false
29
+ @ruby_version = UNSET_VALUE
30
+
26
31
  @auth_files = UNSET_VALUE
27
-
32
+
28
33
  @seed = UNSET_VALUE
29
34
  @project_reference = UNSET_VALUE
30
35
  @project_branch = UNSET_VALUE
31
-
36
+
37
+ @environment = UNSET_VALUE
38
+ @build = true
32
39
  @provision = false
33
40
  @dry_run = false
34
41
  end
35
-
42
+
36
43
  #---
37
-
44
+
38
45
  def finalize!
39
46
  super
40
47
  @user_home = nil if @user_home == UNSET_VALUE
41
48
  @user_home_env_var = nil if @user_home_env_var == UNSET_VALUE
42
-
49
+
43
50
  @root_user = nil if @root_user == UNSET_VALUE
44
51
  @root_home = nil if @root_home == UNSET_VALUE
45
-
52
+
46
53
  @bootstrap = nil if @bootstrap == UNSET_VALUE
47
54
  @bootstrap_path = nil if @bootstrap_path == UNSET_VALUE
48
55
  @bootstrap_glob = nil if @bootstrap_glob == UNSET_VALUE
49
56
  @bootstrap_init = nil if @bootstrap_init == UNSET_VALUE
57
+ @bootstrap_scripts = nil if @bootstrap_scripts == UNSET_VALUE
58
+ @ruby_version = nil if @ruby_version == UNSET_VALUE
59
+
50
60
  @auth_files = nil if @auth_files == UNSET_VALUE
51
-
61
+
52
62
  @seed = nil if @seed == UNSET_VALUE
53
63
  @project_reference = nil if @project_reference == UNSET_VALUE
54
64
  @project_branch = nil if @project_branch == UNSET_VALUE
65
+
66
+ @environment = nil if @environment == UNSET_VALUE
55
67
  end
56
-
68
+
57
69
  #-----------------------------------------------------------------------------
58
70
  # Property accessor / modifiers
59
-
60
- attr_accessor :network, :node
71
+
72
+ attr_accessor :network, :node
61
73
  attr_accessor :force_updates, :user_home, :user_home_env_var, :root_user, :root_home
62
-
63
- attr_accessor :bootstrap, :bootstrap_path, :bootstrap_glob, :bootstrap_init, :auth_files
74
+
75
+ attr_accessor :bootstrap, :bootstrap_path, :bootstrap_glob, :bootstrap_init, :bootstrap_scripts
76
+ attr_accessor :reboot, :dev_build, :ruby_version, :auth_files
64
77
  attr_accessor :seed, :project_reference, :project_branch
65
- attr_accessor :provision, :dry_run
66
-
78
+ attr_accessor :environment, :build, :provision, :dry_run
79
+
67
80
  #-----------------------------------------------------------------------------
68
81
  # Validation
69
82
 
70
83
  def validate(machine)
71
84
  errors = _detected_errors
72
-
85
+
73
86
  # TODO: Validation (with action config validators)
74
-
87
+
75
88
  { "CORL provisioner" => errors }
76
89
  end
77
90
  end
@@ -3,20 +3,20 @@ module VagrantPlugins
3
3
  module CORL
4
4
  module Provisioner
5
5
  class CORL < ::Vagrant.plugin("2", :provisioner)
6
-
6
+
7
7
  #-----------------------------------------------------------------------------
8
8
  # Constructor / Destructor
9
-
9
+
10
10
  def initialize(machine, config)
11
11
  super
12
12
  end
13
-
13
+
14
14
  #-----------------------------------------------------------------------------
15
15
  # Operations
16
16
 
17
17
  def configure(root_config)
18
18
  end
19
-
19
+
20
20
  #---
21
21
 
22
22
  def provision
@@ -26,10 +26,10 @@ class CORL < ::Vagrant.plugin("2", :provisioner)
26
26
  # This serves as a Vagrant VM manager.
27
27
  ::CORL::Vagrant.command = Command::Launcher.new([], @machine.env)
28
28
  end
29
-
29
+
30
30
  network = config.network
31
31
  node = config.node
32
-
32
+
33
33
  if network && node
34
34
  # Provision the server
35
35
  success = network.init_node(node, clean(::CORL.config(:vagrant_node_init, {
@@ -42,30 +42,36 @@ class CORL < ::Vagrant.plugin("2", :provisioner)
42
42
  :bootstrap_path => config.bootstrap_path,
43
43
  :bootstrap_glob => config.bootstrap_glob,
44
44
  :bootstrap_init => config.bootstrap_init,
45
+ :bootstrap_scripts => config.bootstrap_scripts,
46
+ :reboot => config.reboot,
47
+ :dev_build => config.dev_build,
48
+ :ruby_version => config.ruby_version,
45
49
  :auth_files => config.auth_files,
46
50
  :seed => config.seed,
47
51
  :project_reference => config.project_reference,
48
52
  :project_branch => config.project_branch,
53
+ :environment => config.environment,
54
+ :build => config.build,
49
55
  :provision => config.provision,
50
56
  :dry_run => config.dry_run
51
57
  }).export))
52
-
58
+
53
59
  node.warn("CORL provisioner failed", { :i18n => false }) unless success
54
60
  end
55
61
  end
56
62
  end
57
-
63
+
58
64
  #-----------------------------------------------------------------------------
59
65
  # Utilities
60
-
66
+
61
67
  def clean(options)
62
68
  options.keys.each do |key|
63
69
  value = options[key]
64
70
  if value.nil?
65
71
  options.delete(key)
66
- end
72
+ end
67
73
  end
68
- options
74
+ options
69
75
  end
70
76
  protected :clean
71
77
  end
@@ -25,6 +25,8 @@ class Bootstrap < Nucleon.plugin_class(:nucleon, :cloud_action)
25
25
  register_str :home_env_var, 'HOME'
26
26
  register_str :home, nil
27
27
 
28
+ register_str :ruby_version, nil
29
+
28
30
  register_str :bootstrap_glob, '**/*.sh'
29
31
  register_str :bootstrap_init, 'bootstrap.sh'
30
32
 
@@ -3,42 +3,43 @@ module Nucleon
3
3
  module Action
4
4
  module Node
5
5
  class Build < Nucleon.plugin_class(:nucleon, :cloud_action)
6
-
6
+
7
7
  #-----------------------------------------------------------------------------
8
8
  # Info
9
-
9
+
10
10
  def self.describe
11
11
  super(:node, :build, 620)
12
12
  end
13
-
13
+
14
14
  #-----------------------------------------------------------------------------
15
15
  # Settings
16
-
16
+
17
17
  def configure
18
18
  super do
19
19
  register_str :environment
20
+ register_array :providers
20
21
  end
21
22
  end
22
-
23
+
23
24
  #---
24
-
25
+
25
26
  def arguments
26
27
  [ :environment ]
27
28
  end
28
29
 
29
30
  #-----------------------------------------------------------------------------
30
31
  # Operations
31
-
32
+
32
33
  def execute
33
34
  super do |node|
34
- info('start')
35
+ info('start')
36
+
35
37
  ensure_node(node) do
36
38
  settings.delete(:environment) if settings[:environment] == ''
37
-
39
+
38
40
  if settings.has_key?(:environment)
39
- node.create_fact(:corl_environment, settings[:environment])
40
- end
41
-
41
+ CORL.create_fact(:corl_environment, settings[:environment])
42
+ end
42
43
  node.build(settings)
43
44
  end
44
45
  end