HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/logs.cpython-312.pyc
�

�f�'��Z�dZddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZmZdd
lmZddlmZmZmZmZmZdZGd
�de
�Zedd�edd�edd�gZedd�edd�edd�edd�edd�edd �ed!d"�ed#d$�ed%d&�ed'd(�ed)d(�ed*d+�gZd,e fd-�Z!d,e fd.�Z"d;d/�Z#d0�Z$d1�Z%d2�Z&d3�Z'd4�Z(d5�Z)d<d6e*fd7�Z+d8�Z,d9�Z-e.d:k(rej^e-��yy)=zGDefine 'collect-logs' utility and handler to include in cloud-init cmd.�N)�datetime)�Path)�
NamedTuple)�read_cfg_paths)�Paths)�Init)�ProcessExecutionError�subp)�tempdir)�chdir�copy�
ensure_dir�get_config_logfiles�
write_filez/run/cloud-initc�"�eZdZUeed<eed<y)�
ApportFile�path�labelN)�__name__�
__module__�__qualname__�str�__annotations__���:/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.pyrr"s��

�I��Jrrz(/var/log/installer/autoinstall-user-data�AutoInstallUserDataz/autoinstall.yaml�AutoInstallYAMLz'/etc/cloud/cloud.cfg.d/99-installer.cfg�InstallerCloudCfgz//var/log/installer/ubuntu_desktop_installer.log�UdiLogz-/var/log/installer/subiquity-server-debug.log�SubiquityServerDebugz-/var/log/installer/subiquity-client-debug.log�SubiquityClientDebugz%/var/log/installer/curtin-install.log�	CurtinLogz0/var/log/installer/subiquity-curtin-install.conf�CurtinInstallConfigz8/var/log/installer/curtin-install/subiquity-initial.conf�CurtinConfigInitialz:/var/log/installer/curtin-install/subiquity-curthooks.conf�CurtinConfigCurtHooksz8/var/log/installer/curtin-install/subiquity-extract.conf�CurtinConfigExtractz=/var/log/installer/curtin-install/subiquity-partitioning.conf�CurtinConfigPartitioningz(/var/log/installer/curtin-error-logs.tar�CurtinErrorz$/var/log/installer/curtin-errors.tarz(/var/log/installer/block/probe-data.json�	ProbeData�returnc�8�t�}|jd�S)N�userdata_raw)r�
get_ipath_cur��pathss r�_get_user_data_filer1Ts����E����~�.�.rc�8�t�}|jd�S)N�data)r�	get_cpathr/s r�_get_cloud_data_pathr5Ys����E��?�?�6�"�"rc
���|stjdd��}|jdddddd	�
�|jddd
d��t�}|jddddddj	|���|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)�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�userdatazPOptionally include user-data from {0} which could contain sensitive information.)r=r<r>r?)�argparse�ArgumentParser�add_argumentr1�format)�parser�user_data_files  r�
get_parserrH^s�����(�(��C�
���������
�
�
�������#�
*���)�*�N�
�������
�
&�&,�f�^�&<��
��Mrc��dg}tj�dk7r'|jti�jd�|S)z>Return a list of files to ignore for /run/cloud-init directoryzhook-hotplug-cmdr�instance_data_sensitive)�os�getuid�appendr�lookups)�curdir�files�
ignored_filess   r�_copytree_rundir_ignore_filesrR�sB��	��M�
�y�y�{�a�����U�2�Y�.�.�/H�I�J��rc�0�ttjj|��	t	|�j
}t
||�td|zd|�|S#t$r/}t
|t|��td|zd|�Yd}~yd}~wwxYw)�CHelper which runs a command and writes output or error to filename.�
collected %s
��collecting %s failed.
N)
rrKr�dirnamer
�stdoutr�_debugr	r)�cmd�filename�msgr;�output�es      r�_write_command_output_to_filer`�s����r�w�w���x�(�)���c��!�!��
	�8�V�$���#�%�q�)�4��
��
!�>��8�S��V�$��(�3�.��9�=�=��>�s�A�	B�&%B�Bc�^�ttjj|��	t	|d�5}tj|||��ddd�td|zd|�y#1swY�xYw#t$r/}t|t|��td|zd|�Yd}~yd}~wwxYw)rT�w)rY�stderrNrUrVrW)rrKrrX�open�
subprocess�callrZ�OSErrorrr)r[r\r]r;�fr_s      r�_stream_command_output_to_fileri�s����r�w�w���x�(�)�5�
�(�C�
 �	5�A��O�O�C��!�4�	5�	��#�%�q�)�4�
	5�	5���>��8�S��V�$��(�3�.��9�=�=��>�s.�A4�A(�A4�(A1�-A4�4	B,�=%B'�'B,c�N�||kr tjj|�yy�N)�sysrc�write)r]�levelr;s   rrZrZ�s!���	���
�
�����rc��tjj|�rt||�t	d|zd|�yt	d|zd|�y)Nzcollected file: %s
rVzfile %s did not exist
�)rKr�isfiler
rZ)r�out_dirr;s   r�
_collect_filers�s@��	�w�w�~�~�d���T�7���%��,�a��;��(�4�/��I�>rc���tD]h}t||jz�j}|j	�stt
|��t|jt
|�|��j|rrtD]h}t||jz�j}|j	�stt
|��t|jt
|�|��jyy)z'Obtain subiquity logs and config files.N)	�INSTALLER_APPORT_FILESrr�parent�existsrrrs� INSTALLER_APPORT_SENSITIVE_FILES)�log_dir�include_userdatar;�src_file�destination_dirs     r�collect_installer_logsr}�s���*�F���w����6�7�>�>���%�%�'��s�?�+�,��h�m�m�S��%9�9�E�	F�
�8�	J�H�"�7�X�]�]�#:�;�B�B�O�"�)�)�+��3��/�0��(�-�-��_�)=�y�I�		J�rrzc�b�|r7tj�dk7r tjj	d�ytg��}tjj|�}tj�j�jd�}td��5}tjj||�}tdd	gtjj|d
�d|��}tgd
�tjj|d�d|��}|s|r|nd}td|�t!d|zd|�t#dgtjj|d�d|��t#gd�tjj|d�d|��|j%�t'|j(�D]}t+|||��|rt-�}	t+|	||�t/|||�tjj|d�}
t1|
�tjj3t4�rT	t7j8t4tjj|
d�t:��t!dt4zd|�nt!dt4zd|�tjj3tjjt4d ��rWtAtC��}|j3�r4t7j8t?|�tA|t?|�z��tE|�5tGd!d"||jI|d#zd$�g�ddd�ddd�tjj	d%|z�y#t6j<$rU}tjj	d�tjj	t?|�dz�Yd}~���d}~wwxYw#1swY��xYw#1swY��xYw)&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
rV)�ds_depszcloud-init-logs-%Y-%m-%dz/tmp)�dir�
cloud-initz	--version�versionzcloud-init --version)r[r\r]r;)z
dpkg-queryz--showz-f=${Version}
r�zdpkg-versionzdpkg versionz
not-availablez	version: z!collected cloud-init version: %s
�dmesgz	dmesg.txtzdmesg output)�
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
�disabled�tar�czvf�/�z	Wrote %s
)%rKrLrlrcrmrr�abspathr�utcnow�date�strftimer�joinr`�printrZri�read_cfgr�cfgrsr1r}rrw�CLOUDINIT_RUN_DIR�shutil�copytreerR�Errorrrr5rr
�replace)
�tarfilerzr;�initry�tmp_dirr��dpkg_ver�logrG�run_dirr_�cloud_data_dirs
             r�collect_logsr��sK���B�I�I�K�1�,��
