corl 0.5.6 → 0.5.7

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -1
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +4 -0
  5. data/README.rdoc +125 -517
  6. data/Rakefile +57 -0
  7. data/VERSION +1 -1
  8. data/bootstrap/os/ubuntu/00_base.sh +10 -7
  9. data/bootstrap/os/ubuntu/05_ruby.sh +4 -4
  10. data/corl.gemspec +32 -5
  11. data/info/AUTOMATION.rdoc +5 -0
  12. data/info/INSTALLATION.rdoc +163 -0
  13. data/info/PACKAGING.rdoc +171 -0
  14. data/info/PLUGINS.rdoc +57 -0
  15. data/info/TODO.rdoc +27 -0
  16. data/lib/CORL/configuration/file.rb +2 -2
  17. data/lib/CORL/machine/docker.rb +327 -0
  18. data/lib/CORL/machine/vagrant.rb +142 -107
  19. data/lib/CORL/node/docker.rb +269 -0
  20. data/lib/CORL/node/vagrant.rb +23 -0
  21. data/lib/CORL/provisioner/puppetnode.rb +52 -27
  22. data/lib/core/facade.rb +36 -34
  23. data/lib/core/mixin/builder.rb +44 -44
  24. data/lib/core/mixin/machine/ssh.rb +34 -34
  25. data/lib/core/mod/vagrant.rb +32 -0
  26. data/lib/core/plugin/cloud_action.rb +1 -1
  27. data/lib/core/plugin/machine.rb +85 -85
  28. data/lib/core/plugin/network.rb +23 -9
  29. data/lib/core/plugin/node.rb +10 -7
  30. data/lib/core/plugin/provisioner.rb +3 -3
  31. data/lib/core/vagrant/action.rb +15 -13
  32. data/lib/core/vagrant/actions/include_overrides.rb +17 -0
  33. data/lib/core/vagrant/actions/init_keys.rb +9 -5
  34. data/lib/core/vagrant/commands/launcher.rb +1 -1
  35. data/lib/core/vagrant/config.rb +343 -143
  36. data/lib/core/vagrant/plugins.rb +14 -14
  37. data/lib/corl.rb +3 -7
  38. data/lib/nucleon/action/node/provision.rb +15 -4
  39. data/lib/nucleon/action/node/seed.rb +2 -2
  40. data/lib/nucleon/extension/vagrant.rb +30 -0
  41. data/locales/en.yml +5 -0
  42. data/rdoc/site/0.5.7/README.rdoc +595 -0
  43. data/rdoc/site/0.5.7/info/AUTOMATION.rdoc +382 -0
  44. data/rdoc/site/0.5.7/info/INSTALLATION.rdoc +543 -0
  45. data/rdoc/site/0.5.7/info/PACKAGES.rdoc +556 -0
  46. data/rdoc/site/0.5.7/info/PACKAGING.rdoc +563 -0
  47. data/rdoc/site/0.5.7/info/PLUGINS.rdoc +534 -0
  48. data/rdoc/site/0.5.7/info/TODO.rdoc +412 -0
  49. data/tmp/README.rdoc +217 -0
  50. data/tmp/info/AUTOMATION.rdoc +6 -0
  51. data/tmp/info/INSTALLATION.rdoc +158 -0
  52. data/tmp/info/PACKAGES.rdoc +177 -0
  53. data/tmp/info/PACKAGING.rdoc +184 -0
  54. data/tmp/info/PLUGINS.rdoc +129 -0
  55. data/tmp/info/README.rdoc +217 -0
  56. data/tmp/info/TODO.rdoc +36 -0
  57. metadata +41 -3
  58. data/TODO.rdoc +0 -12
@@ -32,6 +32,18 @@ class Vagrant < Nucleon.plugin_class(:CORL, :node)
32
32
 
33
33
  #---
34
34
 
35
+ def public_ip(reset = false)
36
+ return machine.public_ip if machine
37
+ nil
38
+ end
39
+
40
+ def private_ip(reset = false)
41
+ return machine.private_ip if machine
42
+ nil
43
+ end
44
+
45
+ #---
46
+
35
47
  def vm=vm
