�
oB�]c@s&ddlZddlZddlZddlZddlZddlZddlZddlmZddl m
Z
ddl mZdZej
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|.cfg.
The files are shell style syntax, and examples are in the tests
provided here. There is no good documentation on this unfortunately.
DEVICE= 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_nameserverstDOMAINSEARCHt,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�scCsE|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|d6dd
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_metaclasstABCMetatobjectRRR`RRPRRRcRRrRyR�(((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyts*4 W