File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/event.cpython-310.pyc
o
�N�g� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
mZ ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlmZ e�e�Z dZ!dZ"dZ#dZ$d d
ddd
dddddd�
Z% d1dd�Z&d2dd�Z'd3dd�Z(dde$fdd�Z)G dd � d �Z*G d!d"� d"e*�Z+G d#d$� d$e+�Z,G d%d&� d&�Z-G d'd(� d(e*�Z.G d)d*� d*�Z/G d+d,� d,e
j0j1j2�Z3G d-d.� d.e
j0j1j2�Z4G d/d0� d0�Z5dS )4a�
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'
� N)�MutableMapping)�SaltInvocationError)zstate.highstatez state.slsz
�/�salt�auth�job�key�minion�syndic�run�wheel�cloud�
fileserver�queue)
r r r r r
r r r
r r TFc C sR |r
t jj�dd� |p|d }| dkrt||||||d�S t| ||||||d�S )aG
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.
ZChlorinez�The 'transport' kwarg has been deprecated and it will be removed in the Chlorine release, as such, its usage is no longer required.�sock_dir�master��listen�io_loop� keep_loop�raise_errors)r �utilsZversionsZ
warn_until�MasterEvent� SaltEvent)�noder � transport�optsr r r r � r �D/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/event.py� get_eventj s0 ���r c C s t || |||d�S )zA
Return an event object suitable for the named transport
)r r r )r )r r r r r r r r �get_master_event� s
�r � c
C s� z|dg}W n
t y Y dS w t||�}zt| | d dd�}|j||d� W dS tyD } zt�d|||� W Y d}~dS d}~ww )zO
Fire an event containing the arguments passed to an orchestration job
�argsr F)r )�tagz-Failed to fire args event %s with data %s: %sN)� NameError�tagifyr �
fire_event� Exception�log�warning)r �jidZtag_data�prefixZ
tag_suffixr# Z_event�excr r r � fire_args� s �
���r- c C s� |t �||�g}t| d�r|�| � n|�| � t|�D ]"\}}z
tjj� || �||<