예제 #1
0
 def test_topfile_order(self, Matcher, get_file_client):
     opts = {
         'renderer': 'yaml',
         'state_top': '',
         'pillar_roots': [],
         'extension_modules': '',
         'environment': 'base',
         'file_roots': [],
     }
     grains = {
         'os': 'Ubuntu',
         'os_family': 'Debian',
         'oscodename': 'raring',
         'osfullname': 'Ubuntu',
         'osrelease': '13.04',
         'kernel': 'Linux'
     }
     # glob match takes precedence
     self._setup_test_topfile_mocks(Matcher, get_file_client, 1, 2)
     pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'base')
     self.assertEqual(pillar.compile_pillar()['ssh'], 'bar')
     # nodegroup match takes precedence
     self._setup_test_topfile_mocks(Matcher, get_file_client, 2, 1)
     pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'base')
     self.assertEqual(pillar.compile_pillar()['ssh'], 'foo')
예제 #2
0
파일: pillar_test.py 프로젝트: mahak/salt
 def test_pillar_multiple_matches(self, Matcher, get_file_client):
     # Uses the ``recurse_list`` strategy.
     opts = {
         'renderer': 'yaml',
         'state_top': '',
         'pillar_roots': [],
         'extension_modules': '',
         'environment': 'base',
         'file_roots': [],
         'pillar_source_merging_strategy': 'recurse_list',
     }
     grains = {
         'os': 'Ubuntu',
         'os_family': 'Debian',
         'oscodename': 'raring',
         'osfullname': 'Ubuntu',
         'osrelease': '13.04',
         'kernel': 'Linux'
     }
     self._setup_test_topfile_mocks(Matcher, get_file_client, 1, 2)
     pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'base')
     # Pillars should be merged, but only once per pillar file.
     self.assertDictEqual(pillar.compile_pillar()['generic'], {
         'key1': ['value1', 'value2', 'value3'],
         'key2': {
             'sub_key1': [],
             'sub_key2': [],
         }
     })
예제 #3
0
파일: pillar.py 프로젝트: herlo/salt
def data(key=None):
    '''
    Returns the pillar derived from the configured pillar source. The pillar
    source is derived from the file_client option in the minion config

    CLI Example::

        salt '*' pillar.data

    With the optional key argument, you can select a subtree of the
    pillar data.::

        salt '*' pillar.data key='roles'
    '''
    pillar = salt.pillar.get_pillar(
        __opts__,
        __grains__,
        __opts__['id'],
        __opts__['environment'])

    ret = pillar.compile_pillar()

    if key:
        ret = ret.get(key, {})

    return ret
