관리-도구
편집 파일: events.cpython-39.pyc
a ����'�Dg$����������������������@���s����d�Z�ddlZddlZddlZddlZddlmZ�ddlm Z �ddl mZmZ�ddl mZ�dZdZd Ze�e�ZG�d d��de�Zed�ZG�d d��d�ZG�dd��de�Zddd�Zejdfdd�Zdd��ZG�dd��d�Zdd��ZdS�)z� events for reporting. The events here are designed to be used with reporting. They can be published to registered handlers with report_event. �����N)�List)�performance)�available_handlers�instantiated_handler_registry)�ReportingHandlerZfinish�start� cloudinitc�������������������@���s���e�Zd�Zdd��ZdS�)�_namesetc�����������������C���s���||�v�r|S�t�d|���d�S�)Nz%s not a valid value)�AttributeError)�self�name��r ����>/usr/lib/python3.9/site-packages/cloudinit/reporting/events.py�__getattr__ ���s����z_nameset.__getattr__N)�__name__� __module__�__qualname__r���r ���r ���r ���r���r ������s���r ���)�SUCCESS�WARN�FAILc�������������������@���s.���e�Zd�ZdZedfdd�Zdd��Zdd��ZdS�) �ReportingEventz"Encapsulation of event formatting.Nc�����������������C���s2���||�_�||�_||�_||�_|d�u�r(t���}||�_d�S��N)� event_typer����description�origin�time� timestamp)r���r���r���r���r���r���r ���r ���r����__init__,���s����zReportingEvent.__init__c�����������������C���s���d��|�j|�j|�j�S�)z"The event represented as a string.z {0}: {1}: {2})�formatr���r���r����r���r ���r ���r���� as_string<���s�����zReportingEvent.as_stringc�����������������C���s���|�j�|�j|�j|�j|�jd�S�)z&The event represented as a dictionary.�r���r���r���r���r���r!���r���r ���r ���r����as_dictB���s�����zReportingEvent.as_dict)r���r���r����__doc__�DEFAULT_EVENT_ORIGINr���r ���r"���r ���r ���r ���r���r���)���s���� r���c�����������������������s8���e�Zd�Zejdf��fdd� Zdd��Z��fdd�Z���ZS�)�FinishReportingEventNc��������������������sD���t�t|���t||��||�_|d�u�r&g�}||�_|tvr@td|���d�S�)NzInvalid result: %s)�superr%���r����FINISH_EVENT_TYPE�result� post_files�status� ValueError)r���r���r���r(���r)����� __class__r ���r���r���N���s���� �zFinishReportingEvent.__init__c�����������������C���s���d��|�j|�j|�j|�j�S�)Nz{0}: {1}: {2}: {3})r���r���r���r(���r���r���r ���r ���r���r ���[���s�����zFinishReportingEvent.as_stringc��������������������s0���t�t|�����}|�j|d<�|�jr,t|�j�|d<�|S�)z'The event represented as json friendly.r(����files)r&���r%���r"���r(���r)����_collect_file_info)r����datar,���r ���r���r"���`���s ���� zFinishReportingEvent.as_dict) r���r���r���r*���r���r���r ���r"���� __classcell__r ���r ���r,���r���r%���M���s���� r%���c��������������������sT�����si�����fdd�t�j���D��}ttj����}|D�]}t|�|v�rDq2|�|���q2dS�)a���Report an event to all registered event handlers except those whose type is in excluded_handler_types. This should generally be called via one of the other functions in the reporting module. :param excluded_handler_types: List of handlers types to exclude from reporting the event to. :param event_type: The type of the event; this should be a constant from the reporting module. c��������������������s���h�|�]\}}|��v�r|�qS�r ���r ���)�.0Z hndl_typeZhndl_cls��excluded_handler_typesr ���r���� <setcomp>y���s����zreport_event.<locals>.<setcomp>N)r���Zregistered_items�items�listr����values�typeZ publish_event)�eventr4���Zexcluded_handler_classes�handlersZhandlerr ���r3���r����report_eventi���s���� ��r<���c�����������������C���s���t�|�|||d�}t|�S�)zVReport a "finish" event. See :py:func:`.report_event` for parameter details. �r)���)r%���r<���)� event_name�event_descriptionr(���r)���r:���r ���r ���r����report_finish_event����s�����r@���c�����������������C���s���t�t|�|�}t|�S�)a'��Report a "start" event. :param event_name: The name of the event; this should be a topic which events would share (e.g. it will be the same for start and finish events). :param event_description: A human-readable description of the event that has occurred. )r����START_EVENT_TYPEr<���)r>���r?���r:���r ���r ���r����report_start_event����s���� rB���c�������������������@���s����e�Zd�ZdZdddejdfdd�Zdd��Zdd��Zd d ��Z e dd���Zejd d���Ze dd���Z e jdd���Z dd��Zdd��ZdS�)�ReportEventStackaK��Context Manager for using :py:func:`report_event` This enables calling :py:func:`report_start_event` and :py:func:`report_finish_event` through a context manager. :param name: the name of the event :param description: the event's description, passed on to :py:func:`report_start_event` :param message: the description to use for the finish event. defaults to :param:description. :param parent: :type parent: :py:class:ReportEventStack or None The parent of this event. The parent is populated with results of all its children. The name used in reporting is <parent.name>/<name> :param reporting_enabled: Indicates if reporting events should be generated. If not provided, defaults to the parent's value, or True if no parent is provided. :param result_on_exception: The result value to set if an exception is caught. default value is FAIL. :param post_files: Can hold filepaths of files that are to get posted/created regarding a given event. Something like success or failure information in a given log file. For each filepath, if it's a valid regular file it will get: read & encoded as base64 at the close of the event. Default value, if None, is an empty list. Nc�����������������C���s����||�_�||�_||�_||�_||�_tj|�_|d�u�r2g�}||�_|d�u�rP|rL|j }nd}||�_ |rnd� |j|f�|�_n|�j|�_i�|�_d�S�)NT�/) �parentr���r����message�result_on_exceptionr*���r���r(���r)����reporting_enabled�join�fullname�children)r���r���r���rF���rE���rH���rG���r)���r ���r ���r���r�������s,���� ��zReportEventStack.__init__c�����������������C���s���d|�j�|�j|�jf�S�)Nz.ReportEventStack(%s, %s, reporting_enabled=%s))r���r���rH���r���r ���r ���r����__repr__����s �����zReportEventStack.__repr__c�����������������C���s4���t�j|�_|�jrt|�j|�j��|�jr0d|�jj|�j <�|�S�)N)NN) r*���r���r(���rH���rB���rJ���r���rE���rK���r���r���r ���r ���r���� __enter__����s����zReportEventStack.__enter__c�����������������C���sP���t�jt�jfD�]6}|�j���D�]&\}\}}||kr||�jf����S�qq|�j|�jfS�r���)r*���r���r���rK���r6���rF���r(���)r���Zcand_result�_name�valueZ_msgr ���r ���r����_childrens_finish_info���s ����z'ReportEventStack._childrens_finish_infoc�����������������C���s���|�j�S�r���)�_resultr���r ���r ���r���r(�����s����zReportEventStack.resultc�����������������C���s���|t�vrtd|���||�_d�S�)Nz'%s' not a valid result)r*���r+���rQ����r���rO���r ���r ���r���r(�����s����c�����������������C���s���|�j�d�ur|�j�S�|�jS�r���)�_messager���r���r ���r ���r���rF�����s���� zReportEventStack.messagec�����������������C���s ���||�_�d�S�r���)rS���rR���r ���r ���r���rF�����s����c�����������������C���s���|r|�j�|�jfS�|����S�r���)rG���rF���rP���)r����excr ���r ���r����_finish_info��s����zReportEventStack._finish_infoc�����������������C���sD���|���|�\}}|�jr&||f|�jj|�j<�|�jr@t|�j|||�jd��d�S�)Nr=���)rU���rE���rK���r���rH���r@���rJ���r)���)r����exc_type� exc_value� tracebackr(����msgr ���r ���r����__exit__!��s�����zReportEventStack.__exit__)r���r���r���r#���r*���r���r���rL���rM���rP����propertyr(����setterrF���rU���rZ���r ���r ���r ���r���rC�������s(���*� ' rC���c�������������� ���C���s����|�sd�S�g�}|�D�]�}t�j�|�s&d�}nlt�d|�����L�t|d��"}t�|����� ��}W�d�����n1�sj0����Y��W�d�����n1�s�0����Y��|� ||dd���q|S�)NzReading �rb�base64)�path�content�encoding)�osr_����isfiler���ZTimed�openr^���Z b64encode�read�decode�append)r.����ret�fnamer`����fpr ���r ���r���r/���+��s�����Nr/���)N) r#���r^���ZloggingZos.pathrb���r����typingr���r���r���Zcloudinit.reportingr���r���Zcloudinit.reporting.handlersr���r'���rA���r$���Z getLoggerr���ZLOG�setr ���r*���r���r%���r<���r���r@���rB���rC���r/���r ���r ���r ���r����<module>���s.��� $ � �