HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/cloudinit/cmd/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/cmd/__pycache__/clean.cpython-312.pyc
�

�f�����dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZmZmZddlmZmZmZmZmZmZd	Ze
d
ddd
dgZdgZdd�Zdd�Zd�Zd�Zedk(re�yy)zEDefine 'clean' utility and handler as part of cloud-init commandline.�N)�settings)�uses_systemd)�CLOUDINIT_NETPLAN_FILE)�Init)�ProcessExecutionError�runparts�subp)�del_dir�del_file�error�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.)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.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�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
�h�tg��}|j�|r%t|j�D]
}t	|��|rLt|�j
ddg�r0tD]'}tj|�D]
}t	|���)|r2t|�j
ddg�rtD]
}t	|��tjj|jj�sytjj|jjd�}tjd|jjz�D]L}||k(r|s�	tjj|�rt!|�st#|�nt	|��N	t-t.j0�y#t$$r/}t'dj)|t+|���Yd	}~y
d	}~wwxYw#t2$r)}t'dt.j0�d|���Yd	}~y
d	}~wwxYw)
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.
    )�ds_depsrrrr�seedz%s/*zCould not remove {0}: {1}N�zFailure during run-parts of z: )r�read_cfgr
�cfgr�set�intersection�GEN_NET_CONFIG_FILES�glob�GEN_SSH_CONFIG_FILES�os�path�isdir�paths�	cloud_dir�joinrr
�OSErrorr�format�strrr�CLEAN_RUNPARTS_DIR�	Exception)	rrr �init�log_filer7�conf�	seed_path�es	         r(�remove_artifactsrFms������D��M�M�O��+�D�H�H�5�	�H��X��	���]�+�8�8�%��9K�L�(�	�D��	�	�$��
�����
�	���]�+�8�8�	����)�	�D��T�N�	��7�7�=�=����-�-�.�������T�Z�Z�1�1�6�:�I��	�	�&�4�:�:�#7�#7�7�8�
���9��[��	��w�w�}�}�T�"�7�4�=���
�����
����,�,�-�
���	��-�4�4�T�3�q�6�B�C���	��
��
�*�8�+F�+F�*G�r�!��M�	
���	�s1�&AG�*G?�	G<�
$G7�7G<�?	H1�H,�,H1c	��t|j|j|j�}|jr,t�rt
tdd��ntt�|dk(r |jrgd�}	t|d��|S|S#t$r1}tdj|t|���d	}Yd
}~|Sd
}~wwxYw)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)rFrrr �
machine_idrr�ETC_MACHINE_IDr�rebootr	rrr=r>)�name�args�	exit_code�cmdrEs     r(�handle_clean_argsrS�s��� ����$�*�*�D�,>�,>��I�����>��~�'8�u�E�
�^�$��A�~�$�+�+�'��	���e�$���9���%�	��?�F�F���Q���
�
�I����	�s�:
B�	C�&C�Cc�r�t�}tjtd|j	���y)z4Tool to collect and tar all cloud-init related logs.rN)r)�sys�exitrS�
parse_argsr&s r(�mainrX�s&��
�\�F��H�H�
�w��(9�(9�(;�
<�=r*�__main__)N)FN) �__doc__r#r4r6rU�	cloudinitr�cloudinit.distrosr�cloudinit.net.netplanr�cloudinit.stagesr�cloudinit.subprrr	�cloudinit.utilr
rrr
rrrMr3r5r)rFrSrX�__name__�r*r(�<module>rcs���L���	�
��*�8�!�@�@���#���3�E�F�2�1�
��0���
@�F/
�d�4>��z���F�r*