Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/lib/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/lib/network.pyc


Tc@s!dZddlZddlZddlZddlZddlZddlZdddgZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZerepeZdZdZdZdZdZdZdeedZddZdZdZdS(sG
Network introspection utilities using ioctl and the /proc filesystem.
iNtget_active_device_infotget_network_traffictis_64iiiiii'iFii i(cCstjddkS(s>Returns C{True} if the platform is 64-bit, otherwise C{False}.tli(tstructtcalcsize(((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pyR'sccsd}tjdd|t}|jd}tjd|t|}tjdtj|jt	|d}|j
}t}x_td|tD]K}|||t!}	|	|	j
d }
|
|kr|j|
|
VqqWdS(sZGenerator yields active network interface names.

    @param sock: a socket instance.
    itBtitiLN(tarraytIF_STRUCT_SIZEtbuffer_infoRtpacktunpacktfcntltioctltfilenotSIOCGIFCONFttostringtsettrangetindextadd(tsocktmax_interfacest
interfacestbuffer_sizetpacked_bytestbyte_lengthtresultt
already_foundRtifreq_structtinterface_name((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pytget_active_interfaces0s%	
cCs9tjtj|jttjd|d dd!S(sReturn the broadcast address associated to an interface.

    @param sock: a socket instance.
    @param interface: The name of the interface.
    t256siii(tsockett	inet_ntoaRRRtSIOCGIFBRDADDRRR(Rt	interface((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pytget_broadcast_addressLs	cCs9tjtj|jttjd|d dd!S(sReturn the network mask associated to an interface.

    @param sock: a socket instance.
    @param interface: The name of the interface.
    R"iii(R#R$RRRtSIOCGIFNETMASKRR(RR&((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pytget_netmaskXs	cCs9tjtj|jttjd|d dd!S(sReturn the IP address associated to the interface.

    @param sock: a socket instance.
    @param interface: The name of the interface.
    R"iii(R#R$RRRtSIOCGIFADDRRR(RR&((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pytget_ip_addressds	cCs`tj|jttjd|d }djg|dd!D]}dt|^q?d S(s
    Return the hardware MAC address for an interface in human friendly form,
    ie. six colon separated groups of two hexadecimal digits.

    @param sock: a socket instance.
    @param interface: The name of the interface.
    R"itiis%02x:i(RRRt
SIOCGIFHWADDRRRtjointord(RR&tmac_addresstchar((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pytget_mac_addressps%cCsFtj|jttjd|d }tjd|dd!dS(sReturn the integer value of the interface flags for the given interface.

    @param sock: a socket instance.
    @param interface: The name of the interface.
    @see /usr/include/linux/if.h for the meaning of the flags.
    R"itHiii(RRRtSIOCGIFFLAGSRRR
(RR&tdata((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pyt	get_flags}s%tloc	Cs.g}ztjtjtjtj}xt|D]}||krLq4n|rdd|krdq4n|r|d|kr|q4ni|d6}t|||d<t|||d<t|||d<t|||d<t	|||d<t
||\}}||d	<||d
<|j|q4WWd~X|S(sp
    Returns a dictionary containing information on each active network
    interface present on a machine.
    t.t:R&t
ip_addressR0tbroadcast_addresstnetmasktflagstspeedtduplexN(R#tAF_INETt
SOCK_DGRAMt
IPPROTO_IPR!R+R2R'R)R6tget_network_interface_speedtappend(	tskipped_interfacest	skip_vlant
skip_aliastresultsRR&tinterface_infoR>R?((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pyRs0


s
/proc/net/devcCst|d}|j}|j|djd\}}}g|jD]}d|^qN}|jg|jD]}d|^qwi}xm|dD]a}	d|	krqn|	jd\}
}|
j}
tt|tt	|j||
<qW|S(se
    Retrieves an array of information regarding the network activity per
    network interface.
    trit|srecv_%sssend_%siR9(
topent	readlinestclosetsplittextendtstriptdicttziptmaptlong(tsource_filetnetdevtlinest_treceive_columnsttransmit_columnstcolumntcolumnstdevicestlinetdeviceR5((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pyRs
#*,cCsrtj}d|krntjtjdtjtjtjtjdd}d|krntj}qnn|S(s
    Return the current fqdn of the machine, trying hard to return a meaningful
    name.

    In particular, it means working against a NetworkManager bug which seems to
    make C{getfqdn} return localhost6.localdomain6 for machine without a domain
    since Maverick.
    t	localhostiiN(	R#tgetfqdntgetaddrinfotgethostnametNoneR@RARBtAI_CANONNAME(tfqdn((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pytget_fqdns	c	Cs*tjdtdd}tjd|}tjd||jd}d}y;tj|t||j}tj	d|\}}Wn\t
k
r}|jtjkrt
jd	n|jtjkr|nd}t}nX|d
krd}n|dkrt}nt|}||fS(s
    Return the ethernet device's advertised link speed.

    The return value can be one of:
        * 10, 100, 1000, 2500, 10000: The interface speed in Mbps
        * -1: The interface does not support querying for max speed, such as
          virtio devices for instance.
        * 0: The cable is not connected to the interface. We cannot measure
          interface speed, but could if it was plugged in.
    tI39sRi'Rt16sPiit12xHB28xsECould not determine network interface speed, operation not permitted.ii(RRtETHTOOL_GSETR	RRRtSIOCETHTOOLRR
tIOErrorterrnotEPERMtloggingtwarnt
EOPNOTSUPPtFalsetbool(	RR t
cmd_structt
status_cmdtpackedR>tresR?te((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pyRCs*	
		(slo(t__doc__R	RR#RRoRqt__all__RR4R(R%R*R-RmRltIF_STRUCT_SIZE_32tIF_STRUCT_SIZE_64RR
R!R'R)R+R2R6tTrueRRRhRC(((s9/usr/lib/python2.7/dist-packages/landscape/lib/network.pyt<module>s<
						
	!