%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/logs.cpython-35.pyc



"�T`J�@s<dZddlZddlmZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZmZmZmZdd	gZd
ZdZddd
�Zdd�Zdd�Zdd�Zdd�Zddd�Zdd�Zdd�Zedkr8eje��dS)zGDefine 'collect-logs' utility and handler to include in cloud-init cmd.�N)�datetime)�INSTANCE_JSON_SENSITIVE_FILE)�tempdir)�ProcessExecutionError�subp)�chdir�copy�
ensure_dir�
write_filez/var/log/cloud-init.logz/var/log/cloud-init-output.logz/run/cloud-initz%/var/lib/cloud/instance/user-data.txtcCs�|stjdddd�}|jddddd	d
ddd
d�|jddd	dd
d�|jddd	dddddd
djt��|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.
    �progzcollect-logsZdescriptionz)Collect and tar all cloud-init debug infoz	--verbosez-v�action�count�defaultr�dest�	verbosity�helpzBe more verbose.z	--tarfilez-tzcloud-init.tar.gzzOThe tarfile to create containing all collected logs. Default: cloud-init.tar.gzz--include-userdataz-uF�
store_true�userdatazPOptionally include user-data from {0} which could contain sensitive information.)�argparse�ArgumentParser�add_argument�format�USER_DATA_FILE)�parser�r�:/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.py�
get_parsers			

rcCstj�dkrfStfS)z3Return a list of files to ignore if we are non-rootr)�os�getuidr)�curdir�filesrrr� _copytree_ignore_sensitive_files3sr!cCs�yt|�\}}WnLtk
rd}z,t|t|��td|d|�WYdd}~Xn&Xt||�td|d|�|SdS)zCHelper which runs a command and writes output or error to filename.zcollecting %s failed.
�Nz
collected %s
)rrr
�str�_debug)�cmd�filename�msgr�out�_�errr�_write_command_output_to_file:s'
r+cCs ||krtjj|�dS)N)�sys�stderr�write)r'�levelrrrrr$Gsr$cCsNtjj|�r6t||�td|d|�ntd|d|�dS)Nzcollected file: %s
r"zfile %s did not exist
�)r�path�isfilerr$)r1Zout_dirrrrr�
_collect_fileLs
r3c
Csy|r,tj�dkr,tjjd�dStjj|�}tj�j	�j
d�}dj|�}tdd���}tjj
||�}tdd	gtjj
|d
�d|�}tdd
ddgtjj
|d�d|�}|s|r�|nd}td|d|�tdgtjj
|d�d|�tddddgtjj
|d�d|�xtD]}t|||�qoW|r�tt||�tjj
|d�}	t|	�tjjt�rtjttjj
|	d�dt�tdtd|�ntdtd|�t|��+td d!||j|d"d#�g�Wd$QRXWd$QRXtjjd%|�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
r"z%Y-%m-%dzcloud-init-logs-{0}�dirz/tmpz
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 bootZrun�ignorezcollected dir %s
zdirectory '%s' did not exist
ZtarZczvf�/�Nz	Wrote %s
)rrr,r-r.r1�abspathrZutcnow�dateZstrftimerr�joinr+r$�CLOUDINIT_LOGSr3rr	�exists�CLOUDINIT_RUN_DIR�shutilZcopytreer!rr�replace)
�tarfileZinclude_userdatarr:Zlog_dirZtmp_dirr5Zdpkg_ver�logZrun_dirrrr�collect_logsTsX		



	

4rCcCst|j|j|j�S)z:Handle calls to 'cloud-init collect-logs' as a subcommand.)rCrArr)�name�argsrrr�handle_collect_logs_args�srFcCst�}td|j��S)z4Tool to collect and tar all cloud-init related logs.zcollect-logs)rrF�
parse_args)rrrr�main�s	rH�__main__)�__doc__rrrr?r,Zcloudinit.sourcesrZcloudinit.temp_utilsrZcloudinit.subprrZcloudinit.utilrrr	r
r<r>rrr!r+r$r3rCrFrH�__name__�exitrrrr�<module>s,"
7

Zerion Mini Shell 1.0