HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-87-generic #88-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 09:28:41 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/cmd/__pycache__/clean.cpython-312.pyc
�

쑛h��� �dZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZddl
mZddlmZddlmZdd	lmZmZmZdd
lmZmZmZmZmZej:e�ZdZ edd
dddgZ!dgZ"dd�Z#dd�Z$d�Z%d�Z&edk(re&�yy)zFDefine 'clean' utility and handler as part of cloud-init command line.�N)�settings�sources)�	cc_mounts)�uses_systemd)�log_util)�CLOUDINIT_NETPLAN_FILE)�Init)�ProcessExecutionError�runparts�subp)�del_dir�del_file�get_config_logfiles�is_link�
write_filez/etc/machine-idz-/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	��|stjdd��}|jdddddd	�
�|jdddd�
�|jddddd�
�|jdddddd�
�|jddgd�gddd��|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.)rrrz-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�
datasource�fstab�+�
remove_configzbRemove cloud-init generated config files of a certain type. Config types: all, ssh_config, network)�choicesr�nargsrr)�argparse�ArgumentParser�add_argument��parsers �5/usr/lib/python3/dist-packages/cloudinit/cmd/clean.py�
get_parserr,-s�����(�(��$�
���������
�
&�
��������
C��	��������
J����������
�
D�
�������
���
�2��� �M�c
�:�|j�|r%t|j�D]
}t|��|rLt	|�jddg�r0tD]'}tj|�D]
}t|���)|r2t	|�jddg�rtD]
}t|��|r0t	|�jddg�rtj�|xrt	|�jddg�}tjj|jj�s+t!j"dt$t&j(��y|r	|j+�j-�tjj3|jjd
�}tjd|jjz�D]L}||k(r|s�	tjj|�rt5|�st7|�nt|��N	tAtBjD�y#t.j0$r.t!j"d	t$t&j(��Y��
wxYw#t8$r9}	t!j:dj=|t?|	���Yd
}	~	yd
}	~	wwxYw#tF$r3}	t!j:dtBjD�d|	���Yd
}	~	yd
}	~	wwxYw)a�Helper which removes artifacts dir and optionally log files.

    @param: init: Init object to use
    @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, datasource, fstab.
    @returns: 0 on success, 1 otherwise.
    rrrr!r zArtifacts already cleaned.)�log�	log_levelrz%No datasource found, nothing cleaned.�seedz%s/*zCould not remove {0}: {1}N�zFailure during run-parts of z: )$�read_cfgr�cfgr�set�intersection�GEN_NET_CONFIG_FILES�glob�GEN_SSH_CONFIG_FILESr�
cleanup_fstab�os�path�isdir�paths�	cloud_dirr�	multi_log�LOG�logging�INFO�fetchrr�DataSourceNotFoundException�joinrr
�OSError�error�format�strrr�CLEAN_RUNPARTS_DIR�	Exception)
�initrrr#�log_filer<�conf�clean_datasource�	seed_path�es
          r+�remove_artifactsrSrs���	�M�M�O��+�D�H�H�5�	�H��X��	���]�+�8�8�%��9K�L�(�	�D��	�	�$��
�����
�	���]�+�8�8�	����)�	�D��T�N�	���]�+�8�8�%��9I�J����!�$���]�);�)H�)H�	���*���7�7�=�=����-�-�.����(���l�l�	
�
��	��J�J�L��� ������T�Z�Z�1�1�6�:�I��	�	�&�4�:�:�#7�#7�7�8�
���9��[��	��w�w�}�}�T�"�7�4�=���
�����
����,�,�-�
��5�2�2�	����7��!�,�,�
�
�	�� �	��N�N�6�=�=�d�C��F�K�L���	��
�����*�8�+F�+F�*G�r�!��M�	
���	�sC�-I�7AJ�;K�=J�J�	K�".K�K�	L�')L�Lc	���tg��}t||j|j|j�}|j
r,t
�rttdd��ntt�|dk(r:|jr.|jjddd�	�}	t|d
��|S|S#t$r;}tj dj#|t%|���d
}Yd}~|Sd}~wwxYw)z3Handle calls to 'cloud-init clean' as a subcommand.)�ds_depszuninitialized
i$)�moder�reboot�nowN)rV�delay�messageF)�capturez-Could not reboot this system using "{0}": {1}r2)r	rSrrr#�
machine_idrr�ETC_MACHINE_IDrrW�distro�shutdown_commandrr
rrHrIrJ)�name�argsrM�	exit_code�cmdrRs      r+�handle_clean_argsrd�s������D� ��d���� 0� 0�$�2D�2D��I�����>��~�'8�u�E�
�^�$��A�~�$�+�+��k�k�*�*����+�
��	���e�$���9���%�	��N�N�?�F�F���Q���
�
�I����	�s�!
B2�2	C6�;0C1�1C6c�r�t�}tjtd|j	���y)z4Tool to collect and tar all cloud-init related logs.rN)r,�sys�exitrd�
parse_argsr)s r+�mainri�s&��
�\�F��H�H�
�w��(9�(9�(;�
<�=r-�__main__)N)FN)'�__doc__r&r8rBr;rf�	cloudinitrr�cloudinit.configr�cloudinit.distrosr�
cloudinit.logr�cloudinit.net.netplanr�cloudinit.stagesr	�cloudinit.subpr
rr�cloudinit.utilr
rrrr�	getLogger�__name__rAr]r7r9r,rSrdri�r-r+�<module>rws���M����	�
�'�&�*�"�8�!�@�@����g����!��"���3�E�F�2�1�
��0���
B�JE
�P�:>��z���F�r-