36
48
  myself[:vm] = vm
37
49
  end
@@ -52,6 +64,17 @@ class Vagrant < Nucleon.plugin_class(:CORL, :node)
52
64
 
53
65
  #---
54
66
 
67
+ def image=image
68
+ # Images can not be set
69
+ end
70
+
71
+ def image(reset = false)
72
+ return machine.image if machine
73
+ nil
74
+ end
75
+
76
+ #---
77
+
55
78
  def shares=shares
56
79
  myself[:shares] = shares
57
80
  init_shares
@@ -86,6 +86,9 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
86
86
  # Puppet initialization
87
87
 
88
88
  def init_puppet(node, profiles)
89
+ require 'puppet'
90
+ require 'puppet/configurer'
91
+
89
92
  Puppet.initialize_settings
90
93
 
91
94
  apply_environment = nil
@@ -93,6 +96,8 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
93
96
 
94
97
  environment, environment_directory = ensure_environment(node)
95
98
 
99
+ return nil unless environment
100
+
96
101
  Puppet::Util::Log.newdestination(id)
97
102
  Puppet::Transaction::Report.indirection.cache_class = :yaml
98
103
 
@@ -269,47 +274,57 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
269
274
  start_time = Time.now
270
275
  apply_environment = init_puppet(node, processed_profiles)
271
276
 
272
- Puppet.override(:environments => Puppet::Environments::Static.new(apply_environment)) do
273
- puppet_node = get_puppet_node(apply_environment.name)
274
- @compiler = Puppet::Parser::Compiler.new(puppet_node)
277
+ if apply_environment.nil?
278
+ success = false
279
+ else
280
+ Puppet.override(:environments => Puppet::Environments::Static.new(apply_environment)) do
281
+ puppet_node = get_puppet_node(apply_environment.name)
282
+ @compiler = Puppet::Parser::Compiler.new(puppet_node)
275
283
 
276
- # Register Puppet module plugins
277
- register
284
+ # Register Puppet module plugins
285
+ register
278
286
 
279
- # Include defaults
280
- classes = include_location.call(:default, {}, true)
287
+ # Include defaults
288
+ classes = include_location.call(:default, {}, true)
281
289
 
282
- # Import needed profiles
283
- include_location.call(:profiles, {}, false)
290
+ # Import needed profiles
291
+ include_location.call(:profiles, {}, false)
284
292
 
285
- processed_profiles.each do |profile|
286
- classes[profile.to_s] = { :require => 'Anchor[profile_start]' }
287
- end
293
+ processed_profiles.each do |profile|
294
+ classes[profile.to_s] = { :require => 'Anchor[profile_start]' }
295
+ end
288
296
 
289
- puppet_node.classes = classes
297
+ puppet_node.classes = classes
290
298
 
291
- # Compile catalog
292
- compiler.compile
299
+ # Compile catalog
300
+ compiler.compile
293
301
 
294
- catalog = compiler.catalog.to_ral
295
- catalog.finalize
296
- catalog.retrieval_duration = Time.now - start_time
302
+ catalog = compiler.catalog.to_ral
303
+ catalog.finalize
304
+ catalog.retrieval_duration = Time.now - start_time
297
305
 
298
- unless config.get(:dry_run, false)
299
- info("\n", { :prefix => false, :i18n => false })
300
- info("Starting configuration run at #{Time.now.to_s}", { :i18n => false })
306
+ unless config.get(:dry_run, false)
307
+ info("\n", { :prefix => false, :i18n => false })
308
+ info("Starting configuration run at #{Time.now.to_s}", { :i18n => false })
301
309
 
302
- # Configure the machine
303
- Puppet.push_context({ :current_environment => apply_environment }, "CORL environment for configurer transaction")
310
+ # Configure the machine
311
+ Puppet.push_context({ :current_environment => apply_environment }, "CORL environment for configurer transaction")
304
312
 
305
- configurer = Puppet::Configurer.new
306
- if ! configurer.run(:catalog => catalog, :pluginsync => false)
307
- success = false
313
+ configurer = Puppet::Configurer.new
314
+ if ! configurer.run(:catalog => catalog, :pluginsync => false)
315
+ success = false
316
+ end
308
317
  end
