Your IP : 216.73.216.176


Current Path : /snap/core22/current/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Current File : //snap/core22/current/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-310.pyc

o

�t�h*7�@sJddlZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZddl
mZmZddlmZddddd	d
ddd
ddd�ZdZdZdZedddfZeZdededefdd�Zde	ede	efdd�Zde	ede	efdd�Zde	ede	efdd�Zdedefdd �Zdedejfd!d"�Zd#ejd$ejdefd%d&�Z d'ed(edefd)d*�Z!d+ejd'ed(edefd,d-�Z"dedefd.d/�Z#Gd0d1�d1�Z$de
eeeeffd2d3�Z%de
eeeeffd4d5�Z&de
eeeeffd6d7�Z'	8dBd9eed:edeeefd;d<�Z(d9eed:edeeefd=d>�Z)d?ede
e	eeffd@dA�Z*dS)C�N)�IO�Any�Dict�List�Optional�Tuple�Union�cast)�subp�util)�uses_systemd�delta�description�elapsed�
event_type�indent�level�name�origin�result�	timestamp�
total_time)z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%T�
successful�failure�	container����msg�event�returncCsTt��D]\}}||vr!|dvr|�|d|�}q|�|d|�}q|jdi|��S)N)r
rrz
{%s:08.5f}z{%s}�)�
format_key�items�replace�format)rr�i�jrr�8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py�
format_record9s�r'cC�|r|�d�SdS)Nr��get�rrrr&�
event_nameD�
r,cCr()Nrr)r+rrr&rJr-cCst|�}|r
|�d�dSdS)N�/r)r,�split)rrrrr&�event_parentPsr0cCs"|�d�}|dur
td��t|�S)NrzEvent is missing a 'timestamp')r*�
ValueError�float)r�tsrrr&�event_timestampWs
r4cCstj�t|�tjj�S�N)�datetime�
fromtimestampr4�timezone�utcr+rrr&�event_datetime^s�r:�t1�t2cCs||��Sr5)�
total_seconds)r;r<rrr&�
delta_secondsdsr>�start�finishcCstt|�t|��Sr5)r>r:)r?r@rrr&�event_durationhsrA�
start_timecCsX|��}t|�}d}|r|d|�d�dd7}|�t||�t|t|��|d��|S)N�|� r.�z`->)r
rr)�copyr,�count�updaterAr>r:)rBr?r@�recordrrrrr&�event_recordls��rJcCsd|S)NzTotal Time: %3.5f seconds
r)rrrr&�total_time_record�srKc@sPeZdZdZddedeefdd�Zdeeeeffdd	�Z	de
fd
d�ZdS)
�SystemctlReaderzQ
    Class for dealing with all systemctl subp calls in a consistent manner.
    N�property�	parametercCsFd|_t�d�dg|_|r|j�|�|j�d|dg�|��|_dS)N�	systemctl�showz-pz--timestamp=us+utc)�stdoutr
�which�args�append�extend�_subpr)�selfrMrNrrr&�__init__�szSystemctlReader.__init__rc
CsTztj|jdd�\}}|r|WS||_WdSty)}z|WYd}~Sd}~ww)z�
        Make a subp call based on set args and handle errors by setting
        failure code

        :return: whether the subp call failed or not
        T��captureN)r
rSrQ�	Exception)rW�value�err�systemctl_failrrr&rV�s��zSystemctlReader._subpcCsv|jrtd�|j���|jdurtd��|j�d�d��}|��r*t|�d}|Stj�	|d�j
tjjd��
�}|S)	z{
        If subp call succeeded, return the timestamp from subp as a float.

        :return: timestamp as a float
        zBSubprocess call to systemctl has failed, returning error code ({})Nz.stdout of subprocess call to systemctl is None�=rEi@Bz%a %Y-%m-%d %H:%M:%S.%f %Z)�tzinfo)r�RuntimeErrorr#rQr/�strip�	isnumericr2r6�strptimer"r8r9r)rW�valrrrr&�convert_val_to_float�s&	�
����z$SystemctlReader.convert_val_to_floatr5)�__name__�
__module__�__qualname__�__doc__�strrrXrr[rVr2rfrrrr&rL�s
rLcCs2t�rt�St��sdt��d��vrt�StS)a)
    Determine which init system a particular linux distro is using.
    Each init system (systemd, 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.
    �gentoo�system)r�gather_timestamps_using_systemdr�
is_FreeBSD�system_info�lower�gather_timestamps_using_dmesg�TIMESTAMP_UNKNOWNrrrr&�dist_check_timestamp�s

rtc	Cs�zMtjdgdd�\}}|d��}|D]7}|�d��d�dkrJ|�d���}|d�d	�}t|�}tt���tt�	��}||}t
|||fWSqWtStyWYtSw)
a
    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
    �dmesgTrYrzUTF-8�userrrE�])
r
�
splitlines�decode�findr/rbr2�timer�uptime�SUCCESS_CODEr[rs)	�data�_�
split_entriesr$�splitup�stripped�user_space_timestamp�kernel_start�
kernel_endrrr&rr�s$����rrc
Cs�z0t��rtd���}td���}ntd���}td���}td���|}tdd���|}WntyH}zt|�tWYd}~Sd}~wwt��rOtnt}||||||fS)z�
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization. and cloud-init systemd unit activation

    :return: the three timesread_propertystamps
    �UserspaceTimestamp�UserspaceTimestampMonotonic�KernelTimestamp�KernelTimestampMonotonic�InactiveExitTimestampMonotoniczcloud-init-localN)	r�is_containerrLrfr[�printrs�CONTAINER_CODEr})r��monotonic_offsetr��cloudinit_sysd�e�statusrrr&rns^�����������������rn�(%n) %d seconds in %I%D�events�print_formatc	Cs�t|dd�d�}g}d}d}i}g}g}tt|��D]�}	||	}
z||	d}Wnty3d}Ynwt|
�dkr�|rU|
�d�d	krU|�t|��|�|�g}d}d}|durct|
�}||t	|
�<t
|
�t
|�kr�t|�d
kr�tt|�}|�t
|t||
|���q|�d|
�d��|�|
�q|��}t
|
�t
|�kr�|r�t|||
�}
|�t
d|
�d
�||
�d�p�d7}q|�|�q|�t|��|�|�|S)as
    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 print_format: formatting to represent event, time stamp,
    and time taken by the event in one line

    :return: boot records ordered chronologically
    cSs|dS)Nrr)�xrrr&�<lambda>Wsz"generate_records.<locals>.<lambda>)�keyNgrEr?rz
init-localr@zStarting stage: %szFinished stage: (%n) %d seconds�
r
)�sorted�range�len�
IndexErrorrr*rTrKr:r0r,r	rr'rJ�pop)r�r��
sorted_events�recordsrBr�stage_start_time�boot_records�unprocessedr�r�next_evt�prev_evtrIrrr&�generate_recordsHsl�


���
����
r�cCst||d�S)a<
    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�rrr&�show_events�s
r��infilecCsX|��}|��stj�d|j�t�d�zt�|�|fWSt	y+d|fYSw)z�
    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
    zEmpty file %s
rEN)
�readrb�sys�stderr�writer�exit�json�loadsr1)r�r~rrr&�load_events_infile�s
�r�)r�)+r6r�r�r{�typingrrrrrrrr	�	cloudinitr
r�cloudinit.distrosrr r}�	FAIL_CODEr�rs�Eventrkr'r,rr0r2r4r:r>rArJrKrLrtrrrnr�r�r�rrrr&�<module>sp(����
�U;���

�"P"