mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge branch '2019.2.1' into do_key_test
This commit is contained in:
commit
75ac7086c5
@ -5,6 +5,7 @@ Jinja loading utils to enable a more powerful backend for jinja templates
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import atexit
|
||||
import collections
|
||||
import logging
|
||||
import os.path
|
||||
@ -54,8 +55,18 @@ class SaltCacheLoader(BaseLoader):
|
||||
Templates are cached like regular salt states
|
||||
and only loaded once per loader instance.
|
||||
'''
|
||||
|
||||
_cached_client = None
|
||||
|
||||
@classmethod
|
||||
def shutdown(cls):
|
||||
if cls._cached_client is None:
|
||||
return
|
||||
cls._cached_client.destroy()
|
||||
cls._cached_client = None
|
||||
|
||||
def __init__(self, opts, saltenv='base', encoding='utf-8',
|
||||
pillar_rend=False):
|
||||
pillar_rend=False, _file_client=None):
|
||||
self.opts = opts
|
||||
self.saltenv = saltenv
|
||||
self.encoding = encoding
|
||||
@ -69,7 +80,7 @@ class SaltCacheLoader(BaseLoader):
|
||||
self.searchpath = [os.path.join(opts['cachedir'], 'files', saltenv)]
|
||||
log.debug('Jinja search path: %s', self.searchpath)
|
||||
self.cached = []
|
||||
self._file_client = None
|
||||
self._file_client = _file_client
|
||||
# Instantiate the fileclient
|
||||
self.file_client()
|
||||
|
||||
@ -77,9 +88,14 @@ class SaltCacheLoader(BaseLoader):
|
||||
'''
|
||||
Return a file client. Instantiates on first call.
|
||||
'''
|
||||
if not self._file_client:
|
||||
self._file_client = salt.fileclient.get_file_client(
|
||||
self.opts, self.pillar_rend)
|
||||
# If there was no file_client passed to the class, create a cache_client
|
||||
# and use that. This avoids opening a new file_client every time this
|
||||
# class is instantiated
|
||||
if self._file_client is None:
|
||||
if not SaltCacheLoader._cached_client:
|
||||
SaltCacheLoader._cached_client = salt.fileclient.get_file_client(
|
||||
self.opts, self.pillar_rend)
|
||||
self._file_client = SaltCacheLoader._cached_client
|
||||
return self._file_client
|
||||
|
||||
def cache_file(self, template):
|
||||
@ -171,6 +187,9 @@ class SaltCacheLoader(BaseLoader):
|
||||
raise TemplateNotFound(template)
|
||||
|
||||
|
||||
atexit.register(SaltCacheLoader.shutdown)
|
||||
|
||||
|
||||
class PrintableDict(OrderedDict):
|
||||
'''
|
||||
Ensures that dict str() and repr() are YAML friendly.
|
||||
|
Loading…
Reference in New Issue
Block a user