Viewing File: /usr/lib/python2.7/site-packages/cloudinit/net/eni.pyc


oB]c@sddlZddlZddlZddlZddlmZddlmZddlmZddl	m
Zddl	mZej
eZdd	d
ddd
gZddddddddgZddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,gZd-Zd.Zed/Zd0Zd1Zd2Zd3Zd4ejfd5YZded6Zdd7ZdS(8iNi(tParserError(trenderer(tsubnet_is_ipv6(tlog(tutilspre-uptupspost-uptdownspre-downs	post-downt
bridge_ageingtbridge_bridgepriot	bridge_fdt
bridge_gcinittbridge_hellot
bridge_maxagetbridge_maxwaitt
bridge_stptaddresstnetmaskt	broadcasttnetworktmetrictgatewaytpointtopointtmediatmtuthostnamet
leasehourst	leasetimetvendortclienttbootfiletserverthwaddrtprovidertframetnetnumtendpointtlocaltttlc
Csg}ddddddddd	d
g
}x|jD]\}}|dkrUq7n|dkr|d|d|df}n|r7||kr7t|tkrd
j|}nd|kr|jdd}n|jdj||q7q7Wt|S(NRRRRRtpointopointRtscopet
dns_searchtdns_nameserverss%s/%stprefixt t_t-s    {0} {1}(titemsttypetlisttjointreplacetappendtformattsorted(tifacetsubnettcontentt	valid_maptkeytvalue((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt_iface_add_subnet%s.	 c
	Cs|dkrgSg}dddddddd	d
g	}ddd
g}idd6}|d
dkrs|jdnx0|jD]"\}}t|tkr||rdnd}n|s||krqn|dkr|r||krtjd|d||qqn||krYx3|D]+}	|jdj|j|||	q$Wqnt|tkr}dj	|}n|jdj|j|||qWt
|S(Nitcontrolt	device_idtdrivertindextinettmodetnametsubnetsR/tbridge_pathcosttbridge_portpriotbridge_waitportt	hwaddresstmac_addresstbondtbridget
infinibandtvlantontoffRsZNetwork config: ignoring %s device-level mtu:%s because ipv4 subnet-level mtu:%s provided.s    {0} {1}R+(RJRKRLRM(R3R.R/tbooltLOGtwarningR4tgetR0R1R5(
R6R@tipv4_subnet_mtuR8t
ignore_maptmultiline_keystrenamesR:R;tv((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt_iface_add_attrsCsJ		

))cCs|d}|d}|dkr)d}n#|d
krBd|}n
d|}|j}|ji|d6|d6d	j|d
j|g}|r|jdr|jdj|n|S(NRCR=tautothotplugsallow-s
# control-tfullnametcverbs{cverb} {fullname}siface {fullname} {inet} {mode}RIs    hwaddress {mac_address}(R[(tcopytupdateR4RSR3(R6R@trender_hwaddressR\R=R]tsubsttlines((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt_iface_start_entry|s

	

c	Csd	}x|jD]}|j}|jdr:qn|jd}|d}|dkr|d}|jdstjj||}nx/tj|D]}	tj	|	}
g|
D]T}tjj
tjj|	|rtjd|d	k	rtjj|	|^q}
xi|
D]a}t
|d}
|
jj}Wd	QXtjj|}t||tjj||qWqWq|d
kr>|d}|jdstjj||}nxtj|D]a}	t
|	d}
|
jj}Wd	QXtjj|	}t||tjj||qWq|dkrxu|dD]4}||kr{i|d6||<nt||d<qUWq|d
kr |dd!\}}}||kri|d6||<n)d||krtd||fn|||d<|||d<|}q|dkrd|ddkrI|d}n
|d}|||d<q|tkr|d|||<q|tkr|||krg|||<n|||jdj|dq|jdrd||kri||d<n|dkrVg||dd<x}|dD]}||ddj|q0Wq|dkrg||dd<x.|dD]}||ddj|qWqq|jdrdd||kri||d<n|tkr|jddd}|d||d|<q|dkrag||dd<x.|dD]}||ddj|q;Wq|d kr|djd!kr|d||dd!<qa|d||dd!<q|d"krd#||dkri||dd#<n|d||dd#|d<q|d$krd%||dkr@i||dd%<n|d||dd%|d<qq|jd&rd'||kri||d'<n|jd&dd}|d||d'|<qqWx5|jD]'}d||krt||d<qqWd	S((s}Parses the file contents, placing result into ifaces.

    '_source_path' is added to every dictionary entry to define which file
    the configration information came from.

    :param ifaces: interface dictionary
    :param contents: contents of interfaces file
    :param src_dir: directory interfaces file was located
    :param src_path: file path the `contents` was read
    t#R+issource-directoryit/s^[a-zA-Z0-9_-]+$trNtsourceRZt_source_pathR6itfamilys:Interface %s can only be defined once. Re-defined in '%s'.tmethodRHtetherisdns-tdnss
