oB]c@sdZddlZddlZddlZddlmZdZdZdZ de fd YZ e dZ d e fdYZdefdYZdZe jddZdZde fdYZdZdS(s events for reporting. The events here are designed to be used with reporting. They can be published to registered handlers with report_event. iNi(tinstantiated_handler_registrytfinishtstartt cloudinitt_namesetcBseZdZRS(cCs$||kr|Std|dS(Ns%s not a valid value(tAttributeError(tselftname((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt __getattr__s (t__name__t __module__R(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRstSUCCESStWARNtFAILtReportingEventcBs/eZdZeddZdZdZRS(s"Encapsulation of event formatting.cCsL||_||_||_||_|dkr?tj}n||_dS(N(t event_typeRt descriptiontorigintNonettimet timestamp(RRRRRR((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt__init__$s     cCsdj|j|j|jS(s"The event represented as a string.s {0}: {1}: {2}(tformatRRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt as_string.scCs6i|jd6|jd6|jd6|jd6|jd6S(s&The event represented as a dictionary.RRRRR(RRRRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pytas_dict3sN(R R t__doc__tDEFAULT_EVENT_ORIGINRRRR(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR!s tFinishReportingEventcBs,eZejddZdZdZRS(cCsftt|jt||||_|dkr:g}n||_|tkrbtd|ndS(NsInvalid result: %s( tsuperRRtFINISH_EVENT_TYPEtresultRt post_fileststatust ValueError(RRRRR((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR<s      cCs"dj|j|j|j|jS(Ns{0}: {1}: {2}: {3}(RRRRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRGscCsEtt|j}|j|d<|jrAt|j|d/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRKs   N(R R R R RRRR(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR:s cCs1x*tjjD]\}}|j|qWdS(s Report an event to all registered event handlers. This should generally be called via one of the other functions in the reporting module. :param event_type: The type of the event; this should be a constant from the reporting module. N(Rtregistered_itemstitemst publish_event(teventt_thandler((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt report_eventTs cCs"t|||d|}t|S(sVReport a "finish" event. See :py:func:`.report_event` for parameter details. R(RR+(t event_nametevent_descriptionRRR(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pytreport_finish_eventbs cCstt||}t|S(s'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. (RtSTART_EVENT_TYPER+(R,R-R(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pytreport_start_eventms tReportEventStackcBseZdZd d d ejd dZdZdZdZ e dZ e j dZ e dZ e j dZ d Zd ZRS( sContext 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. cCs||_||_||_||_||_tj|_|dkrNg}n||_ |dkr~|ru|j }q~t }n||_ |rdj |j |f|_ n |j|_ i|_dS(Nt/(tparentRRtmessagetresult_on_exceptionR R RRRtreporting_enabledtTruetjointfullnametchildren(RRRR4R3R6R5R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRs$              cCsd|j|j|jfS(Ns.ReportEventStack(%s, %s, reporting_enabled=%s)(RRR6(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt__repr__scCsNtj|_|jr+t|j|jn|jrJd|jj |j /usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt __enter__s    cCslxYtjtjfD]E}x<|jjD]+\}\}}||kr)||jfSq)WqW|j|jfS(N(R R R R:R&R4R(Rt cand_resultt_nametvaluet_msg((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt_childrens_finish_infos " cCs|jS(N(t_result(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRscCs,|tkrtd|n||_dS(Ns'%s' not a valid result(R R!RB(RR?((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRs cCs|jdk r|jS|jS(N(t_messageRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR4scCs ||_dS(N(RC(RR?((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR4scCs |r|j|jfS|jS(N(R5R4RA(Rtexc((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt _finish_infoscCsf|j|\}}|jr:||f|jj|j/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt__exit__s   N(R R RRR R RR;R<RAtpropertyRtsetterR4RERJ(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR1{s      cCs|s dSg}x~|D]v}tjj|s8d}n3t|d"}tj|jj}WdQX|j i|d6|d6dd6qW|S(Ntrbtpathtcontenttbase64tencoding( RtosRNtisfiletopenRPt b64encodetreadtdecodetappend(R"trettfnameROtfp((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR#s  !(sSUCCESSsWARNsFAIL(RRPtos.pathRRRtRRR/RtsetRR tobjectRRR+R RR.R0R1R#(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt s       p