%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/states/module.pyo

�
���^c@@s*dZddlmZmZmZddlZddlZddlZddl	Zddl
mZddlm
Z
ddlmZddlmZddlmZd	�Zejjjed
�Zee�ddej�d
��Zdd�Zd�Zd�Zd�Zejjjed�Z dS(u_
Execution of Salt modules from within states
============================================

With `module.run` these states allow individual execution module calls to be
made via states. To call a single module function use a :mod:`module.run <salt.states.module.run>`
state:

.. code-block:: yaml

    mine.send:
      module.run:
        - network.interfaces

Note that this example is probably unnecessary to use in practice, since the
``mine_functions`` and ``mine_interval`` config parameters can be used to
schedule updates for the mine (see :ref:`here <salt-mine>` for more info).

It is sometimes desirable to trigger a function call after a state is executed,
for this the :mod:`module.wait <salt.states.module.wait>` state can be used:

.. code-block:: yaml

    fetch_out_of_band:
      module.run:
        - git.fetch:
          - cwd: /path/to/my/repo
          - user: myuser
          - opts: '--all'

Another example:

.. code-block:: yaml

    mine.send:
      module.run:
        - network.ip_addrs:
          - interface: eth0

And more complex example:

.. code-block:: yaml

    eventsviewer:
      module.run:
        - task.create_task:
          - name: events-viewer
          - user_name: System
          - action_type: Execute
          - cmd: 'c:\netops\scripts\events_viewer.bat'
          - trigger_type: 'Daily'
          - start_date: '2017-1-20'
          - start_time: '11:59PM'

Please note, this is a new behaviour of `module.run` function.

With the previous `module.run` there are several differences:

- The need of `name` keyword
- The need of `m_` prefix
- No way to call more than one function at once

For example:

.. code-block:: yaml

    mine.send:
      module.wait:
        - name: network.interfaces
        - watch:
          - file: /etc/network/interfaces

All arguments that the ``module`` state does not consume are passed through to
the execution module function being executed:

.. code-block:: yaml

    fetch_out_of_band:
      module.run:
        - name: git.fetch
        - cwd: /path/to/my/repo
        - user: myuser
        - opts: '--all'

Due to how the state system works, if a module function accepts an
argument called, ``name``, then ``m_name`` must be used to specify that
argument, to avoid a collision with the ``name`` argument.

Here is a list of keywords hidden by the state system, which must be prefixed
with ``m_``:

* fun
* name
* names
* state
* saltenv

For example:

.. code-block:: yaml

    disable_nfs:
      module.run:
        - name: service.disable
        - m_name: nfs

Note that some modules read all or some of the arguments from a list of keyword
arguments. For example:

.. code-block:: yaml

    mine.send:
      module.run:
        - func: network.ip_addrs
        - kwargs:
            interface: eth0

.. code-block:: yaml

    cloud.create:
      module.run:
        - func: cloud.create
        - provider: test-provider
        - m_names:
          - test-vlad
        - kwargs: {
              ssh_username: 'ubuntu',
              image: 'ami-8d6d9daa',
              securitygroup: 'default',
              size: 'c3.large',
              location: 'ap-northeast-1',
              delvol_on_destroy: 'True'
          }

Another example that creates a recurring task that runs a batch file on a
Windows system:

.. code-block:: yaml

    eventsviewer:
      module.run:
        - name: task.create_task
        - m_name: 'events-viewer'
        - user_name: System
        - kwargs: {
              action_type: 'Execute',
              cmd: 'c:\netops\scripts\events_viewer.bat',
              trigger_type: 'Daily',
              start_date: '2017-1-20',
              start_time: '11:59PM'
        }

Another option is to use the new version of `module.run`. With which you can call one (or more!)
functions at once the following way:

.. code-block:: yaml

    call_something:
      module.run:
        - git.fetch:
          - cwd: /path/to/my/repo
          - user: myuser
          - opts: '--all'

By default this behaviour is not turned on. In order to do so, please add the following
configuration to the minion:

.. code-block:: yaml

    use_superseded:
      - module.run

i(tabsolute_importtprint_functiontunicode_literalsN(tsix(trange(tzip(tSaltInvocationError(twith_deprecatedcK@s i|d6id6td6dd6S(u�
    Run a single module function only if the watch statement calls it

    ``name``
        The module function to execute

    ``**kwargs``
        Pass any arguments needed to execute the function

    .. note::
        Like the :mod:`cmd.run <salt.states.cmd.run>` state, this state will
        return ``True`` but not actually execute, unless one of the following
        two things happens:

        1. The state has a :ref:`watch requisite <requisites-watch>`, and
           the state which it is watching changes.

        2. Another state has a :ref:`watch_in requisite
           <requisites-watch-in>` which references this state, and the state
           wth the ``watch_in`` changes.
    unameuchangesuresultuucomment(tTrue(tnametkwargs((s6/usr/lib/python2.7/site-packages/salt/states/module.pytwait�s
uwatchuSodiumtpolicycK@sd|kr|jd�nit|�d6id6dd6dd6}g|j�D]}d|krQ|^qQ}g}g}xW|D]O}|jd�d}|tkr�|j|�q�td	r�|j|�q�q�W|s�|r�d
j|r&dj	dt
|�d
kpdddj|�p d�p)d|rhdj	dt
|�d
kpMdddj|�pbd�pkdg�j�|d<|p�||d<n|ddkrt|d<g}g}x%|D]}|jd�d}y�t
|d|jd�d|j|��}	t|	|djdi��s_t|	t�r�|jdj	||	jdd���q�nH|jdj	|t|	t�r�|	jdd�n|	��|	|d|<Wq�ttfk
r�}
|jdj	||
��q�Xq�Wdj||�|d<t|�|d<n|S(u:
    Run a single module function or a range of module functions in a batch.
    Supersedes ``module.run`` function, which requires ``m_`` prefix to
    function-specific parameters.

    :param returner:
        Specify a common returner for the whole batch to send the return data

    :param kwargs:
        Pass any arguments needed to execute the function(s)

    .. code-block:: yaml

      some_id_of_state:
        module.run:
          - network.ip_addrs:
            - interface: eth0
          - cloud.create:
            - names:
              - test-isbm-1
              - test-isbm-2
            - ssh_username: sles
            - image: sles12sp2
            - securitygroup: default
            - size: 'c3.large'
            - location: ap-northeast-1
            - delvol_on_destroy: True


    :return:
    unameuchangesuucommenturesultu.u:iutestu u"Unavailable function{plr}: {func}.tplritfuncu, u$Function{plr} {func} to be executed.treturnerureturnert	func_argsuretu'{0}' failed: {1}u(error message N/A)u{0}: {1}uSuccessN(tpoptlisttNonetkeystsplitt__salt__tappendt__opts__tjointformattlentstripRt_call_functiontgett_get_resultt
isinstancetdictRt	TypeErrortbool(R
tretRt	functionstmissingtteststfailurestsuccesst_functfunc_rettex((s6/usr/lib/python2.7/site-packages/salt/states/module.pytrun�s\"

+

.

.!cK@s~tjjjt|�}tt|jt|jp4g�|jpEg��}|jt|jpcg�t|jpug� }git	}}}x�t
|jd�p�g�D]o}	t|	t�s�|j
|	�q�xGtj|	�D]6}
|
|kr|j
|	|
�q�q�|j|	�q�Wq�W|j�t|jp9g�t|jpKg�}t|�}g}
|r�||kr�x0|jD]"}||kr�|
j
|�q�q�Wn|
r�tdjdj|
����n'||kr�tdj||���nt|||�}|d	k	rztjjtt�}||krz||itdd6|d6|d6tjjjt�d6�qzn|S(
ug
    Calls a function from the specified module.

    :param name:
    :param kwargs:
    :return:
    u	func_argsuMissing arguments: {0}u, u-Function expects {0} parameters, got only {1}uiduretufunujidN(tsalttutilstargstget_function_argspecRR!RRtdefaultstFalsetreversedRR RRtiterkeystupdatetreverseRRRRtloadert	returnersRtjidtgen_jid(R	RR
targspectfunc_kwRtarg_typetna_typetkw_typetfuncsett	kwarg_keyt_exp_prmt_passed_prmR&targtmretR9((s6/usr/lib/python2.7/site-packages/salt/states/module.pyR7sB /"
(!	'cK@si|d6id6dd6dd6}|tkrOdj|�|d<t|d<|Stdrpdj|�|d<|Stjjjt|�}g}i}d	}d	}t	|jt
�r�t|j�}nt	|jt
�r�t|j�}nxTt|d
dd�D]<}||}	||	dkr|j|	||j|<qqWx�|D]�}
|
dkr~d|kr|jd�||
<qn�|
d
kr�d|kr|jd�||
<qnb|
dkr�d|kr|jd�||
<qn1|
dkrd|kr|jd�||
<qn|
|krG|j|
�||
<qGqGWt�}x�|jD]�}
|
dkred}nZ|
d
krzd}nE|
dkr�d}n0|
dkr�d}n|
dkr�d}n|
}||kr�|
|kr�|j|�qJn|
|kr
|j||
�qJ|j|j|��qJW|rld}
x!|D]}
|
dj|
�7}
q7W|
|d<t|d<|S|jr]|jdkr�d}ni|jd
kr�d}nQ|jdkr�d}n9|jdkr�d}n!|jdkr�d}n	|j}||kr]|j|�}t	|t
�sJd}|j|j�|d<t|d<|S|j|�q]ni}|jr�|j|kr�|j|j�}t	|t�s�d}|j|j�|d<t|d<|Sny3|jr�t|||�}nt||�}Wn4tk
r2}dj||�|d<t|d<|SX|dk	sK|ik	r\||dd<nd|kr�itdd6|d6|d
6tjjjt�d6}tjjtt�}|d|kr�||d|�q�ndj|�|d<t||d�|d<|S( u\
    .. deprecated:: 2017.7.0
       Function name stays the same, behaviour will change.

    Run a single module function

    ``name``
        The module function to execute

    ``returner``
        Specify the returner to send the return of the module execution to

    ``kwargs``
        Pass any arguments needed to execute the function
    unameuchangesuucommenturesultu$Module function {0} is not availableutestu%Module function {0} is set to executeiii����um_nameufunum_funustateum_stateusaltenvu	m_saltenvunamesum_namesu$The following arguments are missing:u {0}u'{0}' must be a list.u'{0}' must be a dict.u6Module function {0} threw an exception. Exception: {1}uretureturneruidujiduModule function {0} executedN(RRRR3RR.R/R0R1R RRR2ttupleRRtsettaddRtvarargstextendtkeywordsR!t	ExceptionR:R;R8R9R(R	R
R$taspecR0R2targlentdeflentindtminusRER&trargtcommentRJtmsgtnkwargsRFtetret_retR9((s6/usr/lib/python2.7/site-packages/salt/states/module.pyt_runps�




 
						



							

	
cC@s�t}t|t�r6|jdd�dkr6t}n�t|t�rN|}n�|jdi�}t|t�r�t|jdi�t�r�|jdi�}q�|jdd�dkr�t}q�t|�}n|S(Nuretcodeiureturesult(RR R!RR3R#t_get_dict_result(R+tchangestrestchanges_ret((s6/usr/lib/python2.7/site-packages/salt/states/module.pyRs'			cC@szt}xmtj|�D]\\}}|dkrD|tkrDt}Pqt|t�rt|�}|tkrrPqrqqW|S(Nuresult(RRt	iteritemsR3R R!RZ(tnodeR$tkeytval((s6/usr/lib/python2.7/site-packages/salt/states/module.pyRZ su	mod_watch(!t__doc__t
__future__RRRtsalt.loaderR.tsalt.utils.argstsalt.utils.functoolstsalt.utils.jidtsalt.extRtsalt.ext.six.movesRRtsalt.exceptionsRtsalt.utils.decoratorsRRR/t	functoolstalias_functiontwatchtglobalstOPT_INR-RRRYRRZt	mod_watch(((s6/usr/lib/python2.7/site-packages/salt/states/module.pyt<module>�s$	$Z9	�		

Zerion Mini Shell 1.0