dns-searchtsearchsdns-nameserverstnameserverstbridge_RKttbridge_portstportst	bridge_hwtmacREtpathcostRFtportpriosbond-RJ(tNonet
splitlineststript
startswithtsplittostpathR1tglobtlistdirtisfiletretmatchtopentreadtabspatht_parse_deb_config_datatdirnametTrueRtNET_CONFIG_OPTIONStNET_CONFIG_COMMANDSR3tNET_CONFIG_BRIDGE_OPTIONSR2tlowertkeystFalse(tifacestcontentstsrc_dirtsrc_pathtcurriftlineR{toptiontparsed_src_dirt
expanded_pathtdir_contentsR}tentrytfptsrc_datat	abs_entrytnew_src_pathtabs_pathR6RiRjtvaltdomainRt
bridge_optiontbond_option((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyRs


!3
!
	

% # !$cCsei}t|d}|jj}WdQXtjj|}t||tjj|||S(s+Parses a debian network configuration file.RfN(RRRyR|R}RRR(R}RRRR((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pytparse_deb_configscCs)i}t||ddddt|S(NRR(RRwt_ifaces_to_net_config_data(teni_dataR((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pytconvert_eni_data!sc
Csi}x|jD]\}}|jdd}||kr|dkrSd}nd}i|d6|d6gd6||<d	|kr|d	||d
<qni|d6|dd6}|jd
rd
|d<n
d|d<|jddkr|d|d<nx+dD]#}||kr||||<qqWd|krxHdD]=}||dkrA|d|rA|d||d|<qAqAWn||dj|qWidd6gt|D]}	||	^qd6S(sReturn network config that represents the ifaces data provided.
    ifaces = parse_deb_config("/etc/network/interfaces")
    config = ifaces_to_net_config_data(ifaces)
    state = parse_net_config_data(config).t:itlotloopbacktphysicalR/RCRDRHRIt_orig_eni_nameRjRZR=tmanualtstaticRRRRRlRnRmtdns_itversiontconfig(snetmasksgateways	broadcast(snameserversssearch(R.t	partitionRSR3R5(
RtdevsRCtdatatdevnametdtypeR7tcopy_keytntd((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyR(s4	



 
tRenderercBsMeZdZddZddZedZedZdddZ	RS(s@Renders network information in a /etc/network/interfaces format.cCsR|si}n|jdd|_|jdd|_|jdd|_dS(Nteni_pathsetc/network/interfacest
eni_headert
netrules_paths(etc/udev/rules.d/70-persistent-net.rules(RSRRwRR(tselfR((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt__init__Us	Rpc
Csg}|d}|d}d}idd6dd6}d}|dd	krc|d
d	krcd}n)|ddkr|d
dkrd}nd}	xdddgD]}
|r|
dkrqn|
dkr|	d|||
||
f7}	q|
|kr|
dkr[d||
kr#|	d7}	n
|	d7}	d
|krw|	d||
|d
f7}	qwqz|	d||
||
f7}	qqW|j||	||j||	||S(sWhen rendering routes for an iface, in some cases applying a route
        may result in the route command returning non-zero which produces
        some confusing output for users manually using ifup/ifdown[1].  To
        that end, we will optionally include an '|| true' postfix to each
        route line allowing users to work with ifup/ifdown without using
        --force option.

        We may at somepoint not want to emit this additional postfix, and
        add a 'strict' flag to this function.  When called with strict=True,
        then we will not append the postfix.

        1. http://askubuntu.com/questions/168033/
                 how-to-set-static-routes-in-ubuntu-server
        spost-up route addspre-down route dels || truetgwRRRpRs0.0.0.0Rs defaults::R*is -A inet6 defaults%s %s %sRs	 -A inet6s -nets %s/%ss %s %s(R3(RtroutetindentR8RRtor_truetmappingt
default_gwt
route_linetk((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt
_render_route]s:


 	 	"

"#c

Csg}|jdi}|jdd}|rhxt|D]$\}}d}||d<|d|d<|jdd|d<d}	t|r|	d	7}	n|jd
}|	|d<|ddks|ddks|dd
krd|d<|dk	r|rdnd|d<qn|ddkr>d|d<d|d<nk|ddkred|d<d|d<nDt|r|ddkr|dk	r|rdnd|d<qntg|D]}
d|d|
k^qkrd|d<ntt||d|t||t	|||}x6|jdgD]"}|j
|j|ddq.W|j|q=Wnyg}d|ksd|kr|jdj
|n|jdj
||j
t	|dd d!d|j||S("NRDs	accept-raR@R/RBR=RZRAt6Rtdhcp4tdhcp6sipv6_dhcpv6-statefultdhcpt1t0t	accept_rasipv6_dhcpv6-statelesst
ipv6_slaacRsauto %sRCtaliasR`troutesRs    sbond-mastersbond-slavessauto {name}siface {name} {inet} {mode}iRT(RStpopRwt	enumerateRRR0RcR<RYtextendRR3R4(
RR6R`tsectionsRDRR@R7RTtsubnet_inetRRbR((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt
_render_ifacesZ


 




'
 
c
sidd6dd6dd6idd6dd6gd	6}x;|jD]-}|jddkr@tj|}q@q@W|j}|rd
j||d	dd<n|j}|rd
j||d	dd
<nidd6dd6dd6dd6dd6dd6g}|j|j|x`t	|jdfdD]=}|jddkrZq9n|j|j|d|q9Wx*|j
D]}|j|j|qWdjg|D]}	dj|	^qdS(s1Given state, emit etc/network/interfaces content.RRCRR/RARRZR=RDR+iR)R(iiRLiRJiRKiRMR:cs|d|dfS(NR/RC((R(torder(s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt<lambda>sR`s

