Class: Nucleon::Plugin::CloudAction
- Inherits:
-
Object
- Object
- Nucleon::Plugin::CloudAction
- Defined in:
- lib/core/plugin/cloud_action.rb
Class Method Summary collapse
-
.namespace ⇒ Object
—————————————————————————– Property accessor / modifiers.
Instance Method Summary collapse
-
#configure ⇒ Object
—.
-
#ensure_network(network, &block) ⇒ Object
—.
- #ensure_node(node, &block) ⇒ Object
-
#execute(use_network = true, &code) ⇒ Object
—.
-
#execute_remote(node, network, op, data) ⇒ Object
—.
-
#init_network(path = nil) ⇒ Object
—.
-
#node_config ⇒ Object
—————————————————————————– Settings.
-
#node_exec ⇒ Object
—.
-
#node_ignore ⇒ Object
—.
-
#sanitize_remote(network, remote) ⇒ Object
—————————————————————————– Utilities.
-
#validate(node = nil, network = nil) ⇒ Object
—————————————————————————– Operations.
Class Method Details
.namespace ⇒ Object
Property accessor / modifiers
37 38 39 |
# File 'lib/core/plugin/cloud_action.rb', line 37 def self.namespace :corl end |
Instance Method Details
#configure ⇒ Object
43 44 45 46 47 48 |
# File 'lib/core/plugin/cloud_action.rb', line 43 def configure super do yield if block_given? node_config end end |
#ensure_network(network, &block) ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/core/plugin/cloud_action.rb', line 182 def ensure_network(network, &block) codes :network_failure if network block.call else myself.status = code.network_failure end end |
#ensure_node(node, &block) ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/core/plugin/cloud_action.rb', line 192 def ensure_node(node, &block) codes :node_failure if node block.call else myself.status = code.node_failure end end |
#execute(use_network = true, &code) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/core/plugin/cloud_action.rb', line 107 def execute(use_network = true, &code) if use_network super(true, true) do node_exec do |node, network| hook_config = { :node => node, :network => network } code.call(node, network) if code && extension_check(:exec_init, hook_config) myself.status = extension_set(:exec_exit, status, hook_config) end end else super(false, false, &code) end end |
#execute_remote(node, network, op, data) ⇒ Object
175 176 177 178 |
# File 'lib/core/plugin/cloud_action.rb', line 175 def execute_remote(node, network, op, data) # Implement in sub classes if needed data end |
#init_network(path = nil) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/core/plugin/cloud_action.rb', line 158 def init_network(path = nil) # Get network configuration path if CORL.admin? network_path = lookup(:corl_network) Dir.mkdir(network_path) unless File.directory?(network_path) else network_path = ( path.nil? ? Dir.pwd : File.(path) ) end # Load network if it exists network_config = extended_config(:network, { :directory => network_path }) network = CORL.network(network_path, network_config, settings[:net_provider]) network end |
#node_config ⇒ Object
Settings
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 89 90 |
# File 'lib/core/plugin/cloud_action.rb', line 53 def node_config node_plugins = CORL.loaded_plugins(:CORL, :node) register :parallel, :bool, true, 'corl.core.action.options.parallel' register :net_remote, :str, :edit, 'corl.core.action.options.net_remote' register :net_provider, :str, :corl, 'corl.core.action.options.net_provider' do |value| value = value.to_sym network_plugins = CORL.loaded_plugins(:CORL, :network) unless network_plugins.keys.include?(value) warn('corl.core.action.errors.network_provider', { :value => value, :choices => network_plugins.keys.join(", ") }) next false end true end register :node_provider, :str, :local, 'corl.core.action.options.node_provider' do |value| value = value.to_sym node_providers = node_plugins.keys unless CORL.vagrant? || node_providers.include?(value) warn('corl.core.action.errors.node_provider', { :value => value, :choices => node_providers.join(", ") }) next false end true end register :nodes, :array, [], 'corl.core.action.options.nodes' do |values| success = true values.each do |value| if info = CORL.plugin_class(:CORL, :node).translate_reference(value) if ! node_plugins.keys.include?(info[:provider].to_sym) || info[:name].empty? warn('corl.core.action.errors.nodes', { :value => value, :provider => info[:provider], :name => info[:name] }) success = false end end end success end end |
#node_exec ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/core/plugin/cloud_action.rb', line 124 def node_exec network = init_network # # A fork in the road... # if network && network.has_nodes? && ! settings[:nodes].empty? # Execute action on remote nodes success = network.batch(settings[:nodes], settings[:node_provider], settings[:parallel]) do |node| exec_config = Config.new(settings) exec_config.delete(:nodes) result = node.action(plugin_provider, exec_config) do |op, data| execute_remote(node, network, op, data) end result.status == code.success end myself.status = code.batch_error unless success else # Execute statement locally node = nil node = network.local_node if network if validate(node, network) yield(node, network) if block_given? else puts "\n" + I18n.t('nucleon.core.exec.help.usage') + ': ' + help + "\n" unless quiet? myself.status = code.validation_failed end end end |
#node_ignore ⇒ Object
94 95 96 |
# File 'lib/core/plugin/cloud_action.rb', line 94 def node_ignore [ :parallel, :net_remote, :net_provider, :node_provider, :nodes ] end |
#sanitize_remote(network, remote) ⇒ Object
Utilities
205 206 207 |
# File 'lib/core/plugin/cloud_action.rb', line 205 def sanitize_remote(network, remote) remote && network.remote(remote) ? remote : nil end |
#validate(node = nil, network = nil) ⇒ Object
Operations
101 102 103 |
# File 'lib/core/plugin/cloud_action.rb', line 101 def validate(node = nil, network = nil) super(node, network) end |