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,33 +2,33 @@
2
2
  module CORL
3
3
  module Provisioner
4
4
  class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
5
-
5
+
6
6
  @@puppet_lock = Mutex.new
7
-
7
+
8
8
  #---
9
-
9
+
10
10
  @@status = {}
11
-
11
+
12
12
  def self.status
13
13
  @@status
14
14
  end
15
-
15
+
16
16
  #---
17
-
17
+
18
18
  def self.network
19
19
  @@network
20
20
  end
21
-
21
+
22
22
  def self.node
23
23
  @@node
24
24
  end
25
-
25
+
26
26
  #-----------------------------------------------------------------------------
27
27
  # Provisioner plugin interface
28
-
28
+
29
29
  def normalize(reload)
30
30
  super do
31
- if CORL.log_level == :debug
31
+ if [ :debug, :info, :warn ].include? CORL.log_level
32
32
  Puppet.debug = true
33
33
  end
34
34
  unless reload
@@ -47,67 +47,70 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
47
47
  str = msg.respond_to?(:multiline) ? msg.multiline : msg.to_s
48
48
  str = msg.source == "Puppet" ? str : "#{CORL.blue(msg.source)}: #{str}"
49
49
  level = levels[msg.level]
50
-
51
- if [ :warn, :error ].include?(level[:send])
50
+
51
+ if [ :error ].include?(level[:send])
52
52
  ::CORL::Provisioner::Puppetnode.status[name] = 111
53
53
  end
54
-
54
+
55
55
  CORL.ui_group("puppetnode::#{name}(#{CORL.yellow(level[:name])})", :cyan) do |ui|
56
56
  ui.send(level[:send], str)
57
57
  end
58
+ puts caller if level[:send] == :error && [ :warn, :error ].include?(CORL.log_level)
58
59
  end
59
60
  end
60
61
  end
61
62
  end
62
63
  end
63
-
64
+
64
65
  #---
65
-
66
+
66
67
  def register(options = {})
67
68
  Util::Puppet.register_plugins(Config.ensure(options).defaults({ :puppet_scope => scope }))
68
69
  end
69
-
70
+
70
71
  #-----------------------------------------------------------------------------
71
72
  # Property accessor / modifiers
72
-
73
+
73
74
  def compiler
74
75
  @compiler
75
76
  end
76
-
77
+
77
78
  #---
78
-
79
+
79
80
  def scope
80
81
  return compiler.topscope if compiler
81
82
  nil
82
83
  end
83
-
84
+
84
85
  #-----------------------------------------------------------------------------
85
86
  # Puppet initialization
86
-
87
- def init_puppet(node, profiles)
87
+
88
+ def init_puppet(node, profiles)
88
89
  Puppet.initialize_settings
89
-
90
+
90
91
  apply_environment = nil
91
92
  locations = build_locations(node)
92
-
93
- environment, environment_directory = ensure_environment(node)
94
-
95
- Puppet::Util::Log.newdestination(id)
93
+
94
+ environment, environment_directory = ensure_environment(node)
95
+
96
+ Puppet::Util::Log.newdestination(id)
96
97
  Puppet::Transaction::Report.indirection.cache_class = :yaml
97
-
98
+
98
99
  Puppet[:graph] = true if CORL.log_level == :error
99
-
100
+
100
101
  Puppet[:node_terminus] = :plain
101
102
  Puppet[:data_binding_terminus] = :corl
102
103
  Puppet[:default_file_terminus] = :file_server
103
-
104
+
104
105
  unless profiles.empty?
105
106
  modulepath = profiles.collect do |profile|
106
- profile_directory = File.join(network.directory, locations[:puppet_module][profile.to_sym])
107
- File.directory?(profile_directory) ? profile_directory : nil
107
+ profile_path = locations[:puppet_module][profile.to_sym]
108
+ profile_directory = nil
109
+ profile_directory = File.join(network.directory, profile_path) if profile_path
110
+ profile_directory && File.directory?(profile_directory) ? profile_directory : nil
108
111
  end.compact
109
112
  end
110
-
113
+
111
114
  if manifest = gateway
112
115
  if manifest.match(/^packages\/.*/)
113
116
  manifest = File.join(network.build_directory, manifest)
@@ -115,54 +118,54 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
115
118
  manifest = File.join(network.directory, directory, manifest)
116
119
  end
117
120
  end
118
-
121
+
119
122
  Puppet[:environment] = environment
120
123
  Puppet::Node::Environment.create(environment.to_sym, modulepath, manifest)
