%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/event.pyc

�
���^c@@sAdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
yddlmZWn!e
k
r�ddlmZnXddlmZddlmZddlmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl!Zddl"Zddl#Zddl$Zddl%Zddl&Ze	j'e(�Z)dd	fZ*e+d
�Z,e+d�Z-dZ.i
d
d
6dd6dd6dd6dd6dd6dd6dd6dd6dd6Z/e0de0e1e0e2e2d�Z3e1e0e2d�Z4dd�Z5dde.d�Z6de7fd��YZ8de8fd ��YZ9d!e9fd"��YZ:d#e7fd$��YZ;d%e8fd&��YZ<d'e7fd(��YZ=d)ej>j?j@fd*��YZAd+ej>j?j@fd,��YZBd-e7fd.��YZCdS(/u�
Manage events

Events are all fired off via a zeromq 'pub' socket, and listened to with local
zeromq 'sub' sockets


All of the formatting is self contained in the event module, so we should be
able to modify the structure in the future since the same module used to read
events is the same module used to fire off events.

Old style event messages were comprised of two parts delimited at the 20 char
point. The first 20 characters are used for the zeromq subscriber to match
publications and 20 characters was chosen because it was at the time a few more
characters than the length of a jid (Job ID).  Any tags of length less than 20
characters were padded with "|" chars out to 20 characters.

Although not explicit, the data for an event comprised a python dict that was
serialized by msgpack.

New style event messages support event tags longer than 20 characters while
still being backwards compatible with old style tags.

The longer tags better enable name spaced event tags which tend to be longer.
Moreover, the constraint that the event data be a python dict is now an
explicit constraint and fire-event will now raise a ValueError if not. Tags
must be ascii safe strings, that is, have values less than 0x80

Since the msgpack dict (map) indicators have values greater than or equal to
0x80 it can be unambiguously determined if the start of data is at char 21
or not.

In the new style, when the tag is longer than 20 characters, an end of tag
string is appended to the tag given by the string constant TAGEND, that is, two
line feeds '

'.  When the tag is less than 20 characters then the tag is
padded with pipes "|" out to 20 characters as before.  When the tag is exactly
20 characters no padded is done.

The get_event method intelligently figures out if the tag is longer than 20
characters.


The convention for namespacing is to use dot characters "." as the name space
delimiter. The name space "salt" is reserved by SaltStack for internal events.

For example:
Namespaced tag
    'salt.runner.manage.status.start'

