Class SaltClient
java.lang.Object
com.suse.salt.netapi.client.SaltClient
Salt API client.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AsyncHttpClientThe async connection factory objectprivate final com.google.gson.Gsonprivate final URI -
Constructor Summary
ConstructorsConstructorDescriptionSaltClient(URI url, AsyncHttpClient asyncHttpClient) Constructor for connecting to a given URL. -
Method Summary
Modifier and TypeMethodDescription<R> CompletionStage<R> call(Call<?> call, Client client, Optional<Target<?>> target, Map<String, Object> custom, com.google.gson.reflect.TypeToken<R> type, AuthMethod auth) events(Token token, long sessionIdleTimeout, long idleTimeout, int maxMsgSize, EventListener... listeners) Returns a WebSocket @ClientEndpoint annotated object connected to the /ws ServerEndpoint.login(String username, String password, AuthModule eauth) Non-blocking version of login() returning a CompletionStage with the token.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).stats()Query statistics from the CherryPy Server.
-
Field Details
-
asyncHttpClient
The async connection factory object -
uri
-
gson
private final com.google.gson.Gson gson
-
-
Constructor Details
-
SaltClient
Constructor for connecting to a given URL.- Parameters:
url- the Salt API URLasyncHttpClient- http client to use for the salt api
-
-
Method Details
-
login
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
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
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
WebSocketEventStreaminterface 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 authenticationsessionIdleTimeout- session idle timeout to pass to the http client configidleTimeout- idle timeout to pass to the http client configmaxMsgSize- maximum event data size to acceptlisteners- 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)
-