Method: CORL::Plugin::Network#init_node

Defined in:
lib/core/plugin/network.rb

#init_node(node, options = {}) ⇒ Object




347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/core/plugin/network.rb', line 347

def init_node(node, options = {})
  config  = Config.ensure(options)
  success = true
  
  bootstrap_requested = config.has_key?(:bootstrap)
  bootstrap           = config.delete(:bootstrap, false)
  
  seed_requested      = config.has_key?(:seed)
  seed                = config.delete(:seed, false)
  
  unless node.cache_setting(:initialized)
    bootstrap = true unless bootstrap_requested
    seed      = true unless seed_requested
  end
     
  provision = config.delete(:provision, true)
  
  if bootstrap
    # Bootstrap machine
    success = node.bootstrap(home, extended_config(:bootstrap, config)) do |op, data|
      block_given? ? yield("bootstrap_#{op}".to_sym, data) : data
    end
  end
      
  if success
    if seed
      seed_project = config.get(:project_reference, nil)
      save_config  = { :commit => true, :remote => remote_name, :push => true }
                       
      if seed_project && remote_name
        # Reset project remote
        seed_info = Plugin::Project.translate_reference(seed_project)
                  
        if seed_info
          seed_url    = seed_info[:url]
          seed_branch = seed_info[:revision] if seed_info[:revision]
        else
          seed_url = seed_project                
        end
        set_remote(:origin, seed_url) if remote_name.to_sym == :edit
        set_remote(remote_name, seed_url)
        save_config[:pull] = false
      end
        
      # Save network changes (preliminary)
      success = node.save(extended_config(:node_save, save_config))
      
      if success && seed_project
        # Seed machine with remote project reference
        result = node.node_seed({
          :project_reference => seed_project,
          :project_branch    => seed_branch
        }) do |op, data|
          yield("seed_#{op}".to_sym, data)
        end
        success = result.status == code.success
      end
    end
    
    node.set_cache_setting(:initialized, true) if success
    
    if success && provision
      # Run configured provisioners on machine
      result = node.node_provision(config) do |op, data|
        yield("provision_#{op}".to_sym, data)  
      end
      success = result.status == code.success
    end
      
    # Update local network project
    success = load({ :remote => remote_name, :pull => true }) if success
  end
  success
end