�
���
2�	
�����D��g�g�o�o�g�&�G��o�o��$�$�&�/�/�0J�K�G�	�V�	�CO���'�'�,�,�w��0��/��{�+��W�W�\�\�'�9�5�&��	
��1�I��W�W�\�\�'�>�:���	
���"*�h��G�
�k�7�#��3�g�=�q�)�L�&��	��W�W�\�\�'�;�7���		
�	'�A��W�W�\�\�'�=�9�1��		
�	
�
�
��&�t�x�x�0�	3�C��#�w�	�2�	3��0�2�N��.�'�9�=��w�(8�)�D��'�'�,�,�w��.���7��
�7�7�>�>�+�,�
0����%��G�G�L�L��,�7�8��
�'�*;�;�Q�	�J��0�3D�D���
�
�7�7�>�>�"�'�'�,�,�'8�*�E�F�!�"6�"8�9�N��$�$�&������'���3�~�#6�6�7���7�^�	O��%���'�/�/�'�C�-��*L�M�N�	O�ECO�H�J�J���\�G�+�,���+�<�<�
0��
�
� � �!L�M��
�
� � ��Q��$��/�/��
0��$	O�	O��ECO�CO�sQ�"F+P%�>N.�CP%�#P�;P%�.P�A
P�P%�P�P%�P"	�P%�%P.c�X�t|j|j|j�S)z:Handle calls to 'cloud-init collect-logs' as a subcommand.)r�r�rAr;)�name�argss  r�handle_collect_logs_argsr�&s������d�m�m�T�^�^�D�Drc�J�t�}td|j��S)z4Tool to collect and tar all cloud-init related logs.r7)rHr��
parse_args)rFs r�mainr�+s��
�\�F�#�N�F�4E�4E�4G�H�Hr�__main__rk)r)0�__doc__rBrKr�rerlr�pathlibr�typingr�cloudinit.cmd.develr�cloudinit.helpersr�cloudinit.stagesr�cloudinit.subpr	r
�cloudinit.temp_utilsr�cloudinit.utilrr
rrrr�rrxrurr1r5rHrRr`rirZrsr}�boolr�r�r�r�exitrrr�<module>r�s���N��	�
��
����.�#�!�6�(���&������2�4I���"�$5�6��8�:M�N�$� ��@�(�K��7�9O���7�9O���6��D��:����B����D����B����G�"��
�9�=�I��5�}�E��9�;�G�C"��J/�S�/�
#�c�#�
+�\��
5��
?�J�U
�D�U
�pE�
I��z���C�H�H�T�V��r