+
    iN7                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H	t	H
t
 ^ RIHtHtHtHtHtHtHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHtHtHt ]! ]P@                  ]PB                  ! ]"4      4      t# ! R	 R
]4      t$]$! RR4      ]$! RR4      ]$! RR4      .t%]$! RR4      ]$! RR4      ]$! RR4      ]$! RR4      ]$! RR4      ]$! RR4      ]$! RR4      ]$! RR 4      ]$! R!R"4      ]$! R#R$4      ]$! R%R$4      ]$! R&R'4      .t&RNR( R) llt'R* R+ lt(R, R- lt)R. R/ lt*R0 R1 lt+R2 R3 lt,R4 R5 lt-R6 R7 lt.]P^                  ! R84      3R9 R: llt0R; R< lt1R= R> lt2R? R@ lt3]P^                  ! RA4      ]P^                  ! RB4      RC3RD RE llt4RF RG lt5RORH RI llt6RJ RK lt7]"RL8X  d/   ]Pp                  ! ]7! RM]'! 4       Ps                  4       4      4       R# R# )PzGDefine 'collect-logs' utility and handler to include in cloud-init cmd.N)datetimetimezone)AnyDictIteratorList
NamedTupleOptionalcast)loggers)Init)ProcessExecutionErrorsubp)tempdir)copyget_config_logfiles
write_filec                   ,   a  ] tR t^t o V 3R ltRtV tR# )
ApportFilec                2   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   # )   pathlabel)str)format__classdict__s   ":/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.py__annotate__ApportFile.__annotate__   s     
I J      N)__name__
__module____qualname____firstlineno____annotate_func____static_attributes____classdictcell__)r   s   @r   r   r      s      r   r   z(/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	ProbeDatac                n    V ^8  d   QhR\         \        P                  ,          R\        P                  /# )r   parserreturn)r	   argparseArgumentParser)r   s   "r   r   r   O   s-     6 6X,,-66r   c           	         V '       g   \         P                  ! RRR7      p V P                  RRR^ RRR	7       V P                  R
RRRR7       V P                  RRRRRRR7       V P                  RRRRRR7       V # )a  Build 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.
zcollect-logsz)Collect and tar all cloud-init debug info)progdescriptionz	--verbosez-vcount	verbosityzBe more verbose.)actiondefaultdesthelpz	--tarfilez-tzcloud-init.tar.gzzOThe tarfile to create containing all collected logs. Default: cloud-init.tar.gz)rA   rC   z--include-userdataz-uF
store_trueuserdataz?DEPRECATED: This is default behavior and this flag does nothing)rA   r@   rB   rC   z--redact-sensitivez-rzRedact potentially sensitive data from logs. Sensitive data may include passwords or keys in user data and root read-only files.)rA   r@   rC   )r9   r:   add_argument)r7   s   &r   
get_parserrG   O   s     ((C
    #*   M  	 $  
 Mr   c          	          V ^8  d   QhR\         \        ,          R\        P                  R\        R\        \        ,          /# )r   cmd	file_pathmsgr8   )r   r   pathlibPathr	   )r   s   "r   r   r      s<      	c|| 
 c]	r   c                N   VP                   P                  RRR7        \        V 4      P                  p\	        W4       \
        P                  RW!P                  4       V#   \         d9   p\	        T\        T4      4       \
        P                  RT4       Rp Rp?T# Rp?ii ; i)zCHelper which runs a command and writes output or error to filename.Tparentsexist_okcollected %s to file '%s'collecting %s failed.N)
parentmkdirr   stdoutr   LOGdebugstemr   r   )rI   rJ   rK   outputes   &&&  r   _write_command_output_to_filer\      s     4$7Dc!! 	9%		-sNNCM ! 9c!f%		)3/ Ms   A! !B$,-BB$c                j    V ^8  d   QhR\         \        ,          R\        P                  R\        RR/# )r   rI   rJ   rK   r8   N)r   r   rL   rM   )r   s   "r   r   r      s:     D D	cD&||D25D	Dr   c                   VP                   P                  RRR7        VP                  R4      ;_uu_ 4       p\        P                  ! WVR7       RRR4       \
        P                  RW!P                  4       R#   + '       g   i     L2; i  \         d7   p\        T\        T4      4       \
        P                  RT4        Rp?R# Rp?ii ; i)zHelper which runs a command and writes output or error to filename.

