Current File : //usr/share/netplan/netplan_cli/cli/commands/__pycache__/ip.cpython-312.pyc
�

Z9
gV���dZddlZddlZddlZddlZddlmZddlmZddd�d	d
d�d�ZGd�d
ej�Z
Gd�dej�Zy)znetplan ip command line�N)�CalledProcessError�)�utilsz#run/systemd/netif/leases/{lease_id}�ifindex)�pattern�methodz<var/lib/NetworkManager/internal-{lease_id}-{interface}.lease�
nm_connection)�networkd�NetworkManagerc�$��eZdZ�fd�Zd�Z�xZS)�	NetplanIpc�*��t�|�ddd��y)N�ipz'Retrieve IP information from the systemF��
command_id�description�leaf��super�__init__��self�	__class__s ��1/usr/share/netplan/netplan_cli/cli/commands/ip.pyrzNetplanIp.__init__*s���
���D�%N�#�	�	%�c��t�|_|jjddd��}|j	|jj
|j��|j
�|j�y)N�leases�Display IP leasesF)�help�add_help)�func�commandclass)�NetplanIpLeases�command_leases�
subparsers�
add_parser�set_defaults�run�
parse_args�run_command)r�p_ip_leasess  rr(z
NetplanIp.run/sn��-�/����o�o�0�0��6I�:?�1�A��	� � �d�&9�&9�&=�&=�D�L_�L_� �`��������r)�__name__�
__module__�__qualname__rr(�
__classcell__�rs@rr
r
(s
���%�

rr
c�*��eZdZ�fd�Zd�Zd�Z�xZS)r#c�*��t�|�ddd��y)Nz	ip leasesrTrrrs �rrzNetplanIpLeases.__init__>s���
���K�%8�"�	�	$rc���|jjdd��|jjdd��|j|_|j	�|j�y)N�	interfacez1Interface for which to display IP lease settings.)r�
--root-dirzBSearch for configuration files in this root directory instead of /)�parser�add_argument�command_ip_leasesr!r)r*)rs rr(zNetplanIpLeases.runCsa����� � ��&Y�	!�	[���� � ��&j�	!�	l��*�*��	��������rc�Z���jdk(r�j��fd�}tj�g}�jr|d�jgz
}|d�jgz
}tjd|�	tj|d��}i}jd�}|D])}|j�jd�\}}|||<�+||�y#t$r@td�jztj�	�tjd
�Y��wxYw)
Nrc	����
fd�}�
fd�}t|dd}t|dd}	td|z��}tjj	d�
j
r)tjj
�
j
�nd|j�
j|�	��}tjj|�s|jd
d�}t|�5}|j�D]}t|j���	ddd�y#1swYyxYw#t$rS}	td�
j�d
t!|	���t"j$��t#j&d�Yd}	~	yd}	~	wwxYw)Nc�D��tjjd�jd�}	t	|�5}|j�dj
�cddd�S#1swYyxYw#t$r&}tjd|t|���d}~wwxYw)Nz/sys/class/netrrzCannot read file %s: %s)�os�path�joinr4�open�	readlines�strip�	Exception�logging�debug�str)�	ifindex_f�f�ers   �r�lease_method_ifindexzXNetplanIpLeases.command_ip_leases.<locals>.find_lease_file.<locals>.lease_method_ifindexTs����G�G�L�L�)9�4�>�>�9�U�	���i��8�A� �{�{�}�Q�/�5�5�7�8�8�8�� ���M�M�";�Y��A��O����s4�A0�!A$�	A0�$A-�)A0�-A0�0	B�9!B�Bc���	tjdd�jg�}|j�D]�}d|vs�|j	d�dj�j
�}tjddd|g�}|j�D]:}d|vs�|j	d�dj�j
�ccS��	td
��#t$r}td	t|�z��d}~wwxYw)N�dev�showzGENERAL.CONNECTION�:��con�idzconnection.uuidz@Could not find a NetworkManager connection for the interface: %sz<Could not find a NetworkManager connection for the interface)	r�	nmcli_outr4�
splitlines�split�rstriprArBrE)�
nmcli_dev_out�line�conn_id�
nmcli_con_outrHrs     �r�lease_method_nm_connectionz^NetplanIpLeases.command_ip_leases.<locals>.find_lease_file.<locals>.lease_method_nm_connection]s���
q�$)�O�O�U�F�D�N�N�4S�$T�M� -� 8� 8� :�O��/�4�7�&*�j�j��o�a�&8�&?�&?�&A�&G�&G�&I�G�,1�O�O�U�F�D�RY�<Z�,[�M�(5�(@�(@�(B�O��#4��#<�+/�:�:�c�?�1�+=�+D�+D�+F�+L�+L�+N�$N�O�	O� � ^�_�_��!�q�#�$f�il�mn�io�$o�p�p��q�s)�9C!�A C!�3C!�C!�!	D�*D�D�backendrr�
lease_method_�/�)r4�lease_idzNetworkManager/internal-zNetworkManager/dhclient-zNo lease found for interface 'z': ��filerN)�
lease_path�evalr<r=r>�root_dir�abspath�formatr4�isfile�replacer?r@�printrTrBrE�sys�stderr�exit)�mappingrIrY�
lease_pattern�lease_methodr^r=rGrVrHrs          �r�find_lease_filez:NetplanIpLeases.command_ip_leases.<locals>.find_lease_fileSsF���
�

`�'�w�y�'9�:�9�E�M�%�g�i�&8�9�(�C�L�
�?�4��,� >�?�A���w�w�|�|�C�FJ�m�m�B�G�G�O�O�D�M�M�$B�Y[�$1�$8�$8�4�>�>�BJ�%9�%L�M���w�w�~�~�d�+��<�<�(B�D^�_�D��$�Z�-�1� !���
�-���d�k�k�m�,�-�-�-�-���
�����QT�UV�QW�X��:�:�'��������
�s7�CD0�+/D$�D0�$D-�)D0�-D0�0	F�9A	F�Fr5z	--mappingzcommand ip leases: running %sT)�textz:No lease found for interface '%s' (not managed by Netplan)r_rN�,�=)r4�print_usager�get_generator_pathrcrCrD�
subprocess�check_outputrrhrirjrkrSrA)	rro�argv�outrl�	mapping_s�keyvalue�key�values	`        rr8z!NetplanIpLeases.command_ip_leasesNs����>�>�V�#�����2	�h�(�(�*�+���=�=��\�4�=�=�1�1�D���d�n�n�-�-��	�
�
�5�t�<�	��)�)�$�T�:�C����I�I�c�N�	�!�	!�H�!���)�/�/��4�J�C�� �G�C�L�	!�	�� ��"�	��N�QU�Q_�Q_�_�fi�fp�fp�q��H�H�Q�K�	�s�C!�!AD*�)D*)r,r-r.rr(r8r/r0s@rr#r#<s���$�
	�K!rr#)�__doc__rCr<rirurr]rra�NetplanCommandr
r#�rr�<module>r�sd��$��	�
��)��9���
R�!��	�
���$�$��(]!�e�*�*�]!r