corl 0.4.1 → 0.4.2

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 (48) hide show
  1. data/.gitmodules +1 -1
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +15 -8
  4. data/VERSION +1 -1
  5. data/bootstrap/os/ubuntu/00_base.sh +10 -1
  6. data/bootstrap/os/ubuntu/05_ruby.sh +6 -0
  7. data/bootstrap/os/ubuntu/06_puppet.sh +6 -6
  8. data/bootstrap/os/ubuntu/09_nucleon.sh +14 -0
  9. data/bootstrap/os/ubuntu/10_corl.sh +7 -2
  10. data/corl.gemspec +16 -9
  11. data/lib/CORL/action/authorize.rb +57 -0
  12. data/lib/CORL/action/bootstrap.rb +5 -0
  13. data/lib/CORL/action/destroy.rb +64 -0
  14. data/lib/CORL/action/exec.rb +9 -0
  15. data/lib/CORL/action/image.rb +39 -7
  16. data/lib/CORL/action/images.rb +4 -3
  17. data/lib/CORL/action/lookup.rb +2 -2
  18. data/lib/CORL/action/regions.rb +51 -0
  19. data/lib/CORL/action/seed.rb +1 -1
  20. data/lib/CORL/action/spawn.rb +8 -9
  21. data/lib/CORL/action/ssh.rb +74 -0
  22. data/lib/CORL/action/start.rb +37 -5
  23. data/lib/CORL/action/stop.rb +37 -5
  24. data/lib/CORL/configuration/file.rb +34 -7
  25. data/lib/CORL/event/puppet.rb +1 -1
  26. data/lib/CORL/machine/aws.rb +153 -0
  27. data/lib/CORL/machine/physical.rb +14 -5
  28. data/lib/CORL/machine/rackspace.rb +58 -0
  29. data/lib/CORL/network/default.rb +1 -1
  30. data/lib/CORL/node/aws.rb +40 -16
  31. data/lib/CORL/node/local.rb +4 -3
  32. data/lib/CORL/node/rackspace.rb +25 -7
  33. data/lib/CORL/provisioner/puppetnode.rb +11 -9
  34. data/lib/core/errors.rb +6 -0
  35. data/lib/core/mod/fog_aws_server.rb +38 -0
  36. data/lib/core/plugin/action.rb +3 -11
  37. data/lib/core/plugin/configuration.rb +20 -2
  38. data/lib/{CORL/machine/fog.rb → core/plugin/fog_machine.rb} +92 -92
  39. data/lib/core/plugin/{fog.rb → fog_node.rb} +20 -7
  40. data/lib/core/plugin/machine.rb +58 -37
  41. data/lib/core/plugin/network.rb +76 -111
  42. data/lib/core/plugin/node.rb +271 -87
  43. data/lib/core/plugin/provisioner.rb +1 -1
  44. data/lib/corl.rb +6 -14
  45. data/locales/en.yml +18 -1
  46. metadata +39 -32
  47. data/lib/CORL/node/google.rb +0 -111
  48. data/lib/core/util/ssh.rb +0 -286
@@ -6,8 +6,8 @@ class Machine < CORL.plugin_class(:base)
6
6
  #-----------------------------------------------------------------------------
7
7
  # Machine plugin interface
8
8
 
9
- def normalize
10
- myself.plugin_name = nil if plugin_name.to_s == plugin_provider.to_s
9
+ def normalize(reload)
10
+ myself.plugin_name = node[:id]
11
11
  end
12
12
 
13
13
  #-----------------------------------------------------------------------------
@@ -83,15 +83,21 @@ class Machine < CORL.plugin_class(:base)
83
83
  end
84
84
 
85
85
  #-----------------------------------------------------------------------------
86
- # Management
86
+ # Management
87
+
88
+ def init_ssh(ssh_port)
89
+ # Implement in sub classes if needed
90
+ end
91
+
92
+ #---
87
93
 
88
94
  def load
89
95
  success = true
90
96
 
91
- logger.debug("Loading #{plugin_provider} machine: #{name}")
97
+ logger.debug("Loading #{plugin_provider} machine: #{plugin_name}")
92
98
  success = yield if block_given?
93
99
 
94
- logger.warn("There was an error loading the machine #{name}") unless success
100
+ logger.warn("There was an error loading the machine #{plugin_name}") unless success
95
101
  success
