Current File : //usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyo
�
oB�]c@svddlZddlZddlZddlmZddlmZeje�Z	d�Z
defd��YZdS(i����N(tmask_to_net_prefix(tutilcCs�|jd�}|jd�}g}x?ttd��D]+}|jt||�t||�@�q7Wdjg|D]}t|�^qs�S(s�
    Return the subnet for a given ip address and a netmask
    @return (str): the subnet
    @param ip: ip address
    @param netmask: netmask
    t.i(tsplittlisttrangetappendtinttjointstr(tiptnetmasktip_arrayt
mask_arraytresulttindextx((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt
gen_subnets)tNicConfiguratorcBsweZed�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
edd�Z
d	�Zdd
�ZRS(cCsw||_i|_d|_d|_|r7|j�n-x*|jD]}|j|j|jj�<qAW|j	�|_
dS(s
        Initialize the Nic Configurator
        @param nics (list) an array of nics to configure
        @param use_system_devices (Bool) Get the MAC names from the system
        if this is True. If False, then mac names will be retrieved from
         the specified nics.
        N(tnicstmac2NametNonetipv4PrimaryGatewaytipv6PrimaryGatewaytfind_devicestnametmactlowertget_primary_nict_primaryNic(tselfRtuse_system_devicestnic((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt__init__#s				
cCsug|jD]}|jr
|^q
}|s/dSt|�dkritdg|D]}|j^qN��n|dSdS(s|
        Retrieve the primary nic if it exists
        @return (NicBase): the primary nic if exists, None otherwise
        is!There can only be one primary niciN(RtprimaryRtlent	ExceptionR(RR tprimary_nics((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyR8s%"c
Cs�dddg}tj|�\}}tjdd|�d}d}xd|D]\}tj||�}|soqKn|jd�j�}|jdd�d	}	|	|j|<qKWd
S(sb
        Create the mac2Name dictionary
        The mac address(es) are in the lower case
        R
taddrtshows\n\d+: s
is3link/ether (([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2}))t:iN(RtsubptreRtsearchtgroupRR(
Rtcmdtoutputt_errtsectionstmacPattsectiontmatchRR((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyRFs
c
Cs	|jj�}|jj|�}|s=td|j��ng}idd6|d6|d6}g}g}|j||�\}}	|j|�|j|	�|j||�\}}	|j|�|j|	�|ji|d6�|j	|�|r|j|�n|S(s�
        Return the config list needed to configure a nic
        @return (list): the subnets and routes list to configure the nic
        @param nic (NicBase): the nic to configure
        sNo known device has MACADDR: %stphysicalttypeRtmac_addresstsubnets(
RRRtgett
ValueErrortgen_ipv4textendtgen_ipv6tupdateR(
RR RRt
nics_cfg_listtcfgtsubnet_listt
route_listR7troutes((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pytgen_one_nicXs&




cCs�i}g}|jr,|jidd6�n|jj�}|jj�dkrYd}n|dkr�|jidd6�|g|fS|jidd6�|j}|s�|g|fS|d}|jr�|ji|jd	6�n|jr|ji|jd
6�n|jrL|j	rL|j	d|_
|ji|j
d6�|g|fS|jr�|j	r�|ji|j||j	|j�d6�n|g|fS(
s+
        Return the set of subnets and routes needed to configure the
        IPv4 settings of a nic
        @return (set): the set of subnet and routes to configure the gateways
        @param name (str): subnet and route list for the nic
        @param nic (NicBase): the nic to configure
        tautotcontroltdisabledtmanualtstatictdhcpR5itaddressRtgatewayRB(
tonbootR=t	bootProtoRt	ipv4_modet
staticIpv4R
RR"tgatewaysRRtgen_ipv4_route(RRR tsubnetRAt	bootprototaddrstv4((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyR:|s6			
	

		
&cCsig}t|�}xP|D]H}dt||�|f}|ji|d6dd6|d6dd6�qW|S(s�
        Return the routes list needed to configure additional Ipv4 route
        @return (list): the route list to configure the gateways
        @param nic (NicBase): the nic to configure
        @param gateways (str list): the list of gateways
        s%s/%dtdestinationtrouteR5RKi'tmetric(RRR(RR RPRRAtcidrRKRV((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyRQ�s
cCsq|jsggfSg}|j}x<|D]4}idd6|jd6|jd6}|j|�q)Wg}||fS(s
        Return the set of subnets and routes needed to configure the
        gateways for a nic
        @return (set): the set of subnets and routes to configure the gateways
        @param name (str): name of the nic
        @param nic (NicBase): the nic to configure
        tstatic6R5RJR(t
staticIpv6R
RR(RRR R@RTR&RRRA((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyR<�s		
	



cCs@g}x3|D]+}|jidd6|jd6dd6�q
W|S(NRWR5RKi'RX(RRK(RRR RTRAR&((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt
_genIpv6Route�s

cCsW|r#tjd�|j|�ng}x'|jD]}|j|j|��q3W|S(s@Return the config elements that are needed to configure the nicssConfiguring the interfaces file(tloggertinfot	configureRR;RC(RR_tosfamilyR>R ((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pytgenerate�s
cCsFtjd�tjddgdddg�tjddd	g�dS(
NsClearing DHCP leasestpkilltdhclienttrcsiitrms-fs/var/lib/dhcp/*(R]R^RR)(R((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt
clear_dhcp�s
cCs�|s|dkr$tjd�dSd}tjj|d�}tjj|d�}tjj|�r�tjj|�r�tj||�nddg}tj|d	d
j|��|j	�dS(s^
        Configure the /etc/network/interfaces
        Make a back up of the original
        tdebians3Debian OS not detected. Skipping the configure stepNs/etc/networkt
interfacess&interfaces.before_vmware_customizationsH# DO NOT EDIT THIS FILE BY HAND -- AUTOMATICALLY GENERATED BY cloud-inits&source /etc/network/interfaces.d/*.cfgtcontents
(
R]R^tostpathRtexiststrenameRt
write_fileRf(RR`t
containingDirt
interfaceFiletoriginalFiletlines((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyR_�s
	%	N(t__name__t
__module__tTrueR!RRRCR:RQR<R\tFalseRRaRfR_(((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyR"s			$	1			

	(
tloggingRjR*tcloudinit.net.network_stateRt	cloudinitRt	getLoggerRsR]RtobjectR(((sS/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt<module>s