Current File : //usr/lib/python2.7/site-packages/cloudinit/net/eni.pyo
�
oB�]c@s�ddlZddlZddlZddlZddlmZddlmZddlmZddl	m
Zddl	mZej
e�Zdd	d
ddd
gZddddddddgZddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,gZd-�Zd.�Zed/�Zd0�Zd1�Zd2�Zd3�Zd4ejfd5��YZded6�Zdd7�ZdS(8i����Ni(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
Cs�g}ddddddddd	d
g
}x�|j�D]�\}}|dkrUq7n|dkr|d|d|df}n|r7||kr7t|�tkr�d
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|jd�nx0|j�D]"\}}t|�tkr�||r�dnd}n|s�||kr�q�n|dkr|r||kr�tjd|d||�q�q�n||krYx3|D]+}	|jdj|j||�|	��q$Wq�nt|�tkr}dj	|�}n|jdj|j||�|��q�Wt
|�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|d6�d	j|�d
j|�g}|r�|jd�r�|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�|j�D]�}|j�}|jd�r:qn|jd�}|d}|dkr�|d}|jd�s�tjj||�}nx/tj|�D]�}	tj	|	�}
g|
D]T}tjj
tjj|	|��r�tjd|�d	k	r�tjj|	|�^q�}
xi|
D]a}t
|d��}
|
j�j�}Wd	QXtjj|�}t||tjj|�|�qWq�Wq|d
kr>|d}|jd�s�tjj||�}nx�tj|�D]a}	t
|	d��}
|
j�j�}Wd	QXtjj|	�}t||tjj|�|�q�Wq|dkr�xu|dD]4}||kr{i|d6||<nt||d<qUWq|d
kr |dd!\}}}||kr�i|d6||<n)d||kr�td||f��n|||d<|||d<|}q|dkrd|ddkrI|d}n
|d}|||d<q|tkr�|d|||<q|tkr�|||kr�g|||<n|||jdj|d��q|jd�r�d||kri||d<n|dkrVg||dd<x}|dD]}||ddj|�q0Wq�|dkr�g||dd<x.|dD]}||ddj|�qWq�q|jd�rdd||kr�i||d<n|tkr|jddd�}|d||d|<q�|dkrag||dd<x.|dD]}||ddj|�q;Wq�|d kr�|dj�d!kr�|d||dd!<qa|d||dd!<q�|d"krd#||dkr�i||dd#<n|d||dd#|d<q�|d$kr�d%||dkr@i||dd%<n|d||dd%|d<q�q|jd&�rd'||kr�i||d'<n|jd&dd�}|d||d'|<qqWx5|j�D]'}d||kr�t||d<q�q�Wd	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.pyR��s�


!3
!
	

% # !$cCsei}t|d��}|j�j�}WdQXtjj|�}t||tjj|�|�|S(s+Parses a debian network configuration file.RfN(R�R�RyR|R}R�R�R�(R}R�R�R�R�((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pytparse_deb_configscCs)i}t||dddd�t|�S(NR�R�(R�Rwt_ifaces_to_net_config_data(teni_dataR�((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pytconvert_eni_data!sc
Cs�i}x�|j�D]�\}}|jd�d}||kr�|dkrSd}nd}i|d6|d6gd6||<d	|kr�|d	||d
<q�ni|d6|dd6}|jd
�r�d
|d<n
d|d<|jd�dkr|d|d<nx+dD]#}||kr||||<qqWd|kr�xHdD]=}||dkrA|d|rA|d||d|<qAqAWn||dj|�qWidd6gt|�D]}	||	^q�d6S(s�Return 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(
R�tdevsRCtdatatdevnametdtypeR7tcopy_keytntd((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyR�(s4	



 
tRenderercBsMeZdZdd�Zdd�Zed�Zed�Zddd�Z	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(RSR�RwR�R�(tselfR�((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt__init__Us	Rpc
Cs�g}|d}|d}d}idd6dd6}d}|dd	krc|d
d	krcd}n)|ddkr�|d
dkr�d}nd}	x�dddgD]�}
|r�|
dkr�q�n|
dkr�|	d|||
||
f7}	q�|
|kr�|
dkr[d||
kr#|	d7}	n
|	d7}	d
|krw|	d||
|d
f7}	qwqz|	d||
||
f7}	q�q�W|j||	|�|j||	|�|S(s�When 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 %sR�s	 -A inet6s -nets %s/%ss %s %s(R3(R�troutetindentR8RRtor_truetmappingt
default_gwt
route_linetk((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt
_render_route]s:


 	 	"

"#c

Cs�g}|jdi�}|jdd�}|rhx�t|�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<q�n�|ddkr>d|d<d|d<nk|ddkred|d<d|d<nDt|�r�|ddkr�|dk	r�|r�dnd|d<q�ntg|D]}
d|d|
k^q�kr�d|d<ntt||d|�t||�t	|||��}x6|jdg�D]"}|j
|j|dd��q.W|j|�q=Wnyg}d|ks�d|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_slaacR�sauto %sRCtaliasR`troutesR�s    sbond-mastersbond-slavessauto {name}siface {name} {inet} {mode}iRT(RStpopRwt	enumerateRR�R0RcR<RYtextendR�R3R4(
R�R6R`tsectionsRDR�R@R7RTtsubnet_inetR�RbR�((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt
_render_iface�sZ


 




'
 
c
s�idd6dd6dd6idd6dd6gd	6}x;|j�D]-}|jd�dkr@tj|�}q@q@W|j}|r�d
j|�|d	dd<n|j}|r�d
j|�|d	dd
<nidd6dd6dd6dd6dd6dd6�g}|j|j|��x`t	|j�d�fd��D]=}|jd�dkrZq9n|j|j|d|��q9Wx*|j
�D]}|j|j|��q�Wdjg|D]}	dj|	�^q��dS(s1Given state, emit etc/network/interfaces content.R�RCR�R/RAR�RZR=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_searchdomainsR�R�R5titer_routesR3R�(
R�t
network_stateR`R�R6Rnt
searchdomainsR�R�ts((R�s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt_render_interfaces�s:		
cCs�tj||j�}tjtjj|��|jr@|jnd}tj|||j	|��|j
r�tj||j
�}tjtjj|��tj||j|��ndS(NRp(Rttarget_pathR�t
ensure_dirR|R}R�R�t
write_fileR�R�t_render_persistent_net(R�R�t	templatesttargettfpenitheadertnetrules((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pytrender_network_state�s		N(
t__name__t
__module__t__doc__RwR�R�R�R�R�R�(((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyR�Rs2A/cCsrd}tdi|d6|d6dd6�}|s9d}n|jd�sU|d7}n|j|d|�}||S(	Nsetc/network/interfacesR�R�R�R�Rps
R`(R�RwtendswithR�(R�R�R`R�RR�((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/sbinRmR�setc/network/interfaces(RtwhichR�R�R|R}R�R�(R�texpectedRmtpteni((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt	availables
(R^R~R|R�RpRRR�Rt	cloudinitRtloggingRt	getLoggerR�RQR�R�R�R<RYR�RcR�R�R�R�R�RwR�R�(((s5/usr/lib/python2.7/site-packages/cloudinit/net/eni.pyt<module>s4		9	�			*