HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/cloudinit/reporting/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/reporting/__pycache__/handlers.cpython-311.pyc
�

܍~c�9��L�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m	Z	ddlm
Z
ddlmZddl
mZddl
mZmZddlmZeje��ZGd�d	e��ZGd
�dej���ZGd
�de��ZGd�de��ZGd�de��ZGd�de��ZeeeeeefZe��Z e �!de��e �!de��e �!de��e �!de��dS)�N)�datetime)�Event)�Union)�log)�
url_helper�util)�DictRegistryc��eZdZdS)�ReportExceptionN)�__name__�
__module__�__qualname__���>/usr/lib/python3/dist-packages/cloudinit/reporting/handlers.pyrrs�������Drrc�8�eZdZdZejd���Zd�ZdS)�ReportingHandlerz�Base class for report handlers.

    Implement :meth:`~publish_event` for controlling what
    the handler does with an event.
    c��dS)zPublish an event.Nr��self�events  r�
publish_eventzReportingHandler.publish_event"����rc��dS)z0Ensure ReportingHandler has published all eventsNr�rs r�flushzReportingHandler.flush&rrN)rr
r�__doc__�abc�abstractmethodrrrrrrrsL��������	�� � ��� �?�?�?�?�?rr)�	metaclassc�*��eZdZdZd�fd�	Zd�Z�xZS)�
LogHandlerzBPublishes events to the cloud-init log at the ``DEBUG`` log level.�DEBUGc�T��tt|�����t|t��rnb|}	tt|�����}n7#t$r*t�
d|��tj}YnwxYw||_dS)Nzinvalid level '%s', using WARN)
�superr"�__init__�
isinstance�int�getattr�logging�upper�	Exception�LOG�warning�WARN�level)rr0�input_level�	__class__s   �rr&zLogHandler.__init__-s����
�j�$���(�(�*�*�*��e�S�!�!�	%���K�
%��������7�7�����
%�
%�
%����<�k�J�J�J������
%������
�
�
s�'A*�*1B�Bc���tjd�dd|j|jg����}|�|j|�����dS)N�.�	cloudinit�	reporting)r*�	getLogger�join�
event_type�namerr0�	as_string)rr�loggers   rrzLogHandler.publish_event:sY���"��H�H�k�;��0@�%�*�M�N�N�
�
��	�
�
�4�:�u���0�0�1�1�1�1�1r)r#)rr
rrr&r�
__classcell__�r2s@rr"r"*sR�������L�L�������2�2�2�2�2�2�2rr"c��eZdZdZd�ZdS)�PrintHandlerzPrint the event as a string.c�H�t|�����dS�N)�printr;rs  rrzPrintHandler.publish_eventDs ��
�e�o�o��� � � � � rN)rr
rrrrrrr@r@As)������&�&�!�!�!�!�!rr@c�>��eZdZ						d�fd�	Zd�Zd�Zd�Z�xZS)�WebHookHandlerNc� ��tt|�����t||||g��r%t	j||||���}|j|_ntj|_||_||_||_	tj��|_t��|_tj��|_t#j|j���|_d|j_|j���dS)N)�consumer_key�	token_key�token_secret�consumer_secret��targetT)r%rEr&�anyr�OauthUrlHelper�readurl�endpoint�timeout�retriesr�fetch_ssl_details�ssl_detailsr�flush_requested�queue�Queue�	threading�Thread�process_requests�event_processor�daemon�start)
rrPrGrHrIrJrQrR�oauth_helperr2s
         �rr&zWebHookHandler.__init__Is����	�n�d�#�#�,�,�.�.�.���i���G�H�H�		.�%�4�)�#�)� /�	���L�(�/�D�L�L�%�-�D�L� ��
��������1�3�3���$�w�w����[�]�]��
�(�/�t�7L�M�M�M���&*���#���"�"�$�$�$�$�$rc���d}	|j���r�|dkr�t�d��|j���sK|j���|j���|j����Kd}|j�d���}	|�	|d|d|d|d|dd	�
��d}n>#t$r1}t�d|d|��|dz
}Yd}~nd}~wwxYw|j���n#|j���wxYw��o)NrT�zNMultiple consecutive failures in WebHookHandler. Cancelling all queued events.��block���F)�datarQrRrT�log_req_respz0Failed posting event: %s. This was caused by: %s)rU�is_setr-r.rV�empty�
get_nowait�	task_done�getrOr,)r�consecutive_failed�args�es    rrZzWebHookHandler.process_requestsjs�����"	'��#�*�*�,�,�

