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.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/salt_client.rb', line 8 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 raise("Could not login to the salt master") end @token = response.body.fetch("return")[0]["token"] end |
Instance Method Details
#call(target, function, arguments) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/salt_client.rb', line 25 def call(target, function, arguments) parameters = { client: "local", tgt: target, fun: function } parameters[:arg] = arguments if arguments response = Unirest.post @server, headers: { "Accept": "application/json", "X-Auth-Token": @token }, parameters: parameters if response.code != 200 raise("Something went wrong when calling your method") end response.body["return"][0] end |