관리-도구
편집 파일: logs.cpython-39.opt-1.pyc
a ����'�Dg{7����������������������@���s4��d�Z�ddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z �ddlmZm Z mZmZmZmZmZ�ddlmZ�ddlmZ�ddlmZmZ�ddlmZ�dd lmZmZmZ�eej e�!e"��Z#G�d d��de�Z$e$dd �e$dd�e$dd�gZ%e$dd�e$dd�e$dd�e$dd�e$dd�e$dd�e$dd�e$d d!�e$d"d#�e$d$d%�e$d&d%�e$d'd(�gZ&d^eej'�ej'd)�d*d+�Z(ee)�ej*e)ee)�d,�d-d.�Z+ee)�ej*e)dd,�d/d0�Z,ej*ej*e-dd1�d2d3�Z.ej*e-dd4�d5d6�Z/ej*dd7�d8d9�Z0ej*e-dd4�d:d;�Z1e e)ef�eej*�d<�d=d>�Z2e�*d?�fej*eej*�d@�dAdB�Z3ej*eej*�dC�dDdE�Z4ej*eej*�dF�dGdH�Z5ej*e e)ef�ej*ej*e-ddI�dJdK�Z6e�*dL�e�*dM�dNfe)e e)ef�ej*ej*e-ddO�dPdQ�Z7e8ddR�dSdT�Z9d_e)e8e-e-ddV�dWdX�Z:e)ej;e8dY�dZd[�Z<e"d\k�r0e�=e<d]e(���>�����dS�)`zGDefine 'collect-logs' utility and handler to include in cloud-init cmd.�����N)�datetime�timezone)�Any�Dict�Iterator�List� NamedTuple�Optional�cast)�loggers)�Init)�ProcessExecutionError�subp)�tempdir)�copy�get_config_logfiles� write_filec�������������������@���s���e�Zd�ZU�eed<�eed<�dS�)� ApportFile�pathZlabelN)�__name__� __module__�__qualname__�str�__annotations__��r���r����</usr/lib/python3.9/site-packages/cloudinit/cmd/devel/logs.pyr������s��� r���z(/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)�parser�returnc�����������������C���sh���|�st�jddd�}�|�jdddddd d ��|�jddd dd��|�jddddddd��|�jdddddd��|�S�)a2��Build 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. zcollect-logsz)Collect and tar all cloud-init debug info)�prog�descriptionz --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�userdataz?DEPRECATED: This is default behavior and this flag does nothing)r#���r"���r$���r%���z--redact-sensitivez-rz�Redact potentially sensitive data from logs. Sensitive data may include passwords or keys in user data and root read-only files.)r#���r"���r%���)�argparse�ArgumentParser�add_argument)r���r���r���r���� get_parserO���sF������� � �r+���)�cmd� file_path�msgr���c�������������� ���C���s����|j�jddd��zt|��j}W�nB�ty`�}�z*t|t|���t�d|��d}W�Y�d}~n$d}~0�0�t||��t�d||j ��|S�)zCHelper which runs a command and writes output or error to filename.T��parents�exist_ok�collecting %s failed.N�collected %s to file '%s') �parent�mkdirr����stdoutr ���r���r����LOG�debug�stem)r,���r-���r.����output�er���r���r����_write_command_output_to_file����s���� r<���c�������������� ���C���s����|j�jddd��z>|�d�� }tj|�||d��W�d����n1�sB0����Y��W�n>�ty��}�z&t|t|���t� d|��W�Y�d}~nd}~0�0�t� d||j ��dS�)z�Helper which runs a command and writes output or error to filename. `subprocess.call` is invoked directly here to stream output to the file. Otherwise memory usage can be high for large outputs. Tr/����w)r6����stderrNr2���r3���)r4���r5����open� subprocess�call�OSErrorr���r���r7���r8���r9���)r,���r-���r.����fr;���r���r���r����_stream_command_output_to_file����s����2"rD���)r����out_dir�include_sensitiver���c�����������������C���s`���|�����rP|s|����jtj@�rB|jddd��t|�|��t�d|���q\t�d|���nt�d|���dS�)z-Collect a file into what will be the tarball.Tr/���zcollected file: %sz#sensitive file %s was not collectedzfile %s did not existN) �is_file�stat�st_mode�S_IROTHr5���r���r7���r8���Ztrace)r���rE���rF���r���r���r���� _collect_file����s���� rK���)�log_dirrF���r���c�����������������C���sx���t�D�]2}t�|�|jdd���j}tt�|j�|dd��q|rttD�]2}t�|�|jdd���j}tt�|j�|dd��q@dS�)z'Obtain subiquity logs and config files.����NT)rF���)�INSTALLER_APPORT_FILES�pathlib�Pathr���r4���rK���� INSTALLER_APPORT_SENSITIVE_FILES)rL���rF���Zsrc_fileZdestination_dirr���r���r����_collect_installer_logs����s���� � �rR���)rL���r���c�����������������C���s<���t�ddg|�d�dd�}t�g�d�|�d�dd�}|s8|p6d }d S�)z8Include cloud-init version and dpkg version in the logs.� cloud-initz --version�versionzcloud-init --version�r,���r-���r.���)z dpkg-queryz--showz-f=${Version} rS���zdpkg-versionzdpkg versionz not-availableN)r<���)rL���rT���Zdpkg_verr���r���r����_collect_version_info����s������rV���c�����������������C���sL���|rt�dg|�d�dd��t�g�d�|�d�dd��t�g�d�t�|�d �d d��dS�)z0Include dmesg and journalctl output in the logs.Zdmesgz dmesg.txtzdmesg outputrU���)� journalctlz--boot=0�-o� short-precisezjournal.txtzsystemd journal of current boot)rW���z --boot=-1rX���rY���zjournal-previous.txtz systemd journal of previous bootN)rD���rO���rP���)rL���rF���r���r���r����_collect_system_logs����s ������ �rZ���)�log_cfgr���c�����������������c���s���t�|��D�]}t�|�V��qdS�)z7Get paths for cloud-init.log and cloud-init-output.log.N)r���rO���rP���)r[���r���r���r���r����_get_cloudinit_logs����s����r\���z /etc/cloud)� etc_cloud_dirr���c�����������������#���s4���|�d�|�d�dg����fdd�|���d�D��E�dH��dS�)z�Get paths for all files in /etc/cloud. Excludes: /etc/cloud/keys because it may contain non-useful sensitive data. /etc/cloud/templates because we already know its contents �keysZ templatesz99-installer.cfgc�����������������3���s&���|�]}|j���vr|j��vr|V��qd�S��N)�namer4���)�.0r�����ignorer���r���� <genexpr>��s����z!_get_etc_cloud.<locals>.<genexpr>z**/*N��glob)r]���r���rb���r����_get_etc_cloud���s���� � �rg���)� cloud_dirr���c�������������� ���C���s:���t��|��d�|��d�|��d�dd��|��d�D��|��d��S�)zkGet paths for files in /var/lib/cloud. Skip user-provided scripts, semaphores, and old instances. zdata/*z handlers/*zseed/*c�����������������s���s���|�]}|����r|V��qd�S�r_���)rG����ra����pr���r���r���rd����������z%_get_var_lib_cloud.<locals>.<genexpr>z instance/*zinstance/handlers)� itertools�chainrf����rh���r���r���r����_get_var_lib_cloud��s�����ro���)�run_dirr���c�����������������C���s���dd��|���d�D��S�)z�Get all paths under /run/cloud-init except for hook-hotplug-cmd. Note that this only globs the top-level directory as there are currently no relevant files within subdirectories. c�����������������s���s���|�]}|j�d�kr|V��qdS�)zhook-hotplug-cmdN)r`���ri���r���r���r���rd���*��rk���z_get_run_dir.<locals>.<genexpr>�*re����rp���r���r���r����_get_run_dir$��s����rs���)rL���r[���rp���rh���rF���r���c�����������������C���s����t�|���t|�|��t|�|��t|�D�]"}t||�t�|�j�d��d��q$t � t��t|d�t |d��D�]"}t||�t�|�j�d��|��qddS�)z8Collect all cloud-init logs into the provided directory.�/Trn���rr���N)rV���rZ���rR���r\���rK���rO���rP���r4����relative_torl���rm���rg���ro���rs���)rL���r[���rp���rh���rF���Zlogfiler���r���r����_collect_logs_into_tmp_dir-��s&���� ���rv���z/run/cloud-initz/var/lib/cloudT)�tarfiler[���rp���rh���rF���r���c�����������������C���s����t�j�|��}�t�tj�����d�}t |d��T}t �||�}t|||||d��t dd|�d|t|��|��d�d�g��W�d ����n1�s�0����Y��t�d |���d S�)a���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 log_cfg: The cloud-init base configuration containing logging cfg. :param run_dir: The path to the cloud-init run directory. :param cloud_dir: The path to the cloud-init cloud directory. :param include_sensitive: Boolean, true means include sensitive data. zcloud-init-logs-%Y-%m-%d)�dir)rL���r[���rp���rh���rF����tarZczfz-Crt�����NzWrote %s)�osr����abspathr���Znowr���Zutc�date�strftimer���rO���rP���rv���r���r����replacer7����info)rw���r[���rp���rh���rF���Zdir_nameZtmp_dirrL���r���r���r����collect_logsN��s,��������" r����)r!���r���c�����������������C���s^���t�����|�dkrtj}n|�dkr(tj}nt�j}t�|��t���}|� t� d���t�|��dS�)z�Set up the logger for CLI use. The verbosity controls which level gets printed to stderr. By default, DEBUG and TRACE are hidden. r���rM���z%(message)sN)r���Z reset_logging�logging�INFO�DEBUGZTRACEr7���ZsetLevelZ StreamHandlerZsetFormatterZ FormatterZ addHandler)r!����levelZhandlerr���r���r���� _setup_loggerw��s���� r����F)rw���r!����redact_sensitive�include_userdatar���c�����������������C���sx���t�|��t���dkrtd��|r*t�d��tg�d�}|����t|�|j t �|jj �t �|jj�|�d��|stt�d��dS�)z:Handle calls to 'cloud-init collect-logs' as a subcommand.r���z!This command must be run as root.z;The --include-userdata flag is deprecated and does nothing.)Zds_deps)rw���r[���rp���rh���rF���z�WARNING: Sensitive data may have been included in the collected logs. Please review the contents of the tarball before sharing or rerun with --redact-sensitive to redact sensitive data.N)r����r{����getuid�RuntimeErrorr7���Zwarningr���Zread_cfgr����ZcfgrO���rP����pathsrp���rh���)rw���r!���r����r�����initr���r���r����collect_logs_cli���s(����� ��r����)�_name�argsr���c�������������� ���C���sb���t������}zt|j|j|j|jd��W�dS��ty\�}�zt|t j d��W�Y�d}~dS�d}~0�0�dS�)z}Handle the CLI interface to the module. Parse CLI args, redirect all exceptions to stderr, and return an exit code. )r!���rw���r����r����r���)�fileNrM���)r+���� parse_argsr����r!���rw���r����r'���� Exception�print�sysr>���)r����r����r;���r���r���r����handle_collect_logs_args���s���� �r�����__main__rz���)N)r���TF)?�__doc__r(���rl���r����r{���rO���rH���r@���r����r���r����typingr���r���r���r���r���r ���r ���Z cloudinit.logr���Zcloudinit.stagesr���Zcloudinit.subpr ���r���Zcloudinit.temp_utilsr���Zcloudinit.utilr���r���r���ZCustomLoggerTypeZ getLoggerr���r7���r���rQ���rN���r)���r+���r���rP���r<���rD����boolrK���rR���rV���rZ���r\���rg���ro���rs���rv���r�����intr����r����� Namespacer�����exitr����r���r���r���r����<module>���s����$�� ��������&���:�� ��� � �� �$� �)�����!