309
318
  end
310
319
  end
311
320
 
312
321
  rescue Exception => error
322
+ if [ :debug, :info, :warn, :error ].include? CORL.log_level
323
+ logger.error("Puppetnode provisioner experienced an error:")
324
+ logger.error(error.inspect)
325
+ logger.error(error.message)
326
+ logger.error(Util::Data.to_yaml(error.backtrace))
327
+ end
313
328
  Puppet.log_exception(error)
314
329
  success = false
315
330
  end
@@ -326,7 +341,17 @@ class Puppetnode < Nucleon.plugin_class(:CORL, :provisioner)
326
341
  def ensure_environment(node)
327
342
  base_directory = Puppet[:environmentpath]
328
343
  environment = node.lookup(:corl_environment)
329
- env_directory = File.join(base_directory, environment)
344
+
345
+ if environment.nil?
346
+ environment = node.lookup(:environment)
347
+
348
+ if environment.nil?
349
+ error("Environment facts 'corl_environment' or 'environment' must be set to provision", { :i18n => false })
350
+ return []
351
+ end
352
+ end
353
+
354
+ env_directory = File.join(base_directory, environment)
330
355
 
331
356
  FileUtils.mkdir_p(env_directory)
332
357
  FileUtils.mkdir_p(File.join(env_directory, 'manifests'))
data/lib/core/facade.rb CHANGED
@@ -4,9 +4,9 @@ module Facade
4
4
 
5
5
  #-----------------------------------------------------------------------------
6
6
  # Facter lookup
7
-
7
+
8
8
  @@facts = {}
9
-
9
+
10
10
  def facts(reset = false)
11
11
  if reset || @@facts.empty?
12
12
  @@facts = {} if reset
@@ -18,103 +18,105 @@ module Facade
18
18
  end
19
19
  @@facts
20
20
  end
21
-
21
+
22
22
  #---
23
-
23
+
24
24
  def create_fact(name, value, weight = 1000)
