public class SaltClient extends Object
Constructor and Description |
---|
SaltClient(URI url)
Constructor for connecting to a given URL.
|
SaltClient(URI url,
ConnectionFactory connectionFactory)
Constructor for connecting to a given URL using a specific connection factory.
|
SaltClient(URI url,
ConnectionFactory connectionFactory,
ExecutorService executor)
Constructor for connecting to a given URL using a specific connection factory.
|
SaltClient(URI url,
ExecutorService executor)
Constructor for connecting to a given URL.
|
Modifier and Type | Method and Description |
---|---|
<R> R |
call(Call<?> call,
Client client,
String endpoint,
Optional<Map<String,Object>> custom,
com.google.gson.reflect.TypeToken<R> type)
|
<R> R |
call(Call<?> call,
Client client,
String endpoint,
com.google.gson.reflect.TypeToken<R> type)
Convenience method to make a call without arguments.
|
EventStream |
events(EventListener... listeners)
Returns a WebSocket @ClientEndpoint annotated object connected
to the /ws ServerEndpoint.
|
ClientConfig |
getConfig()
Directly access the configuration.
|
ResultInfoSet |
getJobResult(ScheduledJob job)
Query for the result of a supplied job.
|
ResultInfoSet |
getJobResult(String job)
Query for the result of a supplied job.
|
Map<String,Job> |
getJobs()
Get previously run jobs.
|
Future<Map<String,Job>> |
getJobsAsync()
Asynchronously get previously run jobs.
|
Map<String,Object> |
getMinionDetails(String minionId)
Query for details (grains) of the specified minion.
|
Future<Map<String,Object>> |
getMinionDetailsAsync(String minionId)
Query for details (grains) of the specified minion asynchronously.
|
Map<String,Map<String,Object>> |
getMinions()
Query for all minions and immediately return a map of minions keyed by minion id.
|
Future<Map<String,Map<String,Object>>> |
getMinionsAsync()
Asynchronously query for all minions and return a map of minions keyed by minion id.
|
Key.Names |
keys()
Query general key information.
|
Future<Key.Names> |
keysAsync()
Asynchronously query general key information.
|
Token |
login(String username,
String password,
AuthModule eauth)
Perform login and return the token.
|
Future<Token> |
loginAsync(String username,
String password,
AuthModule eauth)
Asynchronously perform login and return a Future with the token.
|
boolean |
logout()
Perform logout and clear the session token from the config.
|
Future<Boolean> |
logoutAsync()
Asynchronously perform logout and clear the session token from the config.
|
<T> 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> Future<Map<String,Object>> |
runAsync(String username,
String password,
AuthModule eauth,
String client,
Target<T> target,
String function,
List<Object> args,
Map<String,Object> kwargs)
Asynchronously start any execution command bypassing normal session handling.
|
<T> 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).
|
boolean |
sendEvent(String eventTag,
String eventData)
Trigger an event in Salt with the specified tag and data.
|
Future<Boolean> |
sendEventAsync(String eventTag,
String eventData)
Asynchronously trigger an event in Salt with the specified tag and data.
|
void |
setProxy(ProxySettings settings)
Configure to use a proxy when connecting to the Salt API.
|
<T> ScheduledJob |
startCommand(Target<T> target,
String function,
List<Object> args,
Map<String,Object> kwargs)
Generic interface to start any execution command and immediately return an object
representing the scheduled job.
|
<T> Future<ScheduledJob> |
startCommandAsync(Target<T> target,
String function,
List<Object> args,
Map<String,Object> kwargs)
Asynchronously start any execution command and immediately return an object
representing the scheduled job.
|
Stats |
stats()
Query statistics from the CherryPy Server.
|
Future<Stats> |
statsAsync()
Asynchronously query statistics from the CherryPy Server.
|
public SaltClient(URI url)
url
- the Salt API URLpublic SaltClient(URI url, ConnectionFactory connectionFactory)
url
- the Salt API URLconnectionFactory
- ConnectionFactory implementationpublic SaltClient(URI url, ExecutorService executor)
url
- the Salt API URLexecutor
- ExecutorService to be used for async operationspublic SaltClient(URI url, ConnectionFactory connectionFactory, ExecutorService executor)
url
- the Salt API URLconnectionFactory
- ConnectionFactory implementationexecutor
- ExecutorService to be used for async operationspublic ClientConfig getConfig()
public void setProxy(ProxySettings settings)
settings
- the proxy settingspublic Token login(String username, String password, AuthModule eauth) throws SaltException
POST /login
username
- the usernamepassword
- the passwordeauth
- the eauth typeSaltException
- if anything goes wrongpublic Future<Token> loginAsync(String username, String password, AuthModule eauth)
POST /login
username
- the usernamepassword
- the passwordeauth
- the eauth typepublic boolean logout() throws SaltException
POST /logout
SaltException
- if anything goes wrongpublic Future<Boolean> logoutAsync()
POST /logout
public Map<String,Map<String,Object>> getMinions() throws SaltException
GET /minions
SaltException
- if anything goes wrongpublic Future<Map<String,Map<String,Object>>> getMinionsAsync() throws SaltException
GET /minions
SaltException
- if anything goes wrongpublic Map<String,Object> getMinionDetails(String minionId) throws SaltException
GET /minions/<minion-id>
minionId
- the minion IDSaltException
- if anything goes wrongpublic Future<Map<String,Object>> getMinionDetailsAsync(String minionId) throws SaltException
GET /minions/<minion-id>
minionId
- the minion IDSaltException
- if anything goes wrongpublic <T> ScheduledJob startCommand(Target<T> target, String function, List<Object> args, Map<String,Object> kwargs) throws SaltException
POST /minions
T
- type of the tgt property for this commandtarget
- the targetfunction
- the function to executeargs
- list of non-keyword argumentskwargs
- map containing keyword argumentsSaltException
- if anything goes wrongpublic <T> Future<ScheduledJob> startCommandAsync(Target<T> target, String function, List<Object> args, Map<String,Object> kwargs)
POST /minions
T
- type of the tgt property for this commandtarget
- the targetfunction
- the function to executeargs
- list of non-keyword argumentskwargs
- map containing keyword argumentspublic ResultInfoSet getJobResult(ScheduledJob job) throws SaltException
GET /job/<job-id>
job
- ScheduledJob
object representing scheduled jobResultInfoSet
representing result set from minionsSaltException
- if anything goes wrongpublic ResultInfoSet getJobResult(String job) throws SaltException
GET /job/<job-id>
job
- String representing scheduled jobResultInfoSet
representing result set from minionsSaltException
- if anything goes wrongpublic Map<String,Job> getJobs() throws SaltException
GET /jobs
SaltException
- if anything goes wrongpublic Future<Map<String,Job>> getJobsAsync()
GET /jobs
public <T> Map<String,Object> run(String username, String password, AuthModule eauth, String client, Target<T> target, String function, List<Object> args, Map<String,Object> kwargs) throws SaltException
POST /run
T
- type of the tgt property for this commandusername
- the usernamepassword
- the passwordeauth
- the eauth typeclient
- the clienttarget
- the targetfunction
- the function to executeargs
- list of non-keyword argumentskwargs
- map containing keyword argumentsSaltException
- if anything goes wrongpublic <T> Map<String,Result<SSHRawResult>> runRawSSHCommand(String command, Target<T> target, SaltSSHConfig cfg) throws SaltException
T
- type of the tgt property for this commandcommand
- to be executedtarget
- glob type, targets to be reached by the commandcfg
- SaltSSH config holderSaltException
public <T> Future<Map<String,Object>> runAsync(String username, String password, AuthModule eauth, String client, Target<T> target, String function, List<Object> args, Map<String,Object> kwargs)
POST /run
T
- type of the tgt property for this commandusername
- the usernamepassword
- the passwordeauth
- the eauth typeclient
- the clienttarget
- the targetfunction
- the function to executeargs
- list of non-keyword argumentskwargs
- map containing keyword argumentspublic Stats stats() throws SaltException
GET /stats
SaltException
- if anything goes wrongpublic Future<Stats> statsAsync()
GET /stats
public Key.Names keys() throws SaltException
Required permissions: @wheel
GET /keys
SaltException
- if anything goes wrongpublic Future<Key.Names> keysAsync()
Required permissions: @wheel
GET /keys
public EventStream events(EventListener... listeners) throws SaltException
The stream object supports the EventStream
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
loginAsync(String, String, AuthModule)
must be called prior
to calling this method.
GET /events
listeners
- event listeners to be added before the stream is initializedSaltException
- in case of an error during websocket stream initializationpublic boolean sendEvent(String eventTag, String eventData) throws SaltException
POST /hook
eventTag
- the event tageventData
- the event data. Must be valid JSON.SaltException
- if anything goes wrongpublic Future<Boolean> sendEventAsync(String eventTag, String eventData)
POST /hook
eventTag
- the event tageventData
- the event data. Must be valid JSON.public <R> R call(Call<?> call, Client client, String endpoint, Optional<Map<String,Object>> custom, com.google.gson.reflect.TypeToken<R> type) throws SaltException
R
- the object type that will be returnedcall
- the callclient
- the client to useendpoint
- the endpointcustom
- map of argumentstype
- return type as a TypeTokenSaltException
- if anything goes wrongpublic <R> R call(Call<?> call, Client client, String endpoint, com.google.gson.reflect.TypeToken<R> type) throws SaltException
R
- the object type that will be returnedcall
- the callclient
- the client to useendpoint
- the endpointtype
- return type as a TypeTokenSaltException
- if anything goes wrongCopyright © 2016. All rights reserved.