HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/net/__pycache__/cmdline.cpython-310.pyc
o

�Ad6$�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZdZ
dZGdd�dejd�ZGd	d
�d
e�ZegZddd�Zd
d�Zddd�Zdd�Zdd�Zdd�Zddd�ZdS)�N)�util)�get_devicelist�read_sys_net_safez#/run/initramfs/open-iscsi.interface�disabledc@s8eZdZdZejdefdd��Zejdefdd��Z	dS)�InitramfsNetworkConfigSourcezBABC for net config sources that read config written by initramfses�returncC�dS)zAIs this initramfs config source applicable to the current system?N���selfr	r	�7/usr/lib/python3/dist-packages/cloudinit/net/cmdline.py�
is_applicable�z*InitramfsNetworkConfigSource.is_applicablecCr)z;Render a v1 network config from the initramfs configurationNr	r
r	r	r�
render_config rz*InitramfsNetworkConfigSource.render_configN)
�__name__�
__module__�__qualname__�__doc__�abc�abstractmethod�boolr
�dictrr	r	r	rrsr)�	metaclassc@s6eZdZdZd
dd�Zdefdd�Zdefdd	�ZdS)�KlibcNetworkConfigSourcez�InitramfsNetworkConfigSource for klibc initramfs (i.e. Debian/Ubuntu)

    Has three parameters, but they are intended to make testing simpler, _not_
    for use in production code.  (This is indicated by the prepended
    underscores.)
    NcCst||_||_||_|jdurt�|_|jdurt��|_|jdur6i|_t�D]}t|d�}|r5||j|<q'dSdS)N�address)�_files�
_mac_addrs�_cmdline�_get_klibc_net_cfg_filesr�get_cmdlinerr)rrrr�k�mac_addrr	r	r�__init__-s 






��z!KlibcNetworkConfigSource.__init__rcCsF|jr!t�|j�D]}|�d�s|�d�rdSq	tj�t�r!dSdS)aD
        Return whether this system has klibc initramfs network config or not

        Will return True if:
            (a) klibc files exist in /run, AND
            (b) either:
                (i) ip= or ip6= are on the kernel cmdline, OR
                (ii) an open-iscsi interface file is present in the system
        zip=zip6=TF)	r�shlex�splitr�
startswith�os�path�exists�_OPEN_ISCSI_INTERFACE_FILE)r�itemr	r	rr
?s
�z&KlibcNetworkConfigSource.is_applicablecCst|j|jd�S)N)�files�	mac_addrs)�config_from_klibc_net_cfgrrr
r	r	rrRs�z&KlibcNetworkConfigSource.render_config)NNN)	rrrrr"rr
rrr	r	r	rr%s

rc
Cs�|duri}t�|�}zd|vr|dn|d}Wnty*}ztd�|�d}~ww|�d|�d��}|s@|�d�r>d}nd	}|d
vrJtd|��d|gd
�}||vrZ|||d<dD]�}|d|vreq\|�|d|�}|d	krsd}|dd�}	|dkr�||d|	d<dD]}
||
|vr�|||
|	|
��<q�g}dD]}|�||�}
|
r�t|
�d��r�|�|||�q�|r�||	d<|�d�}|r�d|vr�|�	d�|	d<n|�	�|	d<|d�|	�q\||fS)a�Convert a klibc written shell content file to a 'config' entry
    When ip= is seen on the kernel command line in debian initramfs
    and networking is brought up, ipconfig will populate
    /run/net-<name>.cfg.

    The files are shell style syntax, and examples are in the tests
    provided here.  There is no good documentation on this unfortunately.

    DEVICE=<name> is expected/required and PROTO should indicate if
    this is 'none' (static) or 'dhcp' or 'dhcp6' (LP: #1621507).
    note that IPV6PROTO is also written by newer code to address the
    possibility of both ipv4 and ipv6 getting addresses.

    Full syntax is documented at:
    https://git.kernel.org/pub/scm/libs/klibc/klibc.git/plain/usr/kinit/ipconfig/README.ipconfig
    N�DEVICE�DEVICE6z&no 'DEVICE' or 'DEVICE6' entry in data�PROTO�	IPV6PROTO�filename�dhcp�none)r4r3�dhcp6zUnexpected value for PROTO: %s�physical)�type�name�subnets�mac_address)�IPV4�IPV6�ADDR�static�manual)r7�controlr)�NETMASK�	BROADCAST�GATEWAY)�DNS0�DNS1z:.0�dns_nameservers�DOMAINSEARCH�,�
dns_searchr9)
r�load_shell_content�KeyError�
ValueError�get�lower�len�strip�appendr$)�contentr,�datar8�e�proto�iface�pre�	cur_proto�subnet�key�dns�nskey�ns�searchr	r	r�_klibc_to_config_entry\sd

��
�
��
r_cCst�d�t�d�S)Nz/run/net-*.confz/run/net6-*.conf)�globr	r	r	rr�src	Cs�|durt�}g}i}|D]Y}tt�|�|d�\}}||vrY||d}|�d�|�d�krFtdj|d�||d�|�d�|�d�d���|d�|d�||d�	|�q
|g|d	�||<|�	|�q
|d
d�S)N)r,�entryr:zedevice '{name}' was defined multiple times ({files}) but had differing mac addresses: {old} -> {new}.� r+)r8r+�old�newr9)r+ra�)�config�version)
rr_r�	load_filerMrL�format�join�extendrQ)r+r,�entries�names�cfg_filer8ra�prevr	r	rr-�s2

���	
r-cCs(tD]}|�}|��sq|��SdS)a
    Return v1 network config for initramfs-configured networking (or None)

    This will consider each _INITRAMFS_CONFIG_SOURCES entry in turn, and return
    v1 network configuration for the first one that is applicable.  If none are
    applicable, return None.
    N)�_INITRAMFS_CONFIG_SOURCESr
r)�src_cls�
cfg_sourcer	r	r�read_initramfs_config�srsc	Cs�t�|��@}d}z4ztjd|d�}|��WW|r|��Wd�Sty<|YW|r4|��Wd�Sw|rD|��ww1sHwYdS)N�rb)�mode�fileobj)�io�BytesIO�gzip�GzipFile�read�close�IOError)�blob�iobuf�gzfpr	r	r�_decomp_gzip�s$
��
��r�c	Cs:z
t�|�}Wt|�Sttfyt�d|�YdSw)z�Decode a string base64 encoding, if gzipped, uncompress as well

    :return: decompressed unencoded string of the data or empty string on
       unencoded data.
    z`Expected base64 encoded kernel commandline parameter network-config. Ignoring network-config=%s.�)�base64�	b64decode�	TypeErrorrL�logging�errorr�)rSr~r	r	r�_b64dgz�s	���r�cCsj|durt��}d|vr3d}|��D]}|�d�r!|�dd�d}q|r3|tkr,ddiSt�t|��SdS)Nznetwork-config=�=rerfr)rrr$r%�&KERNEL_CMDLINE_NETWORK_CONFIG_DISABLED�	load_yamlr�)�cmdline�data64�tokr	r	r�read_kernel_cmdline_configs
�r�)N)NN)rr�r`ryrwr�r&r#�	cloudinitr�
cloudinit.netrrr)r��ABCMetarrrpr_rr-rsr�r�r�r	r	r	r�<module>s,4
]