`subprocess.call` is invoked directly here to stream output to the file.
Otherwise memory usage can be high for large outputs.
TrO   w)rV   stderrNrR   rS   )rT   rU   open
subprocesscallrW   rX   rY   OSErrorr   r   )rI   rJ   rK   fr[   s   &&&  r   _stream_command_output_to_filerf      s     4$7D^^C  AOOC!4 ! 			-sNNC !  09c!f%		)3//0s.   B A;B ;B	B C+C

Cc                h    V ^8  d   QhR\         P                  R\         P                  R\        RR/# )r   r   out_dirinclude_sensitiver8   NrL   rM   bool)r   s   "r   r   r      s4     1 1
,,1!(1BF1	1r   c                t   V P                  4       '       d   V'       g6   V P                  4       P                  \        P                  ,          '       d7   VP	                  RRR7       \        W4       \        P                  RV 4       R# \        P                  RV 4       R# \        P                  RV 4       R# )z-Collect a file into what will be the tarball.TrO   zcollected file: %sz#sensitive file %s was not collectedzfile %s did not existN)	is_filestatst_modeS_IROTHrU   r   rW   rX   trace)r   rh   ri   s   &&&r   _collect_filerr      sq     ||~~		 3 3dll B BMM$M6II*D1II;TB		)40r   c                H    V ^8  d   QhR\         P                  R\        RR/# r   log_dirri   r8   Nrj   )r   s   "r   r   r      s(      \\.2	r   c                   \          F`  p\        P                  ! WP                  R,          4      P                  p\        \        P                  ! VP                  4      VRR7       Kb  	  V'       dm   \         F`  p\        P                  ! WP                  R,          4      P                  p\        \        P                  ! VP                  4      VRR7       Kb  	  R# R# )z'Obtain subiquity logs and config files.:   NNT)ri   N)INSTALLER_APPORT_FILESrL   rM   r   rT   rr    INSTALLER_APPORT_SENSITIVE_FILES)ru   ri   src_filedestination_dirs   &&  r   _collect_installer_logsr|      s     +!,,wb0ABIILL'"	
 + 8H%ll7MM"4EFMMOX]]+"& 9 r   c                <    V ^8  d   QhR\         P                  RR/# )r   ru   r8   N)rL   rM   )r   s   "r   r   r      s     . .7<< .D .r   c                    \        RR.V R,          RR7      p\        . R
OV R,          RR7      pV'       g   T;'       g    RpR	# R	# )z8Include cloud-init version and dpkg version in the logs.
cloud-initz	--versionversionzcloud-init --versionrI   rJ   rK   zdpkg-versionzdpkg versionznot-availableN)z
dpkg-queryz--showz-f=${Version}
r   )r\   )ru   r   dpkg_vers   &  r   _collect_version_infor      sP    +;'I%"G
 -EN*H
 --o r   c                H    V ^8  d   QhR\         P                  R\        RR/# rt   rj   )r   s   "r   r   r      s(      \\.2	r   c                    V'       d   \        R.V R,          RR7       \        . R
OV R,          RR7       \        . RO\        P                  ! V R4      RR7       R	# )z0Include dmesg and journalctl output in the logs.dmesgz	dmesg.txtzdmesg outputr   zjournal.txtzsystemd journal of current bootzjournal-previous.txtz systemd journal of previous bootN)
journalctlz--boot=0-oshort-precise)r   z	--boot=-1r   r   )rf   rL   rM   )ru   ri   s   &&r   _collect_system_logsr      sV     &	+	

 #=M)-
 #>,,w(>?.r   c                |    V ^8  d   QhR\         \        \        3,          R\        \        P
                  ,          /# )r   log_cfgr8   )r   r   r   r   rL   rM   )r   s   "r   r   r      s-     ! !#s(^!gll!r   c              #  b   "   \        V 4       F  p\        P                  ! V4      x  K  	  R# 5i)z7Get paths for cloud-init.log and cloud-init-output.log.N)r   rL   rM   )r   r   s   & r   _get_cloudinit_logsr      s%      $G,ll4   -s   -/z
/etc/cloudc                n    V ^8  d   QhR\         P                  R\        \         P                  ,          /# )r   etc_cloud_dirr8   rL   rM   r   )r   s   "r   r   r      s)      <<gllr   c              #     a"   V R,          V R,          R.oV3R lV P                  R4       4        Rj  xL
  R#  L5i)zGet paths for all files in /etc/cloud.

Excludes:
  /etc/cloud/keys because it may contain non-useful sensitive data.
  /etc/cloud/templates because we already know its contents
keys	templatesz99-installer.cfgc              3   t   <"   T F-  pVP                   S9  g   K  VP                  S9  g   K)  Vx  K/  	  R # 5iN)namerT   ).0r   ignores   & r   	<genexpr>!_get_etc_cloud.<locals>.<genexpr>  s7      .D99F" 	'+{{&'@ 	.s   88
8z**/*Nglob)r   r   s   &@r   _get_etc_cloudr      sD      	#	F!&&v.  s   2><>c                n    V ^8  d   QhR\         P                  R\        \         P                  ,          /# )r   	cloud_dirr8   r   )r   s   "r   r   r     s'      ',, 8GLL3I r   c           	         \         P                  ! V P                  R4      V P                  R4      V P                  R4      R V P                  R4       4       V P                  R4      4      # )zcGet paths for files in /var/lib/cloud.

Skip user-provided scripts, semaphores, and old instances.
zdata/*z
handlers/*zseed/*c              3   T   "   T F  qP                  4       '       g   K  Vx  K   	  R # 5ir   )rm   )r   ps   & r   r   %_get_var_lib_cloud.<locals>.<genexpr>  s     @0qIIK0s   (
(z
instance/*zinstance/handlers)	itertoolschainr   r   s   &r   _get_var_lib_cloudr     sW    
 ??x |$x @INN<0@*+ r   c                n    V ^8  d   QhR\         P                  R\        \         P                  ,          /# )r   run_dirr8   r   )r   s   "r   r   r   $  s'      ',, 8GLL+A r   c                $    V P                  R4      # )zGet all paths under /run/cloud-init except for hook-hotplug-cmd.

Note that this only globs the top-level directory as there are currently
no relevant files within subdirectories.
*r   r   s   &r   _get_run_dirr   $  s     <<r   c                    V ^8  d   QhR\         P                  R\        \        \        3,          R\         P                  R\         P                  R\
        RR/# )r   ru   r   r   r   ri   r8   N)rL   rM   r   r   r   rk   )r   s   "r   r   r   -  sX     
 
\\
#s(^
 \\
 ||	

 
 

r   c                   \        V 4       \        W4       \        W4       \        V4       FD  p\	        VV \
        P                  ! V4      P                  P                  R4      ,          R4       KF  	  \        P                  ! \        4       \        VR7      \        VR7      4       FD  p\	        VV \
        P                  ! V4      P                  P                  R4      ,          V4       KF  	  R# )z8Collect all cloud-init logs into the provided directory./Tr   r   N)r   r   r|   r   rr   rL   rM   rT   relative_tor   r   r   r   r   )ru   r   r   r   ri   logfiles   &&&&& r   _collect_logs_into_tmp_dirr   -  s     '"4G7&w/ 	gll7+22>>sCC	
	 0 ??Y/W%
 	gll7+22>>sCC	
r   z/run/cloud-initz/var/lib/cloudTc                    V ^8  d   QhR\         R\        \         \        3,          R\        P                  R\        P                  R\
        RR/# )r   tarfiler   r   r   ri   r8   N)r   r   r   rL   rM   rk   )r   s   "r   r   r   N  sT     &" &"&"#s(^&" \\&" ||	&"
 &" 
&"r   c                   \         P                  P                  V 4      p \        P                  ! \
        P                  4      P                  4       P                  R4      p\        VR7      ;_uu_ 4       p\        P                  ! We4      p\        VVVVVR7       \        RRV RV\        V4      P                  V R2R4      .4       R	R	R	4       \         P#                  R
V 4       R	#   + '       g   i     L(; i)a  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 log_cfg: The cloud-init base configuration containing logging cfg.
:param run_dir: The path to the cloud-init run directory.
:param cloud_dir: The path to the cloud-init cloud directory.
:param include_sensitive: Boolean, true means include sensitive data.
zcloud-init-logs-%Y-%m-%d)dir)ru   r   r   r   ri   tarczfz-Cr    NzWrote %s)osr   abspathr   nowr   utcdatestrftimer   rL   rM   r   r   r   replacerW   info)r   r   r   r   ri   dir_nametmp_dirru   s   &&&&&   r   collect_logsr   N  s     ggoog&GX\\"'')223MN  
W		,,w1"/	
 	G$$y]B7		
 
& HHZ!' 
	s   5AC))C9	c                (    V ^8  d   QhR\         RR/# )r   r?   r8   N)int)r   s   "r   r   r   w  s      S T r   c                x   \         P                  ! 4        V ^ 8X  d   \        P                  pM(V ^8X  d   \        P                  pM\         P
                  p\        P                  V4       \        P                  ! 4       pVP                  \        P                  ! R4      4       \        P                  V4       R# )zSet up the logger for CLI use.

The verbosity controls which level gets printed to stderr. By default,
DEBUG and TRACE are hidden.
z%(message)sN)r   reset_loggingloggingINFODEBUGTRACErW   setLevelStreamHandlersetFormatter	Formatter
addHandler)r?   levelhandlers   &  r   _setup_loggerr   w  sx     A~	aLL##%G**=9:NN7r   c          
      L    V ^8  d   QhR\         R\        R\        R\        RR/# )r   r   r?   redact_sensitiveinclude_userdatar8   N)r   r   rk   )r   s   "r   r   r     s:     
 


 
 	

 

r   c                   \        V4       \        P                  ! 4       ^ 8w  d   \        R4      hV'       d   \        P                  R4       \        . R7      pVP                  4        \        V VP                  \        P                  ! VP                  P                  4      \        P                  ! VP                  P                  4      V'       * R7       V'       g   \        P                  R4       R# R# )z:Handle calls to 'cloud-init collect-logs' as a subcommand.z!This command must be run as root.z;The --include-userdata flag is deprecated and does nothing.)ds_deps)r   r   r   r   ri   zWARNING:
Sensitive data may have been included in the collected logs.
Please review the contents of the tarball before sharing or
rerun with --redact-sensitive to redact sensitive data.N)r   r   getuidRuntimeErrorrW   warningr   read_cfgr   cfgrL   rM   pathsr   r   )r   r?   r   r   inits   &&&& r   collect_logs_clir     s     )	yy{a>??I	
 DMMOTZZ//0,,tzz334.. F	
 r   c                P    V ^8  d   QhR\         R\        P                  R\        /# )r   _nameargsr8   )r   r9   	Namespacer   )r   s   "r   r   r     s'      C x/A/A c r   c                   \        4       P                  4       p \        VP                  VP                  VP
                  VP                  R7       ^ #   \         d'   p\        T\        P                  R7        Rp?^# Rp?ii ; i)zuHandle the CLI interface to the module.

Parse CLI args, redirect all exceptions to stderr, and return an exit code.
)r?   r   r   r   )fileN)rG   
parse_argsr   r?   r   r   rE   	Exceptionprintsysr`   )r   r   r[   s   && r   handle_collect_logs_argsr     se    
 <""$D
nnLL!22!]]		
  acjj!s   7A BA??B__main__r   r   )    TF):__doc__r9   r   r   r   rL   rn   rb   r   r   r   typingr   r   r   r   r   r	   r
   cloudinit.logr   cloudinit.stagesr   cloudinit.subpr   r   cloudinit.temp_utilsr   cloudinit.utilr   r   r   CustomLoggerType	getLoggerr!   rW   r   ry   rx   rG   r\   rf   rr   r|   r   r   r   rM   r   r   r   r   r   r   r   r   exitr   r    r   r   <module>r      s   N    	    
 ' H H H ! ! 6 ( @ @
7##W%6%6x%@A  24I "$568:MN$   @(K79O 79O 6D: B D B G"
 9=I5}E9;GC" J6r&D&1*. ,! #*,,|"<,
H $LL):;%ll+;<"&"R&
B& zHH%b*,*A*A*CDE r   