'�1C�a�1G�1G����4�����*�*�*�,�,�+��J�)�)�+�+�+��J�(�(�*�*�*��*�*�*�,�,�+�&'�"��:�>�>��>�-�-�D�
'������G��a�� ��G� ��G� $�Q��!&�
����&'�"�"���
(�
(�
(����F���G�����
#�a�'�"�"�"�"�"�"�����

(�����
�$�$�&�&�&�&���
�$�$�&�&�&�&����E"	's0�?;C;�:E�;
D6�'D1�,E�1D6�6E�E.c��|���}t�d|j|��|j�|jt
j|��|j|j	|j
f��dS)NzQueuing POST to %s, data: %s)�as_dictr-�debugrPrV�put�json�dumpsrQrRrT)rr�
event_datas   rrzWebHookHandler.publish_event�s{���]�]�_�_�
��	�	�*��M��	
�	
�	
�
	
�
����
��
�:�&�&������ �
�	
�	
�	
�	
�	
rc���|j���t�d��|j���|j���dS)Nz(WebHookHandler flushing remaining events)rU�setr-rrrVr8�clearrs rrzWebHookHandler.flush�sW���� � �"�"�"��	�	�<�=�=�=��
��������"�"�$�$�$�$�$r)NNNNNN)rr
rr&rZrrr=r>s@rrErEHs��������������%�%�%�%�%�%�B$'�$'�$'�L
�
�
�"%�%�%�%�%�%�%rrEc���eZdZdZdZdZdZeezZdZdZ	dZ
dZd	Zd
Z
dZe
df�fd
�	Zed���Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z�xZS)�HyperVKvpReportingHandlera,
    Reports events to a Hyper-V host using Key-Value-Pair exchange protocol
    and can be used to obtain high level diagnostic information from the host.

    To use this facility, the KVP user-space daemon (hv_kvp_daemon) has to be
    running. It reads the kvp_file when the host requests the guest to
    enumerate the KVP's.

    This reporter collates all events for a module (origin|name) in a single
    json string in the dictionary.

    For more information, see
    https://technet.microsoft.com/en-us/library/dn798287.aspx#Linux%20guests
    iii�
CLOUD_INIT�msg�result�msg_i)�,�:z/var/lib/hyperv/.kvp_pool_1FNc����tt|�����||_t�|j��||_t
j��|_|�	��|_
d�|j|j
��|_
tj|j���|_d|j_|j���dS)Nz{0}|{1}rKT)r%r{r&�_kvp_file_path�_truncate_guest_pool_file�_event_typesrVrW�q�_get_incarnation_no�incarnation_no�format�EVENT_PREFIX�event_key_prefixrXrY�_publish_event_routine�publish_threadr\r])r�
kvp_file_path�event_typesr2s   �rr&z"HyperVKvpReportingHandler.__init__�s����
�'��.�.�7�7�9�9�9�+���!�;�;���	
�	
�	
�(���������"�6�6�8�8��� )� 0� 0���t�2�!
�!
���(�.��.�
�
�
���&*���"���!�!�#�#�#�#�#rc��|jrdStj��ttj����z
}	t
j�|��|kr)t|d��5	ddd��n#1swxYwYn9#ttf$r%}t�d|��Yd}~nd}~wwxYwd|_dS#d|_wxYw)a
        Truncate the pool file if it has not been truncated since boot.
        This should be done exactly once for the file indicated by
        KVP_POOL_FILE_GUEST constant above. This method takes a filename
        so that we can use an arbitrary file during unit testing.
        Since KVP is a best-effort telemetry channel we only attempt to
        truncate the file once and only if the file has not been modified
        since boot. Additional truncation can lead to loss of existing
        KVPs.
        N�wz$failed to truncate kvp pool file, %sT)
