wqee2 发表于 2015-5-28 08:39:57

SaltStack源码分析之pillar模块

/usr/lib/python2.6/site-packages/salt/modules/pillar.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def get(key, default='', merge=False, delimiter=':'):
    '''
    .. versionadded:: 0.14

    Attempt to retrieve the named value from pillar, if the named value is not
    available return the passed default. The default return is an empty string.

    If the merge parameter is set to ``True``, the default will be recursively
    merged into the returned pillar data.

    The value can also represent a value in a nested dict using a ":" delimiter
    for the dict. This means that if a dict in pillar looks like this::

      {'pkg': {'apache': 'httpd'}}

    To retrieve the value associated with the apache key in the pkg dict this
    key can be passed::

      pkg:apache

    merge
      Specify whether or not the retrieved values should be recursively
      merged into the passed default.

      .. versionadded:: 2014.7.0

    delimiter
      Specify an alternate delimiter to use when traversing a nested dict

      .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

      salt '*' pillar.get pkg:apache
    '''
    if merge:
      ret = salt.utils.traverse_dict_and_list(__pillar__, key, {}, delimiter)
      if isinstance(ret, collections.Mapping) and \
                isinstance(default, collections.Mapping):
            return salt.utils.dictupdate.update(default, ret)

    return salt.utils.traverse_dict_and_list(__pillar__,
                                             key,
                                             default,
                                             delimiter)







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def items(*args):
    '''
    Calls the master for a fresh pillar and generates the pillar data on the
    fly

    Contrast with :py:func:`raw` which returns the pillar data that is
    currently loaded into the minion.

    CLI Example:

                                             default,
                                             delimiter)


def items(*args):
    '''
    Calls the master for a fresh pillar and generates the pillar data on the
    fly

    Contrast with :py:func:`raw` which returns the pillar data that is
    currently loaded into the minion.

    CLI Example:

    .. code-block:: bash

      salt '*' pillar.items
    '''
    # Preserve backwards compatibility
    if args:
      return item(*args)

    pillar = salt.pillar.get_pillar(
      __opts__,
      __grains__,
      __opts__['id'],
      __opts__['environment'])

    return pillar.compile_pillar()

# Allow pillar.data to also be used to return pillar data
data = items



页: [1]
查看完整版本: SaltStack源码分析之pillar模块