mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Add runner for execution modules (#33949)
* Add runner for execution modules * Make sure all modules load and fix argument passing * Fix lint error * Add docs for salt runner
This commit is contained in:
parent
b1d03528c0
commit
34135e1f67
@ -144,6 +144,14 @@ This code will call the `run` function in the :mod:`cmd <salt.modules.cmdmod>`
|
||||
module and pass the argument ``bar`` to it.
|
||||
|
||||
|
||||
Calling Execution Modules on the Salt Master
|
||||
============================================
|
||||
|
||||
.. versionadded:: Carbon
|
||||
Execution modules can now also be called via the :command:`salt-run` command
|
||||
using the :ref:`salt runner <salt_salt_runner>`.
|
||||
|
||||
|
||||
Preloaded Execution Module Data
|
||||
===============================
|
||||
|
||||
|
@ -33,6 +33,7 @@ Full list of runner modules
|
||||
pkg
|
||||
queue
|
||||
reactor
|
||||
salt
|
||||
saltutil
|
||||
sdb
|
||||
search
|
||||
|
6
doc/ref/runners/all/salt.runners.salt.rst
Normal file
6
doc/ref/runners/all/salt.runners.salt.rst
Normal file
@ -0,0 +1,6 @@
|
||||
=================
|
||||
salt.runners.salt
|
||||
=================
|
||||
|
||||
.. automodule:: salt.runners.salt
|
||||
:members:
|
@ -9,6 +9,13 @@ Features
|
||||
|
||||
- Minions can run in stand-alone mode to use beacons and engines without
|
||||
having to connect to a master. (Thanks @adelcast!)
|
||||
- Added a ``salt`` runner to allow running salt modules via salt-run.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-run salt.cmd test.ping
|
||||
# call functions with arguments and keyword arguments
|
||||
salt-run salt.cmd test.arg 1 2 3 a=1
|
||||
|
||||
Config Changes
|
||||
==============
|
||||
|
67
salt/runners/salt.py
Normal file
67
salt/runners/salt.py
Normal file
@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
.. versionadded:: Carbon
|
||||
|
||||
This runner makes Salt's
|
||||
execution modules available
|
||||
on the salt master.
|
||||
|
||||
.. _salt_salt_runner:
|
||||
Salt's execution modules are normally available
|
||||
on the salt minion. Use this runner to call
|
||||
execution modules on the salt master.
|
||||
Salt :ref:`execution modules <writing-execution-modules>`
|
||||
are the functions called by the ``salt`` command.
|
||||
|
||||
Execution modules can be
|
||||
called with ``salt-run``:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-run salt.cmd test.ping
|
||||
# call functions with arguments and keyword arguments
|
||||
salt-run salt.cmd test.arg 1 2 3 key=value a=1
|
||||
|
||||
Execution modules are also available to salt runners:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
__salt__['salt.cmd'](fun=fun, args=args, kwargs=kwargs)
|
||||
|
||||
'''
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
import logging
|
||||
|
||||
# import salt libs
|
||||
from salt.loader import minion_mods, utils
|
||||
|
||||
log = logging.getLogger(__name__) # pylint: disable=invalid-name
|
||||
|
||||
|
||||
def cmd(fun, *args, **kwargs):
|
||||
'''
|
||||
Execute ``fun`` with the given ``args`` and ``kwargs``.
|
||||
Parameter ``fun`` should be the string :ref:`name <all-salt_modules>`
|
||||
of the execution module to call.
|
||||
|
||||
Note that execution modules will be *loaded every time*
|
||||
this function is called.
|
||||
|
||||
CLI example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-run salt.cmd test.ping
|
||||
# call functions with arguments and keyword arguments
|
||||
salt-run salt.cmd test.arg 1 2 3 a=1
|
||||
'''
|
||||
log.debug('Called salt.cmd runner with minion function %s', fun)
|
||||
|
||||
kws = dict((k, v) for k, v in kwargs.items() if not k.startswith('__'))
|
||||
|
||||
# pylint: disable=undefined-variable
|
||||
return minion_mods(
|
||||
__opts__,
|
||||
utils=utils(__opts__)).get(fun)(*args, **kws)
|
32
tests/integration/runners/salt.py
Normal file
32
tests/integration/runners/salt.py
Normal file
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Tests for the salt runner
|
||||
|
||||
.. versionadded:: Carbon
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import salt libs
|
||||
import integration
|
||||
|
||||
|
||||
class SaltRunnerTest(integration.ShellCase):
|
||||
'''
|
||||
Test the salt runner
|
||||
'''
|
||||
def test_salt_cmd(self):
|
||||
'''
|
||||
salt.cmd
|
||||
'''
|
||||
ret = self.run_run_plus('salt.cmd', 'test.ping')
|
||||
self.assertTrue(ret.get('out')[0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(SaltRunnerTest)
|
Loading…
Reference in New Issue
Block a user