File: //usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/clean.cpython-310.pyc
o
�Ad� � @ s� d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
Z
ddlmZm
Z
mZ ddlmZmZmZmZmZmZ dZdd d
�Zddd
�Zdd� Zdd� Zedkr[e� dS 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 | s t 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)�prog�descriptionz-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 s. t g d�}|�� | rt|j�D ]}t|� qtj�|jj �s!dS tj�
|jj d�}t�d|jj �D ]<}||kr<|s<q3ztj�|�rLt|�sLt
|� nt|� W q3 tyo } ztd�|t|��� W Y d}~ dS d}~ww zttj� W dS ty� } ztdtj� d |� �� W Y d}~dS d}~ww )
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.
)�ds_depsr �seedz%s/*zCould not remove {0}: {1}N� zFailure during run-parts of z: )r �read_cfgr �cfgr �os�path�isdir�paths� cloud_dir�join�globr r �OSErrorr
�format�strr r �CLEAN_RUNPARTS_DIR� Exception)r r �init�log_file� seed_pathr'