ó oBú]c@sádZddlZddlZddlZddlmZdZdZdZ de fd „ƒYZ e dƒZ d e fd„ƒYZdefd„ƒYZd„Ze jdd„Zd„Zde fd„ƒYZd„ZdS(s events for reporting. The events here are designed to be used with reporting. They can be published to registered handlers with report_event. iÿÿÿÿNi(tinstantiated_handler_registrytfinishtstartt cloudinitt_namesetcBseZd„ZRS(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/eZdZedd„Zd„Zd„ZRS(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|jƒS(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,eZejdd„Zd„Zd„ZRS(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|jƒS(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*tjjƒD]\}}|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 tReportEventStackcBs˜eZdZd d d ejd d„Zd„Zd„Zd„Z e d„ƒZ e j d„ƒZ e d„ƒZ e j d„ƒZ d „Zd „ZRS( sÙ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 / :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||_ |r«dj |j |fƒ|_ n |j|_ i|_dS(Nt/(tparentRRtmessagetresult_on_exceptionR R RRRtreporting_enabledtTruetjointfullnametchildren(RRRR4R3R6R5R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRšs$              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|jƒn|jrJd|jj |j /usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt __enter__¹s    cCslxYtjtjfD]E}x<|jjƒD]+\}\}}||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_infoÁs " cCs|jS(N(t_result(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRÈscCs,|tkrtd|ƒ‚n||_dS(Ns'%s' not a valid result(R R!RB(RR?((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRÌs cCs|jdk r|jS|jS(N(t_messageRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR4ÒscCs ||_dS(N(RC(RR?((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR4ØscCs |r|j|jfS|jƒS(N(R5R4RA(Rtexc((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt _finish_infoÜscCsf|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|jƒƒjƒ}WdQX|j i|d6|d6dd6ƒqW|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