�_already_truncated_pool_file�time�floatr�uptime�os�path�getmtime�open�OSError�IOErrorr-r.)�cls�kvp_file�	boot_timeros    rr�z3HyperVKvpReportingHandler._truncate_guest_pool_file�s+���+�	��F��I�K�K�%���
�
�"6�"6�6�	�	4��w����)�)�I�5�5��(�C�(�(��������������������������!�	C�	C�	C��K�K�>��B�B�B�B�B�B�B�B�����	C����04�C�,�,�,��t�C�,�3�3�3�3sS�3B�2B�4B�B�B�B�B�C�C�B=�8C�=C�C�	Cc���tj��}	ttj��t	|��z
��S#t
$rt�d|��YdSwxYw)z�
        use the time passed as the incarnation number.
        the incarnation number is the number which are used to
        distinguish the old data stored in kvp and the new data.
        z"uptime '%s' not in correct format.r)rr�r(r�r��
ValueErrorr-r.)r�
uptime_strs  rr�z-HyperVKvpReportingHandler._get_incarnation_no�sl���[�]�]�
�	��t�y�{�{�U�:�%6�%6�6�7�7�7���	�	�	��K�K�<�j�I�I�I��1�1�	���s�/A�%A.�-A.c#�K�t|jd��5}tj|tj��|�|��|�|j��}t|��|jkrK|�	|��}|V�|�|j��}t|��|jk�Ktj|tj
��ddd��dS#1swxYwYdS)z-iterate the kvp file from the current offset.�rbN)r�r��fcntl�flock�LOCK_EX�seek�read�HV_KVP_RECORD_SIZE�len�_decode_kvp_item�LOCK_UN)r�offset�f�record_data�kvp_items     r�
_iterate_kvpsz'HyperVKvpReportingHandler._iterate_kvps�s%����
�$�%�t�
,�
,�	*���K��5�=�)�)�)�
�F�F�6�N�N�N��&�&��!8�9�9�K��k�"�"�d�&=�=�=��0�0��=�=�������f�f�T�%<�=�=���k�"�"�d�&=�=�=�
�K��5�=�)�)�)�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*����	*�	*�	*�	*�	*�	*s�CC6�6C:�=C:c�r�d�|j|j|jt	j����S)z�
        the event key format is:
        CLOUD_INIT|<incarnation number>|<event_type>|<event_name>|<uuid>
        [|subevent_index]
        z{0}|{1}|{2}|{3})r�r�r9r:�uuid�uuid4rs  r�
_event_keyz$HyperVKvpReportingHandler._event_keys3��!�'�'��!�5�#3�U�Z�����
�
�	
rc��tjd|j|jfz|�d��|�d����}|S)Nz%ds%ds�utf-8)�struct�pack�HV_KVP_EXCHANGE_MAX_KEY_SIZE�HV_KVP_EXCHANGE_MAX_VALUE_SIZE�encode)r�key�valuerfs    r�_encode_kvp_itemz*HyperVKvpReportingHandler._encode_kvp_itemsS���{���1��3��
�

�J�J�w����L�L��!�!�
�
���rc�n�t|��}||jkr(td�||j�����|d|j��d���d��}||j|j��d���d��}||d�S)Nz$record_data len not correct {0} {1}.rr��)r�r�)r�r�rr�r��decode�strip)rr��record_data_len�k�vs     rr�z*HyperVKvpReportingHandler._decode_kvp_item!s����k�*�*���d�5�5�5�!�6�=�=�#�T�%<�����
�
��D�=�=�>�
�V�G�_�_�
�U�6�]�]�	
�
��1�D�4K�K�
��V�G�_�_�
�U�6�]�]�	
��1�%�%�%rc�:�t|jd��5}tj|tj��|D]}|�|���|���tj|tj��ddd��dS#1swxYwYdS)N�ab)r�r�r�r�r��writerr�)rr�r�rfs    r�_append_kvp_itemz*HyperVKvpReportingHandler._append_kvp_item8s���
�$�%�t�
,�
,�	*���K��5�=�)�)�)�#�
�
������
�
�
�
�
�G�G�I�I�I��K��5�=�)�)�)�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*����	*�	*�	*�	*�	*�	*s�A-B�B�Bc	�^�||j=tj|��}|dt|��dz
�}d}g}d|jzdz}	|||j<d||j<tj||j���}|jt|��z
dz
}	|�|d	�|j|d|	��
����}
d�||��}|�	|�
||
����|dz
}||	d�}t|��dkrn��|S)Nrcr�"z":""T���
separators�z"{key}":"{desc}")r��descz{}|{})�MSG_KEYrtrur��DESC_IDX_KEY�JSON_SEPARATORS�HV_KVP_AZURE_MAX_VALUE_SIZE�replacer��appendr�)rr��	meta_data�description�des_in_json�i�result_array�message_place_holder�data_without_desc�
room_for_descr��subkeys            r�_break_downz%HyperVKvpReportingHandler._break_down@se���d�l�#��j��-�-��!�!�s�;�'7�'7�!�';�"<�=��
����"�T�\�1�F�:��	�+,�I�d�'�(�&(�I�d�l�#� $�
��d�&:�!�!�!���0�3�7H�3I�3I�I�A�M�
�&�-�-�$�"�)�)���;�~�
�~�+F�*�����E��^�^�C��+�+�F����� 5� 5�f�e� D� D�E�E�E�
��F�A�%�m�n�n�5�K��;���1�$�$��)	�*�rc���|�|��}|j|jtj|j�����dzd�}t||j��r|j	||j<|j
||j<tj
||j���}t|��|jkr|�|||j
��S|�||��}|gS)z�
        encode the event into kvp data bytes.
        if the event content reaches the maximum length of kvp value.
        then it would be cut to multiple slices.
        �Z)r:�type�tsr�)r�r:r9r�utcfromtimestamp�	timestamp�	isoformat�hasattr�
