관리-도구
편집 파일: cmdline.cpython-39.opt-1.pyc
a ����'�Dg�$����������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dlm Z �d�dl mZmZ�dZ dZe�e�ZG�dd��de�jd�ZG�d 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�������������������@���s8���e�Zd�ZdZejed�dd��Zejed�dd��Z dS�)�InitramfsNetworkConfigSourcezBABC for net config sources that read config written by initramfses��returnc�����������������C���s���dS�)zAIs this initramfs config source applicable to the current system?N����selfr ���r ����9/usr/lib/python3.9/site-packages/cloudinit/net/cmdline.py� is_applicable���s����z*InitramfsNetworkConfigSource.is_applicablec�����������������C���s���dS�)z;Render a v1 network config from the initramfs configurationNr ���r ���r ���r ���r���� render_config"���s����z*InitramfsNetworkConfigSource.render_configN) �__name__� __module__�__qualname__�__doc__�abc�abstractmethod�boolr ����dictr���r ���r ���r ���r���r������s ���r���)� metaclassc�������������������@���s6���e�Zd�ZdZd dd�Zed�dd�Zed�dd �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.) Nc�����������������C���sp���||�_�||�_||�_|�j�d�u�r$t��|�_�|�jd�u�r8t���|�_|�jd�u�rli�|�_t��D�]}t|d�}|rN||�j|<�qNd�S�)N�address)�_files� _mac_addrs�_cmdline�_get_klibc_net_cfg_filesr����get_cmdliner���r���)r���r���r���r����kZmac_addrr ���r ���r����__init__/���s���� z!KlibcNetworkConfigSource.__init__r���c�����������������C���s<���|�j�r8t�|�j�D�]}|�d�r�dS�qtj�t�r8dS�dS�)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 ���A���s���� z&KlibcNetworkConfigSource.is_applicablec�����������������C���s���t�|�j|�jd�S�)N)�files� mac_addrs)�config_from_klibc_net_cfgr���r���r ���r ���r ���r���r���T���s�����z&KlibcNetworkConfigSource.render_config)NNN) r���r���r���r���r ���r���r ���r���r���r ���r ���r ���r���r���'���s��� r���c�������������� ���C���s���|du�ri�}t��|��}zd|v�r(|d�n|d�}W�n.�ty`�}�ztd�|�W�Y�d}~n d}~0�0�|�d|�d��}|s�|�d�r�d}nd }|d v�r�d }|dvr�td|���d |g�d�}||v�r�||�|d<�dD��]}|d�|vr�q�|�|d�|�}|d k�rd}|dd�} |dk�r&||d��| d<�dD�](} || �|v��r*||| ��| | ���<��q*g�}dD�]<}|�||��} | �r\t| �d���r\|�|||�����q\|�r�|| d<�|�d�}|�r�d|v��r�|� 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) or 'static' or 'off' (LP: 2065787). Note that IPV6PROTO is also written 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 NZDEVICEZDEVICE6z&no 'DEVICE' or 'DEVICE6' entry in dataZPROTOZ IPV6PROTO�filename�dhcp�none)�staticZoff)r.���r-���Zdhcp6zUnexpected value for PROTO: %sZphysical)�type�name�subnets�mac_address)ZIPV4ZIPV6ZADDRr/���Zmanual)r0���Zcontrolr���)ZNETMASKZ BROADCASTZGATEWAY)ZDNS0ZDNS1z:.0Zdns_nameserversZDOMAINSEARCH�,Z dns_searchr2���) r���Zload_shell_content�KeyError� ValueError�get�lower�len�strip�appendr"���)Zcontentr*����datar1����e�protoZifaceZpreZ cur_protoZsubnet�keyZdnsZnskey�ns�searchr ���r ���r����_klibc_to_config_entry^���s`���� � rB���c�������������������C���s���t���d�t���d��S�)Nz/run/net-*.confz/run/net6-*.conf)�globr ���r ���r ���r���r�������s����r���c�������������� ���C���s����|�d�u�rt���}�g�}i�}|�D�]�}tt�|�|d�\}}||v�r�||�d�}|�d�|�d�kr�tdj|d�||�d��|�d�|�d�d���|d��|d���||�d�� |��q|g|d �||<�|� |��q|d d�S�)N)r*����entryr3���zedevice '{name}' was defined multiple times ({files}) but had differing mac addresses: {old} -> {new}.� r)���)r1���r)����old�newr2���)r)���rD�������)�config�version) r���rB���r���Zload_text_filer7���r6����format�join�extendr;���)r)���r*����entries�namesZcfg_filer1���rD����prevr ���r ���r���r+�������s0���� � �� r+���c������������������C���s(���t�D�]}�|���}|���sq|�����S�dS�)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���)Zsrc_clsZ cfg_sourcer ���r ���r����read_initramfs_config����s����rR���c�������������� ���C���s����t��|����}d�}zxz4tjd|d�}|���W�W�|r8|����W��d�����S��tyx���|��Y�W�|rh|����W��d�����S�0�W�|r�|����n|r�|����0�W�d�����n1�s�0����Y��d�S�)N�rb)�modeZfileobj)�io�BytesIO�gzipZGzipFile�read�close�IOError)�blobZiobufZgzfpr ���r ���r����_decomp_gzip����s"���� �� �r\���c�������������� ���C���s<���zt��|��}W�n$�ttfy2���t�d|���Y�dS�0�t|�S�)z�Decode a string base64 encoding, if gzipped, uncompress as well :return: decompressed unencoded string of the data or empty string on unencoded data. zaExpected base64 encoded kernel command line parameter network-config. Ignoring network-config=%s.��)�base64Z b64decode� TypeErrorr6����LOG�errorr\���)r<���r[���r ���r ���r����_b64dgz��s�����rb���c�����������������C���sj���|�d�u�rt����}�d|�v�rfd�}|����D�]}|�d�r$|�dd�d�}q$|rf|tkrXddiS�t��t|��S�d�S�)Nznetwork-config=�=rH���rI���r���)r���r���r"���r#����&KERNEL_CMDLINE_NETWORK_CONFIG_DISABLEDZ load_yamlrb���)ZcmdlineZdata64�tokr ���r ���r����read_kernel_cmdline_config��s���� rf���)N)NN)N)r���r^���rC���rW���rU���Zloggingr$���r!���Z cloudinitr���Z cloudinit.netr���r���r'���rd���Z getLoggerr���r`����ABCMetar���r���rQ���rB���r���r+���rR���r\���rb���rf���r ���r ���r ���r����<module>���s,��� 4 `