Current File : //lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pyo
�
oB�]c@sdZddlZddlmZddlZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZddgZd	Zd
Zdd�Zd�Zd
�Zd�Zd�Zdd�Zd�Zd�Zedkreje��ndS(sGDefine 'collect-logs' utility and handler to include in cloud-init cmd.i����N(tdatetime(tINSTANCE_JSON_SENSITIVE_FILE(ttempdir(tProcessExecutionErrortchdirtcopyt
ensure_dirtsubpt
write_files/var/log/cloud-init.logs/var/log/cloud-init-output.logs/run/cloud-inits%/var/lib/cloud/instance/user-data.txtcCs�|s!tjdddd�}n|jddddd	d
ddd
d�|jddd	dd
d�|jddd	tddddd
djt��|S(s2Build 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.
    tprogscollect-logstdescriptions)Collect and tar all cloud-init debug infos	--verboses-vtactiontcounttdefaultitdestt	verbositythelpsBe more verbose.s	--tarfiles-tscloud-init.tar.gzsOThe tarfile to create containing all collected logs. Default: cloud-init.tar.gzs--include-userdatas-ut
store_truetuserdatasPOptionally include user-data from {0} which could contain sensitive information.(targparsetArgumentParsertadd_argumenttFalsetformattUSER_DATA_FILE(tparser((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pyt
get_parsers		

cCstj�dkrdStfS(s3Return a list of files to ignore if we are non-rooti((tostgetuidR(tcurdirtfiles((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pyt _copytree_ignore_sensitive_files3scCs|yt|�\}}Wn:tk
rR}t|t|��td|d|�n&Xt||�td|d|�|SdS(sCHelper which runs a command and writes output or error to filename.scollecting %s failed.
is
collected %s
N(RRRtstrt_debug(tcmdtfilenametmsgRtoutt_te((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pyt_write_command_output_to_file:s
cCs#||krtjj|�ndS(N(tsyststderrtwrite(R$tlevelR((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pyR!GscCsNtjj|�r6t||�td|d|�ntd|d|�dS(Nscollected file: %s
isfile %s did not exist
i(RtpathtisfileRR!(R-tout_dirR((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pyt
_collect_fileLs
ic
Cs}|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}ntd|d|�tdgtjj
|d�d|�tddddgtjj
|d�d|�xtD]}t|||�qrW|r�tt||�ntjj
|d�}	t|	�tjjt�rtjttjj
|	d�dt�tdtd|�ntdtd|�t|��+td d!||j|d"d#�g�Wd$QXWd$QXtjjd%|�dS(&s�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.
    isMTo include userdata, root user is required. Try sudo cloud-init collect-logs
is%Y-%m-%dscloud-init-logs-{0}tdirs/tmps
cloud-inits	--versiontversionscloud-init --versions
dpkg-querys--shows-f=${Version}
sdpkg-versionsdpkg versions
not-availables!collected cloud-init version: %s
tdmesgs	dmesg.txtsdmesg outputt
journalctls--boot=0s-os
short-precisesjournal.txtssystemd journal of current boottruntignorescollected dir %s
sdirectory '%s' did not exist
ttartczvft/tNs	Wrote %s
(RRR)R*R+R-tabspathRtutcnowtdatetstrftimeRRtjoinR(R!tCLOUDINIT_LOGSR0RRtexiststCLOUDINIT_RUN_DIRtshutiltcopytreeRRRtreplace(
ttarfiletinclude_userdataRR=tlog_dirttmp_dirR2tdpkg_vertlogtrun_dir((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pytcollect_logsTsX		



	

2cCst|j|j|j�S(s:Handle calls to 'cloud-init collect-logs' as a subcommand.(RMRFRR(tnametargs((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pythandle_collect_logs_args�scCst�}td|j��S(s4Tool to collect and tar all cloud-init related logs.scollect-logs(RRPt
parse_args(R((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pytmain�s	t__main__(t__doc__RRRRCR)tcloudinit.sourcesRtcloudinit.temp_utilsRtcloudinit.utilRRRRRRR@RBRtNoneRRR(R!R0RMRPRRt__name__texit(((s</usr/lib/python2.7/site-packages/cloudinit/cmd/devel/logs.pyt<module>s*.		
		7