mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Normalize case for functions vs classes, add mine shortcut
This commit is contained in:
parent
a6c4f8a743
commit
b262a8f146
@ -91,42 +91,27 @@ manager to automatically have their ``watch_in`` set to
|
|||||||
Including and Extending
|
Including and Extending
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
To include other states use the Include() function. It takes one name per
|
To include other states use the ``include()`` function. It takes one name per
|
||||||
state to include.
|
state to include.
|
||||||
|
|
||||||
To extend another state use the Extend() function on the name when creating
|
To extend another state use the ``extend()`` function on the name when creating
|
||||||
a state.
|
a state.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:linenos:
|
:linenos:
|
||||||
#!pyobjects
|
#!pyobjects
|
||||||
|
|
||||||
Include('http', 'ssh')
|
include('http', 'ssh')
|
||||||
|
|
||||||
Service.running(Extend('apache'),
|
Service.running(extend('apache'),
|
||||||
watch=[{'file': '/etc/httpd/extra/httpd-vhosts.conf'}])
|
watch=[{'file': '/etc/httpd/extra/httpd-vhosts.conf'}])
|
||||||
|
|
||||||
Pillar data
|
Salt object
|
||||||
^^^^^^^^^^^
|
^^^^^^^^^^^
|
||||||
Pyobjects provides a shortcut function for calling ``salt['pillar.get']`` that
|
|
||||||
helps maintain the readability of your state files. It can be accessed using
|
|
||||||
the ``Pillar`` object.
|
|
||||||
|
|
||||||
The following lines are functionally equivalent:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
:linenos:
|
|
||||||
#!pyobjects
|
|
||||||
|
|
||||||
value = Pillar('foo:bar:baz', 'qux')
|
|
||||||
value = salt['pillar.get']('foo:bar:baz', 'qux')
|
|
||||||
|
|
||||||
SaltObject
|
|
||||||
^^^^^^^^^^
|
|
||||||
In the spirit of the object interface for creating state data pyobjects also
|
In the spirit of the object interface for creating state data pyobjects also
|
||||||
provides a simple object interface to the ``__salt__`` object.
|
provides a simple object interface to the ``__salt__`` object.
|
||||||
|
|
||||||
An object named ``Salt`` exists in scope for your sls files and will dispatch
|
A function named ``salt`` exists in scope for your sls files and will dispatch
|
||||||
its attributes to the ``__salt__`` dictionary.
|
its attributes to the ``__salt__`` dictionary.
|
||||||
|
|
||||||
The following lines are functionally equivalent:
|
The following lines are functionally equivalent:
|
||||||
@ -135,8 +120,32 @@ The following lines are functionally equivalent:
|
|||||||
:linenos:
|
:linenos:
|
||||||
#!pyobjects
|
#!pyobjects
|
||||||
|
|
||||||
ret = Salt.cmd.run(bar)
|
ret = salt.cmd.run(bar)
|
||||||
ret = salt['cmd.run'](bar)
|
ret = __salt__['cmd.run'](bar)
|
||||||
|
|
||||||
|
Pillar, grain & mine data
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
Pyobjects provides shortcut functions for calling ``pillar.get``,
|
||||||
|
``grains.get`` & ``mine.get`` on the ``__salt__`` object. This helps maintain
|
||||||
|
the readability of your state files.
|
||||||
|
|
||||||
|
Each type of data can be access by a function of the same name: ``pillar()``,
|
||||||
|
``grains()`` and ``mine()``.
|
||||||
|
|
||||||
|
The following pairs of lines are functionally equivalent:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
:linenos:
|
||||||
|
#!pyobjects
|
||||||
|
|
||||||
|
value = pillar('foo:bar:baz', 'qux')
|
||||||
|
value = __salt__['pillar.get']('foo:bar:baz', 'qux')
|
||||||
|
|
||||||
|
value = grains('pkg:apache')
|
||||||
|
value = __salt__['grains.get']('pkg:apache')
|
||||||
|
|
||||||
|
value = mine('os:Fedora', 'network.interfaces', 'grain')
|
||||||
|
value = __salt__['mine.get']('os:Fedora', 'network.interfaces', 'grain')
|
||||||
|
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
@ -148,10 +157,7 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from salt.loader import states
|
from salt.loader import states
|
||||||
from salt.utils.pyobjects import StateRegistry, SaltObject
|
from salt.utils.pyobjects import StateRegistry, StateFactory, SaltObject
|
||||||
from salt.utils.pyobjects import StateFactory # pylint: disable=W0611
|
|
||||||
# DO NOT REMOVE THE DISABLE ABOVE, it's used in an exec call below
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -192,8 +198,8 @@ def render(template, saltenv='base', sls='',
|
|||||||
_globals[mod_upper] = _st_locals[mod_upper]
|
_globals[mod_upper] = _st_locals[mod_upper]
|
||||||
|
|
||||||
# add our Include and Extend functions
|
# add our Include and Extend functions
|
||||||
_globals['Include'] = _registry.include
|
_globals['include'] = _registry.include
|
||||||
_globals['Extend'] = _registry.make_extend
|
_globals['extend'] = _registry.make_extend
|
||||||
|
|
||||||
# for convenience
|
# for convenience
|
||||||
try:
|
try:
|
||||||
@ -202,6 +208,7 @@ def render(template, saltenv='base', sls='',
|
|||||||
'salt': SaltObject(__salt__),
|
'salt': SaltObject(__salt__),
|
||||||
'pillar': __salt__['pillar.get'],
|
'pillar': __salt__['pillar.get'],
|
||||||
'grains': __salt__['grains.get'],
|
'grains': __salt__['grains.get'],
|
||||||
|
'mine': __salt__['mine.get'],
|
||||||
|
|
||||||
# the "dunder" formats are still available for direct use
|
# the "dunder" formats are still available for direct use
|
||||||
'__salt__': __salt__,
|
'__salt__': __salt__,
|
||||||
|
Loading…
Reference in New Issue
Block a user