예제 #4
0
파일: pillar.py 프로젝트: iquaba/salt
def items(*args, **kwargs):
    '''
    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.

    pillar : none
        if specified, allows for a dictionary of pillar data to be made
        available to pillar and ext_pillar rendering. these pillar variables
        will also override any variables of the same name in pillar or
        ext_pillar.

        .. versionadded:: 2015.5.0

    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'],
        pillar=kwargs.get('pillar'))

    return pillar.compile_pillar()
예제 #5
0
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()
예제 #6
0
파일: masterapi.py 프로젝트: penta-srl/salt
 def _pillar(self, load):
     '''
     Return the pillar data for the minion
     '''
     if any(key not in load for key in ('id', 'grains')):
         return False
     pillar = salt.pillar.Pillar(
             self.opts,
             load['grains'],
             load['id'],
             load.get('saltenv', load.get('env')),
             load.get('ext'),
             self.mminion.functions)
     data = pillar.compile_pillar()
     if self.opts.get('minion_data_cache', False):
         cdir = os.path.join(self.opts['cachedir'], 'minions', load['id'])
         if not os.path.isdir(cdir):
             os.makedirs(cdir)
         datap = os.path.join(cdir, 'data.p')
         with salt.utils.fopen(datap, 'w+') as fp_:
             fp_.write(
                     self.serial.dumps(
                         {'grains': load['grains'],
                          'pillar': data})
                         )
     return data
예제 #7
0
파일: pillar.py 프로젝트: 11craft/salt
def data(key=''):
    '''
    Returns the pillar derived from the configured pillar source. The pillar
    source is derived from the file_client option in the minion config

    CLI Example::

        salt '*' pillar.data

    With the optional key argument, you can select a subtree of the
    pillar data.::

        salt '*' pillar.data key='roles'
    '''
    pillar = salt.pillar.get_pillar(
            __opts__,
            __grains__,
            __opts__['id'],
            __opts__['environment'])

    compiled_pillar = pillar.compile_pillar()

    if key:
        try:
            ret = compiled_pillar[key]
        except KeyError:
            ret = {}
    else:
        ret = compiled_pillar

    return ret
예제 #8
0
def show_pillar(minion='*', **kwargs):
    '''
    Returns the compiled pillar either of a specific minion
    or just the global available pillars. I assume that no minion
    is using the id ``*``.

    CLI Example:

    shows minion specific pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar 'www.example.com'

    shows global pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar

    shows global pillar for 'dev' pillar environment:

    .. code-block:: bash

        salt-run pillar.show_pillar 'saltenv=dev'

    API Example:

    .. code-block:: python

        import salt.config
        import salt.runner
        opts = salt.config.master_config('/etc/salt/master')
        runner = salt.runner.RunnerClient(opts)
        pillar = runner.cmd('pillar.show_pillar', [])
        print pillar¬
    '''

    saltenv = 'base'
    id_, grains, _ = salt.utils.minions.get_minion_data(minion, __opts__)
    if grains is None:
        grains = {'fqdn': minion}

    for key in kwargs:
        if key == 'saltenv':
            saltenv = kwargs[key]
        else:
            grains[key] = kwargs[key]

    pillar = salt.pillar.Pillar(
        __opts__,
        grains,
        id_,
        saltenv)

    compiled_pillar = pillar.compile_pillar()
    salt.output.display_output(compiled_pillar, 'nested', __opts__)
    return compiled_pillar
예제 #9
0
파일: pillar.py 프로젝트: LinuxJedi/salt
def data():
    '''
    Returns the pillar derived from the configured pillar source. The pillar
    source is derived from the file_client option in the minion config

    CLI Example::

        salt '*' pillar.data
    '''
    pillar = salt.pillar.get_pillar(__opts__, __grains__, __opts__['id'])
    return pillar.compile_pillar()
예제 #10
0
def data():
    """
    Returns the pillar derived from the configured pillar source. The pillar
    source is derived from the file_client option in the minion config

    CLI Example::

        salt '*' pillar.data
    """
    pillar = salt.pillar.get_pillar(__opts__, __grains__, __opts__["id"], __opts__["environment"])
    return pillar.compile_pillar()
예제 #11
0
파일: master.py 프로젝트: cmek/salt
 def _pillar(self, load):
     '''
     Return the pillar data for the minion
     '''
     if 'id' not in load or 'grains' not in load or 'env' not in load:
         return False
     pillar = salt.pillar.Pillar(
             self.opts,
             load['grains'],
             load['id'],
             load['env'])
     return pillar.compile_pillar()
예제 #12
0
파일: master.py 프로젝트: willmurnane/salt
 def _get_live_minion_pillar(self, minion_id=None, minion_grains=None):
     # Returns a dict of pillar data for one minion
     if minion_id is None:
         return {}
     if not minion_grains:
         log.warning(
             'Cannot get pillar data for {0}: no grains supplied.'.format(
                 minion_id))
         return {}
     log.debug('Getting live pillar for {0}'.format(minion_id))
     pillar = salt.pillar.Pillar(self.opts, minion_grains, minion_id,
                                 self.saltenv, self.opts['ext_pillar'])
     log.debug('Compiling pillar for {0}'.format(minion_id))
     ret = pillar.compile_pillar()
     return ret
예제 #13
0
파일: pillar.py 프로젝트: jaypei/salt
def ext(external):
    """
    Generate the pillar and apply an explicit external pillar

    CLI Example::

        salt '*' pillar.ext 'libvirt: _'
    """
    if isinstance(external, basestring):
        external = yaml.load(external)
    pillar = salt.pillar.get_pillar(__opts__, __grains__, __opts__["id"], __opts__["environment"], external)

    ret = pillar.compile_pillar()

    return ret
예제 #14
0
 def test_include(self, tempdir):
     opts = {
         'optimization_order': [0, 1, 2],
         'renderer': 'yaml',
         'renderer_blacklist': [],
         'renderer_whitelist': [],
         'state_top': '',
         'pillar_roots': [],
         'extension_modules': '',
         'saltenv': 'base',
         'file_roots': [],
     }
     grains = {
         'os': 'Ubuntu',
         'os_family': 'Debian',
         'oscodename': 'raring',
         'osfullname': 'Ubuntu',
         'osrelease': '13.04',
         'kernel': 'Linux',
     }
     sls_files = self._setup_test_include_sls(tempdir)
     fc_mock = MockFileclient(
         cache_file=sls_files['top']['dest'],
         get_state=sls_files,
         list_states=[
             'top',
             'test.init',
             'test.sub1',
             'test.sub2',
             'test.sub_wildcard_1',
             'test.sub_with_init_dot',
             'test.sub.with.slashes',
         ],
     )
     with patch.object(salt.fileclient, 'get_file_client',
                       MagicMock(return_value=fc_mock)):
         pillar = salt.pillar.Pillar(opts, grains, 'minion', 'base')
         # Make sure that confirm_top.confirm_top returns True
         pillar.matchers['confirm_top.confirm_top'] = lambda *x, **y: True
         compiled_pillar = pillar.compile_pillar()
         self.assertEqual(compiled_pillar['foo_wildcard'], 'bar_wildcard')
         self.assertEqual(compiled_pillar['foo1'], 'bar1')
         self.assertEqual(compiled_pillar['foo2'], 'bar2')
         self.assertEqual(compiled_pillar['sub_with_slashes'],
                          'sub_slashes_worked')
         self.assertEqual(compiled_pillar['sub_init_dot'],
                          'sub_with_init_dot_worked')
예제 #15
0
 def test_include(self, tempdir):
     opts = {
         "optimization_order": [0, 1, 2],
         "renderer": "yaml",
         "renderer_blacklist": [],
         "renderer_whitelist": [],
         "state_top": "",
         "pillar_roots": [],
         "extension_modules": "",
         "saltenv": "base",
         "file_roots": [],
     }
     grains = {
         "os": "Ubuntu",
         "os_family": "Debian",
         "oscodename": "raring",
         "osfullname": "Ubuntu",
         "osrelease": "13.04",
         "kernel": "Linux",
     }
     sls_files = self._setup_test_include_sls(tempdir)
     fc_mock = MockFileclient(
         cache_file=sls_files["top"]["dest"],
         get_state=sls_files,
         list_states=[
             "top",
             "test.init",
             "test.sub1",
             "test.sub2",
             "test.sub_wildcard_1",
             "test.sub_with_init_dot",
             "test.sub.with.slashes",
         ],
     )
     with patch.object(salt.fileclient, "get_file_client",
                       MagicMock(return_value=fc_mock)):
         pillar = salt.pillar.Pillar(opts, grains, "minion", "base")
         # Make sure that confirm_top.confirm_top returns True
         pillar.matchers["confirm_top.confirm_top"] = lambda *x, **y: True
         compiled_pillar = pillar.compile_pillar()
         self.assertEqual(compiled_pillar["foo_wildcard"], "bar_wildcard")
         self.assertEqual(compiled_pillar["foo1"], "bar1")
         self.assertEqual(compiled_pillar["foo2"], "bar2")
         self.assertEqual(compiled_pillar["sub_with_slashes"],
                          "sub_slashes_worked")
         self.assertEqual(compiled_pillar["sub_init_dot"],
                          "sub_with_init_dot_worked")
예제 #16
0
파일: master.py 프로젝트: jslatts/salt
 def _get_live_minion_pillar(self, minion_id=None, minion_grains=None):
     # Returns a dict of pillar data for one minion
     if minion_id == None:
         return {}
     if not minion_grains:
         log.warn('Cannot get pillar data for {0}: no grains supplied.'.format(minion_id))
         return {}
     log.debug('Getting live pillar for {0}'.format(minion_id))
     pillar = salt.pillar.Pillar(
                         self.opts,
                         minion_grains,
                         minion_id,
                         self.env,
                         self.opts['ext_pillar'])
     log.debug('Compiling pillar for {0}'.format(minion_id))
     ret = pillar.compile_pillar()
     return ret
예제 #17
0
    def test_ext_pillar_first(self):
        '''
        test when using ext_pillar and ext_pillar_first
        '''
        opts = {
            'optimization_order': [0, 1, 2],
            'renderer': 'yaml',
            'renderer_blacklist': [],
            'renderer_whitelist': [],
            'state_top': '',
            'pillar_roots': [],
            'extension_modules': '',
            'saltenv': 'base',
            'file_roots': [],
            'ext_pillar_first': True,
        }
        grains = {
            'os': 'Ubuntu',
            'os_family': 'Debian',
            'oscodename': 'raring',
            'osfullname': 'Ubuntu',
            'osrelease': '13.04',
            'kernel': 'Linux'
        }

        tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
        try:
            sls_files = self._setup_test_topfile_sls_pillar_match(tempdir, )
            fc_mock = MockFileclient(cache_file=sls_files['top']['dest'],
                                     list_states=[
                                         'top', 'ssh', 'ssh.minion', 'generic',
                                         'generic.minion'
                                     ],
                                     get_state=sls_files)
            with patch.object(salt.fileclient, 'get_file_client',
                              MagicMock(return_value=fc_mock)), \
                    patch('salt.pillar.Pillar.ext_pillar',
                          MagicMock(return_value=({'id': 'minion',
                                                  'phase': 'alpha', 'role':
                                                  'database'}, []))):
                pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion',
                                            'base')
                self.assertEqual(pillar.compile_pillar()['generic']['key1'],
                                 'value1')
        finally:
            shutil.rmtree(tempdir, ignore_errors=True)
예제 #18
0
파일: pillar.py 프로젝트: ckraemer/salt
def ext(external):
    """
    Generate the pillar and apply an explicit external pillar

    CLI Example:

    .. code-block:: bash

        salt '*' pillar.ext '{libvirt: _}'
    """
    if isinstance(external, string_types):
        external = yaml.safe_load(external)
    pillar = salt.pillar.get_pillar(__opts__, __grains__, __opts__["id"], __opts__["environment"], external)

    ret = pillar.compile_pillar()

    return ret
예제 #19
0
파일: pillar.py 프로젝트: jaypei/salt
def items(*args):
    """
    This function calls the master for a fresh pillar and generates the pillar
    data on the fly, unlike pillar.raw which returns the pillar data which
    is currently loaded into the minion.

    CLI Example::

        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()
예제 #20
0
파일: pillar.py 프로젝트: yanghao-zh/salt
def ext(external):
    '''
    Generate the pillar and apply an explicit external pillar

    CLI Example:

    .. code-block:: bash

        salt '*' pillar.ext 'libvirt: _'
    '''
    if isinstance(external, basestring):
        external = yaml.safe_load(external)
    pillar = salt.pillar.get_pillar(__opts__, __grains__, __opts__['id'],
                                    __opts__['environment'], external)

    ret = pillar.compile_pillar()

    return ret
예제 #21
0
def items(*args, **kwargs):
    '''
    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.

    pillar
        if specified, allows for a dictionary of pillar data to be made
        available to pillar and ext_pillar rendering. these pillar variables
        will also override any variables of the same name in pillar or
        ext_pillar.

        .. versionadded:: 2015.5.0

    pillarenv
        Pass a specific pillar environment from which to compile pillar data.
        If not specified, then the minion's :conf_minion:`pillarenv` option is
        not used, and if that also is not specified then all configured pillar
        environments will be merged into a single pillar dictionary and
        returned.

        .. versionadded:: 2016.11.2

    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'],
                                    pillar=kwargs.get('pillar'),
                                    pillarenv=kwargs.get('pillarenv')
                                    or __opts__['pillarenv'])

    return pillar.compile_pillar()
