Viewing 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	
Back to Directory File Manager