Add master_tops support in salt-ssh

This commit is contained in:
Matei Albu 2016-12-01 14:38:51 +01:00
parent ca3a9488f1
commit 7037fa116d
2 changed files with 44 additions and 1 deletions

View file

@ -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,7 @@ import salt.state
import salt.loader
import salt.minion
log = logging.getLogger(__name__)
class SSHState(salt.state.State):
'''
@ -66,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):
'''
@ -74,6 +77,38 @@ 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=''):
'''
Create a list of file ref objects to reconcile

View file

@ -2907,7 +2907,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(
@ -2917,6 +2917,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