܍~c#dZddlZddlZddlZddlmZddlmZm Z ddl m Z dZ dZ dZGd d eZed ZGd d ZGddeZddZejdfdZdZGddZdZdS)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)available_handlersinstantiated_handler_registry)ReportingHandlerfinishstart cloudinitceZdZdZdS)_namesetc2||vr|Std|z)Nz%s not a valid value)AttributeError)selfnames eZdZejdffd ZdZfdZxZS)FinishReportingEventNctt|t||||_|g}||_|t vrtd|zdS)NzInvalid result: %s)superr.r#FINISH_EVENT_TYPEresult post_filesstatus ValueError)rrrr2r3 __class__s rr#zFinishReportingEvent.__init__Ksq "D))22 t[     J$   1F:;; ; rcZd|j|j|j|jS)Nz{0}: {1}: {2}: {3})r%rrr2rr&s rr'zFinishReportingEvent.as_stringXs,#** OTY T5E   rctt|}|j|d<|jrt |j|d<|S)z'The event represented as json friendly.r2files)r0r.r*r2r3_collect_file_info)rdatar6s rr*zFinishReportingEvent.as_dict]sM)40088::X ? @.t??DM r) rrrr4rr#r'r* __classcell__)r6s@rr.r.Jsl(.4 < < < < < <   rr.csifdtjD}ttj}|D])}t ||vr||*dS)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. c"h|] \}}|v | Srr).0 hndl_typehndl_clsexcluded_handler_typess r zreport_event..vs3    Ix . . .  . . .rN)rregistered_itemsitemslistrvaluestype publish_event)eventrBexcluded_handler_classeshandlershandlers ` r report_eventrNfs "$!#    #5#F#L#L#N#N    (,%6==??((H%% ==4 4 4 e$$$$%%rcFt||||}t|S)zVReport a "finish" event. See :py:func:`.report_event` for parameter details. r3)r.rN) event_nameevent_descriptionr2r3rJs rreport_finish_eventrSs2 !%v*   E   rcLtt||}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_TYPErN)rQrRrJs rreport_start_eventrVs% +Z9J K KE   rceZdZdZdddejdfdZdZdZdZ e dZ e j dZ e d Z e j d Z d Zd ZdS) 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. Nc||_||_||_||_||_t j|_|g}||_| |r|j }nd}||_ |r"d |j |f|_ n |j|_ i|_ dS)NT/) parentrrmessageresult_on_exceptionr4rr2r3reporting_enabledjoinfullnamechildren)rrrr\r[r^r]r3s rr#zReportEventStack.__init__s  & #6 n  J$  $ )$*$<!!$(!!2  &HHODMM!IDM rc8d|jd|jd|jdS)NzReportEventStack(z, z, reporting_enabled=))rrr^r&s r__repr__zReportEventStack.__repr__s/ III      " " "  rctj|_|jrt |j|j|jrd|jj|j <|S)N)NN) r4rr2r^rVr`rr[rarr&s r __enter__zReportEventStack.__enter__sLn  ! @ t}d.> ? ? ? ; ;.:DK  + rctjtjfD]7}|jD]\}\}}||kr ||jfccS8|j|jfSr)r4rrrarEr\r2)r cand_result_namevalue_msgs r_childrens_finish_infoz'ReportEventStack._childrens_finish_infos"K5 1 1K(, (;(;(=(= 1 1$}tK''!4<000000( 1 T\**rc|jSr)_resultr&s rr2zReportEventStack.results |rcJ|tvrtd|z||_dS)Nz'%s' not a valid result)r4r5rnrrjs rr2zReportEventStack.results,   6>?? ? rc,|j|jS|jSr)_messagerr&s rr\zReportEventStack.messages = $= rc||_dSr)rrrps rr\zReportEventStack.messages  rcJ|r|j|jfS|Sr)r]r\rl)rexcs r _finish_infozReportEventStack._finish_infos,  <,dl; ;**,,,rc||\}}|jr||f|jj|j<|jrt |j|||jdSdS)NrP)rvr[rarr^rSr`r3)rexc_type exc_value tracebackr2msgs r__exit__zReportEventStack.__exit__s{)))44  ; > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Eg8LLMMMM Js9BB B r)r+ros.pathrr!typingrcloudinit.reportingrrcloudinit.reporting.handlersrr1rUr,setr r4rr.rNrrSrVrXr:rrrrs    :99999"<<<<8%%%%@+1.T       EEEEEEEEP     r