%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/net/__pycache__/cmdline.cpython-312.pyc

�

�f2$���ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZdZ
dZeje�ZGd�dej$��ZGd	�d
e�ZegZdd�Zd�Zdd
�Zd�Zd�Zd�Zdd�Zy)�N)�util)�get_devicelist�read_sys_net_safez#/run/initramfs/open-iscsi.interface�disabledc�d�eZdZdZej
defd��Zej
defd��Z	y)�InitramfsNetworkConfigSourcezBABC for net config sources that read config written by initramfses�returnc��y)zAIs this initramfs config source applicable to the current system?N���selfs �7/usr/lib/python3/dist-packages/cloudinit/net/cmdline.py�
is_applicablez*InitramfsNetworkConfigSource.is_applicable���c��y)z;Render a v1 network config from the initramfs configurationNrrs r�
render_configz*InitramfsNetworkConfigSource.render_config"rrN)
�__name__�
__module__�__qualname__�__doc__�abc�abstractmethod�boolr�dictrrrrrrsK��L����P�t�P��P�	���J�t�J��Jrr)�	metaclassc�0�eZdZdZdd�Zdefd�Zdefd�Zy)�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.)
    Nc�0�||_||_||_|j�t�|_|j�t	j
�|_|j�5i|_t
�D] }t|d�}|s�||j|<�"yy)N�address)�_files�
_mac_addrs�_cmdline�_get_klibc_net_cfg_filesr�get_cmdlinerr)r
r!r"r#�k�mac_addrs      r�__init__z!KlibcNetworkConfigSource.__init__/s������$��� ��
��;�;��2�4�D�K��=�=� � �,�,�.�D�M��?�?�"� �D�O�#�%�
2��,�Q�	�:���)1�D�O�O�A�&�
2�#rr	c���|jr[tj|j�D]}|j	d�s�yt
jjt�ryy)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
�items  rrz&KlibcNetworkConfigSource.is_applicableAsO���;�;����D�M�M�2�
 ���?�?�?�3��
 ��w�w�~�~�8�9��rc�D�t|j|j��S)N)�files�	mac_addrs)�config_from_klibc_net_cfgr!r"rs rrz&KlibcNetworkConfigSource.render_configTs��(��+�+��o�o�
�	
r)NNN)	rrrrr(rrrrrrrrr's$���2�$�t��&
�t�
rrc�z�|�i}tj|�}	d|vr|dn|d}|j	d|j	d��}|s|j	d�rd}nd	}|d
vrtd|z��d|gd
�}||vr|||d<dD�]}|dz|vr�|j	|dz|�}|d	k(rd}|dd�}	|dk(r||dz|	d<dD]#}
||
z|vs�|||
z|	|
j�<�%g}dD]K}|j	||z�}
|
s�t
|
jd��s�5|j|||z��M|rD||	d<|j	d�}|r,d|vr|jd�|	d<n|j�|	d<|dj|	���||fS#t$r}td�|�d}~wwxYw)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)r=r<�dhcp6zUnexpected value for PROTO: %s�physical)�type�name�subnets�mac_address)�IPV4�IPV6�ADDR�static�manual)r@�controlr )�NETMASK�	BROADCAST�GATEWAY)�DNS0�DNS1z:.0�dns_nameservers�DOMAINSEARCH�,�
dns_searchrB)
r�load_shell_content�KeyError�
ValueError�get�lower�len�strip�appendr+)�contentr4�datarA�e�proto�iface�pre�	cur_proto�subnet�key�dns�nskey�ns�searchs               r�_klibc_to_config_entryrh^s0��$���	��"�"�7�+�D�J�!)�T�!1�t�H�~�t�I���
�H�H�W�d�h�h�{�3�4�E���8�8�J���E��E��-�-��9�E�A�B�B����
�E��y��(����m�� �'(����<�t�#���H�H�S�7�]�E�2�	���� �I�#��9���� � $�S�6�\� 2�F�9��7�	6�C��S�y�D� �&*�3��9�o��s�y�y�{�#�	6���%�	.�E����#��+�&�B��c�"�(�(�5�/�*��
�
�4��e��,�-�		.�
�(+�F�$�%��X�X�n�-�F���&�=�+1�<�<��+<�F�<�(�+1�<�<�>�F�<�(�
�i�����'�O'(�R��;���E�J��A�B��I��J�s�F � 	F:�)F5�5F:c�X�tjd�tjd�zS)Nz/run/net-*.confz/run/net6-*.conf)�globrrrr$r$�s!���9�9�&�'�$�)�)�4F�*G�G�Grc��|�
t�}g}i}|D]�}ttj|�|��\}}||vr�||d}|j	d�|j	d�k7rQtdj
|dj||d�|j	d�|j	d�����|dj|d�||dj|���|g|d	�||<|j|���|d
d�S)N)r4�entryrCzedevice '{name}' was defined multiple times ({files}) but had differing mac addresses: {old} -> {new}.� r3)rAr3�old�newrB)r3rl�)�config�version)
r$rhr�load_text_filerVrU�format�join�extendrZ)r3r4�entries�names�cfg_filerArl�prevs        rr5r5�s%���}�(�*���G��E��"��,�����)�Y�
���e��5�=���;�w�'�D��x�x�
�&�%�)�)�M�*B�B� �H�HN��!�!�h�h�u�T�{�7�';�<� �H�H�]�3�!�I�I�m�4�	IO�I���
��O�"�"�5��#3�4��$�K�� �'�'��1�%-�J��?�E�$�K��N�N�5�!�)"�,�!�,�,rc�l�tD]+}|�}|j�s�|j�cSy)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_SOURCESrr)�src_cls�
cfg_sources  r�read_initramfs_configr�s=��-�*���Y�
��'�'�)���'�'�)�)�
*�rc�X�tj|�5}d}	tjd|��}|j	�|r|j�cddd�S#t$r |cY|r|j�cddd�SwxYw#|r|j�wwxYw#1swYyxYw)N�rb)�mode�fileobj)�io�BytesIO�gzip�GzipFile�read�close�IOError)�blob�iobuf�gzfps   r�_decomp_gzipr��s���	���D�	�	�U���	��=�=�d�E�:�D��9�9�;���
�
��	�	��
�	��K���
�
��	�	�
	����
�
����	�	�s@�B �&A�B �B�'B�(B �B�B�B�B � B)c��	tj|�}t
|�S#ttf$rtjd|�YywxYw)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�	TypeErrorrU�LOG�errorr�)r\r�s  r�_b64dgzr��sS�������%�������
�z�"���	�	�
;��	
�
�
�s�"�%A
�	A
c��|�tj�}d|vrkd}|j�D])}|jd�s�|jdd�d}�+|r+|tk(rddiStj
t
|��Sy)Nznetwork-config=�=rprqr)rr%r+r,�&KERNEL_CMDLINE_NETWORK_CONFIG_DISABLED�	load_yamlr�)�cmdline�data64�toks   r�read_kernel_cmdline_configr�s������"�"�$���G�#����=�=�?�	.�C��~�~�/�0����3��*�1�-��	.���?�?� �*�-�-��>�>�'�&�/�2�2�r)N)NN)rr�rjr�r��loggingr-r*�	cloudinitr�
cloudinit.netrrr0r��	getLoggerrr��ABCMetarrr|rhr$r5rr�r�r�rrr�<module>r�s����
���	��	���;�B��)3�&��g����!��	J�S�[�[�	J�1
�;�1
�h6�6��Z�zH�-�>�$��&r

Zerion Mini Shell 1.0