96
102
  end
97
103
 
@@ -101,14 +107,14 @@ class Machine < CORL.plugin_class(:base)
101
107
  success = true
102
108
 
103
109
  if created?
104
- logger.debug("Machine #{name} already exists")
110
+ logger.debug("Machine #{plugin_name} already exists")
105
111
  else
106
112
  logger.debug("Creating #{plugin_provider} machine with: #{options.inspect}")
107
113
  config = Config.ensure(options)
108
114
  success = yield(config) if block_given?
109
115
  end
110
116
 
111
- logger.warn("There was an error creating the machine #{name}") unless success
117
+ logger.warn("There was an error creating the machine #{plugin_name}") unless success
112
118
  success
113
119
  end
114
120
 
@@ -122,10 +128,10 @@ class Machine < CORL.plugin_class(:base)
122
128
  config = Config.ensure(options)
123
129
  success = yield(config, success) if block_given?
124
130
  else
125
- logger.debug("Machine #{name} is not running")
131
+ logger.debug("Machine #{plugin_name} is not running")
126
132
  end
127
133
 
128
- logger.warn("There was an error downloading from the machine #{name}") unless success
134
+ logger.warn("There was an error downloading from the machine #{plugin_name}") unless success
129
135
  success
130
136
  end
131
137
 
@@ -139,10 +145,10 @@ class Machine < CORL.plugin_class(:base)
139
145
  config = Config.ensure(options)
140
146
  success = yield(config, success) if block_given?
141
147
  else
142
- logger.debug("Machine #{name} is not running")
148
+ logger.debug("Machine #{plugin_name} is not running")
143
149
  end
144
150
 
145
- logger.warn("There was an error uploading to the machine #{name}") unless success
151
+ logger.warn("There was an error uploading to the machine #{plugin_name}") unless success
146
152
  success
147
153
  end
148
154
 
@@ -156,34 +162,27 @@ class Machine < CORL.plugin_class(:base)
156
162
  config = Config.ensure(options)
157
163
  results = yield(config, results) if block_given?
158
164
  else
159
- logger.debug("Machine #{name} is not running")
165
+ logger.debug("Machine #{plugin_name} is not running")
160
166
  end
161
167
 
162
- logger.warn("There was an error executing command on the machine #{name}") unless results
168
+ logger.warn("There was an error executing command on the machine #{plugin_name}") unless results
163
169
  results
164
170
  end
165
171
 
166
172
  #---
167
173
 
168
- def start(options = {})
169
- success = true
174
+ def terminal(user, options = {})
175
+ status = code.unknown_status
170
176
 
171
177
  if running?
172
- logger.debug("Machine #{name} is already running")
178
+ logger.debug("Launching #{user} terminal on #{plugin_provider} machine with: #{options.inspect}")
179
+ config = Config.ensure(options)
180
+ status = yield(config) if block_given?
173
181
  else
174
- logger.debug("Starting #{plugin_provider} machine with: #{options.inspect}")
175
-
176
- if created?
177
- config = Config.ensure(options)
178
- success = yield(config) if block_given?
179
- else
180
- logger.debug("Machine #{name} does not yet exist")
181
- success = create(options)
182
- end
183
- end
184
-
185
- logger.warn("There was an error starting the machine #{name}") unless success
186
- success
182
+ logger.debug("Machine #{plugin_name} is not running")
183
+ end
184
+ logger.warn("There was an error launching a #{user} terminal on the machine #{plugin_name}") unless status == code.success
185
+ status
187
186
  end
188
187
 
189
188
  #---
@@ -196,10 +195,10 @@ class Machine < CORL.plugin_class(:base)
196
195
  config = Config.ensure(options)
197
196
  success = yield(config) if block_given?
198
197
  else
199
- logger.debug("Machine #{name} does not yet exist")
198
+ logger.debug("Machine #{plugin_name} does not yet exist")
200
199
  end
201
200
 
202
- logger.warn("There was an error reloading the machine #{name}") unless success
201
+ logger.warn("There was an error reloading the machine #{plugin_name}") unless success
203
202
  success
204
203
  end
205
204
 
@@ -213,10 +212,10 @@ class Machine < CORL.plugin_class(:base)
213
212
  config = Config.ensure(options)
