API Usage — VMware Salt API
API Usage
RaaS can be accessed in two ways: via the RPC client (Python) or via cURL over HTTP. The examples throughout the API Interfaces section use RPC client syntax.
Using the RPC Client
The programmatic RPC clients in the sseapiclient module work with Python
version 2.7 and Python version 3.5 or later. The clients connect to SSE via HTTP or
HTTPS and authenticate automatically.
The samples in this guide assume:
client = APIClient(<addr>, <user>, <pwd>)- Default state-based install of eAPI
- SSL enabled
sseapiclientimported. Example:
from sseapiclient import APIClient
API syntax
client.api.<interface>.<method>(parameter=parameter_value)
Example:
from sseapiclient import APIClient
client = APIClient('https://localhost', 'root', 'PASSWORD')
client.api.sec.download_content(auto_ingest=True)
Using cURL
The HTTP (or HTTPS) bridge accepts JSON payloads POSTed to an endpoint exposed by SSE, translates the payloads into RPC calls, then returns the result as JSON. The endpoint supports cookie-based authentication so that authentication credentials need to be passed only once per session. The bridge also allows sending multiple calls in a single payload.
You can use RaaS directly with HTTP and JSON. Note: when xsrf is enabled you will need to obtain an xsrf cookie and token first. When using the Python RPC client, this is done automatically by default.
Example:
curl --user 'root:PASSWORD' --url 'https://localhost/rpc' \
--data '{
"resource": "sec",
"method": "download_content",
"kwarg": {"auto_ingest": true}
}'
cURL call with xsrf header
If xsrf is enabled (default with state install) in
/etc/raas/raas.conf via tornado_xsrf_cookies_enabled: True,
you must provide an X-Xsrftoken header on each REST call. Save a cookie
with an initial GET call, then use the cookie to provide the header token. This cookie
is saved in the $HOME (user's home) directory. The payload is a
dictionary.
curl -k -c $HOME/eAPICookie.txt -u root:PASSWORD 'https://localhost/account/login' >/dev/null
curl -k -u root:PASSWORD -b $HOME/eAPICookie.txt \
-H 'X-Xsrftoken: '$(grep -w '_xsrf' $HOME/eAPICookie.txt | cut -f7)'' \
-X POST https://localhost/rpc \
-d '{
"resource": "sec",
"method": "download_content",
"kwarg": {"auto_ingest": true}
}'