Class: Nucleon::Action::Node::Seed

Inherits:
Object
  • Object
show all
Defined in:
lib/nucleon/action/node/seed.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.describeObject


Info



10
11
12
# File 'lib/nucleon/action/node/seed.rb', line 10

def self.describe
  super(:node, :seed, 625)
end

Instance Method Details

#argumentsObject




51
52
53
# File 'lib/nucleon/action/node/seed.rb', line 51

def arguments
  [ :project_reference ]
end

#configureObject


Settings



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nucleon/action/node/seed.rb', line 17

def configure
  super do
    codes :key_store_failure,
          :project_failure,
          :network_init_failure,
          :network_load_failure,
          :node_load_failure,
          :node_save_failure
    #---
    
    register :project_branch, :str, 'master'
    register :project_reference, :str, nil do |value|
      next true if value.nil?
      
      value           = value.to_sym
      project_plugins = CORL.loaded_plugins(:nucleon, :project)
      
      if @project_info = CORL.plugin_class(:nucleon, :project).translate_reference(value, true)
        provider = @project_info[:provider]
      else
        provider = value
      end
      
      unless project_plugins.keys.include?(provider.to_sym)
        warn('corl.actions.seed.errors.project_reference', { :value => value, :provider => provider, :choices => project_plugins.keys.join(', ') })
        next false
      end
      true
    end      
  end
end

#executeObject


Operations



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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/nucleon/action/node/seed.rb', line 58

def execute
  super do |node, network|
    info('corl.actions.seed.start')
    
    ensure_node(node) do
      admin_exec do
        network_path = lookup(:corl_network)
        backup_path  = File.join(Dir.tmpdir(), 'corl')
        
        info("Generating network SSH deploy keys", { :i18n => false })
        
        if keys = Util::SSH.generate.store
          if @project_info
            project_info = Config.new(@project_info)
          else
            project_info = Config.new({ :provider => :git })
          end
          
          info("Backing up current network configuration", { :i18n => false })
          FileUtils.rm_rf(backup_path)
          FileUtils.mv(network_path, backup_path)
          
          info("Seeding network configuration from #{settings[:project_reference]}", { :i18n => false })
          project = CORL.project(extended_config(:project, {
            :directory   => network_path,
            :reference   => project_info.get(:reference, nil),
            :url         => project_info.get(:url, settings[:project_reference]),
            :revision    => project_info.get(:revision, settings[:project_branch]),
            :create      => true,
            :pull        => true,
            :keys        => keys,
            :internal_ip => CORL.public_ip # Needed for seeding Vagrant VMs
          }), project_info[:provider])
      
          if project
            info("Finalizing network path and removing temporary backup", { :i18n => false })
            FileUtils.chmod_R(0600, network_path)
            FileUtils.rm_rf(backup_path)
            
            info("Reinitializing network", { :i18n => false })
            if network = init_network
              if network.load
                if node = network.local_node(true)
                  info("Updating node network configurations", { :i18n => false })
                  myself.status = code.node_save_failure unless node.save  
                else
                  myself.status = code.node_load_failure
                end                  
              else
                myself.status = code.network_load_failure    
              end
            else
              myself.status = code.network_init_failure
            end     
          else
            myself.status = code.project_failure  
          end            
        else
          myself.status = code.key_store_failure
        end
      end
    end
  end
end