214
213
  success = yield(config) if block_given?
215
214
  else
216
- logger.debug("Machine #{name} is not running")
215
+ logger.debug("Machine #{plugin_name} is not running")
217
216
  end
218
217
 
219
- logger.warn("There was an error creating an image of the machine #{name}") unless success
218
+ logger.warn("There was an error creating an image of the machine #{plugin_name}") unless success
220
219
  success
221
220
  end
222
221
 
@@ -230,10 +229,32 @@ class Machine < CORL.plugin_class(:base)
230
229
  config = Config.ensure(options)
231
230
  success = yield(config) if block_given?
232
231
  else
233
- logger.debug("Machine #{name} is not running")
232
+ logger.debug("Machine #{plugin_name} is not running")
233
+ end
234
+
235
+ logger.warn("There was an error stopping the machine #{plugin_name}") unless success
236
+ success
237
+ end
238
+
239
+ #---
240
+
241
+ def start(options = {})
242
+ success = true
243
+
244
+ if running?
245
+ logger.debug("Machine #{plugin_name} is already running")
246
+ else
247
+ logger.debug("Starting #{plugin_provider} machine with: #{options.inspect}")
248
+
249
+ if created?
250
+ logger.debug("Machine #{plugin_name} has already been created")
251
+ else
252
+ logger.debug("Machine #{plugin_name} does not yet exist")
253
+ success = create(options)
254
+ end
234
255
  end
235
256
 
236
- logger.warn("There was an error stopping the machine #{name}") unless success
257
+ logger.warn("There was an error starting the machine #{plugin_name}") unless success
237
258
  success
238
259
  end
239
260
 
@@ -247,10 +268,10 @@ class Machine < CORL.plugin_class(:base)
247
268
  config = Config.ensure(options)
248
269
  success = yield(config) if block_given?
249
270
  else
250
- logger.debug("Machine #{name} does not yet exist")
271
+ logger.debug("Machine #{plugin_name} does not yet exist")
251
272
  end
252
273
 
253
- logger.warn("There was an error destroying the machine #{name}") unless success
274
+ logger.warn("There was an error destroying the machine #{plugin_name}") unless success
254
275
  success
255
276
  end
256
277
 
@@ -8,11 +8,11 @@ class Network < CORL.plugin_class(:base)
8
8
  #-----------------------------------------------------------------------------
9
9
  # Cloud plugin interface
10
10
 
11
- def normalize
11
+ def normalize(reload)
12
12
  super
13
13
 
14
14
  logger.info("Initializing sub configuration from source with: #{myself._export.inspect}")
15
- myself.config = CORL.configuration(Config.new(myself._export))
15
+ myself.config = CORL.configuration(Config.new(myself._export).import({ :autosave => false })) unless reload
16
16
  end
17
17
 
18
18
  #-----------------------------------------------------------------------------
@@ -52,9 +52,9 @@ class Network < CORL.plugin_class(:base)
52
52
  search_node(provider, name, :groups, [], :array).each do |group|
53
53
  group = group.to_sym
54
54
  groups[group] = [] unless groups.has_key?(group)
55
- groups[group] << { :provider => provider, :name => node_name }
55
+ groups[group] << { :provider => provider, :name => name }
56
56
  end
57
- end
57
+ end
58
58
  groups
59
59
  end
60
60
 
@@ -106,23 +106,25 @@ class Network < CORL.plugin_class(:base)
106
106
 
107
107
  #---
108
108
 
109
- def node_by_ip(public_ip)
109
+ def node_by_ip(public_ip, require_new = false)
110
110
  each_node_config do |provider, name, info|
111
- return node(provider, name) if info[:public_ip] == public_ip
111
+ return node(provider, name, require_new) if info[:public_ip] == public_ip
112
112
  end
113
113
  nil
114
114
  end
115
115
 
116
116
  #---
117
117
 
118
- def local_node
119
- ip_address = lookup(:ipaddress)
120
- local_node = node_by_ip(ip_address)
118
+ def local_node(require_new = false)
119
+ ip_address = CORL.ip_address
120
+ local_node = node_by_ip(ip_address, require_new)
121
121
 
122
122
  if local_node.nil?
123
123
  name = Util::Data.ensure_value(lookup(:hostname), ip_address)