121
124
  end
122
125
  protected :init_puppet
123
-
126
+
124
127
  #---
125
-
128
+
126
129
  def get_puppet_node(environment)
127
130
  Puppet[:node_name_value] = id.to_s
128
-
131
+
129
132
  puppet_node = Puppet::Node.indirection.find(id.to_s, :environment => environment)
130
-
131
- puppet_node.merge(string_map(@@node.facts))
133
+
134
+ puppet_node.merge(string_map(@@node.facts))
132
135
  puppet_node
133
136
  end
134
137
  protected :get_puppet_node
135
-
138
+
136
139
  #-----------------------------------------------------------------------------
137
140
  # Provisioner interface operations
138
-
141
+
139
142
  def build_profile(name, info, package, environment, profiles)
140
143
  super do |processed_info|
141
144
  package_id = id(package)
142
145
  directory = File.join(internal_path(build_directory), package_id.to_s, name.to_s)
143
146
  success = true
144
-
145
- info("Building CORL profile #{blue(name)} modules into #{green(directory)}", { :i18n => false })
146
-
147
+
148
+ #info("Building CORL profile #{blue(name)} modules into #{green(directory)}", { :i18n => false })
149
+
147
150
  if processed_info.has_key?(:modules)
148
151
  status = parallel(:build_module, hash(processed_info[:modules]), directory, name, environment)
149
152
  success = status.values.include?(false) ? false : true
150
-
153
+
151
154
  build_config.set_location(:puppet_module, profile_id(package, name), directory) if success
152
155
  end
153
- success("Build of profile #{blue(name)} finished", { :i18n => false }) if success
156
+ #success("Build of profile #{blue(name)} finished", { :i18n => false }) if success
154
157
  success
155
158
  end
156
159
  end
157
-
160
+
158
161
  def build_module(name, project_reference, directory, profile, environment)
159
162
  module_directory = File.join(directory, name.to_s)
160
163
  full_module_directory = File.join(network.directory, module_directory)
161
164
  module_project = nil
162
165
  success = true
163
-
166
+
164
167
  info("Building #{blue(profile)} Puppet module #{blue(name)} at #{purple(project_reference)} into #{green(module_directory)}", { :i18n => false })
