Class: SaltClient::Client
- Inherits:
-
Object
- Object
- SaltClient::Client
- Defined in:
- lib/salt_client.rb
Instance Method Summary collapse
- #call(target, function, arguments) ⇒ Object
-
#initialize(server, user, pass) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(server, user, pass) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/salt_client.rb', line 5 def initialize(server, user, pass) @server = server response = Unirest.post "#{server}/login", headers: {"Accept": "application/json"}, parameters: { :username => user, :password => pass, :eauth => "pam" } if response.code != 200 abort("Could not login to the salt master") end @token = response.body.fetch("return")[0]["token"] end |
Instance Method Details
#call(target, function, arguments) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/salt_client.rb', line 22 def call(target, function, arguments) response = Unirest.post @server, headers: { "Accept": "application/json", "X-Auth-Token": @token }, parameters: { :client => "local", :tgt => target, :fun => function, :arg => arguments } if response.code != 200 abort("Something went wrong when calling your method") end response.body["return"][0] end |