s
(
titer_interfacesRSR^tdeepcopyR)R1tdns_searchdomainsRRR5titer_routesR3R(
Rt
network_stateR`RR6Rnt
searchdomainsRRts((Rs5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt_render_interfacess:		
cCstj||j}tjtjj||jr@|jnd}tj|||j	||j
rtj||j
}tjtjj|tj||j|ndS(NRp(Rttarget_pathRt
ensure_dirR|R}RRt
write_fileRRt_render_persistent_net(RRt	templatesttargettfpenitheadertnetrules((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pytrender_network_states		N(
t__name__t
__module__t__doc__RwRRRRRR(((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyRRs2A/cCsrd}tdi|d6|d6dd6}|s9d}n|jdsU|d7}n|j|d|}||S(	Nsetc/network/interfacesRRRRRps
R`(RRwtendswithR(RRR`RRR((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pytnetwork_state_to_enis	
	
cCswdddg}ddg}x-|D]%}tj|d|d|s"tSq"Wtj|d}tjj|sstStS(	Ntifquerytifuptifdowns/sbins	/usr/sbinRmRsetc/network/interfaces(RtwhichRRR|R}RR(RtexpectedRmtpteni((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt	availables
(R^R~R|RRpRRRRt	cloudinitRtloggingRt	getLoggerRRQRRRR<RYRRcRRRRRRwRR(((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt<module>s4		9				*
Back to Directory File Manager