Enable syncing proxymodules from the master. Proxymodules can go in /srv/salt/_proxy.

This commit is contained in:
C. R. Oldham 2015-10-06 21:48:34 -06:00
parent 72032650b8
commit 02fc2d9323
3 changed files with 29 additions and 1 deletions

View File

@ -260,7 +260,6 @@ def proxy(opts, functions=None, returners=None, whitelist=None):
''' '''
Returns the proxy module for this salt-proxy-minion Returns the proxy module for this salt-proxy-minion
''' '''
# This is where we should set directories so proxy modules can be loaded from /srv/<something>
ret = LazyLoader(_module_dirs(opts, 'proxy', 'proxy'), ret = LazyLoader(_module_dirs(opts, 'proxy', 'proxy'),
opts, opts,
tag='proxy', tag='proxy',

View File

@ -2491,6 +2491,7 @@ class ProxyMinion(Minion):
to know which master they connected to) to know which master they connected to)
''' '''
log.debug("subclassed _post_master_init") log.debug("subclassed _post_master_init")
self.opts['master'] = master self.opts['master'] = master
self.opts['pillar'] = yield salt.pillar.get_async_pillar( self.opts['pillar'] = yield salt.pillar.get_async_pillar(
@ -2510,7 +2511,16 @@ class ProxyMinion(Minion):
fq_proxyname = self.opts['pillar']['proxy']['proxytype'] fq_proxyname = self.opts['pillar']['proxy']['proxytype']
self.opts['proxy'] = self.opts['pillar']['proxy'] self.opts['proxy'] = self.opts['pillar']['proxy']
# Need to load the modules so they get all the dunder variables
self.functions, self.returners, self.function_errors = self._load_modules()
# we can then sync any proxymodules down from the master
self.functions['saltutil.sync_proxymodules'](saltenv='base')
# Then load the proxy module
self.proxy = salt.loader.proxy(self.opts) self.proxy = salt.loader.proxy(self.opts)
# And re-load the modules so the __proxy__ variable gets injected
self.functions, self.returners, self.function_errors = self._load_modules(proxy=self.proxy) self.functions, self.returners, self.function_errors = self._load_modules(proxy=self.proxy)
self.functions.pack['__proxy__'] = self.proxy self.functions.pack['__proxy__'] = self.proxy
self.proxy.pack['__salt__'] = self.functions self.proxy.pack['__salt__'] = self.functions

View File

@ -390,6 +390,25 @@ def sync_returners(saltenv=None, refresh=True):
return ret return ret
def sync_proxymodules(saltenv=None, refresh=False):
'''
Sync the proxy modules from the _proxy directory on the salt master file
server. This function is environment aware, pass the desired environment
to grab the contents of the _returners directory, base is the default
environment.
CLI Example:
.. code-block:: bash
salt '*' saltutil.sync_proxymodules
'''
ret = _sync('proxy', saltenv)
if refresh:
refresh_modules()
return ret
def sync_output(saltenv=None, refresh=True): def sync_output(saltenv=None, refresh=True):
''' '''
Sync the output modules from the _output directory on the salt master file Sync the output modules from the _output directory on the salt master file