예제 #22
0
파일: comm.py 프로젝트: toby82/shell
def get_pillar(__opts__, minion='*', **kwargs):
    saltenv = 'base'
    id_, grains, _ = salt.utils.minions.get_minion_data(minion, __opts__)
    if grains is None:
        grains = {'fqdn': minion}

    for key in kwargs:
        if key == 'saltenv':
            saltenv = kwargs[key]
        else:
            grains[key] = kwargs[key]

    pillar = salt.pillar.Pillar(
        __opts__,
        grains,
        id_,
        saltenv)
    compiled_pillar = pillar.compile_pillar()
    return compiled_pillar 
예제 #23
0
 def _run_test(nodegroup_order, glob_order, expected):
     tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
     try:
         sls_files = self._setup_test_topfile_sls(
             tempdir,
             nodegroup_order,
             glob_order)
         fc_mock = MockFileclient(
             cache_file=sls_files['top']['dest'],
             list_states=['top', 'ssh', 'ssh.minion',
                          'generic', 'generic.minion'],
             get_state=sls_files)
         with patch.object(salt.fileclient, 'get_file_client',
                           MagicMock(return_value=fc_mock)):
             pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'base')
             # Make sure that confirm_top.confirm_top returns True
             pillar.matchers['confirm_top.confirm_top'] = lambda *x, **y: True
             self.assertEqual(pillar.compile_pillar()['ssh'], expected)
     finally:
         shutil.rmtree(tempdir, ignore_errors=True)
