mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add information about returning a tuple with an error message
This commit is contained in:
parent
fa466519c4
commit
685c2cced6
1 changed files with 23 additions and 4 deletions
|
@ -405,10 +405,29 @@ similar to the following:
|
|||
return __virtualname__
|
||||
return False
|
||||
|
||||
Note that the ``__virtual__()`` function will return either a ``True`` or ``False``
|
||||
value. If it returns a ``True`` value, this ``__virtualname__`` module-level attribute
|
||||
can be set as seen in the above example. This is the name that the module should be
|
||||
referred to as.
|
||||
The ``__virtual__()`` function can return a ``True`` or ``False`` boolean, a tuple,
|
||||
or a string. If it returns a ``True`` value, this ``__virtualname__`` module-level
|
||||
attribute can be set as seen in the above example. This is the string that the module
|
||||
should be referred to as.
|
||||
|
||||
When ``__virtual__()`` returns a tuple, the first item should be a boolean and the
|
||||
second should be a string. This is typically done when the module should not load. The
|
||||
first value of the tuple is ``False`` and the second is the error message to display
|
||||
for why the module did not load.
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only load if git exists on the system
|
||||
'''
|
||||
if salt.utils.which('git') is None:
|
||||
return (False,
|
||||
'The git execution module cannot be loaded: git unavailable.')
|
||||
else:
|
||||
return True
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
|
Loading…
Add table
Reference in a new issue