class Nucleon::Plugin::CloudAction

Public Class Methods

namespace() click to toggle source
   # File lib/core/plugin/cloud_action.rb
46 def self.namespace
47   :corl
48 end

Public Instance Methods

configure() { || ... } click to toggle source
Calls superclass method
   # File lib/core/plugin/cloud_action.rb
62 def configure
63   super do
64     yield if block_given?
65     node_config
66   end
67 end
ensure_network(&block) click to toggle source
    # File lib/core/plugin/cloud_action.rb
183 def ensure_network(&block)
184   codes :network_failure
185 
186   if network
187     block.call
188   else
189     myself.status = code.network_failure
190   end
191 end
ensure_node(node, &block) click to toggle source
    # File lib/core/plugin/cloud_action.rb
193 def ensure_node(node, &block)
194   codes :node_failure
195 
196   if node
197     block.call
198   else
199     myself.status = code.node_failure
200   end
201 end
execute(use_network = true, &code) click to toggle source
Calls superclass method
    # File lib/core/plugin/cloud_action.rb
 99 def execute(use_network = true, &code)
100   if use_network
101     super(true, true) do
102       node_exec do |node|
103         hook_config = { :node => node, :network => network }
104 
105         code.call(node) if code && extension_check(:exec_init, hook_config)
106         myself.status = extension_set(:exec_exit, status, hook_config)
107       end
108     end
109   else
110     super(false, false, &code)
111   end
112 end
execute_remote(node, op, data) click to toggle source
    # File lib/core/plugin/cloud_action.rb
176 def execute_remote(node, op, data)
177   # Implement in sub classes if needed
178   data
179 end
init_network(provider = nil, path = nil) click to toggle source
    # File lib/core/plugin/cloud_action.rb
154 def init_network(provider = nil, path = nil)
155   provider = extension_set(:network_provider, :corl) unless provider
156 
157   # Get network configuration path
158   if CORL.admin?
159     network_path = lookup(:corl_network)
160     Dir.mkdir(network_path) unless File.directory?(network_path)
161   else
162     network_path = ( path.nil? ? Dir.pwd : File.expand_path(path) )
163   end
164 
165   if File.exists?(File.join(network_path, '.nucleon'))
166     # Load network if it exists
167     network_config = extended_config(:network, { :directory => network_path, :new => true })
168     @network       = CORL.network(network_path, network_config, provider)
169   else
170     @network = nil
171   end
172 end
network() click to toggle source
   # File lib/core/plugin/cloud_action.rb
56 def network
57   @network
58 end
network=(network) click to toggle source
   # File lib/core/plugin/cloud_action.rb
52 def network=network
53   @network = network
54 end
node_config() click to toggle source
   # File lib/core/plugin/cloud_action.rb
72 def node_config
73   register_str :user_password, nil, 'corl.core.action.options.user_password'
74 
75   register_str :net_remote, :edit, 'corl.core.action.options.net_remote'
76   register_network_provider :net_provider, :corl, [ 'corl.core.action.options.net_provider', 'corl.core.action.errors.network_provider' ]
77 
78   register_node_provider :node_provider, :local, [ 'corl.core.action.options.node_provider', 'corl.core.action.errors.node_provider' ]
79   register_nodes :nodes, [], [ 'corl.core.action.options.nodes', 'corl.core.action.errors.nodes' ]
80 
81   register_bool :parallel, true, 'corl.core.action.options.parallel'
82 end
node_exec() { |node| ... } click to toggle source
    # File lib/core/plugin/cloud_action.rb
116 def node_exec
117   init_network(settings[:net_provider]) unless network && settings[:net_provider].to_sym == network.plugin_provider
118 
119   network.node_password = settings[:user_password] if network && settings[:user_password]
120 
121   #
122   # A fork in the road...
123   #
124   if network && network.has_nodes? && ! settings[:nodes].empty?
125     # Execute action on remote nodes
126     success = network.batch(settings[:nodes], settings[:node_provider], settings[:parallel]) do |node|
127       exec_config = Config.new(settings, {}, true, false)
128       exec_config.delete(:nodes)
129 
130       result = node.action(plugin_provider, exec_config) do |op, data|
131         execute_remote(node, op, data)
132       end
133       result.status == code.success
134     end
135     myself.status = code.batch_error unless success
136   else
137     # Execute statement locally
138     node = nil
139     node = network.local_node if network
140 
141     settings[:net_remote] = sanitize_remote(settings[:net_remote]) if settings.has_key?(:net_remote)
142 
143     if validate(node, network)
144       yield(node) if block_given?
145     else
146       puts "\n" + I18n.t('nucleon.core.exec.help.usage') + ': ' + help + "\n" unless quiet?
147       myself.status = code.validation_failed
148     end
149   end
150 end
node_ignore() click to toggle source
   # File lib/core/plugin/cloud_action.rb
86 def node_ignore
87   [ :parallel, :node_provider, :nodes ]
88 end
normalize(reload) click to toggle source
Calls superclass method
   # File lib/core/plugin/cloud_action.rb
37 def normalize(reload)
38   super do
39     init_network
40   end
41 end
parse_property_name(property) click to toggle source
    # File lib/core/plugin/cloud_action.rb
218 def parse_property_name(property)
219   property = property.clone
220 
221   if property.size > 1
222     property.shift.to_s + '[' + property.join('][') + ']'
223   else
224     property.shift.to_s
225   end
226 end
remote_message(remote) click to toggle source
    # File lib/core/plugin/cloud_action.rb
212 def remote_message(remote)
213   remote ? "#{remote}" : "LOCAL ONLY"
214 end
sanitize_remote(remote) click to toggle source
    # File lib/core/plugin/cloud_action.rb
206 def sanitize_remote(remote)
207   remote && ( ! network || network.remote(remote) ) ? remote : nil
208 end
validate(node = nil, network = nil) click to toggle source
Calls superclass method
   # File lib/core/plugin/cloud_action.rb
93 def validate(node = nil, network = nil)
94   super(node, network)
95 end