예제 #24
0
파일: pillar.py 프로젝트: yanghao-zh/salt
def items(*args):
    '''
    This function calls the master for a fresh pillar and generates the pillar
    data on the fly, unlike pillar.raw which returns the pillar data which
    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()
예제 #25
0
파일: master.py 프로젝트: kuene/salt
 def _pillar(self, load):
     '''
     Return the pillar data for the minion
     '''
     if 'id' not in load or 'grains' not in load or 'env' not in load:
         return False
     pillar = salt.pillar.Pillar(self.opts, load['grains'], load['id'],
                                 load['env'])
     data = pillar.compile_pillar()
     if self.opts.get('minion_data_cache', False):
         cdir = os.path.join(self.opts['cachedir'], 'minions', load['id'])
         if not os.path.isdir(cdir):
             os.makedirs(cdir)
         datap = os.path.join(cdir, 'data.p')
         with open(datap, 'w+') as fp_:
             fp_.write(
                 self.serial.dumps({
                     'grains': load['grains'],
                     'pillar': data
                 }))
     return data
예제 #26
0
파일: pillar.py 프로젝트: penta-srl/salt
def ext(external):
    '''
    Generate the pillar and apply an explicit external pillar

    CLI Example:

    .. code-block:: bash

        salt '*' pillar.ext '{libvirt: _}'
    '''
    if isinstance(external, basestring):
        external = yaml.safe_load(external)
    pillar = salt.pillar.get_pillar(
        __opts__,
        __grains__,
        __opts__['id'],
        __opts__['environment'],
        external)

    ret = pillar.compile_pillar()

    return ret
예제 #27
0
    def test_pillar_send_extra_minion_data_from_config(self):
        opts = {
            "renderer": "json",
            "pillarenv": "fake_pillar_env",
            "path_to_add": "fake_data",
            "path_to_add2": {
                "fake_data5": "fake_data6",
                "fake_data2": ["fake_data3", "fake_data4"],
            },
            "pass_to_ext_pillars": ["path_to_add"],
        }
        mock_channel = MagicMock(crypted_transfer_decode_dictentry=MagicMock(
            return_value={}))
        with patch(
                "salt.transport.client.ReqChannel.factory",
                MagicMock(return_value=mock_channel),
        ):
            pillar = salt.pillar.RemotePillar(opts, self.grains,
                                              "mocked_minion", "fake_env")

        ret = pillar.compile_pillar()
        self.assertEqual(pillar.channel, mock_channel)
        mock_channel.crypted_transfer_decode_dictentry.assert_called_once_with(
            {
                "cmd": "_pillar",
                "ver": "2",
                "id": "mocked_minion",
                "grains": {},
                "saltenv": "fake_env",
                "pillarenv": "fake_pillar_env",
                "pillar_override": {},
                "extra_minion_data": {
                    "path_to_add": "fake_data"
                },
            },
            dictkey="pillar",
        )
예제 #28
0
파일: master.py 프로젝트: abh/salt
 def _pillar(self, load):
     '''
     Return the pillar data for the minion
     '''
     if 'id' not in load or 'grains' not in load or 'env' not in load:
         return False
     pillar = salt.pillar.Pillar(
             self.opts,
             load['grains'],
             load['id'],
             load['env'])
     data = pillar.compile_pillar()
     if self.opts.get('minion_data_cache', False):
         cdir = os.path.join(self.opts['cachedir'], 'minions', load['id'])
         if not os.path.isdir(cdir):
             os.makedirs(cdir)
         datap = os.path.join(cdir, 'data.p')
         with open(datap, 'w+') as fp_:
             fp_.write(
                     self.serial.dumps(
                         {'grains': load['grains'],
                          'pillar': data})
                         )
     return data
예제 #29
0
def items(*args, **kwargs):
    '''
    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.

    pillar
        If specified, allows for a dictionary of pillar data to be made
        available to pillar and ext_pillar rendering. these pillar variables
        will also override any variables of the same name in pillar or
        ext_pillar.

        .. versionadded:: 2015.5.0

    pillar_enc
        If specified, the data passed in the ``pillar`` argument will be passed
        through this renderer to decrypt it.

        .. note::
            This will decrypt on the minion side, so the specified renderer
            must be set up on the minion for this to work. Alternatively,
            pillar data can be decrypted master-side. For more information, see
            the :ref:`Pillar Encryption <pillar-encryption>` documentation.
            Pillar data that is decrypted master-side, is not decrypted until
            the end of pillar compilation though, so minion-side decryption
            will be necessary if the encrypted pillar data must be made
            available in an decrypted state pillar/ext_pillar rendering.

        .. versionadded:: 2017.7.0

    pillarenv
        Pass a specific pillar environment from which to compile pillar data.
        If not specified, then the minion's :conf_minion:`pillarenv` option is
        not used, and if that also is not specified then all configured pillar
        environments will be merged into a single pillar dictionary and
        returned.

        .. versionadded:: 2016.11.2

    saltenv
        Included only for compatibility with
        :conf_minion:`pillarenv_from_saltenv`, and is otherwise ignored.

    CLI Example:

    .. code-block:: bash

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

    pillarenv = kwargs.get('pillarenv')
    if pillarenv is None:
        if __opts__.get('pillarenv_from_saltenv', False):
            pillarenv = kwargs.get('saltenv') or __opts__['environment']
        else:
            pillarenv = __opts__['pillarenv']

    pillar_override = kwargs.get('pillar')
    pillar_enc = kwargs.get('pillar_enc')

    if pillar_override and pillar_enc:
        try:
            pillar_override = salt.utils.crypt.decrypt(
                pillar_override,
                pillar_enc,
                translate_newlines=True,
                opts=__opts__,
                valid_rend=__opts__['decrypt_pillar_renderers'])
        except Exception as exc:
            raise CommandExecutionError(
                'Failed to decrypt pillar override: {0}'.format(exc))

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

    return pillar.compile_pillar()
