class CORL::Plugin::Network
Public Instance Methods
add_node(provider, name, options = {}) { |:preprocess, hook_config| ... }
click to toggle source
# File lib/core/plugin/network.rb 342 def add_node(provider, name, options = {}) 343 config = Config.ensure(options) 344 345 keypair = config.get(:keypair, nil) 346 return false unless keypair && keypair.is_a?(Util::SSH::Keypair) 347 348 remote_name = config.delete(:remote, :edit) 349 350 node_config = extended_config(:network_new_node, Config.new(Util::Data.clean({ 351 :settings => [ "server" ] | array(config.delete(:groups, [])), 352 :region => config.delete(:region, nil), 353 :machine_type => config.delete(:machine_type, nil), 354 :public_ip => config.delete(:public_ip, nil), 355 :image => config.delete(:image, nil), 356 :user => config.delete(:user, :root), 357 :hostname => name 358 }))) 359 360 # Set node data 361 node = set_node(provider, name, node_config.export) 362 hook_config = { :node => node, :remote => remote_name, :config => config } 363 success = true 364 365 yield(:preprocess, hook_config) if block_given? 366 367 if ! node.local? && node.attach_keys(keypair) && extension_check(:add_node, hook_config) 368 node.keypair = keypair 369 370 # Create new node / machine 371 success = node.create do |op, data| 372 block_given? ? yield("create_#{op}".to_sym, data) : data 373 end 374 375 remote_name = nil if remote_name && ! remote(remote_name) 376 377 if success && node.save({ :remote => remote_name, :message => "Created machine #{name} on #{provider}" }) 378 success = init_node(node, config.defaults({ :bootstrap => true, :seed => true })) do |op, data| 379 block_given? ? yield(op, data) : data 380 end 381 end 382 end 383 success 384 end
attach_data(type, name, data, options = {})
click to toggle source
# File lib/core/plugin/network.rb 324 def attach_data(type, name, data, options = {}) 325 attach_config = Config.ensure(options).import({ :type => :source }) 326 attached_data = nil 327 328 if data.is_a?(String) 329 attached_data = config.attach(type, name, data, attach_config) 330 end 331 attached_data 332 end
attach_files(type, name, files, options = {})
click to toggle source
# File lib/core/plugin/network.rb 308 def attach_files(type, name, files, options = {}) 309 attach_config = Config.ensure(options).import({ :type => :file }) 310 included_files = [] 311 files = [ files ] unless files.is_a?(Array) 312 313 files.each do |file| 314 if file 315 attached_file = config.attach(type, name, file, attach_config) 316 included_files << attached_file unless attached_file.nil? 317 end 318 end 319 included_files 320 end
batch(node_references, default_provider = nil, parallel = true, running = true, &code)
click to toggle source
# File lib/core/plugin/network.rb 484 def batch(node_references, default_provider = nil, parallel = true, running = true, &code) 485 node_references = array(node_references.clone) 486 success = true 487 488 if has_nodes? && ! node_references.empty? 489 # Execute action on selected nodes 490 nodes = nodes_by_reference(node_references, default_provider) 491 492 if CORL.parallel? && parallel 493 values = [] 494 nodes.each do |node| 495 node.password = node_password 496 if ! running || node.running? 497 values << Celluloid::Future.new(node, &code) 498 end 499 end 500 values = values.map { |future| future.value } 501 success = false if values.include?(false) 502 else 503 nodes.each do |node| 504 node.password = node_password 505 if ! running || node.running? 506 proc_success = code.call(node) 507 if proc_success == false 508 success = false 509 end 510 end 511 end 512 end 513 end 514 success 515 end
build()
click to toggle source
# File lib/core/plugin/network.rb 269 def build 270 @build 271 end
build_directory()
click to toggle source
# File lib/core/plugin/network.rb 94 def build_directory 95 File.join(directory, 'build') 96 end
cache()
click to toggle source
# File lib/core/plugin/network.rb 112 def cache 113 config.cache 114 end
config_directory()
click to toggle source
# File lib/core/plugin/network.rb 106 def config_directory 107 File.join(directory, 'config') 108 end
create_builder(name, provider, options = {})
click to toggle source
# File lib/core/plugin/network.rb 275 def create_builder(name, provider, options = {}) 276 CORL.create_plugin(:CORL, :builder, provider, extended_config(name, options).import({ :meta => { :parent => myself }})) 277 end
delete_attachments(ids, options = {})
click to toggle source
# File lib/core/plugin/network.rb 336 def delete_attachments(ids, options = {}) 337 config.delete_attachments(ids, options) 338 end
directory()
click to toggle source
# File lib/core/plugin/network.rb 82 def directory 83 config.directory 84 end
each_node_config(provider = nil) { |node_provider, name, info| ... }
click to toggle source
# File lib/core/plugin/network.rb 472 def each_node_config(provider = nil) 473 node_config.export.each do |node_provider, nodes| 474 if provider.nil? || provider == node_provider 475 nodes.each do |name, info| 476 yield(node_provider, name, info) 477 end 478 end 479 end 480 end
has_nodes?(provider = nil)
click to toggle source
# File lib/core/plugin/network.rb 47 def has_nodes?(provider = nil) 48 node_config(provider).export.empty? ? false : true 49 end
hiera_override_dir()
click to toggle source
# File lib/core/plugin/network.rb 70 def hiera_override_dir 71 File.join(directory, 'config') 72 end
hiera_var()
click to toggle source
# File lib/core/plugin/network.rb 60 def hiera_var 61 @hiera 62 end
hiera_var=(hiera)
click to toggle source
# File lib/core/plugin/network.rb 64 def hiera_var=hiera 65 @hiera = hiera 66 end
home()
click to toggle source
# File lib/core/plugin/network.rb 76 def home 77 extension_set(:home, ( ENV['USER'] == 'root' ? '/root' : ENV['HOME'] )) 78 end
identity_builder(options = {})
click to toggle source
# File lib/core/plugin/network.rb 281 def identity_builder(options = {}) 282 create_builder(:network_identity_builder, :identity, options) 283 end
ignore(files)
click to toggle source
# File lib/core/plugin/network.rb 118 def ignore(files) 119 config.ignore(files) 120 end
init_node(node, options = {}) { |"bootstrap_#{op}".to_sym, data| ... }
click to toggle source
# File lib/core/plugin/network.rb 388 def init_node(node, options = {}) 389 config = Config.ensure(options) 390 success = true 391 392 bootstrap_requested = config.has_key?(:bootstrap) 393 bootstrap = config.delete(:bootstrap, false) 394 395 seed_requested = config.has_key?(:seed) 396 seed = config.delete(:seed, false) 397 seed_project = config.get(:project_reference, nil) 398 399 if seed_project.nil? 400 project_provider = myself.config.project.plugin_provider 401 project_remote = myself.config.remote(:edit) 402 seed_project = "#{project_provider}:::#{project_remote}" 403 end 404 405 unless node.cache_setting(:initialized) 406 bootstrap = true unless bootstrap_requested 407 seed = true unless seed_requested 408 end 409 410 provision = config.delete(:provision, true) 411 412 if bootstrap 413 # Bootstrap machine 414 success = node.bootstrap(home, extended_config(:bootstrap, config)) do |op, data| 415 block_given? ? yield("bootstrap_#{op}".to_sym, data) : data 416 end 417 end 418 419 if success 420 if seed 421 save_config = { :commit => true, :remote => remote_name, :push => true } 422 423 if seed_project && remote_name 424 # Reset project remote 425 seed_info = Plugin::Project.translate_reference(seed_project) 426 427 if seed_info 428 seed_url = seed_info[:url] 429 seed_branch = seed_info[:revision] if seed_info[:revision] 430 else 431 seed_url = seed_project 432 end 433 set_remote(:origin, seed_url) if remote_name.to_sym == :edit 434 set_remote(remote_name, seed_url) 435 save_config[:pull] = false 436 end 437 438 # Save network changes (preliminary) 439 success = node.save(extended_config(:node_save, save_config)) 440 441 if success && seed_project 442 # Seed machine with remote project reference 443 result = node.action(:node_seed, { 444 :project_reference => seed_project, 445 :project_branch => seed_branch 446 }) do |op, data| 447 yield("seed_#{op}".to_sym, data) 448 end 449 success = result.status == code.success 450 end 451 end 452 453 node.set_cache_setting(:initialized, true) if success 454 455 if success && provision 456 # Run configured provisioners on machine 457 result = node.action(:node_provision, config) do |op, data| 458 yield("provision_#{op}".to_sym, data) 459 end 460 success = result.status == code.success 461 end 462 463 # Update local network project 464 success = load({ :remote => remote_name, :pull => true }) if success 465 end 466 success 467 end
key_cache_directory()
click to toggle source
# File lib/core/plugin/network.rb 100 def key_cache_directory 101 File.join(build_directory, 'keys') 102 end
key_directory()
click to toggle source
# File lib/core/plugin/network.rb 88 def key_directory 89 File.join(directory, 'keys') 90 end
load(options = {})
click to toggle source
# File lib/core/plugin/network.rb 296 def load(options = {}) 297 config.load(options) 298 end
local_node(require_new = false)
click to toggle source
# File lib/core/plugin/network.rb 229 def local_node(require_new = false) 230 hostname = lookup(:fqdn) 231 ip_address = CORL.public_ip 232 local_node = node_lookup(ip_address, hostname, require_new) 233 234 if local_node.nil? 235 name = Util::Data.ensure_value(hostname, ip_address) 236 local_node = CORL.node(name, extended_config(:local_node).import({ :meta => { :parent => myself }}), :local) 237 else 238 local_node.network = myself 239 local_node.normalize(true) 240 local_node.localize 241 end 242 243 local_node.password = node_password 244 local_node 245 end
node_groups()
click to toggle source
# File lib/core/plugin/network.rb 144 def node_groups 145 groups = {} 146 147 each_node_config do |provider, name, info| 148 search_node(provider, name, :settings, [], :array).each do |group| 149 group = group.to_sym 150 groups[group] = [] unless groups.has_key?(group) 151 groups[group] << { :provider => provider, :name => name } 152 end 153 end 154 groups 155 end
node_info(references, default_provider = nil)
click to toggle source
# File lib/core/plugin/network.rb 159 def node_info(references, default_provider = nil) 160 groups = node_groups 161 node_info = {} 162 163 default_provider = Manager.connection.type_default(:node) if default_provider.nil? 164 165 references.each do |reference| 166 info = Plugin::Node.translate_reference(reference) 167 info = { :provider => default_provider, :name => reference } unless info 168 name = info[:name].to_sym 169 170 # Check for group membership 171 if groups.has_key?(name) 172 groups[name].each do |member_info| 173 provider = member_info[:provider].to_sym 174 175 node_info[provider] = [] unless node_info.has_key?(provider) 176 node_info[provider] << member_info[:name] 177 end 178 else 179 # Not a group 180 provider = info[:provider].to_sym 181 182 if node_config.export.has_key?(provider) 183 node_found = false 184 185 each_node_config(provider) do |node_provider, node_name, node| 186 if node_name == name 187 node_info[node_provider] = [] unless node_info.has_key?(node_provider) 188 node_info[node_provider] << node_name 189 node_found = true 190 break 191 end 192 end 193 194 unless node_found 195 # TODO: Error or something? 196 end 197 end 198 end 199 end 200 node_info 201 end
node_lookup(public_ip, hostname, require_new = false)
click to toggle source
# File lib/core/plugin/network.rb 205 def node_lookup(public_ip, hostname, require_new = false) 206 matches = {} 207 208 each_node_config do |provider, name, info| 209 # TODO: Abstract this out... (extension hook) 210 if provider == :vagrant && fact(:vagrant_exists) 211 matches[provider] = name if name.to_s == hostname.to_s 212 else 213 matches[provider] = name if info[:public_ip] == public_ip && name.to_s == hostname.to_s 214 end 215 end 216 217 unless matches.empty? 218 if matches.has_key?(:local) && matches.keys.length > 1 219 matches.delete(:local) # No need for local if there is an actual provider 220 end 221 provider = matches.keys[0] 222 return node(provider, matches[provider], require_new) 223 end 224 nil 225 end
node_password()
click to toggle source
# File lib/core/plugin/network.rb 138 def node_password 139 @node_password 140 end
node_password=(password)
click to toggle source
# File lib/core/plugin/network.rb 134 def node_password=password 135 @node_password = password 136 end
nodes_by_reference(references, default_provider = nil, require_new = false)
click to toggle source
# File lib/core/plugin/network.rb 249 def nodes_by_reference(references, default_provider = nil, require_new = false) 250 nodes = [] 251 252 node_info(references, default_provider).each do |provider, names| 253 names.each do |name| 254 nodes << node(provider, name, require_new) 255 end 256 end 257 nodes 258 end
normalize(reload)
click to toggle source
Calls superclass method
# File lib/core/plugin/network.rb 11 def normalize(reload) 12 super 13 14 logger.info("Initializing network: reloading? #{reload}") 15 myself.config = CORL.configuration(Config.new(myself._export, {}, true, false).import({ :autosave => false, :create => false, :new => true })) unless reload 16 17 config.delete(:directory) # TODO: Figure out what to do with this?? 18 19 unless reload 20 @build = Build.new 21 22 config_identities_glob = File.join('config', 'identities', '*') 23 vagrant_identities_path = File.join('config', 'identities', 'vagrant') 24 25 ignore([ 26 'build', 27 config_identities_glob, 28 config_identities_glob + File::SEPARATOR, 29 "!#{vagrant_identities_path}" 30 ]) 31 end 32 end
package_builder(name, options = {})
click to toggle source
# File lib/core/plugin/network.rb 285 def package_builder(name, options = {}) 286 create_builder(:network_package_builder, :package, options) 287 end
project_builder(name, options = {})
click to toggle source
# File lib/core/plugin/network.rb 289 def project_builder(name, options = {}) 290 create_builder(:network_project_builder, :project, options) 291 end
remote(name)
click to toggle source
# File lib/core/plugin/network.rb 124 def remote(name) 125 config.remote(name) 126 end
remove_plugin()
click to toggle source
# File lib/core/plugin/network.rb 36 def remove_plugin 37 CORL.remove_plugin(config) 38 39 each_plugin do |type, provider, name, plugin| 40 CORL.remove_plugin(plugin) 41 end 42 end
save(options = {})
click to toggle source
# File lib/core/plugin/network.rb 302 def save(options = {}) 303 config.save(options) 304 end
set_remote(name, location)
click to toggle source
# File lib/core/plugin/network.rb 128 def set_remote(name, location) 129 config.set_remote(name, location) 130 end
test_node(provider, options = {})
click to toggle source
# File lib/core/plugin/network.rb 262 def test_node(provider, options = {}) 263 config = Config.ensure(options).import({ :meta => { :parent => myself } }) 264 CORL.node(:test, config.export, provider) 265 end