Package com.suse.salt.netapi.client
Class SaltClient
- java.lang.Object
-
- com.suse.salt.netapi.client.SaltClient
-
public class SaltClient extends Object
Salt API client.
-
-
Constructor Summary
Constructors Constructor Description SaltClient(URI url, AsyncHttpClient asyncHttpClient)
Constructor for connecting to a given URL.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> CompletionStage<R>
call(Call<?> call, Client client, Optional<Target<?>> target, Map<String,Object> custom, com.google.gson.reflect.TypeToken<R> type, AuthMethod auth)
WebSocketEventStream
events(Token token, long sessionIdleTimeout, long idleTimeout, int maxMsgSize, EventListener... listeners)
Returns a WebSocket @ClientEndpoint annotated object connected to the /ws ServerEndpoint.CompletionStage<Token>
login(String username, String password, AuthModule eauth)
Non-blocking version of login() returning a CompletionStage with the token.CompletionStage<Boolean>
logout()
Perform logout and clear the session token from the config.<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.<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).CompletionStage<Stats>
stats()
Query statistics from the CherryPy Server.
-
-
-
Constructor Detail
-
SaltClient
public SaltClient(URI url, AsyncHttpClient asyncHttpClient)
Constructor for connecting to a given URL.- Parameters:
asyncHttpClient
- http client to use for the salt apiurl
- the Salt API URL
-
-
Method Detail
-
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 usernamepassword
- the passwordeauth
- 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 usernamepassword
- the passwordeauth
- the eauth typeclient
- the clienttarget
- the targetfunction
- the function to executeargs
- list of non-keyword argumentskwargs
- 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 executedtarget
- glob type, targets to be reached by the commandcfg
- 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:
listeners
- event listeners to be added before the stream is initializedidleTimeout
- idle timeout to pass to the http client configmaxMsgSize
- maximum event data size to acceptsessionIdleTimeout
- session idle timeout to pass to the http client configtoken
- salt session token to use for authentication- 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)
-
-