예제 #30
0
def show_pillar(minion='*', **kwargs):
    '''
    Returns the compiled pillar either of a specific minion
    or just the global available pillars. This function assumes
    that no minion has the id ``*``.
    Function also accepts pillarenv as attribute in order to limit to a specific pillar branch of git

    CLI Example:

    shows minion specific pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar 'www.example.com'

    shows global pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar

    shows global pillar for 'dev' pillar environment:
    (note that not specifying pillarenv will merge all pillar environments
    using the master config option pillar_source_merging_strategy.)

    .. code-block:: bash

        salt-run pillar.show_pillar 'pillarenv=dev'

    shows global pillar for 'dev' pillar environment and specific pillarenv = dev:

    .. code-block:: bash

        salt-run pillar.show_pillar 'saltenv=dev' 'pillarenv=dev'

    API Example:

    .. code-block:: python

        import salt.config
        import salt.runner
        opts = salt.config.master_config('/etc/salt/master')
        runner = salt.runner.RunnerClient(opts)
        pillar = runner.cmd('pillar.show_pillar', [])
        print(pillar)
    '''
    pillarenv = None
    saltenv = 'base'
    id_, grains, _ = salt.utils.minions.get_minion_data(minion, __opts__)
    if grains is None:
        grains = {'fqdn': minion}

    for key in kwargs:
        if key == 'saltenv':
            saltenv = kwargs[key]
        elif key == 'pillarenv':
            # pillarenv overridden on CLI
            pillarenv = kwargs[key]
        else:
            grains[key] = kwargs[key]

    pillar = salt.pillar.Pillar(
        __opts__,
        grains,
        id_,
        saltenv,
        pillarenv=pillarenv)

    compiled_pillar = pillar.compile_pillar()

    # needed because pillar compilation clobbers grains etc via lazyLoader
    # this resets the masterminion back to known state
    __salt__['salt.cmd']('sys.reload_modules')

    return compiled_pillar
