Viewing File: /usr/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.pytmains	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		
Back to Directory File Manager