class Blender::Driver::Salt
Attributes
concurrency[R]
ssl[R]
Public Class Methods
new(config = {})
click to toggle source
Calls superclass method
# File lib/blender/drivers/salt.rb, line 29 def initialize(config = {}) cfg = config.dup @concurrency = cfg.delete(:concurrency) || 1 @ssl = cfg.delete(:ssl) || false super(cfg) end
Public Instance Methods
execute(tasks, hosts)
click to toggle source
# File lib/blender/drivers/salt.rb, line 73 def execute(tasks, hosts) Log.debug("Salt call on [#{hosts.inspect}]") tasks.each do |task| hosts.each_slice(concurrency) do |nodes| cmd = run_command(task.command, nodes) if cmd.exitstatus != 0 && !task.metadata[:ignore_failure] fail ExecutionFailed, cmd.stderr end end end end
exit_status(responses, nodes)
click to toggle source
# File lib/blender/drivers/salt.rb, line 64 def exit_status(responses, nodes) if responses.size == nodes.size ExecOutput.new(0, responses.inspect, '') else ExecOutput.new(-1, '', 'Insufficient number of responses. '\ "Expected:#{nodes.size}, Got:#{responses.size}") end end
run_command(command, nodes)
click to toggle source
# File lib/blender/drivers/salt.rb, line 56 def run_command(command, nodes) responses = salt_call(command, nodes) command.process.call(responses) if command.process exit_status(responses, nodes) rescue StandardError => e ExecOutput.new(-1, '', e.message) end
salt_call(command, host)
click to toggle source
# File lib/blender/drivers/salt.rb, line 36 def salt_call(command, host) responses = [] http_scheme = @ssl ? 'https' : 'http' salt_server_url = "#{http_scheme}://#{config[:host]}:#{config[:port]}" Log.debug("Invoking sall call '#{command.function}' with arguments "\ "'#{command.arguments}' against #{host}") Log.debug("Salt server address #{salt_server_url}") client = SaltClient::Client.new salt_server_url, config[:username], config[:password] host.each do |h| event = client.call(h, command.function, command.arguments) responses << event stdout.puts event.inspect Log.info("Results for #{command.inspect}: #{event}") end responses end