"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/pillar/file_tree.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

file_tree.py  (salt-3002.1):file_tree.py  (salt-3002.2)
# -*- coding: utf-8 -*-
""" """
The ``file_tree`` external pillar allows values from all files in a directory The ``file_tree`` external pillar allows values from all files in a directory
tree to be imported as Pillar data. tree to be imported as Pillar data.
.. note:: .. note::
This is an external pillar and is subject to the :ref:`rules and This is an external pillar and is subject to the :ref:`rules and
constraints <external-pillars>` governing external pillars. constraints <external-pillars>` governing external pillars.
.. versionadded:: 2015.5.0 .. versionadded:: 2015.5.0
skipping to change at line 145 skipping to change at line 144
// This is the main settings file for the corporate // This is the main settings file for the corporate
// internal web app // internal web app
main_setting: probably main_setting: probably
bob_settings: bob_settings:
role: bob role: bob
.. note:: .. note::
The leaf data in the example shown is the contents of the pillar files. The leaf data in the example shown is the contents of the pillar files.
""" """
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import fnmatch import fnmatch
import logging import logging
import os import os
# Import salt libs
import salt.loader import salt.loader
import salt.template import salt.template
import salt.utils.dictupdate import salt.utils.dictupdate
import salt.utils.files import salt.utils.files
import salt.utils.minions import salt.utils.minions
import salt.utils.path import salt.utils.path
import salt.utils.stringio import salt.utils.stringio
import salt.utils.stringutils import salt.utils.stringutils
from salt.ext import six
# Set up logging # Set up logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def _on_walk_error(err): def _on_walk_error(err):
""" """
Log salt.utils.path.os_walk() error. Log salt.utils.path.os_walk() error.
""" """
log.error("%s: %s", err.filename, err.strerror) log.error("%s: %s", err.filename, err.strerror)
skipping to change at line 188 skipping to change at line 183
False, otherwise return True. False, otherwise return True.
""" """
if isinstance(keep_newline, bool): if isinstance(keep_newline, bool):
return not keep_newline return not keep_newline
full_path = os.path.join(prefix, file_name) full_path = os.path.join(prefix, file_name)
for pattern in keep_newline: for pattern in keep_newline:
try: try:
if fnmatch.fnmatch(full_path, pattern): if fnmatch.fnmatch(full_path, pattern):
return False return False
except TypeError: except TypeError:
if fnmatch.fnmatch(full_path, six.text_type(pattern)): if fnmatch.fnmatch(full_path, str(pattern)):
return False return False
return True return True
def _construct_pillar( def _construct_pillar(
top_dir, top_dir,
follow_dir_links, follow_dir_links,
keep_newline=False, keep_newline=False,
render_default=None, render_default=None,
renderer_blacklist=None, renderer_blacklist=None,
renderer_whitelist=None, renderer_whitelist=None,
skipping to change at line 246 skipping to change at line 241
try: try:
with salt.utils.files.fopen(file_path, "rb") as fhr: with salt.utils.files.fopen(file_path, "rb") as fhr:
buf = fhr.read(__opts__["file_buffer_size"]) buf = fhr.read(__opts__["file_buffer_size"])
while buf: while buf:
contents += buf contents += buf
buf = fhr.read(__opts__["file_buffer_size"]) buf = fhr.read(__opts__["file_buffer_size"])
if contents.endswith(b"\n") and _check_newline( if contents.endswith(b"\n") and _check_newline(
prefix, file_name, keep_newline prefix, file_name, keep_newline
): ):
contents = contents[:-1] contents = contents[:-1]
except (IOError, OSError) as exc: except OSError as exc:
log.error("file_tree: Error reading %s: %s", file_path, exc.stre rror) log.error("file_tree: Error reading %s: %s", file_path, exc.stre rror)
else: else:
data = contents data = contents
if template is True: if template is True:
data = salt.template.compile_template_str( data = salt.template.compile_template_str(
template=salt.utils.stringutils.to_unicode(contents), template=salt.utils.stringutils.to_unicode(contents),
renderers=renderers, renderers=renderers,
default=render_default, default=render_default,
blacklist=renderer_blacklist, blacklist=renderer_blacklist,
whitelist=renderer_whitelist, whitelist=renderer_whitelist,
skipping to change at line 497 skipping to change at line 492
ext_pillar_dirs = os.listdir(nodegroups_dir) ext_pillar_dirs = os.listdir(nodegroups_dir)
if len(ext_pillar_dirs) > 0: if len(ext_pillar_dirs) > 0:
for nodegroup in ext_pillar_dirs: for nodegroup in ext_pillar_dirs:
if os.path.isdir(nodegroups_dir) and nodegroup in master_ngroups : if os.path.isdir(nodegroups_dir) and nodegroup in master_ngroups :
ckminions = salt.utils.minions.CkMinions(__opts__) ckminions = salt.utils.minions.CkMinions(__opts__)
_res = ckminions.check_minions( _res = ckminions.check_minions(
master_ngroups[nodegroup], "compound" master_ngroups[nodegroup], "compound"
) )
match = _res["minions"] match = _res["minions"]
if minion_id in match: if minion_id in match:
ngroup_dir = os.path.join( ngroup_dir = os.path.join(nodegroups_dir, str(nodegroup)
nodegroups_dir, six.text_type(nodegroup) )
)
ngroup_pillar = salt.utils.dictupdate.merge( ngroup_pillar = salt.utils.dictupdate.merge(
ngroup_pillar, ngroup_pillar,
_construct_pillar( _construct_pillar(
ngroup_dir, ngroup_dir,
follow_dir_links, follow_dir_links,
keep_newline, keep_newline,
render_default, render_default,
renderer_blacklist, renderer_blacklist,
renderer_whitelist, renderer_whitelist,
template, template,
 End of changes. 8 change blocks. 
10 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)