%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/cloudinit/net/__pycache__/cmdline.cpython-35.pyc



"�T`�#�@s/ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddl	mZdZdZ
Gdd	�d	d
ej�ZGdd�de�ZegZdd
d�Zdd�Zdddd�Zdd�Zdd�Zdd�Zddd�ZdS)�N)�util�)�get_devicelist)�read_sys_net_safez#/run/initramfs/open-iscsi.interface�disabledc@sReZdZdZejeddd���Zejeddd���Z	dS)�InitramfsNetworkConfigSourcezBABC for net config sources that read config written by initramfses)�returncCsdS)zAIs this initramfs config source applicable to the current system?N�)�selfr	r	�7/usr/lib/python3/dist-packages/cloudinit/net/cmdline.py�
is_applicablesz*InitramfsNetworkConfigSource.is_applicablecCsdS)z;Render a v1 network config from the initramfs configurationNr	)r
r	r	r�
render_config!sz*InitramfsNetworkConfigSource.render_configN)
�__name__�
__module__�__qualname__�__doc__�abc�abstractmethod�boolr�dictr
r	r	r	rrs
r�	metaclassc@sUeZdZdZddddd�Zeddd��Zeddd	��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.)
    NcCs�||_||_||_|jdkr6t�|_|jdkrTtj�|_|jdkr�i|_x3t�D](}t|d�}|rv||j|<qvWdS)N�address)�_files�
_mac_addrs�_cmdline�_get_klibc_net_cfg_filesr�get_cmdlinerr)r
rrr�kZmac_addrr	r	r�__init__.s				z!KlibcNetworkConfigSource.__init__)rcCsE|jrAd|jks'd|jkr+dStjjt�rAdSdS)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)rr�os�path�exists�_OPEN_ISCSI_INTERFACE_FILE)r
r	r	rr@s
	z&KlibcNetworkConfigSource.is_applicablecCstd|jd|j�S)N�files�	mac_addrs)�config_from_klibc_net_cfgrr)r
r	r	rr
Rsz&KlibcNetworkConfigSource.render_config)	rrrrrrrrr
r	r	r	rr&srcCs�|dkri}tj|�}y$d|kr:|dn|d}Wn4tk
r{}ztd�|�WYdd}~XnX|jd|jd��}|s�|jd�r�d}nd	}|d"kr�td|��dd
d|dgi}||kr	|||d<xtd#D]l}|d|kr)q|j|d|�}|d	krQd}d|ddi}	|dkr�||d|	d<x6d$D].}
||
|kr�|||
|	|
j�<q�Wg}xQd%D]I}|j||�}
|
r�t|
jd��r�|j|||�q�W|rk||	d<|jd�}|rkd |kr[|j	d �|	d!<n|j	�|	d!<|dj|	�qW||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
    NZDEVICEZDEVICE6z&no 'DEVICE' or 'DEVICE6' entry in dataZPROTOZ	IPV6PROTO�filename�dhcp�none�dhcp6zUnexpected value for PROTO: %s�typeZphysical�name�subnets�mac_address�IPV4�IPV6ZADDRZstaticZcontrolZmanualr�NETMASK�	BROADCAST�GATEWAY�DNS0�DNS1z:.0Zdns_nameserversZDOMAINSEARCH�,Z
dns_search)r)r(r*)r/r0)r1r2r3)r4r5)
rZload_shell_content�KeyError�
ValueError�get�lower�len�strip�append�split)Zcontentr%�datar,�e�protoZifaceZpreZ	cur_protoZsubnet�keyZdnsZnskey�ns�searchr	r	r�_klibc_to_config_entry[sZ$"	



rEcCstjd�tjd�S)Nz/run/net-*.confz/run/net6-*.conf)�globr	r	r	rr�srcCs;|dkrt�}g}i}x|D]�}ttj|�d|�\}}||kr||d}|jd�|jd�kr�tdjd|ddj||d�d|jd�d	|jd����|d
j|d
�||dj	|�q(d|gd|i||<|j	|�q(Wd|dd
iS)Nr%�entryr.zedevice '{name}' was defined multiple times ({files}) but had differing mac addresses: {old} -> {new}.r,r$� �old�newr-�config�versionr)
rrErZ	load_filer9r8�format�join�extendr=)r$r%�entries�namesZcfg_filer,rG�prevr	r	rr&�s(	
	r&cCs4x-tD]%}|�}|j�s%q|j�SWdS)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
	rTcCsztj|��d}d}zCy&tjddd|�}|j�SWntk
rY|SYnXWd|rn|j�XWdQRXdS)N�mode�rbZfileobj)�io�BytesIO�gzipZGzipFile�read�IOError�close)�blobZiobufZgzfpr	r	r�_decomp_gzip�s

r^cCsLytj|�}Wn,ttfk
rAtjd|�dSYnXt|�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.
    z`Expected base64 encoded kernel commandline parameter network-config. Ignoring network-config=%s.�)�base64Z	b64decode�	TypeErrorr8�logging�errorr^)r?r]r	r	r�_b64dgz�s	rdcCs�|dkrtj�}d|kr�d}x9|j�D]+}|jd�r7|jdd�d}q7W|r�|tkr�ddiStjt|��SdS)Nznetwork-config=�=rrKr)rrr>�
startswith�&KERNEL_CMDLINE_NETWORK_CONFIG_DISABLEDZ	load_yamlrd)ZcmdlineZdata64�tokr	r	r�read_kernel_cmdline_configs
ri)rr`rFrYrWrbr Z	cloudinitrr_rrr#rg�ABCMetarrrSrErr&rTr^rdrir	r	r	r�<module>s*2	]

Zerion Mini Shell 1.0