+
    i                     @   R 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 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHt ^ R	IHtHtHtHtHt ]P<                  ! ]4      t R
t!]RRRRR.t"R.t#R R lt$RR lt%RR lt&R t'R t(]R8X  d
   ](! 4        R# R# )zFDefine 'clean' utility and handler as part of cloud-init command line.N)settingssources)	cc_mounts)uses_systemd)log_util)CLOUDINIT_NETPLAN_FILE)Init)ProcessExecutionErrorrunpartssubp)del_dirdel_fileget_config_logfilesis_link
write_filez/etc/machine-idz-/etc/NetworkManager/conf.d/99-cloud-init.confz?/etc/NetworkManager/conf.d/30-cloud-init-ip6-addr-gen-mode.confz@/etc/NetworkManager/system-connections/cloud-init-*.nmconnectionz,/etc/systemd/network/10-cloud-init-*.networkz+/etc/network/interfaces.d/50-cloud-init.cfgz)/etc/ssh/sshd_config.d/50-cloud-init.confc                0    V ^8  d   QhR\         R\        /# )   log_filereturn)strbool)formats   "5/usr/lib/python3/dist-packages/cloudinit/cmd/clean.py__annotate__r   .   s      S T     c                     \         P                  ! V 4      p\        P                  ! VP                  4      '       g'   \        P                  ! VP                  4      '       d   R#  R#   \
         d     R# i ; i)zCheck if a log file should be removed.

Avoid tracebacks from attempting to remove device files.

@param log_file: Path to the log file to check.
@returns: True if the file should be removed, False otherwise.
FT)osstatS_ISBLKst_modeS_ISCHROSError)r   	file_stats   & r   should_remove_log_filer#   .   s`    GGH%	<<	))**dll9;L;L.M.M /N   s   ;A) %A) )A87A8c           
     ,   V '       g   \         P                  ! RRR7      p V P                  RRRRRR	R
7       V P                  RRRRR7       V P                  RRRRRR7       V P                  RRRRRRR
7       V P                  RR. RO. RRRR7       V # )a  Build or extend an arg parser for clean utility.

@param parser: Optional existing ArgumentParser instance representing the
    clean subcommand which will be extended to support the args of
    this utility.