예제 #31
0
def show_pillar(minion="*", **kwargs):
    """
    Returns the compiled pillar either of a specific minion
    or just the global available pillars. This function assumes
    that no minion has the id ``*``.
    Function also accepts pillarenv as attribute in order to limit to a specific pillar branch of git

    CLI Example:

    shows minion specific pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar 'www.example.com'

    shows global pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar

    shows global pillar for 'dev' pillar environment:
    (note that not specifying pillarenv will merge all pillar environments
    using the master config option pillar_source_merging_strategy.)

    .. code-block:: bash

        salt-run pillar.show_pillar 'pillarenv=dev'

    shows global pillar for 'dev' pillar environment and specific pillarenv = dev:

    .. code-block:: bash

        salt-run pillar.show_pillar 'saltenv=dev' 'pillarenv=dev'

    API Example:

    .. code-block:: python

        import salt.config
        import salt.runner
        opts = salt.config.master_config('/etc/salt/master')
        runner = salt.runner.RunnerClient(opts)
        pillar = runner.cmd('pillar.show_pillar', [])
        print(pillar)
    """
    pillarenv = None
    saltenv = "base"
    id_, grains, _ = salt.utils.minions.get_minion_data(minion, __opts__)
    if grains is None:
        grains = {"fqdn": minion}

    for key in kwargs:
        if key == "saltenv":
            saltenv = kwargs[key]
        elif key == "pillarenv":
            # pillarenv overridden on CLI
            pillarenv = kwargs[key]
        else:
            grains[key] = kwargs[key]

    pillar = salt.pillar.Pillar(__opts__,
                                grains,
                                id_,
                                saltenv,
                                pillarenv=pillarenv)

    compiled_pillar = pillar.compile_pillar()
    return compiled_pillar