124
124
  local_node = CORL.node(name, extended_config(:local_node).import({ :meta => { :parent => myself }}), :local)
125
125
  else
126
+ local_node.network = myself
127
+ local_node.normalize(true)
126
128
  local_node.localize
127
129
  end
128
130
  local_node
@@ -130,12 +132,12 @@ class Network < CORL.plugin_class(:base)
130
132
 
131
133
  #---
132
134
 
133
- def nodes_by_reference(references, default_provider = nil)
135
+ def nodes_by_reference(references, default_provider = nil, require_new = false)
134
136
  nodes = []
135
137
 
136
138
  node_info(references, default_provider).each do |provider, names|
137
139
  names.each do |name|
138
- nodes << node(provider, name)
140
+ nodes << node(provider, name, require_new)
139
141
  end
140
142
  end
141
143
  nodes
@@ -143,8 +145,9 @@ class Network < CORL.plugin_class(:base)
143
145
 
144
146
  #---
145
147
 
146
- def test_node(provider)
147
- CORL.node(:test, { :meta => { :parent => myself } }, provider)
148
+ def test_node(provider, options = {})
149
+ config = Config.ensure(options).import({ :meta => { :parent => myself } })
150
+ CORL.node(:test, config.export, provider)
148
151
  end
149
152
 
150
153
  #-----------------------------------------------------------------------------
@@ -183,132 +186,94 @@ class Network < CORL.plugin_class(:base)
183
186
  attached_data = nil
184
187
 
185
188
  if data.is_a?(String)
186
- attached_data = config.attach(type, name, file, attach_config)
189
+ attached_data = config.attach(type, name, data, attach_config)
187
190
  end
188
191
  attached_data
189
192
  end
190
193
 
191
194
  #---
192
195
 
193
- def attach_keys(node, keypair)
194
- save_config = { :pull => false, :push => false }
195
- private_key = attach_data(:keys, "#{node.public_ip}-id_#{keypair.type}", keypair.encrypted_key)
196
- public_key = attach_data(:keys, "#{node.public_ip}-id_#{keypair.type}.pub", keypair.ssh_key)
197
-
198
- if private_key && public_key
199
- save_config[:files] = [ private_key, public_key ]
200
-
201
- node[:private_key] = private_key
202
- node[:public_key] = public_key
203
-
204
- save_config[:message] = "Updating SSH keys for node #{node.plugin_name} (#{node.public_ip})"
205
- node.save(extended_config(:key_save, save_config))
206
- else
207
- false
208
- end
196
+ def delete_attachments(ids, options = {})
197
+ config.delete_attachments(ids, options)
209
198
  end
210
199
 
211
200
  #---
212
201
 
202
+ execute_block_on_receiver :add_node
203
+
213
204
  def add_node(provider, name, options = {})
214
205
  config = Config.ensure(options)
215
206
 
216
207
  keypair = config.delete(:keypair, nil)
217
208
  return false unless keypair && keypair.is_a?(Util::SSH::Keypair)
218
209
 
219
- remote_name = config.delete(:remote, :edit)
220
- dbg(config, 'node add configuration')
210
+ remote_name = config.delete(:remote, :edit)
221
211
 
222
212
  # Set node data
223
- #node = set_node(provider, name, config)
224
- #hook_config = { :node => node, :remote => remote_name, :seed => seed_project, :config => config }
213
+ node = set_node(provider, name, {
214
+ :groups => array(config.delete(:groups, [])),
215
+ :region => config.delete(:region, nil),
216
+ :machine_type => config.delete(:machine_type, nil),
217
+ :image => config.delete(:image, nil),
218
+ :user => config.delete(:user, :root),
219
+ :hostname => name
220
+ })
221
+ hook_config = { :node => node, :remote => remote_name, :config => config }
225
222
  success = true
226
223
 
227
- #yield(:preprocess, hook_config) if block_given?
224
+ yield(:preprocess, hook_config) if block_given?
228
225
 
229
- #if ! node.local? && attach_keys(node, keypair) && extension_check(:add_node, hook_config)
230
- # # Create new node / machine
231
- # success = node.create do |op, data|
232
- # data = yield("create_#{op}".to_sym, data) if block_given?
233
- # data
234
- # end
226
+ if ! node.local? && node.attach_keys(keypair) && extension_check(:add_node, hook_config)
227
+ # Create new node / machine
228
+ success = node.create do |op, data|
229
+ block_given? ? yield("create_#{op}".to_sym, data) : data
230
+ end
235
231
 
