merge commit

This commit is contained in:
C. R. Oldham 2014-07-09 16:10:44 -06:00
commit 426e958296
5 changed files with 106 additions and 9 deletions

View File

@ -6,9 +6,8 @@ In 0.10.4 the `external_nodes` system was upgraded to allow for modular
subsystems to be used to generate the top file data for a highstate run on
the master.
The old `external_nodes` option still works, but will be removed in the
future in favor of the new `master_tops` option which uses the modular
system instead. The master tops system contains a number of subsystems that
The old `external_nodes` option has been removed.
The master tops system contains a number of subsystems that
are loaded via the Salt loader interfaces like modules, states, returners,
runners, etc.
@ -29,3 +28,52 @@ for :doc:`Cobbler <../../ref/tops/all/salt.tops.cobbler>` or:
classes_uri: roles
for :doc:`Reclass <../../ref/tops/all/salt.tops.reclass_adapter>`.
It's also possible to create custom master_tops modules. These modules must go
in a subdirectory called `tops` in the `extension_modules` directory.
The `extension_modules` directory is not defined by default (the
default `/srv/salt/_modules` will NOT work as of this release)
Custom tops modules are written like any other execution module, see the source
for the two modules above for examples of fully functional ones. Below is
a degenerate example:
/etc/salt/master:
.. code-block:: yaml
extension_modules: /srv/salt/modules
master_tops:
customtop: True
/srv/salt/modules/tops/customtop.py:
.. code-block: python
import logging
import sys
# Define the module's virtual name
__virtualname__ = 'customtop'
log = logging.getLogger(__name__)
def __virtual__():
return __virtualname__
def top(**kwargs):
log.debug('Calling top in customtop')
return {'base': ['test']}
`salt minion state.show_top` should then display something like:
.. code-block: bash
$ salt minion state.show_top
minion
----------
base:
- test

View File

@ -1190,6 +1190,17 @@ class RemoteClient(Client):
except SaltReqTimeoutError:
return ''
def _get_channel(self):
'''
Return the right channel
'''
if self.auth:
return self.channel
return salt.transport.Channel.factory(self.opts)
def ext_nodes(self):
'''
Return the metadata derived from the external nodes system on the

View File

@ -201,7 +201,8 @@ def tops(opts):
return {}
whitelist = opts['master_tops'].keys()
load = _create_loader(opts, 'tops', 'top')
return load.filter_func('top', whitelist=whitelist)
topmodules = load.filter_func('top', whitelist=whitelist)
return topmodules
def wheels(opts, whitelist=None):
@ -900,6 +901,7 @@ class Loader(object):
getattr(mod, sname) for sname in dir(mod) if
isinstance(getattr(mod, sname), mod.__class__)
]
# reload only custom "sub"modules i.e is a submodule in
# parent module that are still available on disk (i.e. not
# removed during sync_modules)

View File

@ -866,6 +866,7 @@ class AESFuncs(object):
load.pop('tok')
return load
def _ext_nodes(self, load):
'''
Return the results from an external node classifier if one is
@ -876,6 +877,7 @@ class AESFuncs(object):
return {}
return self.masterapi._ext_nodes(load, skip_verify=True)
def _master_opts(self, load):
'''
Return the master options to the minion

View File

@ -3,10 +3,10 @@
External Nodes Classifier
=========================
The External Nodes Classifier is a master tops subsystem used to hook into
systems used to provide mapping information used by major configuration
management systems. One of the most common external nodes classification
system is provided by Cobbler and is called ``cobbler-ext-nodes``.
The External Nodes Classifier is a master tops subsystem that retrieves mapping
information from major configuration management systems. One of the most common
external nodes classifiers system is provided by Cobbler and is called
``cobbler-ext-nodes``.
The cobbler-ext-nodes command can be used with this configuration:
@ -18,8 +18,32 @@ The cobbler-ext-nodes command can be used with this configuration:
It is noteworthy that the Salt system does not directly ingest the data
sent from the ``cobbler-ext-nodes`` command, but converts the data into
information that is used by a Salt top file.
Any command can replace the call to 'cobbler-ext-nodes' above, but currently the
data must be formatted in the same way that the standard 'cobbler-ext-nodes'
does.
See (admittedly degenerate and probably not complete) example:
```
classes:
- basepackages
- database
```
The above essentially is the same as a top.sls containing
```
base:
'*':
- basepackages
- database
'''
# Import python libs
import subprocess
@ -27,6 +51,11 @@ import subprocess
import yaml
# Import python libs
import logging
log = logging.getLogger(__name__)
def __virtual__():
'''
Only run if properly configured
@ -40,7 +69,7 @@ def top(**kwargs):
'''
Run the command configured
'''
if 'id' not in kwargs['opts']:
if not 'id' in kwargs['opts']:
return {}
cmd = '{0} {1}'.format(
__opts__['master_tops']['ext_nodes'],
@ -52,6 +81,8 @@ def top(**kwargs):
shell=True,
stdout=subprocess.PIPE
).communicate()[0])
if not ndata:
log.info('master_tops ext_nodes call did not return any data')
ret = {}
if 'environment' in ndata:
env = ndata['environment']
@ -65,4 +96,7 @@ def top(**kwargs):
ret[env] = ndata['classes']
else:
return ret
else:
log.info('master_tops ext_nodes call did not have a dictionary with a "classes" key.')
return ret