예제 #32
0
    def test_referencing_preceding_pillars(self):
        '''
        Pillars, that come first in the top file can be referenced from
        the subsequent pillars.
        '''
        opts = {
            'renderer': 'py',
            'renderer_blacklist': [],
            'renderer_whitelist': [],
            'state_top': '',
            'pillar_roots': [],
            'file_roots': {},
            'extension_modules': ''
        }
        grains = {
            'os': 'Ubuntu',
            'os_family': 'Debian',
            'oscodename': 'raring',
            'osfullname': 'Ubuntu',
            'osrelease': '13.04',
            'kernel': 'Linux'
        }
        pillar = salt.pillar.Pillar(opts, grains, 'mocked-minion', 'base')
        top = tempfile.NamedTemporaryFile()
        top.write(b'''#!yaml

base:
    '*':
        - foo
        - bar
''')
        top.flush()
        foo = tempfile.NamedTemporaryFile()
        foo.write(b'''#!py

def run():
    return {'foo': {'spam': 'eggs'}}
''')
        foo.flush()
        bar = tempfile.NamedTemporaryFile()
        bar.write(b'''#!py

def run():
    return {
        'bar': {
            'bacon': __pillar__.get('foo', {}).get('spam', 'cheddar'),
            'sausage': __salt__['pillar.get']('foo:spam', 'cheddar')
        }
    }
''')
        bar.flush()

        def get_state(sls, env):
            return {
                'foo': {
                    'path': '',
                    'dest': foo.name
                },
                'bar': {
                    'path': '',
                    'dest': bar.name
                }
            }[sls]

        pillar.client = MagicMock(
            **{
                'get_state.side_effect': get_state,
                'cache_file.return_value': top.name
            })
        pillar.matcher = MagicMock()
        pillar.matcher.confirm_top.return_value = True
        actual_pillar_data = pillar.compile_pillar()
        expected_pillar_data = {
            'foo': {
                'spam': 'eggs'
            },
            'bar': {
                'bacon': 'eggs',
                'sausage': 'eggs'
            }
        }
        self.assertEqual(actual_pillar_data, expected_pillar_data)
