Current File : //usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyc
�
oB�]c@s&ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddl	mZdZej
ej�defd��Y�Zd	efd
��YZegZdd�Zd�Zddd
�Zd�Zed�Zdd�Zdd�ZdS(i����N(tutili(tget_devicelist(tread_sys_net_safes#/run/initramfs/open-iscsi.interfacetInitramfsNetworkConfigSourcecBs2eZdZejd��Zejd��ZRS(sBABC for net config sources that read config written by initramfsescCsdS(sAIs this initramfs config source applicable to the current system?N((tself((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt
is_applicablescCsdS(s;Render a v1 network config from the initramfs configurationN((R((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt
render_config#s(t__name__t
__module__t__doc__tabctabstractmethodRR(((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyRstKlibcNetworkConfigSourcecBs2eZdZdddd�Zd�Zd�ZRS(s�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.)
    cCs�||_||_||_|jdkr9t�|_n|jdkrZtj�|_n|jdkr�i|_x9t�D]+}t|d�}|r|||j|<q|q|WndS(Ntaddress(	t_filest
_mac_addrst_cmdlinetNonet_get_klibc_net_cfg_filesRtget_cmdlineRR(RRRRtktmac_addr((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt__init__2s				cCsH|jrDd|jks'd|jkr+tStjjt�rDtSntS(sD
        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
        sip=sip6=(RRtTruetostpathtexistst_OPEN_ISCSI_INTERFACE_FILEtFalse(R((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyRDs	cCstd|jd|j�S(Ntfilest	mac_addrs(tconfig_from_klibc_net_cfgRR(R((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyRWsN(RRR	RRRR(((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyR*s	cCs�|d kri}ntj|�}y$d|kr=|dn|d}Wntk
rgtd��nX|jd|jd��}|s�|jd�r�d}q�d}n|d!kr�td
|��nidd6|d
6gd6}||kr|||d<nxvd"D]n}|d|kr$qn|j|d|�}i|d6dd6}|dkro||d|d<nx9d#D]1}	||	|krv|||	||	j�<qvqvWg}
xTd$D]L}|j||�}|r�t|jd��r�|
j	|||�q�q�W|
re|
|d<|jd�}
|
red|
krO|
j
d�|d<qb|
j
�|d<qen|dj	|�qW||fS(%seConvert 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 '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.
    tDEVICEtDEVICE6s&no 'DEVICE' or 'DEVICE6' entry in datatPROTOt	IPV6PROTOtfilenametdhcptstatictdhcp6sUnexpected value for PROTO: %stphysicalttypetnametsubnetstmac_addresstIPV4tIPV6tADDRtmanualtcontrolR
tNETMASKt	BROADCASTtGATEWAYtDNS0tDNS1s:.0tdns_nameserverstDOMAINSEARCHt,t
dns_searchN(R&R%R'(R-R.(R2R3R4(R5R6(RRtload_shell_contenttKeyErrort
ValueErrortgettlowertlentstriptappendtsplit(tcontentRtdataR*tprototifacetpret	cur_prototsubnettkeytdnstnskeytnstsearch((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt_klibc_to_config_entryasX	$
		




cCstjd�tjd�S(Ns/run/net-*.confs/run/net6-*.conf(tglob(((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyR�scCsE|dkrt�}ng}i}x|D]}ttj|�d|�\}}||kr||d}|jd�|jd�kr�tdjd|ddj||d�d|jd�d	|jd����n|d
j	|d
�||dj
|�q+i|gd6|d6||<|j
|�q+Wi|d6dd
6S(NRtentryR,sedevice '{name}' was defined multiple times ({files}) but had differing mac addresses: {old} -> {new}.R*Rt toldtnewR+tconfigitversion(RRRPRt	load_fileR>R=tformattjointextendRB(RRtentriestnamestcfg_fileR*RRtprev((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyR�s(
	cCs7x0tD](}|�}|j�s(qn|j�SWdS(s
    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(t_INITRAMFS_CONFIG_SOURCESRRR(tsrc_clst
cfg_source((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pytread_initramfs_config�s
	c	Cs�tj|��o}d}zKy&tjddd|�}|j�SWntk
ra|r]�n|SXWd|ry|j�nXWdQXdS(Ntmodetrbtfileobj(tiotBytesIORtgziptGzipFiletreadtIOErrortclose(tblobtstricttiobuftgzfp((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt_decomp_gzip�s
	ttrycCsWytj|�}Wn!tk
r6td|��nX|sA|St|d|dk�S(NsInvalid base64 text: %sRoRs(tbase64t	b64decodet	TypeErrorR=Rr(tb64strtgzippedRn((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt_b64dgz�s
cCs�|dkrtj�}nd|kr�d}x<|j�D].}|jd�r:|jdd�d}q:q:W|r�tjt|��SndS(Nsnetwork-config=t=i(RRRRCt
startswitht	load_yamlRy(tcmdlinetdata64ttok((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pytread_kernel_cmdline_configs(R
RtRQRiRgRtsixt	cloudinitRtRRRt
add_metaclasstABCMetatobjectRRR`RRPRRRcRRrRyR�(((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt<module>s*4	W