%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/states/saltmod.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
ZddlZddlZddlmZeje�ZdZd�Zd�Zd�Zed	d
eeeeeeeeeeedeeeeeeed�Zed	d
eeeeeeeeeeed�Zd
ddd�Zd�Zd�Z d�Z!dS(u�
Control the Salt command interface
==================================

This state is intended for use from the Salt Master. It provides access to
sending commands down to minions as well as access to executing master-side
modules. These state functions wrap Salt's :ref:`Python API <python-api>`.

    .. versionadded: 2016.11.0

    Support for masterless minions was added to the ``salt.state`` function,
    so they can run orchestration sls files. This is particularly useful when
    the rendering of a state is dependent on the execution of another state.
    Orchestration will render and execute each orchestration block
    independently, while honoring requisites to ensure the states are applied
    in the correct order.

.. seealso:: More Orchestrate documentation

    * :ref:`Full Orchestrate Tutorial <orchestrate-runner>`
    * :py:func:`The Orchestrate runner <salt.runners.state.orchestrate>`
i(tabsolute_importtunicode_literalstprint_functionN(tsixusaltcC@stS(u
    Named salt
    (t__virtualname__(((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pyt__virtual__/scC@sEy tjjjtt|d�Wntk
r@tjd�nXdS(Nurunu>Unable to fire args event due to missing __orchestration_jid__(	tsalttutilsteventt	fire_argst__opts__t__orchestration_jid__t	NameErrortlogtdebug(ttag_data((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pyt
_fire_args6s
c	@s�t��dg�t��dg�����fd�}ttjj|tjjt�����}x|D]}|j�qrWx?�D]7}|dk	r�|\}}}tj|||�q�q�W�S(u
    Applies a function to each element of a list, returning the resulting list.

    A separate thread is created for each element in the input list and the
    passed function is called for each of the elements. When all threads have
    finished execution a list with the results corresponding to the inputs is
    returned.

    If one of the threads fails (because the function throws an exception),
    that exception is reraised. If more than one thread fails, the exception
    from the first thread (according to the index of the input element) is
    reraised.

    func:
        function that is applied on each input element.
    inputs:
        list of elements that shall be processed. The length of this list also
        defines the number of threads created.
    c@s;�����fd�}tjd|�}|j�|S(Nc@s6y������<Wntj���<nXdS(N(tsystexc_info((terrorstfunctindextinputstoutputs(s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pyt
run_threadZsttarget(t	threadingtThreadtstart(RRtthread(RRRR(Rs7/usr/lib/python2.7/site-packages/salt/states/saltmod.pyt
create_threadYs
N(	tlentNonetlistRtmovestmaptrangetjointreraise(	RRRtthreadsRterrortexc_typet	exc_valuet
exc_traceback((RRRRs7/usr/lib/python2.7/site-packages/salt/states/saltmod.pyt
_parallel_mapBs	-

uglobuc'K@shigd6id6|d6|d6}|r5||d<n|rH||d<ni|d6id6d	d
6td6}yt|�}Wn&tk
r�t|d<d|d
<|SX||d
<||d<d|kr�|d|d<n||d<|r�d}ny|	r
d}|dj|	�nY|rNd}t|t�r:dj|�}n|dj|�nd|d
<t|d<|S|d>k	s�t	j
d�r�|d>k	r�|nt	j
d�|dd<n|r�||dd<n|
d>k	r�|
|dd<n|
d>k	r�|
|dd<n||dd<t|t�r,||dd<nd|d
<t|d<|S|d>k	rftj
|�|d<n|d>k	r||d<n|tks�t	j
d�r�t|d<nt	d d!ko�t	d"d#k}|stid$d%6|d&6|d6|d'6�td(|||�}n�|	r1d	j|jd��|d)<n%|rVd	j|jd��|d*<n|j|jd��t||�}ii|d6t|t�r�|j
d+d,�nd,d+6t	d-6}y"|tt|��d.|d/<Wnttfk
r�nXi}t�} t�}!|d>kr%d?}nnt|tj�rbg|jd�D]}"|"j�^qG}n1t|t�s�|jd0g�jd1�d@}n|r�|r�t|d<d2|d
<|Sx�tj|�D]�\}"}#|#j
d+d	�d,kr�tjd3�nt}$d4|#kr0d|#kr0|#jd4�|#d<nt}%|#j
d5t�rQt}%nGy|#d}$Wntk
rxt}%nX|%r�td6|$d7t�}%n|%s�|"|kr�| j |"�n|$||"<q�nyaxZtj!|$�D]<}&t|&t�r�d|&kr|&dr|$||"<Pqq�q�W|!j |"�Wq�t"k
rdtj#d8t$|$�|$�|!j |"�q�Xq�W|r�id,d+6|d6|d<nt%| �|kr�t|d<d9j&d:j| ��|d
<n`d;|d
<|r�|d
cd<j&d:j|��7<n|!r%|d
cd=j&d:j|!��7<n|s:t	j
d�rd|drd|dtkrdd>|d<qdn|S(Au5

    Invoke a state run on a given target

    name
        An arbitrary name used to track the state execution

    tgt
        The target specification for the state run.

        .. versionadded: 2016.11.0

        Masterless support: When running on a masterless minion, the ``tgt``
        is ignored and will always be the local minion.

    tgt_type
        The target type to resolve, defaults to ``glob``

    ret
        Optionally set a single or a list of returners to use

    ret_config
        Use an alternative returner configuration

    ret_kwargs
        Override individual returner configuration items

    highstate
        Defaults to None, if set to True the target systems will ignore any
        sls references specified in the sls option and call state.highstate
        on the targeted minions

    top
        Should be the name of a top file. If set state.top is called with this
        top file instead of state.sls.

    sls
        A group of sls files to execute. This can be defined as a single string
        containing a single sls file, or a list of sls files

    test
        Pass ``test=true`` or ``test=false`` through to the state function. This
        can be used to overide a test mode set in the minion's config file. If
        left as the default of None and the 'test' mode is supplied on the
        command line, that value is passed instead.

    pillar
        Pass the ``pillar`` kwarg through to the state function

    pillarenv
        The pillar environment to grab pillars from

        .. versionadded:: 2017.7.0

    saltenv
        The default salt environment to pull sls files from

    ssh
        Set to `True` to use the ssh client instead of the standard salt client

    roster
        In the event of using salt-ssh, a roster system can be set

    expect_minions
        An optional boolean for failing if some minions do not respond

    fail_minions
        An optional list of targeted minions where failure is an option

    allow_fail
        Pass in the number of minions to allow for failure before setting
        the result of the execution to False

    concurrent
        Allow multiple state runs to occur at once.

        WARNING: This flag is potentially dangerous. It is designed
        for use when multiple state runs can safely be run at the same
        Do not use this flag for performance optimization.

    queue
        Pass ``queue=true`` through to the state function

    batch
        Execute the command :ref:`in batches <targeting-batch>`. E.g.: ``10%``.

        .. versionadded:: 2016.3.0

    subset
        Number of minions from the targeted set to randomly use

        .. versionadded:: 2017.7.0

    failhard
        pass failhard down to the executing state

        .. versionadded:: 2019.2.2

    Examples:

    Run a list of sls files via :py:func:`state.sls <salt.state.sls>` on target
    minions:

    .. code-block:: yaml

        webservers:
          salt.state:
            - tgt: 'web*'
            - sls:
              - apache
              - django
              - core
            - saltenv: prod

    Run a full :py:func:`state.highstate <salt.state.highstate>` on target
    mininons.

    .. code-block:: yaml

        databases:
          salt.state:
            - tgt: role:database
            - tgt_type: grain
            - highstate: True
    uargukwarguretutimeoutu
ret_configu
ret_kwargsunameuchangesuucommenturesultu5Passed invalid value for 'allow_fail', must be an intutgt_typeusshurosteruexpect_minionsustate.highstateu	state.topu	state.slsu,u0No highstate or sls specified, no execution madeutestupillaru	pillarenvusaltenvuqueueu
concurrentu.Must pass in boolean for value of 'concurrent'ubatchusubsetufailhardu__roleuminionufile_clientulocalustateutypeutgtuargsusaltutil.cmdutopfnumodsuoutu	highstateuidujidu__jid__uwarningsuG'fail_minions' needs to be a list or a comma separated string. Ignored.uNo minions returnedu$Output from salt state not highstateureturnufailedustate.check_resulttrecurseu m_ret did not have changes %s %suRun failed on minions: {0}u, uStates ran successfully.u Updating {0}.u No changes made to {0}.N((('tTruetintt
ValueErrortFalsetappendt
isinstanceR!R%R R
tgettboolRt	text_typeRt__salt__tpoptupdatetdicttnexttitert
StopIterationtKeyErrortsettstring_typestsplittstript
setdefaultt	iteritemsR
twarningt	__utils__taddt
itervaluestAttributeErrorR(ttypeRtformat('tnamettgttsshttgt_typetrett
ret_configt
ret_kwargst	highstatetslsttoptsaltenvttesttpillart	pillarenvtexpect_minionstfail_minionst
allow_failt
concurrentttimeouttbatchtqueuetsubsettorchestration_jidtfailhardtkwargstcmd_kwt	state_rettfunt
masterlesstcmd_retttmp_rettchangestfailt	no_changetminiontmdatatm_rettm_statet
state_item((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pytstatels�"









	

,



&3"			+	


	






%%c	K@sii|d6id6dd6td6}|d+kr7i}nt|
tj�redg|d<|
j�}
ni|
pqgd6|d	6|d
6|d6}|
d+k	r�tj|
�|d<n|d+k	r�||d
<n||d<||d<||d<t|d<|tkstjd�rt|d<n|r+||d<n|r>||d<n|}tdtkrxdj	||�|d<d+|d<|Sy@t
idd6|d6|d6|d6�td|||�}Wn1tk
r�}t
|d<tj|�|d<|SXy"|tt|��d|d<Wnttfk
r'nXi}t�}|d+krLd,}nnt|tj�r�g|jd�D]}|j�^qn}n1t|t�s�|jdg�jd�d-}nxtj|�D]�\}}t
}|jd �rt
|d<|j|�n|jd!t
�r t
}njd"|krNd
|krN|jd"�|d
<n|d
}|	retprt|	|�}|t
kr�t
}n|s�||kr�|j|�q�n|||<q�W|s�t
|d<d#|d$<n�|r�id%d&6|d
6|d<n|r-t
|d<d'j	|d(j|��|d<n
d)|d<|re|dcd*j	|d(j|��7<n|S(.um
    Execute a single module function on a remote minion via salt or salt-ssh

    name
        The name of the function to run, aka cmd.run or pkg.install

    tgt
        The target specification, aka '*' for all minions

    tgt_type
        The target type, defaults to ``glob``

    arg
        The list of arguments to pass into the function

    kwarg
        The dict (not a list) of keyword arguments to pass into the function

    ret
        Optionally set a single or a list of returners to use

    ret_config
        Use an alternative returner configuration

    ret_kwargs
        Override individual returner configuration items

    expect_minions
        An optional boolean for failing if some minions do not respond

    fail_minions
        An optional list of targeted minions where failure is an option

    fail_function
        An optional string that points to a salt module that returns True or False
        based on the returned data dict for individual minions

    ssh
        Set to `True` to use the ssh client instead of the standard salt client

    batch
        Execute the command :ref:`in batches <targeting-batch>`. E.g.: ``10%``.

    subset
        Number of minions from the targeted set to randomly use

        .. versionadded:: 2017.7.0

    failhard
        pass failhard down to the executing state

        .. versionadded:: 2019.2.2

    unameuchangesuucommenturesultu,Please specify 'arg' as a list of arguments.uwarningsuargukwarguretutimeoutubatchusubsetutgt_typeusshuexpect_minionsu	_cmd_metaufailhardu
ret_configu
ret_kwargsutestu,Function {0} would be executed on target {1}ufunctionutypeutgtuargsusaltutil.cmdujidu__jid__u,uG'fail_minions' needs to be a list or a comma separated string. Ignored.uretcodeufailedureturnuNo minions respondeducommandu	highstateuoutu+Running function {0} failed on minions: {1}u, uFunction ran successfully.u Function {0} ran on {1}.N(((R.R R3RR@RAR6R
R4RKRR7t	ExceptionR1R;R<R=R>R?RBR!RCR2RDRGR8R%(RLRMRNRORPRQRRRZR[t
fail_functiontargtkwargR^R_RaRcRdtfunc_retReRgRitexcRkRlRnRoRptm_func((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pytfunction�s�H

	
(








&
"		+	
	
	


"
(uidi,umastercC@s�i|d6id6dd6td6}tjd�rRdj|�|d<d|d<|Stjjj|tdtd	d
tdt	�}d}t
j
�}||}	x�t	r�|jd
t	�}
t
j
�|	k}|
dkr�|r�tjd�q�n |
dkr|rd|d<|St
j
|
d|�r|
dj|�}|dkrod|
dkro|
ddj|�}n|dk	ry|j|�}
Wn!tk
r�tjd|�qX||
=|d7}|djdg�}|j|�tjd|t|��q0tjd||
d�ntjd|
d�t|�dkrmt	|d<djt
j
�|�|d<|S|r�d|d<|Sq�WdS(u
    Watch Salt's event bus and block until a condition is met

    .. versionadded:: 2014.7.0

    name
        An event tag to watch for; supports Reactor-style globbing.
    id_list
        A list of event identifiers to watch for -- usually the minion ID. Each
        time an event tag is matched the event data is inspected for
        ``event_id``, if found it is removed from ``id_list``. When ``id_list``
        is empty this function returns success.
    event_id : id
        The name of a key in the event data. Default is ``id`` for the minion
        ID, another common value is ``name`` for use with orchestrating
        salt-cloud events.
    timeout : 300
        The maximum time in seconds to wait before failing.

    The following example blocks until all the listed minions complete a
    restart and reconnect to the Salt master:

    .. code-block:: yaml

        reboot_all_minions:
          salt.function:
            - name: system.reboot
            - tgt: '*'

        wait_for_reboots:
          salt.wait_for_event:
            - name: salt/minion/*/start
            - id_list:
              - jerry
              - stuart
              - dave
              - phil
              - kevin
              - mike
            - require:
              - salt: reboot_all_minions
    unameuchangesuucommenturesultutestu(Orchestration would wait for event '{0}'usock_diru	transporttoptstlistenitfullu'wait_for_event: No event data; waiting.uTimeout value reached.utagudatau?wait_for_event: Event identifier '%s' not in id_list; skipping.iuminions_seenuOwait_for_event: Event identifier '%s' removed from id_list; %s items remaining.uBwait_for_event: Event identifier '%s' not in event '%s'; skipping.u-wait_for_event: Skipping unmatched event '%s'uAll events seen in {0} seconds.N(R1R
R4RKR RRRt	get_eventR.ttimeR
ttracetfnmatchRR0RCR2RR(RLtid_listtevent_idR^tnodeRPtseventtdel_countert	starttimet	timelimitRtis_timedouttvaltval_idxtminions_seen((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pytwait_for_eventVsf0"

	
	


	

			

c	K@sOy
t}Wn$tk
r0tjd�d}nXtjdt�rri|d6dd6id6dj|�d6}|St	d|d	|d
t
dt|�}|jd�}t|t
�r�d
|kr�t|d<n|jdt�}i|d6i|d6d6|d6}dj||rdnd�|d<t|d<d|krK|d|d<n|S(u1
    Execute a runner module on the master

    .. versionadded:: 2014.7.0

    name
        The name of the function to run
    kwargs
        Any keyword arguments to pass to the runner function

    .. code-block:: yaml

         run-manage-up:
          salt.runner:
            - name: manage.up
    u>Unable to fire args event due to missing __orchestration_jid__utestunameuresultuchangesu(Runner function '{0}' would be executed.ucommentusaltutil.runnerRt__env__tfull_returnureturnuErrorusuccessuRunner function '{0}' {1}.uexecutedufailedu__orchestration__ujidu__jid__N(RRR
RR R
R4R1RKR7R�R.R3R:(RLRdtjidRPtoutt
runner_returntsuccess((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pytrunner�s@



	



c
@s�t|tj�r,ii||6g|6}nt|t�s[i|d6td6id6dd6Sxjtj|�D]Y\}}|dkr�i}ntjj	j
|�}d|kr�||d<n|||<qkWy
t�Wn$tk
r�t
jd�d�nX�fd�}y"t|ttj|���}WnFtjjk
rr}i|d6td6td6id6d	j|�d6SXd
�tjjtj|�|�D�}tgtj|�D]*}|jdd�d
ko�d|k^q��}	�fd��|	r�gtj|�D].\}}|djdd�dkr|^q}
|
}|rPd}nPg|
D]4}dj|tjj||dtdd��^qW}
dj|
�}i}x�tj|�D]/\}}�|d�}|r�|||<q�q�Wn�gtj|�D]*\}}|jdd�dkr�|^q�}
|
}|rBd}n@t|
�dkrjdj|
d�}ndjdj|
��}id�tj|�D�d6}i|d6|d6|d6|d6}|S( uj
    Executes multiple runner modules on the master in parallel.

    .. versionadded:: 2017.x.0 (Nitrogen)

    A separate thread is spawned for each runner. This state is intended to be
    used with the orchestrate runner in place of the ``saltmod.runner`` state
    when different tasks should be run in parallel. In general, Salt states are
    not safe when used concurrently, so ensure that they are used in a safe way
    (e.g. by only targeting separate minions in parallel tasks).

    name:
        name identifying this state. The name is provided as part of the
        output, but not used for anything else.

    runners:
        list of runners that should be run in parallel. Each element of the
        list has to be a dictionary. This dictionary's name entry stores the
        name of the runner function that shall be invoked. The optional kwarg
        entry stores a dictionary of named arguments that are passed to the
        runner function.

    .. code-block:: yaml

        parallel-state:
           salt.parallel_runners:
             - runners:
                 my_runner_1:
                   - name: state.orchestrate
                   - kwarg:
                       mods: orchestrate_state_1
                 my_runner_2:
                   - name: state.orchestrate
                   - kwarg:
                       mods: orchestrate_state_2
    unameuresultuchangesu/The runners parameter must be a string or dict.ucommentu>Unable to fire args event due to missing __orchestration_jid__c@s3td|dd�dtdt|jdi��S(Nusaltutil.runnerunameRR�R�ukwarg(R7R�R.R4(t
runner_config(R�(s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pytcall_runnerQs
usuccessu+One of the runners raised an exception: {0}cS@s#i|]\}}|d|�qS(ureturn((t.0t	runner_idR�((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pys
<dictcomp>hs	u	outputteruu	highstateudatac@s�t|t�siSd|krut|dt�rj|djdd�dkrjd|dkrj|ddS|dSnIi}x<tj|�D]+\}}�|�}|r�|||<q�q�W|SdS(Nuchangesuoutuu	highstateuret(R3R:R4RRD(tobjt
found_changestkeytvaluetchange(textract_changes(s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pyR�wsuretcodeiu+All runner functions executed successfully.u(Runner {0} failed with return value:
{1}unestedt
nested_indentiu
u	exit_codeiuRunner {0} failed.uRunners {0} failed.u, cS@si|]\}}||�qS(((R�R�R�((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pys
<dictcomp>�s	uretN(R3RR@R:R1RDR RRtdatatrepack_dictlistRRR
RR,R!RHt
exceptionst
SaltExceptionRKR"tziptiterkeystallR4toutputt
out_formatR
R%R(RLtrunnersRdR�R�R�RRyR�thighstate_outputtfailed_runnerstall_successfultcommenttrunner_commentsRktrunner_changesRP((R�R�s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pytparallel_runnerss�,	



""@(	>$	
cK@sgi|d6td6id6dd6}y
t}Wn$tk
rRtjd�d}nXtjdt�r�d|d<i|d<dj|�|d<|St	d	|d
|dt
|�}|jd�}t|t�r�d
|kr�t|d<n|jdt
�}i|d6i|d6d6|d6}dj||r/dnd�|d<t
|d<d|krc|d|d<n|S(uM
    Execute a wheel module on the master

    .. versionadded:: 2014.7.0

    name
        The name of the function to run
    kwargs
        Any keyword arguments to pass to the wheel function

    .. code-block:: yaml

        accept_minion_key:
          salt.wheel:
            - name: key.accept
            - match: frank
    unameuresultuchangesuucommentu>Unable to fire args event due to missing __orchestration_jid__utestu'Wheel function '{0}' would be executed.usaltutil.wheelRR�ureturnuErrorusuccessuWheel function '{0}' {1}.uexecutedufailedu__orchestration__ujidu__jid__N(N(R1RRR
RR R
R4RKR7R�R3R:R.(RLRdRPR�R�twheel_returnR�((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pytwheel�s<"





	



("t__doc__t
__future__RRRR�tloggingRRR�t
salt.syspathsRtsalt.exceptionstsalt.outputtsalt.utils.datatsalt.utils.eventtsalt.extRt	getLoggert__name__R
RRRR,R1R R.RsR{R�R�R�R�(((s7/usr/lib/python2.7/site-packages/salt/states/saltmod.pyt<module>sx			,�*�n	<	�

Zerion Mini Shell 1.0