2012-10-25 21:45:16 +00:00
|
|
|
======================
|
|
|
|
Writing netapi modules
|
|
|
|
======================
|
|
|
|
|
2014-06-19 02:54:47 +00:00
|
|
|
:py:mod:`~salt.netapi` modules, put simply, bind a port and start a service.
|
2012-10-25 21:45:16 +00:00
|
|
|
They are purposefully open-ended and can be used to present a variety of
|
|
|
|
external interfaces to Salt, and even present multiple interfaces at once.
|
|
|
|
|
|
|
|
.. seealso:: :ref:`The full list of netapi modules <all-netapi-modules>`
|
|
|
|
|
|
|
|
Configuration
|
|
|
|
=============
|
|
|
|
|
2014-06-19 02:54:47 +00:00
|
|
|
All :py:mod:`~salt.netapi` configuration is done in the :ref:`Salt master
|
2012-10-25 21:45:16 +00:00
|
|
|
config <configuration-salt-master>` and takes a form similar to the following:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2012-11-15 21:53:13 +00:00
|
|
|
rest_cherrypy:
|
|
|
|
port: 8000
|
|
|
|
debug: True
|
|
|
|
ssl_crt: /etc/pki/tls/certs/localhost.crt
|
|
|
|
ssl_key: /etc/pki/tls/certs/localhost.key
|
2012-10-25 21:45:16 +00:00
|
|
|
|
|
|
|
The ``__virtual__`` function
|
|
|
|
============================
|
|
|
|
|
2014-06-19 02:54:47 +00:00
|
|
|
Like all module types in Salt, :py:mod:`~salt.netapi` modules go through
|
2012-10-25 21:45:16 +00:00
|
|
|
Salt's loader interface to determine if they should be loaded into memory and
|
|
|
|
then executed.
|
|
|
|
|
|
|
|
The ``__virtual__`` function in the module makes this determination and should
|
|
|
|
return ``False`` or a string that will serve as the name of the module. If the
|
|
|
|
module raises an ``ImportError`` or any other errors, it will not be loaded.
|
|
|
|
|
|
|
|
The ``start`` function
|
|
|
|
======================
|
|
|
|
|
2014-06-19 02:54:47 +00:00
|
|
|
The ``start()`` function will be called for each :py:mod:`~salt.netapi`
|
2012-10-25 21:45:16 +00:00
|
|
|
module that is loaded. This function should contain the server loop that
|
|
|
|
actually starts the service. This is started in a multiprocess.
|
|
|
|
|
|
|
|
Inline documentation
|
|
|
|
====================
|
|
|
|
|
|
|
|
As with the rest of Salt, it is a best-practice to include liberal inline
|
|
|
|
documentation in the form of a module docstring and docstrings on any classes,
|
2014-06-19 02:54:47 +00:00
|
|
|
methods, and functions in your :py:mod:`~salt.netapi` module.
|
2012-10-25 21:45:16 +00:00
|
|
|
|
|
|
|
Loader “magic” methods
|
|
|
|
======================
|
|
|
|
|
2013-10-25 08:26:57 +00:00
|
|
|
The loader makes the ``__opts__`` data structure available to any function in
|
2014-06-19 02:54:47 +00:00
|
|
|
a :py:mod:`~salt.netapi` module.
|