
* fixes saltstack/salt#62372 unable to use random shuffle and sample functions as Jinja filters * move random_shuffle and random_sample logic to utils * static seed in tests seems to have shifted * static seed in tests require hash module * Change Tiamat to onedir in release notes * Reinstate known issues * Update release notes with onedir package support policy * need to check the version of Netmiko python library and then import the exceptions from different locations depending on the result. * Adding changelog. * swap out if...else for double try...except. * Remove extra fix we don't need anymore * [Docs] include onedir system python note * Update all platforms to use pycparser 2.21 or greater for Py 3.9 or higher, fixes fips fault with openssl v3.x * Remove the PyObjC dependency Signed-off-by: Pedro Algarvio <palgarvio@vmware.com> * Add "<tiamat> python" subcommand to allow execution or arbitrary scripts via bundled Python runtime * Document usage of bundled Python runtime for Client API * Use explicit locals for custom script execution, handle exception in similar fashion as Python * Remove old __file__ replacement * Apply suggestions from code review Co-authored-by: Pedro Algarvio <pedro@algarvio.me> Co-authored-by: nicholasmhughes <nicholasmhughes@gmail.com> Co-authored-by: Alyssa Rock <alyssa.rock@gmail.com> Co-authored-by: Gareth J. Greenaway <gareth@saltstack.com> Co-authored-by: Twangboy <leesh@vmware.com> Co-authored-by: David Murphy < dmurphy@saltstack.com> Co-authored-by: Pedro Algarvio <palgarvio@vmware.com> Co-authored-by: Lukas Raska <lukas@raska.me> Co-authored-by: Pedro Algarvio <pedro@algarvio.me>
3.8 KiB
Python client API
Salt provides several entry points for interfacing with Python
applications. These entry points are often referred to as
*Client()
APIs. Each client accesses different parts of
Salt, either from the master or from a minion. Each client is detailed
below.
Note
For Tiamat-bundled Salt distribution, you need to use the bundled Python runtime as the system Python won't be able to access Salt internals.
To execute scripts via bundled Python runtime, either run the script
with /path/to/salt python script.py
or use
#!/path/to/salt python
shebang
There are many ways to access Salt programmatically.
Salt can be used from CLI scripts as well as via a REST interface.
See Salt's outputter system <all-salt.output>
to retrieve
structured data from Salt as JSON, or as shell-friendly text, or many
other formats.
See the state.event <salt.runners.state.event>
runner to utilize Salt's event bus from shell scripts.
Salt's netapi module provides access to Salt externally via a REST interface. Review the netapi module documentation for more information.
Salt's opts
dictionary
Some clients require access to Salt's opts
dictionary.
(The dictionary representation of the master <configuration-salt-master>
or minion <configuration-salt-minion>
config
files.)
A common pattern for fetching the opts
dictionary is to
defer to environment variables if they exist or otherwise fetch the
config from the default location.
salt.config.client_config
salt.config.minion_config
Salt's Loader Interface
Modules in the Salt ecosystem are loaded into memory using a custom
loader system. This allows modules to have conditional requirements (OS,
OS version, installed libraries, etc) and allows Salt to inject special
variables (__salt__
, __opts__
, etc).
Most modules can be manually loaded. This is often useful in
third-party Python apps or when writing tests. However some modules
require and expect a full, running Salt system underneath. Notably
modules that facilitate master-to-minion communication such as the ~salt.modules.mine
, ~salt.modules.publish
, and
~salt.modules.peer
execution modules. The error KeyError: 'master_uri'
is a
likely indicator for this situation. In those instances use the ~salt.client.Caller
class to execute those modules instead.
Each module type has a corresponding loader function.
salt.loader.minion_mods
salt.loader.raw_mod
salt.loader.states
salt.loader.grains
salt.loader.grain_funcs
Salt's Client Interfaces
LocalClient
salt.client.LocalClient
Salt Caller
salt.client.Caller
Salt Proxy Caller
salt.client.ProxyCaller
RunnerClient
salt.runner.RunnerClient
WheelClient
salt.wheel.WheelClient
CloudClient
salt.cloud.CloudClient
SSHClient
salt.client.ssh.client.SSHClient