@returns: ArgumentParser with proper argument configuration.
cleanzJRemove logs, configs and artifacts so cloud-init re-runs on a clean system)progdescriptionz-lz--logs
store_trueFremove_logszRemove cloud-init logs.)actiondefaultdesthelpz--machine-idzSet /etc/machine-id to 'uninitialized\n' for golden image creation. On next boot, systemd generates a new machine-id. Remove /etc/machine-id on non-systemd environments.)r*   r+   r-   z-rz--rebootz;Reboot system after logs are cleaned so cloud-init re-runs.z-sz--seedremove_seedz5Remove cloud-init seed directory /var/lib/cloud/seed.z-cz	--configs+remove_configzbRemove cloud-init generated config files of a certain type. Config types: all, ssh_config, network)choicesr+   nargsr,   r-   )all
ssh_confignetwork
datasourcefstab)argparseArgumentParseradd_argumentparsers   &r   
get_parserr=   ?   s     (($
 &   C  	 J   D   
 2    Mr   c           
     @   V P                  4        V'       d;   \        V P                  4       F!  p\        V4      '       g   K  \	        V4       K#  	  V'       dX   \        V4      P                  RR.4      '       d6   \         F+  p\        P                  ! V4       F  p\	        V4       K  	  K-  	  V'       d;   \        V4      P                  RR.4      '       d   \         F  p\	        V4       K  	  V'       d8   \        V4      P                  RR.4      '       d   \        P                  ! 4        T;'       d    \        V4      P                  RR.4      p\        P                  P                  V P                  P                   4      '       g.   \"        P$                  ! R\&        \(        P*                  R7       ^ # V'       d     V P-                  4       P/                  4        \        P                  P5                  V P                  P                   R	4      p\        P                  ! R
V P                  P                   ,          4       Fb  pWX8X  d   V'       g   K   \        P                  P                  V4      '       d   \7        V4      '       g   \9        V4       KW  \	        V4       Kd  	   \C        \D        PF                  4       ^ #   \0        P2                   d0    \"        P$                  ! R\&        \(        P*                  R7        EL*i ; i  \:         d<   p	\"        P<                  ! RP?                  T\A        T	4      4      4        Rp	?	 ^# Rp	?	ii ; i  \H         d6   p	\"        P<                  ! R\D        PF                   RT	 24        Rp	?	^# Rp	?	ii ; i)a  Helper which removes artifacts dir and optionally log files.

@param: init: Init object to use
@param: remove_logs: Boolean. Set True to delete the cloud_dir path. False
    preserves them.
@param: remove_seed: Boolean. Set True to also delete seed subdir in
    paths.cloud_dir.
@param: remove_config: List of strings.
    Can be any of: all, network, ssh_config, datasource, fstab.
@returns: 0 on success, 1 otherwise.
r3   r5   r4   r7   r6   zArtifacts already cleaned.)log	log_levelz%No datasource found, nothing cleaned.seedz%s/*zCould not remove {0}: {1}NzFailure during run-parts of z: )%read_cfgr   cfgr#   r   setintersectionGEN_NET_CONFIG_FILESglobGEN_SSH_CONFIG_FILESr   cleanup_fstabr   pathisdirpaths	cloud_dirr   	multi_logLOGloggingINFOfetchr%   r   DataSourceNotFoundExceptionjoinr   r   r!   errorr   r   r
   r   CLEAN_RUNPARTS_DIR	Exception)
initr)   r.   r0   r   rJ   confclean_datasource	seed_pathes
   &&&&      r   remove_artifactsr]      s    	MMO+DHH5H%h//" 6 ]+88%9KLL(D		$ ( ) ]+88	  )DTN )]+88%9IJJ!$  ]);)H)H	* 77==--..(ll	

 	JJL  TZZ116:I		&4::#7#778[	ww}}T""74== 9,,- 5 22 	7!,, 	   	NN6==dCFKL	
  *8+F+F*Gr!M	
 	sO   K $LL"L2M A LLM/MMN(*NNc           	        \        . R7      p\        W!P                  VP                  VP                  4      pVP
                  '       d3   \        4       '       d   \        \        RRR7       M\        \        4       V^ 8X  dA   VP                  '       d/   VP                  P                  RRRR7      p \        VR	R
7       V# V#   \         d=   p\        P                   ! RP#                  T\%        T4      4      4       ^p Rp?T# Rp?ii ; i)z3Handle calls to 'cloud-init clean' as a subcommand.)ds_depszuninitialized
i$  )moderebootnowN)r`   delaymessageF)capturez-Could not reboot this system using "{0}": {1})r   r]   r)   r.   r0   
machine_idr   r   ETC_MACHINE_IDr   ra   distroshutdown_commandr   r	   r   rU   r   r   )nameargsrX   	exit_codecmdr\   s   &&    r   handle_clean_argsrn      s    D  0 0$2D2DI >>~'8uE ^$A~$+++kk** + 
	e$ 9 % 	NN?FFQ
 I	s   4C D1DDc                 v    \        4       p \        P                  ! \        RV P	                  4       4      4       R# )z4Tool to collect and tar all cloud-init related logs.r%   N)r=   sysexitrn   
parse_argsr;   s    r   mainrs      s&    \FHHw(9(9(;<=r   __main__)N)FN))__doc__r8   rG   rP   r   r   rp   	cloudinitr   r   cloudinit.configr   cloudinit.distrosr   cloudinit.logr   cloudinit.net.netplanr   cloudinit.stagesr   cloudinit.subpr	   r
   r   cloudinit.utilr   r   r   r   r   	getLogger__name__rO   rg   rF   rH   r#   r=   r]   rn   rs    r   r   <module>r      s    M    	  
 ' & * " 8 ! @ @  !"3EF21  0 
"BJFR:> zF r   