1
0

index.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. .. _client-apis:
  2. .. _python-api:
  3. =================
  4. Python client API
  5. =================
  6. Salt provides several entry points for interfacing with Python applications.
  7. These entry points are often referred to as ``*Client()`` APIs. Each client
  8. accesses different parts of Salt, either from the master or from a minion. Each
  9. client is detailed below.
  10. .. seealso:: There are many ways to access Salt programmatically.
  11. Salt can be used from CLI scripts as well as via a REST interface.
  12. See Salt's :ref:`outputter system <all-salt.output>` to retrieve structured
  13. data from Salt as JSON, or as shell-friendly text, or many other formats.
  14. See the :py:func:`state.event <salt.runners.state.event>` runner to utilize
  15. Salt's event bus from shell scripts.
  16. Salt's `netapi module`_ provides access to Salt externally via a REST interface.
  17. Review the `netapi module`_ documentation for more information.
  18. .. _`netapi module`: http://docs.saltstack.com/en/latest/topics/netapi/index.html
  19. Salt's ``opts`` dictionary
  20. ==========================
  21. Some clients require access to Salt's ``opts`` dictionary. (The dictionary
  22. representation of the :ref:`master <configuration-salt-master>` or
  23. :ref:`minion <configuration-salt-minion>` config files.)
  24. A common pattern for fetching the ``opts`` dictionary is to defer to
  25. environment variables if they exist or otherwise fetch the config from the
  26. default location.
  27. .. autofunction:: salt.config.client_config
  28. .. autofunction:: salt.config.minion_config
  29. Salt's Loader Interface
  30. =======================
  31. Modules in the Salt ecosystem are loaded into memory using a custom loader
  32. system. This allows modules to have conditional requirements (OS, OS version,
  33. installed libraries, etc) and allows Salt to inject special variables
  34. (``__salt__``, ``__opts__``, etc).
  35. Most modules can be manually loaded. This is often useful in third-party Python
  36. apps or when writing tests. However some modules require and expect a full,
  37. running Salt system underneath. Notably modules that facilitate
  38. master-to-minion communication such as the :py:mod:`~salt.modules.mine`,
  39. :py:mod:`~salt.modules.publish`, and :py:mod:`~salt.modules.peer` execution
  40. modules. The error ``KeyError: 'master_uri'`` is a likely indicator for this
  41. situation. In those instances use the :py:class:`~salt.client.Caller` class
  42. to execute those modules instead.
  43. Each module type has a corresponding loader function.
  44. .. autofunction:: salt.loader.minion_mods
  45. .. autofunction:: salt.loader.raw_mod
  46. .. autofunction:: salt.loader.states
  47. .. autofunction:: salt.loader.grains
  48. .. autofunction:: salt.loader.grain_funcs
  49. Salt's Client Interfaces
  50. ========================
  51. .. _client-interfaces:
  52. .. _local-client:
  53. LocalClient
  54. -----------
  55. .. autoclass:: salt.client.LocalClient
  56. :members: cmd, run_job, cmd_async, cmd_subset, cmd_batch, cmd_iter,
  57. cmd_iter_no_block, get_cli_returns, get_event_iter_returns
  58. Salt Caller
  59. -----------
  60. .. autoclass:: salt.client.Caller
  61. :members: cmd
  62. Salt Proxy Caller
  63. -----------------
  64. .. autoclass:: salt.client.ProxyCaller
  65. :members: cmd
  66. RunnerClient
  67. ------------
  68. .. autoclass:: salt.runner.RunnerClient
  69. :members: cmd, asynchronous, cmd_sync, cmd_async
  70. WheelClient
  71. -----------
  72. .. autoclass:: salt.wheel.WheelClient
  73. :members: cmd, asynchronous, cmd_sync, cmd_async
  74. CloudClient
  75. -----------
  76. .. autoclass:: salt.cloud.CloudClient
  77. :members:
  78. SSHClient
  79. ---------
  80. .. autoclass:: salt.client.ssh.client.SSHClient
  81. :members: cmd, cmd_iter