File: //lib/python3.6/site-packages/cloudinit/cmd/__pycache__/clean.cpython-36.opt-1.pyc
3
\�me� � @ s� d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
Z
ddlmZm
Z
mZ ddlmZmZmZmZmZmZ dZd d
ddd
dgZdgZddd�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-idz/etc/netplan/50-cloud-init.yamlz-/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 C s� | st jddd�} | jdddddd d
� | jddddd
� | jdddddd
� | jddddddd
� | jdddddgg dddd� | 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_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 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)�parser� r# �/usr/lib/python3.6/clean.py�
get_parser) sP r% Fc C s� t g d�}|j� | r2xt|j�D ]}t|� q"W |rrt|�jddg�rrx(tD ] }xtj|�D ]}t|� q^W qNW |r�t|�jddg�r�xt D ]}t|� q�W t
jj|j
j�s�dS t
jj|j
jd�}x�tjd|j
j �D ]|}||kr�| r�q�y0t
jj|��rt|� �rt|� nt|� W q� tk
�rR } ztdj|t|��� d S d
}~X q�X q�W yttj� W n8 tk
�r� } ztdtj� d|� �� d S d
}~X nX dS )
a� 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.
@param: remove_config: List of strings.
Can be any of: all, network, ssh_config.
@returns: 0 on success, 1 otherwise.
)Zds_depsr r r r Zseedz%s/*zCould not remove {0}: {1}� NzFailure during run-parts of z: )r Zread_cfgr Zcfgr �set�intersection�GEN_NET_CONFIG_FILES�glob�GEN_SSH_CONFIG_FILES�os�path�isdir�pathsZ cloud_dir�joinr r �OSErrorr
�format�strr r ZCLEAN_RUNPARTS_DIR� Exception) r r r ZinitZlog_filer- ZconfZ seed_path�er# r# r$ �remove_artifactsl sB
r6 c C s� t |j|j|j�}|jr6t� r.ttddd� ntt� |dkr�|j r�dddg}yt
|dd � W n: tk
r� } ztd
j
|t|��� d}W Y dd}~X nX |S )
z3Handle calls to 'cloud-init clean' as a subcommand.zuninitialized
i$ )�moder Zshutdownz-rZnowF)Zcapturez-Could not reboot this system using "{0}": {1}r&