236
- # if success
237
- # # Bootstrap new machine
238
- # success = node.bootstrap(home, extended_config(:bootstrap, config)) do |op, data|
239
- # data = yield("bootstrap_#{op}".to_sym, data) if block_given?
240
- # data
241
- # end
232
+ if success && node.save({ :remote => remote_name, :message => "Created machine #{name} on #{provider}" })
233
+ # Bootstrap new machine
234
+ success = node.bootstrap(home, extended_config(:bootstrap, config)) do |op, data|
235
+ block_given? ? yield("bootstrap_#{op}".to_sym, data) : data
236
+ end
242
237
 
243
- # if success
244
- # save_config = { :commit => true, :remote => remote_name, :push => true }
238
+ if success
239
+ seed_project = config.get(:project_reference, nil)
240
+ save_config = { :commit => true, :remote => remote_name, :push => true }
245
241
 
246
- # if seed_project && remote_name
247
- # # Reset project remote
248
- # seed_info = Plugin::Project.translate_reference(seed_project)
242
+ if seed_project && remote_name
243
+ # Reset project remote
244
+ seed_info = Plugin::Project.translate_reference(seed_project)
249
245
 
250
- # if seed_info
251
- # seed_url = seed_info[:url]
252
- # seed_branch = seed_info[:revision] if seed_info[:revision]
253
- # else
254
- # seed_url = seed_project
255
- # end
256
- # set_remote(:origin, seed_url) if remote_name.to_sym == :edit
257
- # set_remote(remote_name, seed_url)
258
- # save_config[:pull] = false
259
- # end
260
-
261
- # # Save network changes (preliminary)
262
- # success = node.save(extended_config(:node_save, save_config))
246
+ if seed_info
247
+ seed_url = seed_info[:url]
248
+ seed_branch = seed_info[:revision] if seed_info[:revision]
249
+ else
250
+ seed_url = seed_project
251
+ end
252
+ set_remote(:origin, seed_url) if remote_name.to_sym == :edit
253
+ set_remote(remote_name, seed_url)
254
+ save_config[:pull] = false
255
+ end
256
+
257
+ # Save network changes (preliminary)
258
+ success = node.save(extended_config(:node_save, save_config))
263
259
 
264
- # if success && seed_project
265
- # # Seed machine with remote project reference
266
- # result = node.seed({
267
- # :net_provider => plugin_provider,
268
- # :project_reference => seed_project,
269
- # :project_branch => seed_branch
270
- # }) do |op, data|
271
- # yield("seed_#{op}".to_sym, data)
272
- # end
273
- # success = result.status == code.success
274
- # end
260
+ if success && seed_project
261
+ # Seed machine with remote project reference
262
+ result = node.seed({
263
+ :project_reference => seed_project,
264
+ :project_branch => seed_branch
265
+ }) do |op, data|
266
+ yield("seed_#{op}".to_sym, data)
267
+ end
268
+ success = result.status == code.success
269
+ end
275
270
 
276
- # if success
277
- # # Update local network project
278
- # end
279
- # end
280
- # end
281
- #end
282
-
283
- success
284
- end
285
-
286
- #---
287
-
288
- def remove_node(provider, name = nil)
289
- status = CORL.code.success
290
-
291
- if name.nil?
292
- nodes(provider).each do |node_name, node|
293
- sub_status = remove_node(provider, node_name)
294
- status = sub_status unless status == sub_status
295
- end
296
- else
297
- node = node(provider, name)
298
-
299
- unless node.local?
300
- # Stop node
301
- status = node.run(:stop)
271
+ # Update local network project
272
+ success = load({ :remote => remote_name, :pull => true }) if success
273
+ end
302
274
  end
303
-
304
- if status == CORL.code.success
305
- delete_node(provider, name)
306
- else
307
- ui.warn("Stopping #{provider} node #{name} failed")
308
- end
309
- end
310
-
311
- status
275
+ end
276
+ success
312
277
  end
313
278
 
314
279
  #-----------------------------------------------------------------------------