Salt is written to be completely API centric, Salt minions and master can be built directly into third party applications as a communication layer. The Salt client API is very straightforward.
A number of client command methods are available depending on the exact behavior desired.
LocalClient is the same interface used by the salt command-line tool on the Salt Master. LocalClient is used to send a command to Salt minions to execute execution modules and return the results to the Salt Master.
Importing and using LocalClient must be done on the same machine as the Salt Master and it must be done using the same user that the Salt Master is running as (unless external_auth is configured and authentication credentials are included in the execution.
The cmd method will execute and wait for the timeout period for all minions to reply, then it will return all minion data at once.
Usage:
With authentication:
Compound command usage:
Parameters: |
|
---|---|
Returns: | A dictionary with the result of the execution, keyed by minion ID. A compound command will return a sub-dictionary keyed by function name. |
Used by the salt CLI. This method returns minion returns as the come back and attempts to block until all minions return.
The function signature is the same as cmd() with the following exceptions.
Parameters: | verbose -- Print extra information about the running command |
---|---|
Returns: | A generator |
Yields the individual minion returns as they come in
The function signature is the same as cmd() with the following exceptions.
Blocks while waiting for individual minions to return.
The function signature is the same as cmd() with the following exceptions.
Returns: | None until the next minion returns. This allows for actions to be injected in between minion returns. |
---|
Execute a command and get back the jid, don't wait for anything
The function signature is the same as cmd() with the following exceptions.
Returns: | A job ID |
---|
Caller is the same interface used by the salt-call command-line tool on the Salt Minion.
Importing and using LocalClient must be done on the same machine as a Salt Minion and it must be done using the same user that the Salt Minion is running as.
Usage:
import salt.client
caller = salt.client.Caller()
caller.function('test.ping')
# Or call objects directly
caller.sminion.functions['cmd.run']('ls -l')
Call a single salt function
RunnerClient is the same interface used by the salt-run command-line tool on the Salt Master. It executes runner modules which run on the Salt Master.
Importing and using RunnerClient must be done on the same machine as the Salt Master and it must be done using the same user that the Salt Master is running as.
Execute a runner with the given arguments
Pass in the runner function name and the low data structure
WheelClient is an interface to Salt's wheel modules. Wheel modules interact with various parts of the Salt Master.
Importing and using WheelClient must be done on the same machine as the Salt Master and it must be done using the same user that the Salt Master is running as.
Execute a master control function
Send a function call to a wheel module through the master network interface Expects that one of the kwargs is key 'fun' whose value is the namestring of the function to call