HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3/dist-packages/cloudinit/cmd/__pycache__/clean.cpython-310.pyc
o

�Ad��@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZmZmZmZmZmZdZdd	d
�Zddd
�Zdd�Zdd�Zedkr[e�dSdS)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|s	tjddd�}|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)�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.)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	���
��r FcCs.tgd�}|��|rt|j�D]}t|�qtj�|jj	�s!dStj�
|jj	d�}t�d|jj	�D]<}||kr<|s<q3ztj�|�rLt|�sLt
|�nt|�Wq3tyo}ztd�|t|���WYd}~dSd}~wwzttj�WdSty�}ztdtj�d	|���WYd}~dSd}~ww)
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.
    )�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�strrr�CLEAN_RUNPARTS_DIR�	Exception)rr�init�log_file�	seed_pathr'�errr�remove_artifactsSs>
	

�������r6c
Cs�t|j|j�}|jrt�rttddd�ntt�|dkrM|jrMgd�}z	t	|dd�W|St
yL}ztd�|t
|���d	}WYd
}~|Sd
}~ww|S)z3Handle calls to 'cloud-init clean' as a subcommand.zuninitialized
i$)�moder)�shutdownr�nowF)�capturez-Could not reboot this system using "{0}": {1}r#N)r6rr�
machine_idrr
�ETC_MACHINE_IDr	�rebootrrr
r.r/)�name�args�	exit_code�cmdr5rrr�handle_clean_argszs*�����rBcCst�}t�td|����dS)z4Tool to collect and tar all cloud-init related logs.rN)r �sys�exitrB�
parse_argsrrrr�main�srF�__main__)N)F)�__doc__rr,r&rC�	cloudinitr�cloudinit.distrosr�cloudinit.stagesr�cloudinit.subprrr�cloudinit.utilrr	r
rrr
r<r r6rBrF�__name__rrrr�<module>s$ 	

5'
