Current File : //lib/python2.7/site-packages/cloudinit/analyze/show.pyc
�
oB�]c@s�ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	idd6dd6dd	6d
d6dd
6dd6dd6dd6dd6dd6dd6Z
djge
j�D]*\Z
Zdje
jdd�e�^q��ZdZdZd ZedddfZd!�Zd"�Zd#�Zd$�Zd%�Zd&�Zd'�Zd(�Zd)�Zd*�Zd+�Z d,e!fd-��YZ"d.�Z#d/�Z$d0�Z%e&d1e&e&d2�Z'd3�Z(d4�Z)dS(5i����N(tutil(tuses_systemdtdeltas%dtdescriptions%Dtelapseds%Et
event_types%etindents%Itlevels%ltnames%ntorigins%otresults%rt	timestamps%tt
total_times%Tt s{0}: {1}t%s%%t
successfultfailuret	containercCstxdtj�D]V\}}||kr
|dkrJ|j|d|�}qc|j|d|�}q
q
W|j|�S(NRRRs
{%s:08.5f}s{%s}(RRs	timestamp(t
format_keytitemstreplacetformat(tmsgteventtitj((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt
format_record=scCs�td�|j�D��}|d}g}xc|D][}|d}tjj|�}tj|d�jd�}tj	||�|j
|�q3W|S(Ncss-|]#\}}|dkr||fVqdS(tcontentN(scontent((t.0tktv((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pys	<genexpr>IstfilestpathRtascii(tdictRtosR tbasenametbase64t	b64decodetdecodeRt
write_filetappend(RRRtsavedtftfnametfn_localtfcontent((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytdump_event_filesHs


cCs|r|jd�SdS(NR(tgettNone(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt
event_nameVs
cCs|r|jd�SdS(NR(R0R1(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyR\s
cCs!|rt|�jd�dSdS(Nt/i(R2tsplitR1(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_parentbscCst|jd��S(NR(tfloatR0(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_timestamphscCstjjt|��S(N(tdatetimetutcfromtimestampR7(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_datetimelscCs||j�S(N(t
total_seconds(tt1tt2((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt
delta_secondspscCstt|�t|��S(N(R>R:(tstarttfinish((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_durationtscCsi|j�}|jit||�d6t|t|��d6ddt|�jd�ddd6�|S(	NRRt|R
R3is`->R(tcopytupdateRAR>R:R2tcount(t
start_timeR?R@trecord((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_recordxs	*cCsd|S(NsTotal Time: %3.5f seconds
((R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyttotal_time_record�stSystemctlReadercBs,eZdZdd�Zd�Zd�ZRS(sQ
    Class for dealing with all systemctl subp calls in a consistent manner.
    cCsZd|_ddg|_|r1|jj|�n|jjd|g�|j�|_dS(Ns/bin/systemctltshows-p(R1tepochtargsR)textendtsubpR(tselftpropertyt	parameter((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt__init__�s	cCsTy9tj|jdt�\}}|r+|S||_dSWntk
rO}|SXdS(s�
        Make a subp call based on set args and handle errors by setting
        failure code

        :return: whether the subp call failed or not
        tcaptureN(RRORMtTrueRLR1t	Exception(RPtvalueterrtsystemctl_fail((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRO�s	cCsH|jr$tdj|j���n|jjd�d}t|�dS(s{
        If subp call succeeded, return the timestamp from subp as a float.

        :return: timestamp as a float
        sBSubprocess call to systemctl has failed, returning error code ({})t=ii@B(RtRuntimeErrorRRLR4R6(RPR((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytparse_epoch_as_float�s
			N(t__name__t
__module__t__doc__R1RSROR\(((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRJ�s	cCsCt�rt�Stj�s8dtj�dj�kr?t�StS(s2
    Determine which init system a particular linux distro is using.
    Each init system (systemd, upstart, etc) has a different way of
    providing timestamps.

    :return: timestamps of kernelboot, kernelendboot, and cloud-initstart
    or TIMESTAMP_UNKNOWN if the timestamps cannot be retrieved.
    tgentootsystem(Rtgather_timestamps_using_systemdRt
is_FreeBSDtsystem_infotlowertgather_timestamps_using_dmesgtTIMESTAMP_UNKNOWN(((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytdist_check_timestamp�s
	c	Cs�y�tjdgdt�\}}|dj�}x�|D]�}|jd�jd�dkr8|jd�j�}|djd�}t|�}tt	j	��ttj
��}||}t|||fSq8WWntk
r�nXt
S(	s
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization using dmesg as opposed to systemctl

    :return: the two timestamps plus a dummy timestamp to keep consistency
    with gather_timestamps_using_systemd
    tdmesgRTisUTF-8tuseri����it](RRORUt
splitlinesR'tfindR4tstripR6ttimetuptimetSUCCESS_CODERVRg(	tdatat_t
split_entriesRtsplituptstrippedtuser_space_timestamptkernel_startt
kernel_end((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRf�s
"
	
c
Cs/ttj��ttj��}y�td�j�}tdd�j�}|}t}tj�r�tj	dkr�ttj��ttj
��}ytjd�}|j
}Wn(tk
r�}tdj|���nXt}q�t}n||}||}Wntk
r}	|	GHtSX||||fS(s�
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization. and cloud-init systemd unit activation

    :return: the three timestamps
    tUserspaceTimestampMonotonictInactiveExitTimestampMonotonicscloud-init-localis/proc/1/cmdlinesBCould not determine container boot time from /proc/1/cmdline. ({})(ii(R6RoRRpRJR\Rqtis_containertsystversion_infot	monotonicR#tstattst_atimetOSErrorR[RtCONTAINER_CODEt	FAIL_CODERVRg(
Rxtdelta_k_endt
delta_ci_st	base_timetstatust	file_statRXRytcloudinit_sysdte((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRb�s0""
			
s(%n) %d seconds in %I%DcCsNt|dd��}g}d
}d}i}	g}
g}g}x�tdt|��D]�}
||
}y||
d}Wntk
r�d
}nXt|�dkr�|jd�|
kr�|jt|��|j|�g}d
}d}n|d
krg}
t	|�}||	t
|�<nt|�t|�krpt|�dkr�|jt|t
|||���q�q&|jd	|jd��|j|�|
j|jd��qUqU|j�}t|�t|�krt
|||�}|jtd
|�d�||jd�7}qU|j|�qUW|jt|��|j|�|S(s2
    Take in raw events and create parent-child dependencies between events
    in order to order events in chronological order.

    :param events: JSONs from dump that represents events taken from logs
    :param blame_sort: whether to sort by timestamp or by time taken.
    :param print_format: formatting to represent event, time stamp,
    and time taken by the event in one line
    :param dump_files: whether to dump files into JSONs
    :param log_datafiles: whether or not to log events generated

    :return: boot records ordered chronologically
    tkeycSs|dS(NR((tx((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt<lambda>1sgiiR?RR@sStarting stage: %ssFinished stage: (%n) %d secondss
RN(tsortedR1trangetlent
IndexErrorRR0R)RIR:R5R2RRHtpop(teventst
blame_sorttprint_formatt
dump_filest
log_datafilest
sorted_eventstrecordsRFRtstage_start_timetstages_seentboot_recordstunprocessedR�Rtnext_evttprev_evtRG((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytgenerate_records sZ



	

cCst|d|�S(s<
    A passthrough method that makes it easier to call generate_records()

    :param events: JSONs from dump that represents events taken from logs
    :param print_format: formatting to represent event, time stamp,
    and time taken by the event in one line

    :return: boot records ordered chronologically
    R�(R�(R�R�((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytshow_eventsls
cCsB|j�}ytj|�|fSWntk
r=d|fSXdS(s�
    Takes in a log file, read it, and convert to json.

    :param infile: The Log file to be read

    :return: json version of logfile, raw file
    N(treadtjsontloadst
ValueErrorR1(tinfileRr((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytload_events_infileys

(*R%R8R�R#RoR}t	cloudinitRtcloudinit.distrosRRtjoinRRRRRtformatting_helpRqR�R�RgRR/R2RR5R7R:R>RARHRItobjectRJRhRfRbtFalseR�R�R�(((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt<module>sZ
	=											3		 	/J