ó oBú]c@sàddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZmZddlmZddlmZejrÞddlmZnddlmZe jeƒZd efd „ƒYZejej ƒd e!fd „ƒYƒZ"d e"fd„ƒYZ#de"fd„ƒYZ$de"fd„ƒYZ%de"fd„ƒYZ&e ƒZ'e'j(de#ƒe'j(de$ƒe'j(de%ƒe'j(de&ƒdS(iÿÿÿÿN(tlog(t DictRegistry(t url_helpertutil(tdatetime(tEmpty(t JoinableQueue(tQueuetReportExceptioncBseZRS((t__name__t __module__(((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRstReportingHandlercBs)eZdZejd„ƒZd„ZRS(sƒBase class for report handlers. Implement :meth:`~publish_event` for controlling what the handler does with an event. cCsdS(sPublish an event.N((tselftevent((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt publish_event'scCsdS(s0Ensure ReportingHandler has published all eventsN((R ((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pytflush+s(R R t__doc__tabctabstractmethodRR(((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR st LogHandlercBs#eZdZdd„Zd„ZRS(sBPublishes events to the cloud-init log at the ``DEBUG`` log level.tDEBUGcCs~tt|ƒjƒt|tƒr%nL|}ytt|jƒƒ}Wn*tk rpt j d|ƒtj }nX||_ dS(Nsinvalid level '%s', using WARN( tsuperRt__init__t isinstancetinttgetattrtloggingtuppert ExceptiontLOGtwarningtWARNtlevel(R R t input_level((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR3s  cCsGtjdjdd|j|jgƒƒ}|j|j|jƒƒdS(Nt.t cloudinitt reporting(Rt getLoggertjoint event_typetnameRR t as_string(R R tlogger((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR@s$(R R RRR(((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR0s t PrintHandlercBseZdZd„ZRS(sPrint the event as a string.cCs|jƒGHdS(N(R)(R R ((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRIs(R R RR(((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR+FstWebHookHandlercBs,eZddddddd„Zd„ZRS(c CsŒtt|ƒjƒt||||gƒrUtjd|d|d|d|ƒ|_n d|_||_||_ ||_ t j ƒ|_ dS(Nt consumer_keyt token_keyt token_secrettconsumer_secret(RR,RtanyRtOauthUrlHelpert oauth_helpertNonetendpointttimeouttretriesRtfetch_ssl_detailst ssl_details(R R5R-R.R/R0R6R7((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRNs      c Cs|jr|jj}n tj}yA||jdtj|jƒƒd|jd|jd|j ƒSWn't k r‹t j d|j ƒƒnXdS(NtdataR6R7R9sfailed posting event: %s(R3treadurlRR5tjsontdumpstas_dictR6R7R9RRRR)(R R R;((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR^s    N(R R R4RR(((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR,Ms  tHyperVKvpReportingHandlercBsÏeZdZdZdZeeZdZdZdZdZ dZ d Z e Z e dd „Zed „ƒZd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s, Reports events to a Hyper-V host using Key-Value-Pair exchange protocol and can be used to obtain high level diagnostic information from the host. To use this facility, the KVP user-space daemon (hv_kvp_daemon) has to be running. It reads the kvp_file when the host requests the guest to enumerate the KVP's. This reporter collates all events for a module (origin|name) in a single json string in the dictionary. For more information, see https://technet.microsoft.com/en-us/library/dn798287.aspx#Linux%20guests iit CLOUD_INITtmsgtresulttmsg_it,t:s/var/lib/hyperv/.kvp_pool_1cCs tt|ƒjƒ||_tj|jƒ||_tƒ|_|jƒ|_ dj |j |j ƒ|_ t jd|jƒ|_t|j_|jjƒdS(Nu{0}|{1}ttarget(RR?Rt_kvp_file_patht_truncate_guest_pool_filet _event_typestJQueuetqt_get_incarnation_notincarnation_notformatt EVENT_PREFIXtevent_key_prefixt threadingtThreadt_publish_event_routinetpublish_threadtTruetdaemontstart(R t kvp_file_patht event_types((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR‡s       cCsŸ|jr dStjƒttjƒƒ}zey5tjj|ƒ|kr`t|dƒWdQXnWn)t t fk rŒ}t j d|ƒnXWdt |_XdS(s Truncate the pool file if it has not been truncated since boot. This should be done exactly once for the file indicated by KVP_POOL_FILE_GUEST constant above. This method takes a filename so that we can use an arbitrary file during unit testing. Since KVP is a best-effort telemetry channel we only attempt to truncate the file once and only if the file has not been modified since boot. Additional truncation can lead to loss of existing KVPs. Ntws$failed to truncate kvp pool file, %s(t_already_truncated_pool_filettimetfloatRtuptimetostpathtgetmtimetopentOSErrortIOErrorRRRU(tclstkvp_filet boot_timete((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRH™s  cCsStjƒ}yttjƒt|ƒƒSWn"tk rNtjd|ƒdSXdS(sÀ use the time passed as the incarnation number. the incarnation number is the number which are used to distinguish the old data stored in kvp and the new data. s"uptime '%s' not in correct format.iN(RR^RR\R]t ValueErrorRR(R t uptime_str((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRL±s   ccs¦t|jdƒŽ}tj|tjƒ|j|ƒ|j|jƒ}x?t|ƒ|jkrˆ|j |ƒ}|V|j|jƒ}qJWtj|tj ƒWdQXdS(s-iterate the kvp file from the current offset.trbN( RbRGtfcntltflocktLOCK_EXtseektreadtHV_KVP_RECORD_SIZEtlent_decode_kvp_itemtLOCK_UN(R toffsettft record_datatkvp_item((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt _iterate_kvps¾s cCs%dj|j|j|jtjƒƒS(ss the event key format is: CLOUD_INIT||||