예제 #33
0
    def test_relative_include(self, tempdir):
        join = os.path.join
        with fopen(join(tempdir, 'top.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    base:
                      '*':
                        - includer
                        - simple_includer
                        - includes.with.more.depth
                '''),
                file=f,
            )
        includer_dir = join(tempdir, 'includer')
        os.makedirs(includer_dir)
        with fopen(join(includer_dir, 'init.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    include:
                      - .this
                      - includer.that
                '''),
                file=f,
            )
        with fopen(join(includer_dir, 'this.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    this:
                        is all good
                '''),
                file=f,
            )
        with fopen(join(includer_dir, 'that.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    that:
                        is also all good
                '''),
                file=f,
            )

        with fopen(join(tempdir, 'simple_includer.sls'),
                   'w') as simpleincluder:
            print(
                textwrap.dedent('''
                    include:
                      - .simple
                      - super_simple
                '''),
                file=simpleincluder,
            )
        with fopen(join(tempdir, 'simple.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    simple:
                      simon
                '''),
                file=f,
            )
        with fopen(join(tempdir, 'super_simple.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    super simple:
                      a caveman
                '''),
                file=f,
            )

        depth_dir = join(tempdir, 'includes', 'with', 'more')
        os.makedirs(depth_dir)
        with fopen(join(depth_dir, 'depth.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    include:
                      - .ramble
                      - includes.with.more.doors

                    mordor:
                        has dark depths
                '''),
                file=f,
            )

        with fopen(join(depth_dir, 'ramble.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    found:
                        my precious
                '''),
                file=f,
            )

        with fopen(join(depth_dir, 'doors.sls'), 'w') as f:
            print(
                textwrap.dedent('''
                    mojo:
                        bad risin'
                '''),
                file=f,
            )
        opts = {
            'optimization_order': [0, 1, 2],
            'renderer': 'yaml',
            'renderer_blacklist': [],
            'renderer_whitelist': [],
            'state_top': 'top.sls',
            'pillar_roots': {
                'base': [tempdir]
            },
            'extension_modules': '',
            'saltenv': 'base',
            'file_roots': [],
            'file_ignore_regex': None,
            'file_ignore_glob': None,
        }
        grains = {
            'os': 'Ubuntu',
            'os_family': 'Debian',
            'oscodename': 'raring',
            'osfullname': 'Ubuntu',
            'osrelease': '13.04',
            'kernel': 'Linux',
        }
        pillar = salt.pillar.Pillar(opts, grains, 'minion', 'base')
        # Make sure that confirm_top.confirm_top returns True
        pillar.matchers['confirm_top.confirm_top'] = lambda *x, **y: True

        # Act
        compiled_pillar = pillar.compile_pillar()

        # Assert
        self.assertEqual(compiled_pillar['this'], 'is all good')
        self.assertEqual(compiled_pillar['that'], 'is also all good')
        self.assertEqual(compiled_pillar['simple'], 'simon')
        self.assertEqual(compiled_pillar['super simple'], 'a caveman')
        self.assertEqual(compiled_pillar['mordor'], 'has dark depths')
        self.assertEqual(compiled_pillar['found'], 'my precious')
        self.assertEqual(compiled_pillar['mojo'], "bad risin'")
예제 #34
0
    # Enable logging
    log = logging.getLogger(__name__)

    BASE_DIR = os.getcwd()

    # Set salt pillar, grains and opts settings so they can be applied to modules
    __opts__ = salt.config.minion_config('/etc/salt/minion')
    __opts__['grains'] = salt.loader.grains(__opts__)
    pillar = salt.pillar.get_pillar(
        __opts__,
        __opts__['grains'],
        __opts__['id'],
        __opts__['environment'],
    )
    __opts__['pillar'] = pillar.compile_pillar()
    __salt__ = salt.loader.minion_mods(__opts__)
    __grains__ = __opts__['grains']
    __pillar__ = __opts__['pillar']
    __context__ = {}

    salt.modules.saltutil.__opts__ =  __opts__
    salt.modules.saltutil.__grains__ =  __grains__
    salt.modules.saltutil.__pillar__ =  __pillar__
    salt.modules.saltutil.__salt__ =  __salt__
    salt.modules.saltutil.__context__ =  __context__

from salt.scripts import salt_call

def _bind(form, saltenv=None, umount=False):
    '''
예제 #35
0
def show_pillar(minion='*', **kwargs):
    '''
    Returns the compiled pillar either of a specific minion
    or just the global available pillars. This function assumes
    that no minion has the id ``*``.

    CLI Example:

    shows minion specific pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar 'www.example.com'

    shows global pillar:

    .. code-block:: bash

        salt-run pillar.show_pillar

    shows global pillar for 'dev' pillar environment:
    (note that not specifying pillarenv will merge all pillar environments
    using the master config option pillar_source_merging_strategy.)

    .. code-block:: bash

        salt-run pillar.show_pillar 'pillarenv=dev'

    API Example:

    .. code-block:: python

        import salt.config
        import salt.runner
        opts = salt.config.master_config('/etc/salt/master')
        runner = salt.runner.RunnerClient(opts)
        pillar = runner.cmd('pillar.show_pillar', [])
        print(pillar)
    '''

    saltenv = 'base'
    pillarenv = __opts__['pillarenv'] if 'pillarenv' in __opts__ else None
    id_, grains, _ = salt.utils.minions.get_minion_data(minion, __opts__)
    if grains is None:
        grains = {'fqdn': minion}

    for key in kwargs:
        if key == 'saltenv':
            saltenv = kwargs[key]
        elif key == 'pillarenv':
            pillarenv = kwargs[key]
        else:
            grains[key] = kwargs[key]

    pillar = salt.pillar.Pillar(
        __opts__,
        grains,
        id_,
        saltenv,
        pillarenv=pillarenv)

    compiled_pillar = pillar.compile_pillar()
    return compiled_pillar