165
-
168
+
166
169
  module_project = build_config.manage(:project, extended_config(:puppet_module, {
167
170
  :directory => full_module_directory,
168
171
  :url => project_reference,
@@ -175,55 +178,56 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
175
178
  warn("Puppet module #{cyan(name)} failed to initialize", { :i18n => false })
176
179
  success = false
177
180
  end
178
- success("Build of #{blue(profile)} #{blue(name)} finished", { :i18n => false }) if success
181
+ #success("Build of #{blue(profile)} #{blue(name)} finished", { :i18n => false }) if success
179
182
  success
180
183
  end
181
-
184
+
182
185
  #---
183
-
186
+
184
187
  def lookup(property, default = nil, options = {})
185
188
  Util::Puppet.lookup(property, default, Config.ensure(options).defaults({
186
189
  :provisioner => :puppetnode,
187
190
  :puppet_scope => scope
188
191
  }))
189
192
  end
190
-
193
+
191
194
  #--
192
-
195
+
193
196
  def import(files, options = {})
194
197
  Util::Puppet.import(files, Config.ensure(options).defaults({
195
198
  :puppet_scope => scope,
196
199
  :puppet_import_base => network.directory
197
200
  }))
198
201
  end
199
-
202
+
200
203
  #---
201
-
204
+
202
205
  def add_search_path(type, resource_name)
203
206
  Config.set_options([ :all, type ], { :search => [ resource_name.to_s ] })
204
207
  end
205
-
208
+
206
209
  #---
207
-
210
+
208
211
  def provision(node, profiles, options = {})
209
212
  super do |processed_profiles, config|
210
213
  locations = build_locations(node)
211
214
  success = true
212
-
215
+
213
216
  include_location = lambda do |type, parameters = {}, add_search_path = false|
214
217
  classes = {}
215
-
216
- locations[:package].each do |name, package_directory|
217
- type_gateway = File.join(network.directory, package_directory, "#{type}.pp")
218
- resource_name = resource([ name, type ])
219
-
218
+
219
+ locations[:package].keys.reverse.each do |name|
220
+ package_directory = locations[:package][name]
221
+ type_gateway = File.join(network.directory, package_directory, "#{type}.pp")
222
+ resource_name = resource([ name, type ])
223
+
220
224
  add_search_path(type, resource_name) if add_search_path
221
-
225
+
222
226
  if File.exists?(type_gateway)
223
227
  import(type_gateway)
224
228
  classes[resource_name] = parameters
225
229
  end
226
-
230
+
227
231
  type_directory = File.join(network.directory, package_directory, type.to_s)
228
232
  Dir.glob(File.join(type_directory, '*.pp')).each do |file|
229
233
  resource_name = resource([ name, type, File.basename(file).gsub('.pp', '') ])
@@ -231,19 +235,19 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
231
235
  classes[resource_name] = parameters
232
236
  end
233
237
  end
234
-
238
+
235
239
  type_gateway = File.join(directory, "#{type}.pp")
236
240
  resource_name = resource([ plugin_name, type ])
237
-
241
+
238
242
  add_search_path(type, resource_name) if add_search_path
239
-
243
+
240
244
  if File.exists?(type_gateway)
241
245
  import(type_gateway)
242
246
  classes[resource_name] = parameters
243
247
  end
244
-
248
+
245
249
  type_directory = File.join(directory, type.to_s)
246
-
250
+
247
251
  if File.directory?(type_directory)
248
252
  Dir.glob(File.join(type_directory, '*.pp')).each do |file|
249
253
  resource_name = resource([ plugin_name, type, File.basename(file).gsub('.pp', '') ])
@@ -253,75 +257,77 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
253
257
  end
254
258
  classes
255
259
  end
256
-
260
+
257
261
  @@puppet_lock.synchronize do
258
262
  begin
259
263
  info("Starting catalog generation", { :i18n => false })
260
-
264
+
261
265
  @@status[id] = code.success
262
- @@network = network
266
+ @@network = network
263
267
  @@node = node
264
-
268
+
265
269
  start_time = Time.now
266
270
  apply_environment = init_puppet(node, processed_profiles)
267
-
271
+
268
272
  Puppet.override(:environments => Puppet::Environments::Static.new(apply_environment)) do
269
- puppet_node = get_puppet_node(apply_environment.name)
273
+ puppet_node = get_puppet_node(apply_environment.name)
270
274
  @compiler = Puppet::Parser::Compiler.new(puppet_node)
271
-
275
+
272
276
  # Register Puppet module plugins
273
277
  register
274
-
278
+
275
279
  # Include defaults
276
280
  classes = include_location.call(:default, {}, true)
277
-
281
+
278
282
  # Import needed profiles
279
283
  include_location.call(:profiles, {}, false)
280
-
284
+
281
285
  processed_profiles.each do |profile|
282
286
  classes[profile.to_s] = { :require => 'Anchor[profile_start]' }
283
287
  end
284
-
288
+
285
289
  puppet_node.classes = classes
286
-
290
+
287
291
  # Compile catalog
288
292
  compiler.compile
289
-
293
+
290
294
  catalog = compiler.catalog.to_ral
291
295
  catalog.finalize
292
296
  catalog.retrieval_duration = Time.now - start_time
293
-
297
+
294
298
  unless config.get(:dry_run, false)
295
299
  info("\n", { :prefix => false, :i18n => false })
296
300
  info("Starting configuration run", { :i18n => false })
297
-
301
+
298
302
  # Configure the machine
303
+ Puppet.push_context({ :current_environment => apply_environment }, "CORL environment for configurer transaction")
304
+
299
305
  configurer = Puppet::Configurer.new
300
306
  if ! configurer.run(:catalog => catalog, :pluginsync => false)
301
307
  success = false
302
308
  end
303
309
  end
304
310
  end
305
-
311
+
306
312
  rescue Exception => error
307
313
  Puppet.log_exception(error)
308
- raise error
314
+ success = false
309
315
  end
310
316
  end
311
-
317
+
312
318
  success = false if @@status[id] != code.success
313
319
  success
314
320
  end
315
321
  end
316
-
322
+
317
323
  #-----------------------------------------------------------------------------
318
324
  # Utilities
319
-
325
+
320
326
  def ensure_environment(node)
321
327
  base_directory = Puppet[:environmentpath]
322
328
  environment = node.lookup(:corl_environment)
323
329
  env_directory = File.join(base_directory, environment)
324
-
330
+
325
331
  FileUtils.mkdir_p(env_directory)
326
332
  FileUtils.mkdir_p(File.join(env_directory, 'manifests'))
327
333
  FileUtils.mkdir_p(File.join(env_directory, 'modules'))
data/lib/core/build.rb CHANGED
@@ -1,37 +1,35 @@
1
1
 
2
2
  module CORL
3
- class Build < Core
4
-
5
- include Parallel
6
-
3
+ class Build
4
+
7
5
  #-----------------------------------------------------------------------------
8
6
  # Constructor / destructor
9
-
7
+
10
8
  def initialize
11
- @config = Config.new
12
- @locations = Config.new
13
-
9
+ @config = Config.new({}, {}, true, false)
10
+ @locations = Config.new({}, {}, true, false)
11
+
14
12
  @plurals = {}
15
13
  @types = {}
16
14
  end
17
-
15
+
18
16
  #-----------------------------------------------------------------------------
19
17
  # Build lock
20
-
18
+
21
19
  @@build_lock = Mutex.new
22
-
20
+
23
21
  #---
24
-
22
+
25
23
  def build_lock
26
24
  @@build_lock
27
25
  end
28
-
26
+
29
27
  #-----------------------------------------------------------------------------
30
28
  # Type registration
31
-
29
+
32
30
  def register(type, plural = nil)
33
31
  type = type.to_sym
34
-
32
+
35
33
  if plural
36
34
  plural = plural.to_sym
37
35
  else
@@ -40,73 +38,73 @@ class Build < Core
40
38
  @plurals[plural] = type
41
39
  @types[type] = Config.new
42
40
  end
43
-
41
+
44
42
  #-----------------------------------------------------------------------------
45
43
  # Package configuration
46
-
44
+
47
45
  def config
48
- @config
46
+ @config
49
47
  end
50
-
48
+
51
49
  def import(config)
52
- @config.import(config)
50
+ @config.import(config)
53
51
  end
54
-
52
+
55
53
  #-----------------------------------------------------------------------------
56
54
  # Build locations
57
-
55
+
58
56
  def locations
59
57
  @locations
60
58
  end
61
-
59
+
62
60
  def set_location(provider, name, directory)
63
61
  @locations.set([ provider, name ], directory)
64
62
  end
65
-
63
+
66
64
  def remove_location(provider, name = nil)
67
65
  @locations.delete([ provider, name ])
68
66
  end
69
-
67
+
70
68
  #-----------------------------------------------------------------------------
71
69
  # Addon build types
72
-
70
+
73
71
  def method_missing(method, *args, &code)
74
72
  success = false
75
73
  result = nil
76
-
74
+
77
75
  if method.to_s.match(/^set\_([a-z].*)$/)
78
76
  name = $1.to_sym
79
-
77
+
80
78
  if @types.has_key?(name) && args.length > 2
81
79
  @types[name].set([ args[0], args[1] ], args[2]) if args.length > 2
82
80
  success = true
83
81
  end
84
-
82
+
85
83
  elsif method.to_s.match(/^remove\_([a-z].*)$/)
86
84
  name = $1.to_sym
87
-
85
+
88
86
  if @types.has_key?(name) && args.length > 0
89
87
  @types[name].delete([ args[0], args[1] ])
90
88
  success = true
91
89
  end
92
-
90
+
93
91
  else
94
92
  name = @plurals[method.to_sym]
95
-
93
+
96
94
  if name && @types.has_key?(name)
97
95
  result = @types[name]
98
96
  success = true
99
- end
97
+ end
100
98
  end
101
99
  super unless success # Raise NoMethodError
102
100
  result
103
101
  end
104
-
102
+
105
103
  #-----------------------------------------------------------------------------
106
104
  # Builders
107
-
105
+
108
106
  def manage(plugin_type, options = {})
109
107
  CORL.send(plugin_type, options)
110
- end
108
+ end
111
109
  end
112
110
  end
@@ -409,7 +409,7 @@ class Network < Nucleon.plugin_class(:nucleon, :base)
409
409
 
410
410
  if success && seed_project
411
411
  # Seed machine with remote project reference
412
- result = node.node_seed({
412
+ result = node.action(:node_seed, {
413
413
  :project_reference => seed_project,
414
414
  :project_branch => seed_branch
415
415
  }) do |op, data|
@@ -423,7 +423,7 @@ class Network < Nucleon.plugin_class(:nucleon, :base)
423
423
 
424
424
  if success && provision
425
425
  # Run configured provisioners on machine
426
- result = node.node_provision(config) do |op, data|
426
+ result = node.action(:node_provision, config) do |op, data|
427
427
  yield("provision_#{op}".to_sym, data)
428
428
  end
429
429
  success = result.status == code.success