25
- Facter.collection.add(name.to_sym, {
26
- :value => value,
27
- :weight => weight
25
+ Facter.collection.add(name.to_sym, {
26
+ :value => value,
27
+ :weight => weight
28
28
  })
29
29
  end
30
-
30
+
31
31
  #---
32
-
32
+
33
33
  def fact(name)
34
34
  silence do
35
35
  Facter.value(name)
36
36
  end
37
37
  end
38
-
38
+
39
39
  #-----------------------------------------------------------------------------
40
40
  # Local identification
41
-
41
+
42
42
  def public_ip
43
43
  if Config.fact(:vagrant_exists)
44
- Config.fact(:ipaddress_eth1)
44
+ ip_address = Config.fact(:ipaddress_eth1)
45
+ ip_address = Config.fact(:ipaddress_eth0) unless ip_address
46
+ ip_address
45
47
  else
46
- CORL.ip_address
48
+ CORL.ip_address
47
49
  end
48
50
  end
49
-
51
+
50
52
  #-----------------------------------------------------------------------------
51
53
  # Vagrant related
52
-
54
+
53
55
  def vagrant?
54
56
  Vagrant.command ? true : false
55
57
  end
56
-
58
+
57
59
  #---
58
-
60
+
59
61
  @@vagrant_config_loaded = false
60
-
62
+
61
63
  def vagrant_config_loaded?
62
64
  @@vagrant_config_loaded
63
65
  end
64
-
66
+
65
67
  def vagrant_config(directory, config, &code)
66
68
  Vagrant::Config.register(directory, config, &code)
67
69
  @@vagrant_config_loaded = true
68
70
  end
69
-
71
+
70
72
  #-----------------------------------------------------------------------------
71
73
  # Core plugin type facade
72
-
74
+
73
75
  def configuration(options, provider = nil)
74
76
  plugin(:CORL, :configuration, provider, options)
75
77
  end
76
-
78
+
77
79
  def configurations(data, build_hash = false, keep_array = false)
78
80
  plugins(:CORL, :configuration, data, build_hash, keep_array)
79
81
  end
80
-
82
+
81
83
  #-----------------------------------------------------------------------------
82
84
  # Cluster plugin type facade
83
-
85
+
84
86
  def network(name, options = {}, provider = nil)
85
87
  plugin(:CORL, :network, provider, Config.ensure(options).import({ :name => name }))
86
88
  end
87
-
89
+
88
90
  def networks(data, build_hash = false, keep_array = false)
89
91
  plugins(:CORL, :network, data, build_hash, keep_array)
90
92
  end
91
-
93
+
92
94
  #---
93
-
95
+
94
96
  def node(name, options = {}, provider = nil)
95
97
  plugin(:CORL, :node, provider, Config.ensure(options).import({ :name => name }))
96
98
  end
97
-
99
+
98
100
  def nodes(data, build_hash = false, keep_array = false)
99
101
  plugins(:CORL, :node, data, build_hash, keep_array)
100
102
  end
101
-
103
+
102
104
  #---
103
-
105
+
104
106
  def builder(options, provider = nil)
105
107
  plugin(:CORL, :builder, provider, options)
106
108
  end
107
-
109
+
108
110
  def builders(data, build_hash = false, keep_array = false)
109
111
  plugins(:CORL, :builder, data, build_hash, keep_array)
110
112
  end
111
-
113
+
112
114
  #---
113
-
115
+
114
116
  def provisioner(options, provider = nil)
115
117
  plugin(:CORL, :provisioner, provider, options)
116
118
  end
117
-
119
+
118
120
  def provisioners(data, build_hash = false, keep_array = false)
119
121
  plugins(:CORL, :provisioner, data, build_hash, keep_array)
120
122
  end
@@ -3,54 +3,54 @@ module CORL
3
3
  module Mixin
4
4
  module Builder
5
5
  module Global # Extend
6
-
6
+
7
7
  #-----------------------------------------------------------------------------
8
8
  # Accessors / modifiers
9
-
9
+
10
10
  def resource_joiner
11
11
  '::'
12
12
  end
13
-
13
+
14
14
  #---
15
-
15
+
16
16
  def id_joiner
17
17
  '__'
18
18
  end
19
-
19
+
20
20
  #-----------------------------------------------------------------------------
21
21
  # Utilities
22
-
22
+
23
23
  def id(name = nil)
24
24
  name = 'unknown' if name.nil?
25
25
  name = [ name ] unless name.is_a?(Array)
26
26
  components = []
27
-
27
+
28
28
  name.flatten.each do |component|
29
29
  components << component.to_s.gsub(resource_joiner, id_joiner)
30
30
  end
31
31
  components.join(id_joiner).to_sym
32
32
  end
33
-
33
+
34
34
  #---
35
-
35
+
36
36
  def resource(name = nil, capitalize = false)
37
37
  name = 'unknown' if name.nil?
38
38
  concatenate(name, capitalize, resource_joiner)
39
39
  end
40
-
40
+
41
41
  #---
42
-
42
+
43
43
  def concatenate(components, capitalize = false, joiner = nil)
44
44
  joiner = resource_joiner unless joiner
45
-
45
+
46
46
  if components.is_a?(Array)
47
47
  components = components.collect do |str|
48
- str.to_s.split(id_joiner)
48
+ str.to_s.split(id_joiner)
49
49
  end.flatten
50
50
  else
51
51
  components = [ components.to_s.split(id_joiner) ].flatten
52
52
  end
53
-
53
+
54
54
  if capitalize
55
55
  name = components.collect {|str| str.capitalize }.join(joiner)
56
56
  else
@@ -58,100 +58,100 @@ module Global # Extend
58
58
  end
59
59
  name
60
60
  end
61
-
61
+
62
62
  #---
63
-
63
+
64
64
  def process_environment(settings, environment = nil)
65
- config = Config.new(hash(settings))
65
+ config = Config.new(hash(settings), {}, true, false)
66
66
  env_config = config.delete(:environment)
67
67
  environment = environment.to_sym if environment
68
-
69
- if env_config
68
+
69
+ if env_config
70
70
  if environment && env_config.has_key?(environment)
71
71
  local_env_config = env_config[environment]
72
-
72
+
73
73
  while local_env_config && local_env_config.has_key?(:use) do
74
74
  local_env_config = env_config[local_env_config[:use].to_sym]
75
75
  end
76
-
76
+
77
77
  config.defaults(local_env_config) if local_env_config
78
78
  end
79
79
  config.defaults(env_config[:default]) if env_config.has_key?(:default)
80
80
  end
81
- config.export
81
+ config.export
82
82
  end
83
83
  end
84
84
 
85
85
  #-------------------------------------------------------------------------------
86
86
 
87
87
  module Instance # Include
88
-
88
+
89
89
  extend Global
90
-
90
+
91
91
  #-----------------------------------------------------------------------------
92
92
  # Accessors / modifiers
93
-
93
+
94
94
  def resource_joiner
95
95
  self.class.resource_joiner
96
96
  end
97
-
97
+
98
98
  #---
99
-
99
+
100
100
  def id_joiner
101
101
  self.class.id_joiner
102
102
  end
103
-
103
+
104
104
  #---
105
-
105
+
106
106
  def build_directory
107
107
  network.build_directory
108
108
  end
109
-
109
+
110
110
  #---
111
-
111
+
112
112
  def build_config
113
113
  return network.build if network
114
114
  nil
115
115
  end
116
-
116
+
117
117
  #---
118
-
118
+
119
119
  def build_lock
120
120
  self.class.build_lock
121
121
  end
122
-
122
+
123
123
  #-----------------------------------------------------------------------------
124
124
  # Utilities
125
-
125
+
126
126
  def id(name = nil)
127
127
  name = plugin_name if name.nil?
128
128
  self.class.id(name)
129
129
  end
130
-
130
+
131
131
  #---
132
-
132
+
133
133
  def resource(name = nil, capitalize = false)
134
134
  name = plugin_name if name.nil?
135
135
  self.class.resource(name, capitalize)
136
136
  end
137
-
137
+
138
138
  #---
139
-
139
+
140
140
  def concatenate(components, capitalize = false, joiner = nil)
141
141
  self.class.concatenate(components, capitalize, joiner)
142
142
  end
143
-
143
+
144
144
  #---
145
-
145
+
146
146
  def internal_path(directory)
147
147
  directory.gsub(network.directory + "/", '')
148
148
  end
149
-
149
+
150
150
  #---
151
-
151
+
152
152
  def process_environment(settings, environment = nil)
153
153
  self.class.process_environment(settings, environment)
154
- end
154
+ end
155
155
  end
156
156
  end
157
157
  end
@@ -5,122 +5,122 @@ module SSH
5
5
 
6
6
  #-----------------------------------------------------------------------------
7
7
  # SSH Operations
8
-
8
+
9
9
  def init_ssh_session(reset = false, tries = 12, sleep_secs = 5)
10
10
  ssh_wait_for_ready
11
-
11
+
12
12
  success = true
13
-
14
- public_ip = node.public_ip
13
+
14
+ public_ip = node.public_ip(true)
15
15
  user = node.user
16
16
  ssh_port = node.ssh_port
17
17
  private_key = node.private_key
18
-
19
- ssh_config = Config.new({
18
+
19
+ ssh_config = Config.new({
20
20
  :keypair => node.keypair,
21
21
  :key_dir => node.network.key_cache_directory,
22
- :key_name => node.plugin_name
22
+ :key_name => node.plugin_name
23
23
  })
24
-
24
+
25
25
  begin
26
26
  Util::SSH.session(public_ip, user, ssh_port, private_key, reset, ssh_config)
27
27
  node.keypair = ssh_config[:keypair]
28
-
28
+
29
29
  rescue Net::SSH::HostKeyMismatch => error
30
30
  error.remember_host!
31
31
  sleep 0.2
32
32
  reset = true
33
33
  retry
34
34
 
35
- rescue Errno::ECONNREFUSED, Net::SSH::ConnectionTimeout, Net::SSH::Disconnect => error
35
+ rescue Errno::ECONNREFUSED, Net::SSH::ConnectionTimeout, Net::SSH::Disconnect => error
36
36
  if tries > 1
37
37
  sleep(sleep_secs)
38
-
38
+
39
39
  tries -= 1
40
40
  reset = true
41
41
  retry
42
42
  else
43
43
  success = false
44
44
  end
45
-
45
+
46
46
  rescue => error
47
47
  warn(error, { :i18n => false })
48
48
  success = false
49
49
  end
50
50
  success
51
51
  end
52
-
52
+
53
53
  #---
54
-
54
+
55
55
  def ssh_download(remote_path, local_path, options = {}, &code)
56
56
  config = Config.ensure(options)
57
57
  success = false
58
-
58
+
59
59
  begin
60
60
  if init_ssh_session
61
61
  Util::SSH.download(node.public_ip, node.user, remote_path, local_path, config.export) do |name, received, total|
62
62
  code.call(name, received, total) if code
63
63
  end
64
64
  success = true
65
- end
65
+ end
66
66
  rescue => error
67
67
  error(error.message, { :i18n => false })
68
68
  end
69
-
69
+
70
70
  success
71
71
  end
72
-
72
+
73
73
  #---
74
-
74
+
75
75
  def ssh_upload(local_path, remote_path, options = {}, &code)
76
76
  config = Config.ensure(options)
77
77
  success = false
78
-
78
+
79
79
  begin
80
80
  if init_ssh_session
81
81
  Util::SSH.upload(node.public_ip, node.user, local_path, remote_path, config.export) do |name, sent, total|
82
82
  code.call(name, sent, total) if code
83
83
  end
84
84
  success = true
85
- end
85
+ end
86
86
  rescue => error
87
87
  error(error.message, { :i18n => false })
88
88
  end
89
-
90
- success
89
+
90
+ success
91
91
  end
92
-
92
+
93
93
  #---
94
-
94
+
95
95
  def ssh_exec(commands, options = {}, &code)
96
96
  config = Config.ensure(options)
97
97
  results = nil
98
-
99
- if commands && commands = commands.clone
98
+
99
+ if commands && commands = Util::Data.array(commands)
100
100
  if init_ssh_session
101
101
  results = Util::SSH.exec(node.public_ip, node.user, commands) do |type, command, data|
102
- code.call(type, command, data) if code
102
+ code.call(type, command, data) if code
103
103
  end
104
104
  end
105
105
  end
106
106
  results
107
107
  end
108
-
108
+
109
109
  #---
110
-
110
+
111
111
  def close_ssh_session
112
112
  Util::SSH.close_session(node.public_ip, node.user)
113
113
  end
114
-
114
+
115
115
  #---
116
-
116
+
117
117
  def ssh_terminal(user, options = {})
118
118
  Util::SSH.terminal(node.public_ip, user, Config.ensure(options).export)
119
119
  end
120
-
120
+
121
121
  #-----------------------------------------------------------------------------
122
122
  # Utilities
123
-
123
+
124
124
  def ssh_wait_for_ready
125
125
  # Override in class if needed (see Fog Machine provider)
126
126
  end
@@ -0,0 +1,32 @@
1
+
2
+ module VagrantPlugins
3
+ module CommunicatorSSH
4
+ class Communicator
5
+ # Override Vagrant key insertion (we handle generated keys internally)
6
+ def ready?
7
+ @logger.debug("Checking whether SSH is ready...")
8
+
9
+ # Attempt to connect. This will raise an exception if it fails.
10
+ begin
11
+ connect
12
+ @logger.info("SSH is ready!")
13
+ rescue Vagrant::Errors::VagrantError => e
14
+ # We catch a `VagrantError` which would signal that something went
15
+ # wrong expectedly in the `connect`, which means we didn't connect.
16
+ @logger.info("SSH not up: #{e.inspect}")
17
+ dbg(e.inspect, 'error')
18
+ return false
19
+ end
20
+
21
+ # Verify the shell is valid
22
+ if execute("", error_check: false) != 0
23
+ raise Vagrant::Errors::SSHInvalidShell
24
+ end
25
+
26
+ # If we reached this point then we successfully connected
27
+ dbg('connected')
28
+ true
29
+ end
30
+ end
31
+ end
32
+ end