Class SaltClient

java.lang.Object
com.suse.salt.netapi.client.SaltClient

public class SaltClient extends Object
Salt API client.
  • Field Details

    • asyncHttpClient

      private final AsyncHttpClient asyncHttpClient
      The async connection factory object
    • uri

      private final URI uri
    • gson

      private final com.google.gson.Gson gson
  • Constructor Details

    • SaltClient

      public SaltClient(URI url, AsyncHttpClient asyncHttpClient)
      Constructor for connecting to a given URL.
      Parameters:
      url - the Salt API URL
      asyncHttpClient - http client to use for the salt api
  • Method Details

    • login

      public CompletionStage<Token> login(String username, String password, AuthModule eauth)
      Non-blocking version of login() returning a CompletionStage with the token.

      POST /login

      Parameters:
      username - the username
      password - the password
      eauth - the eauth type
      Returns:
      CompletionStage holding the authentication token
    • logout

      public CompletionStage<Boolean> logout()
      Perform logout and clear the session token from the config.

      POST /logout

      Returns:
      true if the logout was successful, otherwise false
    • run

      public <T> CompletionStage<Map<String,Object>> run(String username, String password, AuthModule eauth, String client, Target<T> target, String function, List<Object> args, Map<String,Object> kwargs)
      Generic interface to start any execution command bypassing normal session handling.

      POST /run

      Type Parameters:
      T - type of the tgt property for this command
      Parameters:
      username - the username
      password - the password
      eauth - the eauth type
      client - the client
      target - the target
      function - the function to execute
      args - list of non-keyword arguments
      kwargs - map containing keyword arguments
      Returns:
      Map key: minion id, value: command result from that minion
    • runRawSSHCommand

      public <T> CompletionStage<Map<String, Result<SSHRawResult>>> runRawSSHCommand(String command, Target<T> target, SaltSSHConfig cfg)
      Calls salt-ssh with a command in raw shell mode (commands bypass Salt and gets executed as shell commands).
      Type Parameters:
      T - type of the tgt property for this command
      Parameters:
      command - to be executed
      target - glob type, targets to be reached by the command
      cfg - SaltSSH config holder
      Returns:
      a map in which every key is a host associated to the result of the raw command
    • stats

      public CompletionStage<Stats> stats()
      Query statistics from the CherryPy Server.

      GET /stats

      Returns:
      the stats
    • events

      public WebSocketEventStream events(Token token, long sessionIdleTimeout, long idleTimeout, int maxMsgSize, EventListener... listeners) throws SaltException
      Returns a WebSocket @ClientEndpoint annotated object connected to the /ws ServerEndpoint.

      The stream object supports the WebSocketEventStream interface which allows the caller to register/unregister for stream event notifications as well as close the event stream.

      Note: login(String, String, AuthModule) or must be called prior to calling this method.

      GET /events

      Parameters:
      token - salt session token to use for authentication
      sessionIdleTimeout - session idle timeout to pass to the http client config
      idleTimeout - idle timeout to pass to the http client config
      maxMsgSize - maximum event data size to accept
      listeners - event listeners to be added before the stream is initialized
      Returns:
      the event stream
      Throws:
      SaltException - in case of an error during websocket stream initialization
    • call

      public <R> CompletionStage<R> call(Call<?> call, Client client, Optional<Target<?>> target, Map<String,Object> custom, com.google.gson.reflect.TypeToken<R> type, AuthMethod auth)