Your IP : 216.73.217.13


Current Path : /usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/logs.cpython-38.pyc

U

�Ad�$�@s�dZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZdd	lmZdd
lmZmZmZmZddgZd
ZGdd�de	�Zedd�edd�edd�gZedd�edd�edd�edd�edd�ed d!�ed"d#�ed$d%�ed&d'�ed(d)�ed*d)�ed+d,�gZed-�d.d/�Zed-�d0d1�ZdFd2d3�Z d4d5�Z!d6d7�Z"d8d9�Z#d:d;�Z$d<d=�Z%dGe&d>�d?d@�Z'dAdB�Z(dCdD�Z)e*dEk�r�e�+e)��dS)HzGDefine 'collect-logs' utility and handler to include in cloud-init cmd.�N)�datetime)�Path)�
NamedTuple)�read_cfg_paths)�Paths)�ProcessExecutionError�subp)�tempdir)�chdir�copy�
ensure_dir�
write_filez/var/log/cloud-init.logz/var/log/cloud-init-output.logz/run/cloud-initc@seZdZUeed<eed<dS)�
ApportFile�pathZlabelN)�__name__�
__module__�__qualname__�str�__annotations__�rr�:/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.pyrs
rz(/var/log/installer/autoinstall-user-dataZAutoInstallUserDataz/autoinstall.yamlZAutoInstallYAMLz'/etc/cloud/cloud.cfg.d/99-installer.cfgZInstallerCloudCfgz//var/log/installer/ubuntu_desktop_installer.logZUdiLogz-/var/log/installer/subiquity-server-debug.logZSubiquityServerDebugz-/var/log/installer/subiquity-client-debug.logZSubiquityClientDebugz%/var/log/installer/curtin-install.logZ	CurtinLogz0/var/log/installer/subiquity-curtin-install.confZCurtinInstallConfigz8/var/log/installer/curtin-install/subiquity-initial.confZCurtinConfigInitialz:/var/log/installer/curtin-install/subiquity-curthooks.confZCurtinConfigCurtHooksz8/var/log/installer/curtin-install/subiquity-extract.confZCurtinConfigExtractz=/var/log/installer/curtin-install/subiquity-partitioning.confZCurtinConfigPartitioningz(/var/log/installer/curtin-error-logs.tarZCurtinErrorz$/var/log/installer/curtin-errors.tarz(/var/log/installer/block/probe-data.jsonZ	ProbeData)�returncCst�}|�d�S)NZuserdata_raw)rZ
get_ipath_cur��pathsrrr�_get_user_data_fileMsrcCst�}|�d�S)N�data)rZ	get_cpathrrrr�_get_cloud_data_pathRsrc	Cs`|stjddd�}|jdddddd	d
�|jddd
dd�t�}|jdddddd�|�d�|S)a2Build or extend and arg parser for collect-logs utility.

    @param parser: Optional existing ArgumentParser instance representing the
        collect-logs subcommand which will be extended to support the args of
        this utility.

    @returns: ArgumentParser with proper argument configuration.
    �collect-logsz)Collect and tar all cloud-init debug info)�progZdescriptionz	--verbosez-v�countr�	verbosityzBe more verbose.)�action�default�dest�helpz	--tarfilez-tzcloud-init.tar.gzzOThe tarfile to create containing all collected logs. Default: cloud-init.tar.gz)r"r$z--include-userdataz-uF�
store_true�userdatazPOptionally include user-data from {0} which could contain sensitive information.)r"r!r#r$)�argparse�ArgumentParser�add_argumentr�format)�parser�user_data_filerrr�
get_parserWs>	���	��r-cCs*dg}t��dkr&|�ti�jd�|S)z>Return a list of files to ignore for /run/cloud-init directoryzhook-hotplug-cmdrZinstance_data_sensitive)�os�getuid�appendrZlookups)�curdir�filesZ
ignored_filesrrr�_copytree_rundir_ignore_files�s
�r3c
Cstzt|�\}}Wn@tk
rP}z"t|t|��td|d|�W5d}~XYn Xt||�td|d|�|SdS)zCHelper which runs a command and writes output or error to filename.zcollecting %s failed.
�Nz
collected %s
)rrr
r�_debug)�cmd�filename�msgr �out�_�errr�_write_command_output_to_file�s"
r<cCs||krtj�|�dS)N)�sys�stderr�write)r8�levelr rrrr5�sr5cCs<tj�|�r(t||�td|d|�ntd|d|�dS)Nzcollected file: %s
r4zfile %s did not exist
�)r.r�isfilerr5)rZout_dirr rrr�
_collect_file�s
rCcCs�tD]:}t||j�j}|��s,tt|��t|jt|�|�q|r�tD]:}t||j�j}|��sptt|��t|jt|�|�qHdS)z'Obtain subiquity logs and config files.N)	�INSTALLER_APPORT_FILESrr�parent�existsrrrC� INSTALLER_APPORT_SENSITIVE_FILES)�log_dir�include_userdatar Zsrc_fileZdestination_dirrrr�collect_installer_logs�srJ)rIcCsl|r t��dkr tj�d�dStj�|�}t���	��
d�}tdd���}tj�||�}t
ddgtj�|d	�d
|�}t
ddd
dgtj�|d�d|�}|s�|r�|nd}td|d|�t
dgtj�|d�d|�t
ddddgtj�|d�d|�tD]}t|||�q�|�rt�}t|||�t|||�tj�|d�}	t|	�tj�t��r�ztjttj�|	d�td�WnFtjk
�r�}
z$tj�d�tj�t|
�d�W5d}
~
XYnXtd td|�ntd!td|�tj�tj�td"���rtt��}|���rt�t|�t|t|���t|��"td#d$||�|d%d&�g�W5QRXW5QRXtj�d'|�dS)(z�Collect all cloud-init logs and tar them up into the provided tarfile.

    @param tarfile: The path of the tar-gzipped file to create.
    @param include_userdata: Boolean, true means include user-data.
    rzMTo include userdata, root user is required. Try sudo cloud-init collect-logs
r4zcloud-init-logs-%Y-%m-%dz/tmp)�dirz
cloud-initz	--version�versionzcloud-init --versionz
dpkg-queryz--showz-f=${Version}
zdpkg-versionzdpkg versionz
not-availablez!collected cloud-init version: %s
Zdmesgz	dmesg.txtzdmesg outputZ
journalctlz--boot=0z-oz
short-precisezjournal.txtzsystemd journal of current boot�run)�ignorez(Failed collecting file(s) due to error:
�
Nzcollected dir %s
zdirectory '%s' did not exist
ZdisabledZtarZczvf�/�z	Wrote %s
) r.r/r=r>r?r�abspathrZutcnow�date�strftimer	�joinr<r5�CLOUDINIT_LOGSrCrrJrrF�CLOUDINIT_RUN_DIR�shutilZcopytreer3�Errorrrrr
r�replace)�tarfilerIr rHZtmp_dirrLZdpkg_ver�logr,Zrun_dirr;Zcloud_data_dirrrr�collect_logs�s���
��
��
&�

�
0r]cCst|j|j|j�S)z:Handle calls to 'cloud-init collect-logs' as a subcommand.)r]r[r&r )�name�argsrrr�handle_collect_logs_args
sr`cCst�}td|���S)z4Tool to collect and tar all cloud-init related logs.r)r-r`�
parse_args)r+rrr�mainsrb�__main__)N)r),�__doc__r'r.rXr=r�pathlibr�typingrZcloudinit.cmd.develrZcloudinit.helpersrZcloudinit.subprrZcloudinit.temp_utilsr	Zcloudinit.utilr
rrr
rVrWrrGrDrrrr-r3r<r5rCrJ�boolr]r`rbr�exitrrrr�<module>s���	��������%
.
T