Ë
    x[hˆ  ã                   óä   — d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZmZmZ dd	lmZmZmZmZmZ d
ZedddddgZdgZdd„Zdd„Zd„ Zd„ Ze dk(  r e«        yy)zFDefine 'clean' utility and handler as part of cloud-init command line.é    N)Úsettings)Ú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           	      ó  — | st        j                  dd¬«      } | j                  dddddd	¬
«       | j                  dddd¬«       | j                  ddddd¬«       | j                  dddddd¬
«       | j                  ddg d¢g ddd¬«       | S )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-idz§Set /etc/machine-id to 'uninitialized
' for golden imagecreation. 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)ÚallÚ
ssh_configÚnetworkú+Úremove_configzbRemove cloud-init generated config files of a certain type. Config types: all, ssh_config, network)Úchoicesr   Únargsr   r   )ÚargparseÚArgumentParserÚadd_argument©Úparsers    ú5/usr/lib/python3/dist-packages/cloudinit/cmd/clean.pyÚ
get_parserr(   *   sì   € ñ Ü×(Ñ(Øð$ô
ˆð ×ÑØØØØØØ&ð ô ð ×ÑØØØðCð ô 	ð ×ÑØØØØØJð ô ð ×ÑØØØØØØDð ô ð ×ÑØØò
ð
 ØØð2ð ô ð €Mó    c           
      óx  — | j                  «        |r%t        | j                  «      D ]  }t        |«       Œ |rLt	        |«      j                  ddg«      r0t        D ]'  }t        j                  |«      D ]  }t        |«       Œ Œ) |r2t	        |«      j                  ddg«      rt        D ]  }t        |«       Œ t        j                  j                  | j                  j                  «      syt        j                  j                  | j                  j                  d«      }t        j                  d| j                  j                  z  «      D ]L  }||k(  r|sŒ	 t        j                  j                  |«      rt        |«      st!        |«       nt        |«       ŒN 	 t-        t.        j0                  «       y# t"        $ r9}t%        j&                  dj)                  |t+        |«      «      «       Y d}~ y	d}~ww xY w# t2        $ r3}t%        j&                  d
t.        j0                  › d|› �«       Y d}~y	d}~ww xY w)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.
    @returns: 0 on success, 1 otherwise.
    r   r   r   r   Úseedz%s/*zCould not remove {0}: {1}Né   zFailure during run-parts of z: )Úread_cfgr   Úcfgr   ÚsetÚintersectionÚGEN_NET_CONFIG_FILESÚglobÚGEN_SSH_CONFIG_FILESÚosÚpathÚisdirÚpathsÚ	cloud_dirÚjoinr   r   ÚOSErrorr   ÚerrorÚformatÚstrr	   r   ÚCLEAN_RUNPARTS_DIRÚ	Exception)	Úinitr   r   r   Úlog_filer5   ÚconfÚ	seed_pathÚes	            r'   Úremove_artifactsrE   m   sÍ  € ð 	‡M�M„OÙÜ+¨D¯H©HÓ5ò 	ˆHÜ�XÕð	áœ˜]Ó+×8Ñ8¸%ÀÐ9KÔLÜ(ò 	ˆDÜŸ	™	 $›ò �Ü˜•ñð	ñ œ˜]Ó+×8Ñ8Ø	�Ðôô )ò 	ˆDÜ�T�Nð	ô �7‰7�=‰=˜Ÿ™×-Ñ-Ô.ØÜ—‘—‘˜TŸZ™Z×1Ñ1°6Ó:€IÜ—	‘	˜& 4§:¡:×#7Ñ#7Ñ7Ó8ò 
ˆØ�9Ò¡[Øð	Ü�w‰w�}‰}˜TÔ"¬7°4¬=Ü˜•ä˜”øð
ðÜ”×,Ñ,Ô-ð øô ò 	Ü�N‰NÐ6×=Ñ=¸dÄCÈÃFÓKÔLÝûð	ûô
 ò Ü�‰Ø*¬8×+FÑ+FÐ*GÀrÈ!ÈÐMô	
ô ûð	ús1   ÅAF8ÆG= Æ8	G:Ç.G5Ç5G:Ç=	H9È)H4È4H9c           	      óò  — t        g ¬«      }t        ||j                  |j                  |j                  «      }|j
                  r,t        «       rt        t        dd¬«       nt        t        «       |dk(  r:|j                  r.|j                  j                  ddd¬	«      }	 t        |d
¬«       |S |S # t        $ r;}t        j                   dj#                  |t%        |«      «      «       d}Y d}~|S d}~ww xY w)z3Handle calls to 'cloud-init clean' as a subcommand.)Úds_depszuninitialized
i$  )Úmoder   ÚrebootÚnowN)rH   ÚdelayÚmessageF)Úcapturez-Could not reboot this system using "{0}": {1}r,   )r   rE   r   r   r   Ú
machine_idr   r   ÚETC_MACHINE_IDr   rI   ÚdistroÚshutdown_commandr
   r   r   r;   r<   r=   )ÚnameÚargsr@   Ú	exit_codeÚcmdrD   s         r'   Úhandle_clean_argsrV   Ÿ   sá   € ä˜Ô€DÜ Øˆd×Ñ × 0Ñ 0°$×2DÑ2Dó€Ið ‡‚ÜŒ>ä”~Ð'8¸uÖEô ”^Ô$Ø�A‚~˜$Ÿ+š+Ø�k‰k×*Ñ*Ø °ð +ó 
ˆð	Ü�˜eÕ$ð Ðˆ9Ðøô %ò 	Ü�N‰NØ?×FÑFØœ˜Q›óôð
 ŒIØÐûð	ús   Â!B2 Â2	C6Â;0C1Ã1C6c                  ór   — t        «       } t        j                  t        d| j	                  «       «      «       y)z4Tool to collect and tar all cloud-init related logs.r   N)r(   ÚsysÚexitrV   Ú
parse_argsr%   s    r'   Úmainr[   ¼   s&   € ä‹\€FÜ‡H�HÔ˜w¨×(9Ñ(9Ó(;Ó<Õ=r)   Ú__main__)N)FN)!Ú__doc__r"   r2   r4   rX   Ú	cloudinitr   Úcloudinit.distrosr   Úcloudinit.logr   Úcloudinit.net.netplanr   Úcloudinit.stagesr   Úcloudinit.subpr   r	   r
   Úcloudinit.utilr   r   r   r   r   rO   r1   r3   r(   rE   rV   r[   Ú__name__© r)   r'   ú<module>rg      s�   ðñ Mã Û Û 	Û 
å Ý *Ý "Ý 8Ý !ß @Ñ @÷õ ð #€àØ3ØEØFØ2Ø1ðÐ ð 0ðÐ ó
@óF/òdò:>ð ˆzÒÙ…Fð r)   