x[h$$dZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z ddl mZdZdZd Zej$eZGd d eZed ZGd dZGddeZddZej6dfdZdZGddZdZy)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_handlersinstantiated_handler_registry)ReportingHandlerfinishstart cloudinitceZdZdZy)_namesetc*||vr|Std|z)Nz%s not a valid value)AttributeError)selfnames )48:X ??.t?DM r) rrrr5rr$r(r+ __classcell__)r7s@rr/r/Ms (.4 < rr/c|si}tjjDchc] \}}||vr| }}}ttjj }|D]!}t ||vr|j|#ycc}}w)aReport 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. N)rregistered_itemsitemslistrvaluestype publish_event)eventexcluded_handler_types hndl_typehndl_clsexcluded_handler_classeshandlershandlers r report_eventrLis "!#$6#F#F#L#L#N  Ix . .    (,%66==?(H% =4 4 e$% sBc6t||||}t|S)zVReport a "finish" event. See :py:func:`.report_event` for parameter details. r4)r/rL) event_nameevent_descriptionr3r4rEs rreport_finish_eventrQs% !%v* E  rc:tt||}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. )rSTART_EVENT_TYPErL)rOrPrEs rreport_start_eventrTs +Z9J KE  rceZdZdZdddej dfdZdZdZdZ e dZ e jdZ e d Z e jd Z d Zd Zy) ReportEventStackaKContext 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 / :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. NcF||_||_||_||_||_t j |_|g}||_||r |j}nd}||_ |r*dj|j|f|_ i|_ y|j|_ i|_ y)NT/) parentrr messageresult_on_exceptionr5rr3r4reporting_enabledjoinfullnamechildren)rrr rZrYr\r[r4s rr$zReportEventStack.__init__s  & #6 nn  J$  $$*$<$<!$(!!2 HHOODM !IIDM rcVd|jd|jd|jdS)NzReportEventStack(z, z, reporting_enabled=))rr r\r's r__repr__zReportEventStack.__repr__s% II     " "  rctj|_|jr t |j |j |jr#d|jj|j<|S)N)NN) r5rr3r\rTr^r rYr_rr's r __enter__zReportEventStack.__enter__sNnn  ! ! t}}d.>.> ? ;;.:DKK  + rctjtjfD]>}|jj D]\}\}}||k(s||j fccS@|j |j fSr)r5rrr_r@rZr3)r cand_result_namevalue_msgs r_childrens_finish_infoz'ReportEventStack._childrens_finish_infoso"KK5 1K(, (;(;(= 1$}tK'!4<<00 1 1 T\\**rc|jSr)_resultr's rr3zReportEventStack.results ||rc>|tvrtd|z||_y)Nz'%s' not a valid result)r5r6rlrrhs rr3zReportEventStack.result s"  6>? ? rcJ|j |jS|jSr)_messager r's rrZzReportEventStack.messages" == $== rc||_yr)rprns rrZzReportEventStack.messages  rcV|r|j|jfS|jSr)r[rZrj)rexcs r _finish_infozReportEventStack._finish_infos) ,,dll; ;**,,rc|j|\}}|jr%||f|jj|j<|jr$t |j |||jyy)NrN)rtrYr_rr\rQr^r4)rexc_type exc_value tracebackr3msgs r__exit__zReportEventStack.__exit__!s`)))4  ;;/5smDKK  +  ! !  sFt  "r)rrrr,r5rr$rbrdrjpropertyr3setterrZrtrzrrrrVrVs$T"KK%N + ]]    ^^- rrVc|syg}|D]}tjj|sd}ngtjd|5t |d5}t j|jj}dddddd|j|dd|S#1swY*xYw#1swY.xYw)NzReading rbbase64)pathcontentencoding) osrisfilerTimedopenr b64encodereaddecodeappend)r:retfnamerfps rr;r;+s  CNww~~e$G""XeW#56 ?t9 ? **27795<<> ? ? Eg8LMN J  ? ? ? ?s$ B92B-B9-B6 2B99C r) r,rloggingos.pathrr"typingrr rcloudinit.reportingrrcloudinit.reporting.handlersrr2rSr- getLoggerrLOGsetr r5rr/rLrrQrTrVr;rrrrs   !:"g!8%@+1..T  EEP r