Your IP : 216.73.216.52


Current Path : /lib/python3/dist-packages/cloudinit/cmd/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/cmd/__pycache__/clean.cpython-38.pyc

U

�Ad��@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZmZmZmZmZmZdZdd	d
�Zddd
�Zdd�Zdd�Zedkr�e�dS)zEDefine 'clean' utility and handler as part of cloud-init commandline.�N)�settings)�uses_systemd)�Init)�ProcessExecutionError�runparts�subp)�del_dir�del_file�error�get_config_logfiles�is_link�
write_filez/etc/machine-idcCsh|stjddd�}|jdddddd	d
�|jddddd
�|jdddddd
�|jddddddd
�|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.
    �cleanzARemove logs and artifacts so cloud-init re-runs on a clean system)�progZdescriptionz-lz--logs�
store_trueF�remove_logszRemove 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.)rrr�-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.)�argparse�ArgumentParser�add_argument��parser�r�5/usr/lib/python3/dist-packages/cloudinit/cmd/clean.py�
get_parsersF	���
��rFcCs8tgd�}|��|r.t|j�D]}t|�q tj�|jj	�sBdStj�
|jj	d�}t�d|jj	�D]|}||krx|sxqfz*tj�|�r�t|�s�t
|�nt|�Wqftk
r�}z td�|t|���WY�dSd}~XYqfXqfzttj�Wn@tk
�r2}z tdtj�d	|���WY�dSd}~XYnXdS)
a4Helper which removes artifacts dir and optionally log files.

    @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.
    @returns: 0 on success, 1 otherwise.
    )Zds_depsrZseedz%s/*zCould not remove {0}: {1}�NzFailure during run-parts of z: )rZread_cfgrZcfgr	�os�path�isdir�pathsZ	cloud_dir�join�globrr�OSErrorr
�format�strrrZCLEAN_RUNPARTS_DIR�	Exception)rrZinitZlog_fileZ	seed_pathr"�errr�remove_artifactsSs4	


�r,c
Cs�t|j|j�}|jr2t�r*ttddd�ntt�|dkr�|jr�dddg}zt	|dd	�Wn:t
k
r�}ztd
�|t
|���d}W5d}~XYnX|S)
z3Handle calls to 'cloud-init clean' as a subcommand.zuninitialized
i$)�moderZshutdownrZnowF)Zcapturez-Could not reboot this system using "{0}": {1}r N)r,rrZ
machine_idrr
�ETC_MACHINE_IDr	Zrebootrrr
r(r))�name�argsZ	exit_code�cmdr+rrr�handle_clean_argszs$
��r2cCst�}t�td|����dS)z4Tool to collect and tar all cloud-init related logs.rN)r�sys�exitr2�
parse_argsrrrr�main�sr6�__main__)N)F)�__doc__rr&r!r3Z	cloudinitrZcloudinit.distrosrZcloudinit.stagesrZcloudinit.subprrrZcloudinit.utilrr	r
rrr
r.rr,r2r6�__name__rrrr�<module>s  	
5
'