i(tabsolute_importtunicode_literalstprint_functionN(tMutableMapping(tFinalize(trange(tsixustate.highstateu	state.slsu

u/usaltuauthujobukeyuminionusyndicurunuwheelucloudu
fileserveruqueueuzeromqc	
C@s�|p
|d}|dkru|dkrMt||d|d|d|d|�St|||d|d|d|d|�S|d	kr�d
dl}|jjj|d|d|d
|�SdS(uG
    Return an event object suitable for the named transport

    :param IOLoop io_loop: Pass in an io_loop if you want asynchronous
                           operation for obtaining events. Eg use of
                           set_event_handler() API. Otherwise, operation
                           will be synchronous.
    usock_diruzeromqutcpumastertlistentio_loopt	keep_looptraise_errorsuraetiNtsock_dirtopts(uzeromqutcp(tMasterEventt	SaltEventtsalt.utils.raeteventtutilst	raeteventt	RAETEvent(	tnodeRt	transportRRRR	R
tsalt((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt	get_eventvs,c	C@sq|dd
kr/t||d|d|d|�S|ddkrmd	d
l}|jjjd|d|d|�Sd
S(uA
    Return an event object suitable for the named transport
    u	transportuzeromqutcpudetectRRR
uraetiNRR(uzeromqutcpudetect(R
RRR(RRRRR
R((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytget_master_event�sucC@s�y|dg}Wntk
r#nlXt||�}y0t||ddt�}|j|d|�Wn)tk
r�}tjd|||�nXdS(uO
    Fire an event containing the arguments passed to an orchestration job
    uargsusock_dirRttagu-Failed to fire args event %s with data %s: %sN(t	NameErrorttagifyRtFalset
fire_eventt	Exceptiontlogtwarning(Rtjidttag_datatprefixt
tag_suffixRt_eventtexc((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt	fire_args�s
cC@s�|tj||�g}t|d�r7|j|�n
|j|�xct|�D]U\}}y!tjjj	||�||<WqQt
k
r�t||�||<qQXqQWtj
g|D]}|r�|^q��S(u`
    convenience function to build a namespaced event tag string
    from joining with the TABPART character the base, prefix and suffix

    If string prefix is a valid key in TAGS Then use the value of key prefix
    Else use prefix string

    If suffix is a list Then join all string elements of suffix individually
    Else use string suffix

    uappend(tTAGStgetthasattrtextendtappendt	enumerateRRtstringutilstto_strt	TypeErrortstrt	TAGPARTERtjoin(tsuffixR"tbasetpartstindext_tpart((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s
!
RcB@seZdZd"d"ed"eed�Zed��Zd�Z	d"d"d�Z
d"d�Zd"d�Zd�Z
dd	�Zed"d
��Zd"d�Zd"d�Zed
��Zed��Zed��Zd�Zd�Zd"ed�Zdded"eed�Zd�Zd�Zded"ed�Zdd�Zdd�Zd�Zdd�Z d�Z!d �Z"d!�Z#RS(#u�
    Warning! Use the get_event function or the code will not be
    RAET compatible
    The base class used to manage salt events
    cC@s�tjjidd6�|_||_|dk	rF||_t|_nt	j
j�|_t|_t|_
t|_d|_d|_||_|dkr�i}n|dkr�tjjj�|_ntjjj�|_|jj|�|dkr|jd}n
||jd<tjjj�rCd|krCd|jd<n|j||�\|_|_g|_g|_|j �|r�|j
r�|j!�ndS(uW
        :param IOLoop io_loop: Pass in an io_loop if you want asynchronous
                               operation for obtaining events. Eg use of
                               set_event_handler() API. Otherwise, operation
                               will be synchronous.
        :param Bool keep_loop: Pass a boolean to determine if we want to keep
                               the io loop or destroy it when the event handle
                               is destroyed. This is useful when using event
                               loops from within third party asynchronous code
        umsgpackuserialumasterusock_diruipc_modeutcpN("RtpayloadtSerialtserialR	tNoneRRt_run_io_loop_syncttornadotiolooptIOLooptTruetcpubtcpusht
subscribertpusherR
tconfigtDEFAULT_MASTER_OPTStcopyRtDEFAULT_MINION_OPTStupdateRtplatformt
is_windowst_SaltEvent__load_uritpuburitpulluritpending_tagstpending_eventst_SaltEvent__load_cache_regextconnect_pub(tselfRRRRRR	R
((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt__init__�s:									
		
cC@stjjjdd�|_dS(u�
        Initialize the regular expression cache and put it in the
        class namespace. The regex search strings will be prepend with '^'
        tprependu^N(RRtcachet
CacheRegextcache_regex(tcls((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt__load_cache_regexs
cC@sk|dkru|jddkrHt|jd�}t|jd�}q/tjj|d�}tjj|d�}n�|jddkr�t|jd�}t|jd	�}n~tt|jd
�}|tjj	j
|jd��j�d }tjj|d
j|��}tjj|dj|��}t
jd|jj|�t
jd|jj|�||fS(u�
        Return the string URI for the location of the pull and pub sockets to
        use for firing and listening to events
        umasteruipc_modeutcputcp_master_pub_portutcp_master_pull_portumaster_event_pub.ipcumaster_event_pull.ipcutcp_pub_portu
tcp_pull_portu	hash_typeuidi
uminion_event_{0}_pub.ipcuminion_event_{0}_pull.ipcu%s PUB socket URI: %su%s PULL socket URI: %s(RtinttostpathR2tgetattrthashlibRRR-tto_bytest	hexdigesttformatRtdebugt	__class__t__name__(RTRRRNROt	hash_typetid_hash((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt
__load_uris0			,		cC@s9|dkrdS|j|�}|jj||g�dS(u�
        Subscribe to events matching the passed tag.

        If you do not subscribe to a tag, events will be discarded by calls to
        get_event that request a different tag. In contexts where many different
        jobs are outstanding it is important to subscribe to prevent one call
        to get_event from discarding a response required by a subsequent call
        to get_event.
        N(R<t_get_match_funcRPR+(RTRt
match_typet
match_func((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt	subscribeFs
c@s�|dkrdS|j|�}|jj||g�|j}g|_x@|D]8�t�fd�|jD��rN|jj��qNqNWdS(uA
        Un-subscribe to events matching the passed tag.
        Nc3@s(|]\}}|�d|�VqdS(utagN((t.0tptagtpmatch_func(tevt(s4/usr/lib/python2.7/site-packages/salt/utils/event.pys	<genexpr>bs(R<RjRPtremoveRQtanyR+(RTRRkRlt
old_events((Rqs4/usr/lib/python2.7/site-packages/salt/utils/event.pytunsubscribeUs		
c	@s��jr
tS�jr�tjjj�j��x�jdkretj
jj�j
d�j��_ny)�jj��fd��t�_Wntk
r�nXWdQXn?�jdkr�tj
jj�j
d�j��_nt�_�jS(u2
        Establish the publish connection
        Rc@s�jjd��S(Nttimeout(RDtconnect((RTRv(s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt<lambda>usN(RBRAR=RRtasynchronoustcurrent_ioloopRRDR<RtipctIPCMessageSubscriberRNtrun_syncR(RTRv((RTRvs4/usr/lib/python2.7/site-packages/salt/utils/event.pyRSes(				


		cC@s9|js
dS|jj�d|_g|_t|_dS(u?
        Close the publish connection (if established)
        N(RBRDtcloseR<RQR(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt	close_pub�s	
		ic	@s��jr
tS�jr�tjjj�j��x�jdkretj
jj�j
d�j��_ny)�jj��fd��t�_Wntk
r�nXWdQXn?�jdkr�tj
jj�j
d�j��_nt�_�jS(ub
        Establish a connection with the event pull socket
        Default timeout is 1 s
        Rc@s�jjd��S(NRv(RERw((RTRv(s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRx�sN(RCRAR=RRRyRzRRER<RR{tIPCMessageClientROR}R(RTRv((RTRvs4/usr/lib/python2.7/site-packages/salt/utils/event.pytconnect_pull�s(				


		cC@s�|dkr(tjjidd6�}ntjra|jt�\}}}|j|dd�}nQ|jtj	j
jt��\}}}tj	j
j|�}|j|dd�}||fS(Numsgpackuserialtencodinguutf-8(
R<RR9R:RtPY2t	partitiontTAGENDtloadsRR-RaR.(RZtrawR;tmtagtseptmdatatdata((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytunpack�s	'cC@s5|dkr|jd}nt|dj|�d�S(Nuevent_match_typeu_match_tag_{0}(R<RR_Rc(RTRk((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRj�sc@s�|dkr|j�}n|j}g|_d}x�|D]��|�d|�r�|dkrx�}tjd|�q�|jj��q:t�fd�|jD��r�|jj��q:tjd��q:W|S(u	Check the pending_events list for events that match the tag

        :param tag: The tag to search for
        :type tag: str
        :param tags_regex: List of re expressions to search for also
        :type tags_regex: list[re.compile()]
        :return:
        utagu'get_event() returning cached event = %sc3@s(|]\}}|�d|�VqdS(utagN((RnRoRp(Rq(s4/usr/lib/python2.7/site-packages/salt/utils/event.pys	<genexpr>�suMget_event() discarding cached event that no longer has any subscriptions = %sN(R<RjRQRttraceR+RsRP(RTRRlRttret((Rqs4/usr/lib/python2.7/site-packages/salt/utils/event.pyt_check_pending�s			
cC@s
|j|�S(u�
        Check if the event_tag matches the search check.
        Uses startswith to check.
        Return True (matches) or False (no match)
        (t
startswith(t	event_tagt
search_tag((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt_match_tag_startswith�scC@s
|j|�S(u�
        Check if the event_tag matches the search check.
        Uses endswith to check.
        Return True (matches) or False (no match)
        (tendswith(R�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt_match_tag_endswith�scC@s|j|�dkS(u�
        Check if the event_tag matches the search check.
        Uses find to check.
        Return True (matches) or False (no match)
        i(tfind(R�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt_match_tag_find�scC@s|jj|�j|�dk	S(u�
        Check if the event_tag matches the search check.
        Uses regular expression search to check.
        Return True (matches) or False (no match)
        N(RYR(tsearchR<(RTR�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt_match_tag_regex�scC@stj||�S(u�
        Check if the event_tag matches the search check.
        Uses fnmatch to check.
        Return True (matches) or False (no match)
        (tfnmatch(RTR�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt_match_tag_fnmatchsc@s!|dkr|j�}ntj�}||}t}|tkrLd}n|dkrad}nx�|tkrw|s�tj�|kr|tkr�|tkr�Pnt}nyy|jr�|jd|�r�Pn|jjd|�}|dkr�Pn|j	||j
�\}	}
i|
d6|	d6�WnZtk
rIidd6id6Stj
jk
rr|jrk�q�dSntk
r�dSX|�d|�s�t�fd�|jD��r�tjd��|jj��n|rd|tj�}qdqdntjd���SWtjd	|�dS(
NiRvudatautagusalt/event/exitc3@s(|]\}}|�d|�VqdS(utagN((RnRoRp(R�(s4/usr/lib/python2.7/site-packages/salt/utils/event.pys	<genexpr>2su'get_event() caching unwanted event = %suget_event() received = %su3_get_event() waited %s seconds and received nothing(R<RjttimeRRARBRSRDt	read_syncR�R;tKeyboardInterruptR>tiostreamtStreamClosedErrorR
tRuntimeErrorRsRPRR�RQR+(RTtwaitRRltno_blocktstartt
timeout_attrun_onceR�R�R�((R�s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt
_get_event
sR
		(	
	
iuc
	C@s-tjd|�|jst�|j|�}|j||�}|dkrtjj	j
|j���|r�|j}	t
|_x^t
r�y|j||||�}PWq�tjjk
r�|j�|jd|�q�q�Xq�W|	|_n|j||||�}WdQXn|dks|r!|S|dSdS(ud
        Get a single publication.
        If no publication is available, then block for up to ``wait`` seconds.
        Return publication if it is available or ``None`` if no publication is
        available.

        If wait is 0, then block forever.

        tag
            Only return events matching the given tag. If not specified, or set
            to an empty string, all events are returned. It is recommended to
            always be selective on what is to be returned in the event that
            multiple requests are being multiplexed.

        match_type
            Set the function to match the search tag with event tags.
             - 'startswith' : search for event tags that start with tag
             - 'endswith' : search for event tags that end with tag
             - 'find' : search for event tags that contain tag
             - 'regex' : regex search '^' + tag event tags
             - 'fnmatch' : fnmatch tag event tags matching
            Default is opts['event_match_type'] or 'startswith'

            .. versionadded:: 2015.8.0

        no_block
            Define if getting the event should be a blocking call or not.
            Defaults to False to keep backwards compatibility.

            .. versionadded:: 2015.8.0

        Notes:

        Searches cached publications first. If no cached publications are found
        that match the given tag specification, new publications are received
        and checked.

        If a publication is received that does not match the tag specification,
        it is DISCARDED unless it is subscribed to via subscribe() which will
        cause it to be cached.

        If a caller is not going to call get_event immediately after sending a
        request, it MUST subscribe the result to ensure the response is not lost
        should other regions of code call get_event for other purposes.
        uGet event. tag: %sRvNudata(RR�R=tAssertionErrorRjR�R<RRRyRzRR
RAR�R>R�R�RRS(
RTR�RtfullRkR�tauto_reconnectRlR�R
((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR>s,4			
!cC@s}|jst�|js+|j�s+dSn|jjdd�}|dkrPdS|j||j�\}}i|d6|d6S(uJ
        Get the raw event without blocking or any other niceties
        RviudatautagN(	R=R�RBRSR<RDR�R�R;(RTR�R�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytget_event_noblock�s	cC@s}|jst�|js+|j�s+dSn|jjdd�}|dkrPdS|j||j�\}}i|d6|d6S(u�
        Get the raw event in a blocking fashion. This is slower, but it decreases the
        possibility of dropped events.
        RvudatautagN(	R=R�RBRSR<RDR�R�R;(RTR�R�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytget_event_block�s	c	c@sLxEtrG|jd|d|d|d|�}|dkr?qn|VqWdS(uJ
        Creates a generator that continuously listens for events
        RR�RkR�N(RARR<(RTRR�RkR�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytiter_events�s		i�c
	@s�tj|�std��nt|t�sEtdj|���n�js�|d
k	rmt|�d}nd
}�j	d|�s�t
Sntjj�j
�|d<t}tjr��jj|�}n�jj|dt�}tjjj|�jddtdtj�}tjd	||�d
jtjjj|�tjjj|�|g�}tjjj|d���jr�tjjj �j!��Ky �j!j"��fd��Wn#t#k
r�}	tj|	��nXWd
QXn�j!j$�j%j&��tS(u�
        Send a single event into the publisher with payload dict "data" and
        event identifier "tag"

        The default is 1000 ms
        u
Empty tag.u Dict object expected, not '{0}'.i�Rvu_stamptuse_bin_typeumax_event_sizetis_msgpackedu"Sending event: tag = %s; data = %stuutf-8c@s�jj��S(N(REtsend((tmsgRT(s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRx�sN('Rt	text_typet
ValueErrort
isinstanceRRcRCR<tfloatR�Rtdatetimetutcnowt	isoformatR�R�R;tdumpsRARRtdicttrimt	trim_dictRtPY3RRdR2R-RaR=RyRzRR}Rtspawn_callbackRER�(
RTR�RRvt	timeout_sttagendt	dump_datatserialized_datateventtex((R�RTs4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�sH		
	 
cC@s5i|d6|d6dd6dd6}|j|d|�S(u�'
        Send a single event to the master, with the payload "data" and the
        event identifier "tag".

        Default timeout is 1000ms
        utagudataueventsupretagufire_masterN(R<R(RTR�RRvR�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytfire_master�s
cC@se|jdk	r|jj�n|jdk	r>|jj�n|jra|jra|jj�ndS(N(RDR<R~RER=R	R(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytdestroysic	
C@st|dt�r�|d|}t|dt�r�|jd�}t|t�rqt|�|krq||}ni}|d|}q�|jdi�}|j|i�}|d|}n&|d}|jdi�}|d}yx�tj|�D]�\}}||d<|jd�}|jd�tkr�|j|dj	|d|d��|d	|d	<|d
|d
<t|d<dj	|d|d�|d<||d<|d
|d
<|j|t
|d	d|d
d|gd��q�q�WWntk
r�nXdS(u3
        Helper function for fire_ret_load
        ufunuretcodeureturnu_|-uresultu{0}.{1}ii����ujiduidusuccessuError: {0}.{1}uuserusubuerrorujobN(R�tlistR(tlenRt	iteritemstsplitRRRcRR(	RTtloadt	fun_indextfunR�tretcodeRR�ttags((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt_fire_ret_load_specific_fun	sN!







cC@s0|jd�r,|jd�r,t|dt�r	t|dt�rMt}nt}x�tdt|d��D]�}|d|}|r�t|d�|kr|d|r|tkr|j||�qqm|dj|d�rm|tkrm|j||�qmqmWq,|dtkr,|j|�q,ndS(uE
        Fire events based on information in the return load
        uretcodeufuniN(	R(R�R�RARRR�t	SUB_EVENTR�(RTR�tmultifunc_orderedR�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt
fire_ret_load?s 	 "cC@s6|jst�|js&|j�n|jj|�S(uO
        Invoke the event_handler callback each time an event arrives.
        (R=R�RBRSRDt
read_async(RTt
event_handler((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytset_event_handler]s	
cC@s&y|j�Wntk
r!nXdS(N(R�R(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt__del__hs
N($Rft
__module__t__doc__R<RARRUtclassmethodRRRMRmRuRSRR�R�RjR�tstaticmethodR�R�R�R�R�R�RR�R�R�RR�R�R�R�R�R�(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�sJ	3	' 	 
					5J		:	6		R
cB@s&eZdZdedeed�ZRS(u�
    Warning! Use the get_event function or the code will not be
    RAET compatible
    Create a master event management object
    cC@s8tt|�jd||d|d|d|d|�dS(NumasterRRR	R
(tsuperR
RU(RTRRRRR	R
((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRUwsN(RfR�R�R<RARRU(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR
qstLocalClientEventcB@seZdZRS(u�
    Warning! Use the get_event function or the code will not be
    RAET compatible
    This class is just used to differentiate who is handling the events,
    specially on logs, but it's the same as MasterEvent.
    (RfR�R�(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR��stNamespacedEventcB@s#eZdZdd�Zd�ZRS(uG
    A wrapper for sending events within a specific base namespace
    cC@s||_||_||_dS(N(R�R4t
print_func(RTR�R4R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRU�s		cC@sH|jj|t|d|j��|jdk	rD|j||�ndS(NR4(R�RRR4R�R<(RTR�R((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s"N(RfR�R�R<RUR(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR��stMinionEventcB@s eZdZeded�ZRS(u�
    Warning! Use the get_event function or the code will not be
    RAET compatible
    Create a master event management object
    cC@sAtt|�jdd|jd�d|d|d|d|�dS(NuminionRusock_dirRRRR
(R�R�RUR((RTRRRR
((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRU�sN(RfR�R�RAR<RRU(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR��stAsyncEventPublishercB@s5eZdZdd�Zd�Zd�Zd�ZRS(u�
    An event publisher class intended to run in an ioloop (within a single process)

    TODO: remove references to "minion_event" whenever we need to use this for other things
    cC@s�tjjj�|_|jd}|jj|�|pGtjjj	�|_
t|_t
t|jd�}|tjjj|jd��j�d }tjj|jddj|��}tjj|�r�tj|�ntjj|jddj|��}tjj|�r&tj|�n|jddkrbt|jd	�}t|jd
�}	n|}|}	tjd|jj|�tjd|jj|	�|jd}
tjj|
�s`ytj|
d
�Wq`t k
r\}tj!d|�|
|kr�ntjj|�s]ytj|d
�WqYt k
rU}tj!d|��qYXq]q`Xntj"j#j$|j|d|j
�|_%tj"j#j&|	d|j
d|j'�|_(tj)d|	�tjj*j+d��|j%j,�|j(j,�WdQXdS(Nusock_diru	hash_typeuidi
uminion_event_{0}_pub.ipcuminion_event_{0}_pull.ipcuipc_modeutcputcp_pub_portu
tcp_pull_portu%s PUB socket URI: %su%s PULL socket URI: %si�uCould not create SOCK_DIR: %sRtpayload_handleruStarting pull socket on %si(-RRFRIRHRRJR>R?R@tcurrentRRt_closingR_R`RR-RaRbR]R^R2RctexiststunlinkR\RRdReRftisdirtmakedirstOSErrorterrorRR{tIPCMessagePublishert	publishertIPCMessageServerthandle_publishtpullertinfotfilest	set_umaskR�(RTRRtdefault_minion_sock_dirRgRhtepub_sock_pathtepull_sock_pathtepub_urit	epull_uritminion_sock_dirR%((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRU�sh
	,	
	
		
	
cC@sDy|jj|�|SWn%tk
r?tjddt�dSXdS(ua
        Get something from epull, publish it out epub, and return the package (or None)
        u,Unexpected error while polling minion eventstexc_infoN(R�tpublishRRtcriticalRAR<(RTtpackageR7((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s
cC@sX|jr
dSt|_t|d�r5|jj�nt|d�rT|jj�ndS(Nu	publisherupuller(R�RAR)R�R~R�(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR~
s		cC@s|j�dS(N(R~(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�sN(RfR�R�R<RUR�R~R�(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR��s
L	
		tEventPublishercB@sVeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(	uk
    The interface that takes master events and republishes them out to anyone
    who wants to listen
    cK@sHtt|�j|�tjjj�|_|jj|�t	|_
dS(N(R�R�RURRFRGRHRRJRR�(RTRtkwargs((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRUscC@s2t|_|j|dd|dd|d�dS(Nuoptst	log_queueu	log_queuetlog_queue_levelulog_queue_level(RAt	_is_childRU(RTtstate((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt__setstate__(s
	

cC@s"i|jd6|jd6|jd6S(Nuoptsu	log_queueulog_queue_level(RR�R(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt__getstate__0s

cC@s�tjjj|jj�tjj�|_	tjj
j|j	��y|jddkr�t
|jd�}t
|jd�}n8tjj|jdd�}tjj|jdd�}tjjj|j|d|j	�|_tjjj|d|j	d	|j�|_tjjjd
��u|jj�|jj�|jddkr�|jdsf|jdr�tjtjj|jdd�d
�nWdQXt||jdd�|j	j�WdQXdS(u:
        Bind the pub and pull sockets for events
        uipc_modeutcputcp_master_pub_portutcp_master_pull_portusock_dirumaster_event_pub.ipcumaster_event_pull.ipcRR�iu
publisher_aclu
external_authi�Ntexitpriorityi(RRtprocesstappendproctitleReRfR>R?R@RRyRzRR\R]R^R2RR{R�R�R�R�R�R�R�R�tchmodRR~(RTR�R�((s4/usr/lib/python2.7/site-packages/salt/utils/event.pytrun7s<	
		
		



 cC@sDy|jj|�|SWn%tk
r?tjddt�dSXdS(ua
        Get something from epull, publish it out epub, and return the package (or None)
        u,Unexpected error while polling master eventsR�N(R�R�RRR�RAR<(RTR�R7((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�gs
cC@sw|jr
dSt|_t|d�r5|jj�nt|d�rT|jj�nt|d�rs|jj�ndS(Nu	publisherupulleruio_loop(R�RAR)R�R~R�R(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR~ts		cC@s'|j�tt|�j||�dS(N(R~R�R�t_handle_signals(RTtsignumtsigframe((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR
s
cC@s|j�dS(N(R~(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR��s(RfR�R�RURRR	R�R~R
R�(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s					0	
		tEventReturncB@sVeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(	u�
    A dedicated process which listens to the master event bus and queues
    and forwards events to the specified returner.
    cK@s�ddl}tt|�j|�||_|jd|_|jjdd�|_|jj�}d|d<|j	j
|�|_	g|_t|_
dS(u[
        Initialize the EventReturn system

        Return an EventReturn instance
        iNuevent_return_queueuevent_return_queue_max_secondsulocalufile_client(tsalt.minionR�R
RURtevent_return_queueR(tevent_return_queue_max_secondsRHtminiontMasterMiniontevent_queueRtstop(RTRR�Rtlocal_minion_opts((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRU�s	
	cC@s2t|_|j|dd|dd|d�dS(NuoptsR�u	log_queueRulog_queue_level(RARRU(RTR((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s
	

cC@s"i|jd6|jd6|jd6S(Nuoptsu	log_queueulog_queue_level(RR�R(RT((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s

cC@s<|jr|j�nt|_tt|�j||�dS(N(Rtflush_eventsRARR�R
R
(RTRR((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR
�s	
	cC@s�t|jdt�r]x~|jdD]2}tjd|�dj|�}|j|�q$Wn:tjd|jd�dj|jd�}|j|�|j2dS(Nuevent_returnu'Calling event returner %s, one of many.u{0}.event_returnu/Calling event returner %s, only one configured.(R�RR�RRdRct_flush_event_singleR(RTtrtevent_return((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s	
cC@s�||jjkr�y|jj||j�Wq�tk
r}}tjd||�tjtjkr~tj	d|j�q~q�Xntjd|�dS(Nu;Could not store events - returner '%s' raised exception: %su'Event data that caused an exception: %su>Could not store return for event(s) - returner '%s' not found.(
Rt	returnersRRRR�tleveltloggingtDEBUGRd(RTRR%((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�s	
		cC@s�tjjj|jj�tdd|jdt�|_	|j	j
dt�}|j	jid�zLd}x?|D]7}|ddkr�t|_
n|j|�r�|jj|�nt}|jdkrOtjj�}|s�|}n||j}|dkrtjd	|�n||jkr0t}d}nt}|rOtjd
�qOnt|j�|jksm|r�tjdt|j��|j�d}n|j
roPqoqoWWd|jr�tjdt|j��|j�nXdS(
u9
        Spin up the multiprocess event returner
        umasterRRR�usalt/event_listen/startutagusalt/event/exitiu(Oldest event in queue is %s seconds old.u9Oldest event has been in queue too long, will flush queueuFlushing %s events.N(RRRRReRfRRRAR�R�RR<Rt_filterRR+RRR�tnowtsecondsRRdR�RR(RTteventstoldesteventR�ttoo_long_in_queuetrightnowtage_in_seconds((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR	�sD
	
	
			cC@s�|d}|jdr t}nt}x1|jdD]"}tj||�r4t}Pq4q4Wx1|jdD]"}tj||�rht}PqhqhW|S(u�
        Take an event and run it through configured filters.

        Returns True if event should be stored, else False
        utaguevent_return_whitelistuevent_return_blacklist(RRRAR�(RTR�RR�twhitelist_matchtblacklist_match((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRs

	(RfR�R�RURRR
RRR	R(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR
�s							9t	StateFirecB@s/eZdZdd�Zdd�Zd�ZRS(u�
    Evaluate the data from a state run and fire events on the master and minion
    for each returned chunk that is not "green"
    This object is made to only run on a minion
    cC@s7||_|s*tjj|j�|_n	||_dS(N(RRtcrypttSAuthtauth(RTRR+((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRU0s	cC@s�i}|r|j|�n|ji|jdd6|d6|d6dd6|jjd�d6�tjjjj|j�}z)y|j	|�Wnt
k
r�nXWd|j�XtS(	u�
        Fire an event off on the master server

        CLI Example:

        .. code-block:: bash

            salt '*' event.fire_master 'stuff to be in the event' 'tag'
        uidutagudatau
_minion_eventucmdRutokN(
RJRR+t	gen_tokenRRtclientt
ReqChanneltfactoryR�RR~RA(RTR�RtpreloadR�tchannel((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR�7s"
	
c@si|jdd6gd6dd6}x�t�d�fd��D]�}�|drg�|drgq>nd	jtj�|d��|dr�d
nd�}|dji|d6�|d
6�q>Wtjjj	j
|j�}z)y|j|�Wntk
rnXWd|j
�XtS(u�
        Pass in a state "running" dict, this is the return dict from a state
        call. The dict will be processed and fire events.

        By default yellows and reds fire events on the master and minion, but
        this can be configured.
        uidueventsu
_minion_eventucmdtkeyc@s�|jdd�S(Nu__run_num__i(R((tk(trunning(s4/usr/lib/python2.7/site-packages/salt/utils/event.pyRxcsuresultuchangesu
state_{0}_{1}uTrueuFalseutagudataN(RtsortedRcRR�R+RRR-R.R/R�RR~RA(RTR4R�tstagRR1((R4s4/usr/lib/python2.7/site-packages/salt/utils/event.pytfire_runningVs,


N(RfR�R�R<RUR�R7(((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyR(*s(DR�t
__future__RRRR]R�R�R`RR�tcollections.abcRtImportErrortcollectionstmultiprocessing.utilRtsalt.ext.six.movesRtsalt.extRttornado.ioloopR>ttornado.iostreamtsalt.configRtsalt.payloadtsalt.utils.asynchronoustsalt.utils.cachetsalt.utils.dicttrimtsalt.utils.filestsalt.utils.platformtsalt.utils.processtsalt.utils.stringutilstsalt.utils.zeromqtsalt.log.setuptsalt.defaults.exitcodestsalt.transport.ipctsalt.transport.clientt	getLoggerRfRR�R0R�R1tSALTR'R<RARRRR&RtobjectRR
R�R�R�R�RRt$SignalHandlingMultiprocessingProcessR�R
R((((s4/usr/lib/python2.7/site-packages/salt/utils/event.pyt<module>3s|

"���	
lm�

Zerion Mini Shell 1.0