RESULT_KEYr~r�r�rtrur�r�r�r�r�)rrr�r�r�rfs      r�
_encode_eventz'HyperVKvpReportingHandler._encode_event^s����o�o�e�$�$���J��$��)�%�/�:�:�D�D�F�F��L�	
�
�	��5�$�/�*�*�	6�).��I�d�o�&�"'�"3�	�$�,���
�9��1E�F�F�F���u�:�:��8�8�8��#�#�C��E�4E�F�F�F��(�(��e�4�4�D��6�Mrc�x�	d}	|j�d���}|dz
}g}|�S||�|��z
}	|j�d���}|dz
}n#tj$rd}YnwxYw|�S	|�|��n9#ttf$r%}t�	d|��Yd}~nd}~wwxYwt|��D]}|j����n0#t|��D]}|j����wxYwn#t$rYdSwxYw��:)NTrrarcFz failed posting events to kvp, %s)
r�rlr�rV�Emptyr�r�r�r-r.�rangerk�EOFError)r�items_from_queuer�encoded_dataro�_s      rr�z0HyperVKvpReportingHandler._publish_event_routineys���	� ��
���
�
��
�.�.�� �A�%� �!���'� �D�$6�$6�u�$=�$=�=�L�%� $��
�
��
� 7� 7��(�A�-�(�(�� �;�%�%�%� $����%����
�'�+��)�)�,�7�7�7�7����)�G�G�G��K�K� B�A�F�F�F�F�F�F�F�F�����G����#�#3�4�4�+�+����(�(�*�*�*�*�+��U�#3�4�4�+�+����(�(�*�*�*�*�+����+���
�
�
����
����/	sq�<D)� A#�"D)�#A7�4D)�6A7�7D)�=B�C8�C	�$C�?C8�C	�	C8�,D)�8-D%�%D)�)
D7�6D7c�h�|jr|j|jvr|j�|��dSdSrB)r�r9r�rsrs  rrz'HyperVKvpReportingHandler.publish_event�s@��� �	�E�$4��8I�$I�$I��F�J�J�u������%J�$Irc�l�t�d��|j���dS)Nz0HyperVReportingHandler flushing remaining events)r-rrr�r8rs rrzHyperVKvpReportingHandler.flush�s(���	�	�D�E�E�E�����
�
�
�
�
r)rr
rrr�r�r�r�r�r�r�r�r��KVP_POOL_FILE_GUESTr�r&�classmethodr�r�r�r�r�r�r�r�r�r�rrr=r>s@rr{r{�sU�������
�
�&*�"�"&��#&� �$�'E�E�� �L��G��J��L� �O�7��#(� �%8�d�$�$�$�$�$�$�&�4�4��[�4�.���
*�
*�
*�
�
�
�
�
�
�&�&�&�.*�*�*����<���6���<���������rr{rrC�webhook�hyperv)"rr�rtr�rVr�rXr�r�rr�typingrr5rr*rr�cloudinit.registryr	r7rr-r,r�ABCMetarr"r@rEr{�HandlerType�available_handlers�
register_itemrrr�<module>r�s����
�
�
���������	�	�	�	�����
�
�
�
�������������������������������$�$�$�$�$�$�&�&�&�&�&�&�&�&�+�+�+�+�+�+��g���!�!��	�	�	�	�	�i�	�	�	�?�?�?�?�?���?�?�?�?�2�2�2�2�2�!�2�2�2�.!�!�!�!�!�#�!�!�!�]%�]%�]%�]%�]%�%�]%�]%�]%�@u�u�u�u�u� 0�u�u�u�t������	���"�\�^�^��� � ��
�3�3�3�� � ��,�7�7�7�� � ��N�;�;�;�� � ��+D�E�E�E�E�Er