From 02fc2d9323ed8fc100315d673be0098d2c6e6e45 Mon Sep 17 00:00:00 2001 From: "C. R. Oldham" Date: Tue, 6 Oct 2015 21:48:34 -0600 Subject: [PATCH] Enable syncing proxymodules from the master. Proxymodules can go in /srv/salt/_proxy. --- salt/loader.py | 1 - salt/minion.py | 10 ++++++++++ salt/modules/saltutil.py | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/salt/loader.py b/salt/loader.py index 51b99c674c..965173c128 100644 --- a/salt/loader.py +++ b/salt/loader.py @@ -260,7 +260,6 @@ def proxy(opts, functions=None, returners=None, whitelist=None): ''' Returns the proxy module for this salt-proxy-minion ''' - # This is where we should set directories so proxy modules can be loaded from /srv/ ret = LazyLoader(_module_dirs(opts, 'proxy', 'proxy'), opts, tag='proxy', diff --git a/salt/minion.py b/salt/minion.py index 991cc8bbad..b5d25a296b 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -2491,6 +2491,7 @@ class ProxyMinion(Minion): to know which master they connected to) ''' log.debug("subclassed _post_master_init") + self.opts['master'] = master self.opts['pillar'] = yield salt.pillar.get_async_pillar( @@ -2510,7 +2511,16 @@ class ProxyMinion(Minion): fq_proxyname = self.opts['pillar']['proxy']['proxytype'] 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) + + # 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.pack['__proxy__'] = self.proxy self.proxy.pack['__salt__'] = self.functions diff --git a/salt/modules/saltutil.py b/salt/modules/saltutil.py index 0829d3c3b6..ded5b6b23f 100644 --- a/salt/modules/saltutil.py +++ b/salt/modules/saltutil.py @@ -390,6 +390,25 @@ def sync_returners(saltenv=None, refresh=True): 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): ''' Sync the output modules from the _output directory on the salt master file