| Current Path : /lib/python3/dist-packages/cloudinit/cmd/__pycache__/ |
| Current File : //lib/python3/dist-packages/cloudinit/cmd/__pycache__/clean.cpython-38.pyc |
U
�Ad� � @ s� d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
Z
ddlmZm
Z
mZ ddlmZmZmZmZmZmZ dZdd d
�Zddd
�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-idc C sh | st jddd�} | jdddddd d
� | jddddd
� | 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.)r r r �-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_parser sF ���
��r Fc C s8 t g d�}|�� | r.t|j�D ]}t|� q tj�|jj �sBdS tj�
|jj d�}t�d|jj �D ]|}||krx|sxqfz*tj�|�r�t|�s�t
|� nt|� W qf tk
r� } z td�|t|��� W Y � dS d}~X Y qfX qfzttj� W n@ tk
�r2 } z tdtj� d |� �� W Y �dS d}~X Y nX dS )
a4 Helper 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_depsr Zseedz%s/*zCould not remove {0}: {1}� NzFailure during run-parts of z: )r Zread_cfgr Zcfgr �os�path�isdir�pathsZ cloud_dir�join�globr r �OSErrorr
�format�strr r ZCLEAN_RUNPARTS_DIR� Exception)r r ZinitZlog_fileZ seed_pathr"