Class: CORL::Action::Spawn

Inherits:
Plugin::CloudAction show all
Includes:
Mixin::Action::Keypair
Defined in:
lib/CORL/action/spawn.rb

Instance Method Summary collapse

Methods included from Mixin::Action::Keypair

#keypair, #keypair=, #keypair_clean, #keypair_config, #keypair_ignore

Methods inherited from Plugin::CloudAction

#ensure_network, #ensure_node, #execute_remote, #init_network, #namespace, #node_config, #node_exec, #node_ignore, #validate

Instance Method Details

#argumentsObject



40
41
42
# File 'lib/CORL/action/spawn.rb', line 40

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

#configureObject


Settings



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/CORL/action/spawn.rb', line 11

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(:bootstrap))
    config.defaults(CORL.action_config(:seed))
  end
end

#executeObject


Operations



47
48
49
50
51
52
53
54
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
# File 'lib/CORL/action/spawn.rb', line 47

def execute
  super do |node, network|
    ensure_network(network) do
      if keypair && keypair_clean
        hostnames     = []
        results       = []
        node_provider = settings.delete(:node_provider)
        
        if CORL.vagrant? && ! CORL.loaded_plugins(: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 settings[:parallel]
            results << network.future.add_node(node_provider, hostname, settings)
          else
            results << network.add_node(node_provider, hostname, settings)    
          end
        end
        results       = results.map { |future| future.value } if settings[:parallel]                  
        myself.status = code.batch_error if results.include?(false)
      else
        myself.status = code.key_failure  
      end        
    end
  end
end

#ignoreObject




36
37
38
# File 'lib/CORL/action/spawn.rb', line 36

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