Class: Nucleon::Action::Node::Spawn

Inherits:
Object
  • Object
show all
Includes:
Mixin::Action::Keypair
Defined in:
lib/nucleon/action/node/spawn.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.describeObject


Info



12
13
14
# File 'lib/nucleon/action/node/spawn.rb', line 12

def self.describe
  super(:node, :spawn, 635)
end

Instance Method Details

#argumentsObject



48
49
50
# File 'lib/nucleon/action/node/spawn.rb', line 48

def arguments
  [ :node_provider, :image, :hostnames ]
end

#configureObject


Settings



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nucleon/action/node/spawn.rb', line 19

def configure
  super do
    codes :key_failure,
          :node_create_failure
    
    register :bootstrap, :bool, true
    register :seed, :bool, true
    register :provision, :bool, true
    
    register :groups, :array, []      
    register :region, :str, nil
    register :machine_type, :str, nil
    register :image, :str, nil
    register :user, :str, nil     
    register :hostnames, :array, nil
      
    keypair_config
    
    config.defaults(CORL.action_config(:node_bootstrap))
    config.defaults(CORL.action_config(:node_seed))
  end
end

#executeObject


Operations



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nucleon/action/node/spawn.rb', line 55

def execute
  super do |node, network|
    ensure_network(network) do
      if keypair && keypair_clean
        hostnames     = []
        results       = []
        node_provider = settings.delete(:node_provider)
        is_parallel   = CORL.parallel? && settings[:parallel]
        
        if CORL.vagrant? && ! CORL.loaded_plugins(:CORL, :node).keys.include?(node_provider.to_sym)
          settings[:machine_type] = node_provider
          settings[:user]         = :vagrant unless settings[:user]            
          node_provider           = :vagrant
        end
        unless settings[:user]
          settings[:user] = :root  
        end
        
        info('corl.actions.spawn.start', { :node_provider => node_provider }) 
        
        settings.delete(:hostnames).each do |hostname|
          hostnames << extract_hostnames(hostname)
        end
        hostnames.flatten.each do |hostname|
          if hostname.is_a?(Hash)
            settings[:public_ip] = hostname[:ip]
            hostname             = hostname[:hostname]  
          end
          
          if is_parallel
            results << network.future.add_node(node_provider, hostname, settings.export)
          else
            results << network.add_node(node_provider, hostname, settings.export)    
          end
        end
        results       = results.map { |future| future.value } if is_parallel                
        myself.status = code.batch_error if results.include?(false)
      else
        myself.status = code.key_failure  
      end        
    end
  end
end

#ignoreObject




44
45
46
# File 'lib/nucleon/action/node/spawn.rb', line 44

def ignore
  node_ignore - [ :parallel, :node_provider ] + [ :bootstrap_nodes ]
end