File 0033-Add-master_tops-support-in-salt-ssh.patch of Package salt.4202

From b459456161c99ab40618c630590a542c668fa735 Mon Sep 17 00:00:00 2001
From: Matei Albu <malbu@suse.de>
Date: Thu, 1 Dec 2016 14:38:51 +0100
Subject: [PATCH 33/38] Add master_tops support in salt-ssh (cherry picked from
 commit 7037fa1)

Add/remove newlines

Needed for the lint check to pass.
(cherry picked from commit 65a0f10)
---
 salt/client/ssh/state.py | 35 +++++++++++++++++++++++++++++++++++
 salt/state.py            | 10 +++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/salt/client/ssh/state.py b/salt/client/ssh/state.py
index a737c77..5134a51 100644
--- a/salt/client/ssh/state.py
+++ b/salt/client/ssh/state.py
@@ -4,6 +4,7 @@ Create ssh executor system
 '''
 from __future__ import absolute_import
 # Import python libs
+import logging
 import os
 import tarfile
 import tempfile
@@ -22,6 +23,8 @@ import salt.state
 import salt.loader
 import salt.minion
 
+log = logging.getLogger(__name__)
+
 
 class SSHState(salt.state.State):
     '''
@@ -65,6 +68,7 @@ class SSHHighState(salt.state.BaseHighState):
         salt.state.BaseHighState.__init__(self, opts)
         self.state = SSHState(opts, pillar, wrapper)
         self.matcher = salt.minion.Matcher(self.opts)
+        self.tops = salt.loader.tops(self.opts)
 
     def load_dynamic(self, matches):
         '''
@@ -72,6 +76,37 @@ class SSHHighState(salt.state.BaseHighState):
         '''
         return
 
+    def _ext_nodes(self):
+        '''
+        Evaluate master_tops locally
+        '''
+        if 'id' not in self.opts:
+            log.error('Received call for external nodes without an id')
+            return {}
+        if not salt.utils.verify.valid_id(self.opts, self.opts['id']):
+            return {}
+        # Evaluate all configured master_tops interfaces
+
+        grains = {}
+        ret = {}
+
+        if 'grains' in self.opts:
+            grains = self.opts['grains']
+        for fun in self.tops:
+            if fun not in self.opts.get('master_tops', {}):
+                continue
+            try:
+                ret.update(self.tops[fun](opts=self.opts, grains=grains))
+            except Exception as exc:
+                # If anything happens in the top generation, log it and move on
+                log.error(
+                    'Top function {0} failed with error {1} for minion '
+                    '{2}'.format(
+                        fun, exc, self.opts['id']
+                    )
+                )
+        return ret
+
 
 def lowstate_file_refs(chunks, extras=''):
     '''
diff --git a/salt/state.py b/salt/state.py
index 7ea76c2..c1d62b7 100644
--- a/salt/state.py
+++ b/salt/state.py
@@ -2625,7 +2625,7 @@ class BaseHighState(object):
                             if isinstance(item, six.string_types):
                                 matches[saltenv].append(item)
                 _filter_matches(match, data, self.opts['nodegroups'])
-        ext_matches = self.client.ext_nodes()
+        ext_matches = self._ext_nodes()
         for saltenv in ext_matches:
             if saltenv in matches:
                 matches[saltenv] = list(
@@ -2635,6 +2635,14 @@ class BaseHighState(object):
         # pylint: enable=cell-var-from-loop
         return matches
 
+    def _ext_nodes(self):
+        '''
+        Get results from an external node classifier.
+        Override it if the execution of the external node clasifier
+        needs customization.
+        '''
+        return self.client.ext_nodes()
+
     def load_dynamic(self, matches):
         '''
         If autoload_dynamic_modules is True then automatically load the
-- 
2.10.2

openSUSE Build Service is sponsored by