oB]c@s&ddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z dZ ej ejdefdYZd efd YZegZdd Zd Zddd ZdZedZddZddZdS(iN(tutili(tget_devicelist(tread_sys_net_safes#/run/initramfs/open-iscsi.interfacetInitramfsNetworkConfigSourcecBs2eZdZejdZejdZRS(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.pyRstKlibcNetworkConfigSourcecBs2eZdZddddZdZdZRS(sInitramfsNetworkConfigSource 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|jdkri|_x9tD]+}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: %stphysicalttypetnametsubnetst mac_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  $            cCstjdtjdS(Ns/run/net-*.confs/run/net6-*.conf(tglob(((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyRsc CsE|dkrt}ng}i}x |D]}ttj|d|\}}||kr||d}|jd|jdkrtdjd|ddj||dd|jdd |jdn|d j |d ||dj |q+i|gd6|d6||<|j |q+Wi|d 6d 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.pyRs(     cCs7x0tD](}|}|js(qn|jSWdS(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_configs     c Cstj|o}d}zKy&tjddd|}|jSWntk ra|r]n|SXWd|ry|jnXWdQXdS(Ntmodetrbtfileobj(tiotBytesIORtgziptGzipFiletreadtIOErrortclose(tblobtstricttiobuftgzfp((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt _decomp_gzips  ttrycCsWytj|}Wn!tk r6td|nX|sA|St|d|dkS(NsInvalid base64 text: %sRoRs(tbase64t b64decodet TypeErrorR=Rr(tb64strtgzippedRn((s9/usr/lib/python2.7/site-packages/cloudinit/net/cmdline.pyt_b64dgzs cCs|dkrtj}nd|krd}x<|jD].}|jdr:|jddd}q:q:W|rtjt|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.pyts*       4  W