ph$dZddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZdd lmZdd lmZmZmZmZd d gZd ZGdde ZeddeddeddgZeddeddeddeddedded d!ed"d#ed$d%ed&d'ed(d)ed*d)ed+d,g Zd-efd.Zd-efd/Zd;d0Z d1Z!d2Z"d3Z#d4Z$d5Z%dReturn a list of files to ignore for /run/cloud-init directoryrinstance_data_sensitive)osgetuidappendrlookups)curdirfiles ignored_filess r_copytree_rundir_ignore_filesrPsAM y{{aU2YY./HIJJJ rc t|\}}t||td|zd||S#t$r<}t|t |td|zd|Yd}~dSd}~wwxYw)zCHelper which runs a command and writes output or error to filename.z collected %s zcollecting %s failed. N)r r_debugrr)cmdfilenamemsgr9out_es r_write_command_output_to_filerZscQ 8S!!!#%q)444 !>>>8SVV$$$(3.9=========>s: B1A;;BcT||kr!tj|dSdSN)sysstderrwrite)rVlevelr9s rrSrSs1  rctj|r&t||t d|zd|dSt d|zd|dS)Nzcollected file: %s rRzfile %s did not exist )rIrisfiler rS)rout_dirr9s r _collect_fileresd w~~d? T7%,a;;;;;(4/I>>>>>rctD]q}t||jzj}|st t |t|jt ||r|rytD]s}t||jzj}|st t |t|jt ||rdSdS)z'Obtain subiquity logs and config files.N) INSTALLER_APPORT_FILESrrparentexistsr rre INSTALLER_APPORT_SENSITIVE_FILES)log_dirinclude_userdatar9src_filedestination_dirs rcollect_installer_logsros*FFw677>%%'' - s?++ , , ,hmS%9%99EEEEJ8 J JH"7X]#:;;BO"))++ 13//000 (-_)=)=y I I I I JJ J Jrrlc |r8tjdkr!tjddStj|}tj d}td5}tj ||}tddgtj |d d |}tgd tj |d d |}|s|r|nd}td|zd|tdgtj |dd|tgdtj |dd|tD]}t!||||rt#}t!|||t%|||tj |d} t'| tjt*r t-jt*tj | dt0nj#t,j$rX} tjdtjt5| dzYd} ~ nd} ~ wwxYwtdt*zd|ntdt*zd|tjtj t*drnt7t9} | r?t-jt5| t7|t5| zt;|5t=dd|||d zd!gdddn #1swxYwYdddn #1swxYwYtjd"|zdS)#zCollect 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 rRzcloud-init-logs-%Y-%m-%dz/tmp)dir cloud-initz --versionversionzcloud-init --version)z dpkg-queryz--showz-f=${Version} rrz dpkg-versionz dpkg versionz not-availablez!collected cloud-init version: %s dmesgz dmesg.txtz dmesg output) journalctlz--boot=0z-oz short-precisez journal.txtzsystemd journal of current bootrun)ignorez(Failed collecting file(s) due to error:  Nzcollected dir %s zdirectory '%s' did not exist disabledtarczvf/z Wrote %s ) rIrJr]r^r_rabspathrutcnowdatestrftimer joinrZrSCLOUDINIT_LOGSrer/ror riCLOUDINIT_RUN_DIRshutilcopytreerPErrorrrr3r r replace) tarfilerlr9rktmp_dirrsdpkg_verlogrErun_dirrYcloud_data_dirs r collect_logsrs BIKK1,,  2   qgoog&&Go$$&&//0JKKG V   AO',,w00/ ; ' GLL) , , "     1 E E E GLL. 1 1       @"*?hhG3g=q)LLL% I GLL+ . .      & = = = GLL- 0 0 -     " 3 3C #w 2 2 2 2  >022N .'9 = = =w(8)DDD',,w..7 7>>+ , ,  0%GLL,778 < 0 0 0   !LMMM   Q$//////// 0 '*;;Q J J J J 03DD    7>>"',,'8*EE F F !"6"8"899N$$&& ''3~#6#66777^^ O O %'//'C-*L*LM N N N O O O O O O O O O O O O O O OAAOAOAOAOAOAOAOAOAOAOAOAOAOAOAODJ\G+,,, 1sc"F$P1?JP1K.AK)$P1)K..C5P1#+P P1P P1!P "P11P58P5cBt|j|j|jS)z:Handle calls to 'cloud-init collect-logs' as a subcommand.)rrr?r9)nameargss rhandle_collect_logs_argsr s  dmT^ D DDrcbt}td|S)z4Tool to collect and tar all cloud-init related logs.r5)rFr parse_args)rDs rmainrs' \\F #NF4E4E4G4G H HHr__main__r\)r),__doc__r@rIrr]rpathlibrtypingrcloudinit.cmd.develrcloudinit.helpersrcloudinit.subprr cloudinit.temp_utilsr cloudinit.utilr r r rrrrrjrgrr/r3rFrPrZrSreroboolrrrrexitrrrrslNM ......######66666666((((((>>>>>>>>>>>>+-MN% J24IJ"$566J8:MNN $ J@(KKJ79OJ79OJ6 DDJ:JBJDJBJG" J9=IIJ5}EEJ9;GGC"J/S//// #c#### ++++\    ??? J J JQ Q DQ Q Q Q hEEE III  z CHTTVVr