Viewing File: /usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyo

ó
oBú]c@sàddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddl	mZmZddlmZddlmZejrÞddlmZnddlmZejeƒZd	efd
„ƒYZejej ƒde!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.pyRst
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 tinput_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|_||_||_	||_
tjƒ|_
dS(Ntconsumer_keyt	token_keyttoken_secrettconsumer_secret(RR,RtanyRtOauthUrlHelpertoauth_helpertNonetendpointttimeouttretriesRtfetch_ssl_detailstssl_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‹tj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	ZeZ
edd
„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_pathtevent_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Œ}tj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toffsettftrecord_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|<incarnation number>|<event_type>|<event_name>|<time>
        u{0}|{1}|{2}|{3}(RNRPR'R(tuuidtuuid4(RR
((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt
_event_keyÊscCs;tjd|j|jf|jdƒ|jdƒƒ}|S(Ns%ds%dssutf-8(tstructtpacktHV_KVP_EXCHANGE_MAX_KEY_SIZEtHV_KVP_EXCHANGE_MAX_VALUE_SIZEtencode(RtkeytvalueR:((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt_encode_kvp_itemÓs
	
cCs’t|ƒ}||jkr9tdj||jƒƒ‚n|d|j!jdƒjdƒ}||j|j!jdƒjdƒ}i|d6|d6S(Ns$record_data len not correct {0} {1}.isutf-8tR‚Rƒ(RrRqRRNRtdecodetstrip(RRwtrecord_data_lentktv((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRsÚs	cCsmt|jdƒU}tj|tjƒx|D]}|j|ƒq/W|jƒtj|tjƒWdQXdS(Ntab(RbRGRlRmRntwriteRRt(RRwRvR:((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt_append_kvp_itemés

cCs||j=tj|ƒ}|dt|ƒd!}d}g}d|jd}xÁtr|||j<d||j<tj|d|jƒ}|jt|ƒd}	|j|dj	d	|jd
||	 ƒƒ}
|j
|j||
ƒƒ|d7}||	}t|ƒdkrPPqPqPW|S(Niis"s":""tt
separatorsis"{key}":"{desc}"R‚tdesc(tMSG_KEYR<R=RrRUtDESC_IDX_KEYtJSON_SEPARATORSR€treplaceRNtappendR„(RR‚t	meta_datatdescriptiontdes_in_jsontitresult_arraytmessage_place_holdertdata_without_desct
room_for_descRƒ((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt_break_downñs,
	

	

cCsÛ|j|ƒ}i|jd6|jd6tj|jƒjƒdd6}t||jƒrk|j	||j<n|j
||j<tj
|d|jƒ}t|ƒ|jkr¾|j|||j
ƒS|j||ƒ}|gSdS(s®
        encode the event into kvp data bytes.
        if the event content reaches the maximum length of kvp value.
        then it would be cut to multiple slices.
        R(ttypetZttsRN(R|R(R'Rtutcfromtimestampt	timestampt	isoformatthasattrt
RESULT_KEYRBR—R‘R<R=R“RrR€RžR„(RR
R‚R–RƒR:((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt
_encode_events

cCs!xtrd}yõ|jjdtƒ}|d7}g}x`|dk	r™||j|ƒ7}y#|jjdtƒ}|d7}Wq:tk
r•d}q:Xq:WzAy|j|ƒWn)tt	fk
rÙ}t
jd|ƒnXWdx!t|ƒD]}|jj
ƒqëWXWqtk
rdSXqWdS(Nitblockis failed posting events to kvp, %s(RURKtgetR4R§tFalsetQueueEmptyErrorRRcRdRRtranget	task_donetEOFError(Rtitems_from_queueR
tencoded_dataRht_((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRS%s,	


cCs3|js|j|jkr/|jj|ƒndS(N(RIR'RKtput(RR
((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRCscCstjdƒ|jjƒdS(Ns0HyperVReportingHandler flushing remaining events(RtdebugRKR&(R((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyRGs
(RDREN(R	R
RR€RRqROR‘R¦R’R“tKVP_POOL_FILE_GUESTRªR[R4RtclassmethodRHRLRyR|R„RsRRžR§RSRR(((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyR?ls4	
										Rtprinttwebhookthyperv()RRzRlR<tsixR_R}RQR\R#RRtcloudinit.registryRRRRtsix.moves.queueRR«tPY2tmultiprocessing.queuesRRJtqueueRR%R	RRRt
add_metaclasstABCMetatobjectRRR+R,R?tavailable_handlerst
register_item(((s@/usr/lib/python2.7/site-packages/cloudinit/reporting/handlers.pyt<module>s:	à	
Back to Directory File Manager