Class: Blender::Driver::Salt
- Inherits:
-
Base
- Object
- Base
- Blender::Driver::Salt
- Defined in:
- lib/blender/drivers/salt.rb
Overview
Salt driver for Blender
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Instance Method Summary collapse
- #execute(tasks, hosts) ⇒ Object
- #exit_status(responses, nodes) ⇒ Object
-
#initialize(config = {}) ⇒ Salt
constructor
A new instance of Salt.
- #run_command(command, nodes) ⇒ Object
- #salt_call(command, host) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Salt
Returns a new instance of Salt.
29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
27 28 29 |
# File 'lib/blender/drivers/salt.rb', line 27 def concurrency @concurrency end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
27 28 29 |
# File 'lib/blender/drivers/salt.rb', line 27 def ssl @ssl end |
Instance Method Details
#execute(tasks, hosts) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# 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.[:ignore_failure] fail ExecutionFailed, cmd.stderr end end end end |
#exit_status(responses, nodes) ⇒ Object
64 65 66 67 68 69 70 71 |
# 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) ⇒ Object
56 57 58 59 60 61 62 |
# 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.) end |
#salt_call(command, host) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |