HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //proc/self/root/usr/share/netplan/netplan_cli/cli/commands/__pycache__/ip.cpython-310.pyc
o

ϐxeV�@szdZddlZddlZddlZddlZddlmZddlmZddd�d	d
d�d�ZGdd
�d
ej	�Z
Gdd�dej	�ZdS)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�NetworkManagercs$eZdZ�fdd�Zdd�Z�ZS)�	NetplanIpc�t�jdddd�dS)N�ipz'Retrieve IP information from the systemF��
command_id�description�leaf��super�__init__��self��	__class__��1/usr/share/netplan/netplan_cli/cli/commands/ip.pyr*�
�zNetplanIp.__init__cCsBt�|_|jjdddd�}|j|jj|jd�|��|��dS)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_leasesrrrr'/s�z
NetplanIp.run)�__name__�
__module__�__qualname__rr'�
__classcell__rrrrr(srcs,eZdZ�fdd�Zdd�Zdd�Z�ZS)r"cr)Nz	ip leasesrTrrrrrrr>rzNetplanIpLeases.__init__cCs<|jjddd�|jjddd�|j|_|��|��dS)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)rrrrr'Cs��zNetplanIpLeases.runc	s��jdkr	����fdd�}t��g}�jr|d�jg7}|d�jg7}t�d|�z	tj|dd�}Wnt	yLt
d	�jtjd
�t�
d�Ynwi}|�d�}|D]}|���d
�\}}|||<qV||�dS)Nrc

s(�fdd�}�fdd�}t|dd}t|dd}zQtd|��}tj�d	�jr2tj��j�nd
|j�j|d��}tj�	|�sH|�
dd
�}t|��}|��D]}t
|���qQWd�WdS1sfwYWdSty�}	zt
d�jt|	�ftjd�t�d�WYd}	~	dSd}	~	ww)Nc
s�tj�d�jd�}z t|��}|��d��Wd�WS1s"wYWdSty?}z
t�	d|t
|���d}~ww)Nz/sys/class/netrrzCannot read file %s: %s)�os�path�joinr/�open�	readlines�strip�	Exception�logging�debug�str)�	ifindex_f�f�errr�lease_method_ifindexTs
(���zXNetplanIpLeases.command_ip_leases.<locals>.find_lease_file.<locals>.lease_method_ifindexc
s�zHt�dd�jg�}|��D]5}d|vrC|�d�d����}t�ddd|g�}|��D]}d|vrB|�d�d����WSq,qWtd
��ty\}ztd	t|���d}~ww)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_outr/�
splitlines�split�rstripr9r:r=)�
nmcli_dev_out�line�conn_id�
nmcli_con_outr@rrr�lease_method_nm_connection]s" ���	���z^NetplanIpLeases.command_ip_leases.<locals>.find_lease_file.<locals>.lease_method_nm_connection�backendrr�
lease_method_�/�)r/�lease_idzNetworkManager/internal-zNetworkManager/dhclient-z%No lease found for interface '%s': %s��filerE)�
lease_path�evalr4r5r6�root_dir�abspath�formatr/�isfile�replacer7r8�printrKr:r=�sys�stderr�exit)
�mappingrArP�
lease_pattern�lease_methodrUr5r?rMr@rrr�find_lease_fileSs4	��
�&����z:NetplanIpLeases.command_ip_leases.<locals>.find_lease_filer0z	--mappingzcommand ip leases: running %sT)�textz:No lease found for interface '%s' (not managed by Netplan)rVrE�,�=)r/�print_usager�get_generator_pathrZr;r<�
subprocess�check_outputrr_r`rarbrJr9)	rrf�argv�outrc�	mapping_s�keyvalue�key�valuerrrr3Ns(

4�

z!NetplanIpLeases.command_ip_leases)r+r,r-rr'r3r.rrrrr"<sr")�__doc__r;r4r`rlrrTrrX�NetplanCommandrr"rrrr�<module>s ���