コード例 #1
0
ファイル: cisco_view.py プロジェクト: hazraa/samples
    def addroute(self, object):
	"""Check to see if this routeobj belongs with this interface
	   It can then be tied to this Interface object
	"""
	if not isinstance(object, Route):
	    return

	isdn=0

	if self.crouter != object.crouter:
	    return

	# Destination is interface or gateway.
	# Check ISDN type 
	# DEBUG
	#print "obj.cdest=",object.cdest, "gw=",self.cgw, "int=",self.cinterface
	
	for gw in self.cgw:
	    isdn=1
	    if object.cdest==gw:
		if self.cstate=="shutdown":
	    	    object.attributes.append(Const.INTERFACE_SHUTDOWN)
	        self.croutes.append(object)

	    #print "%s %s DOWN" % (self.crouter, self.cinterface)
#	else:
#	    print "%s %s UP" % (self.crouter, self.cinterface)

	# Check other permcons links if a gateway on a route is part of ip block
	# on an interface.

	#print "Debug addroute(): obj.cdest [%s] <-> self.cinterface [%s]" % (object.cdest,self.cinterface)

	# For a destination IP
	if not isdn and IPTools.checkip(object.cdest):
	    if type(self.cip)==(""):
		self.cip=[self.cip]
	    if type(self.cip_cidr)==(""):
		self.cip_cidr=[self.cip_cidr]
	    i=0
	    for ip in self.cip:
		 ipcidr = ip+'/'+ str(self.cip_cidr[i])
		 net = IPTools.findnet(ipcidr)

	    	 bits =  IPTools.mask2int(self.cip_cidr)
	    	 lowip = IPTools.ip2int(net)
	    	 highip= IPTools.ip2int(net) + bits	
	
	         testip = IPTools.ip2int(object.cdest)	

	         if testip>=lowip and testip<=highip:
	            self.croutes.append(object)
		    if self.cstate=="shutdown":
	    	        object.attributes.append(Const.INTERFACE_SHUTDOWN)
		 i=i+1

	# For a route with an interface as destination 
	elif object.cdest==self.cinterface:
	        #print "Debug addroute(): obj.cdest [%s] <-> self.cinterface [%s]" % (object.cdest,self.cinterface)
		if self.cstate=="shutdown":
	    	    object.attributes.append(Const.INTERFACE_SHUTDOWN)

		for i in range(0, len(self.cip)):
		    ipcidr=self.cip[i] + "/" + str(self.cip_cidr[i])

		    net = IPTools.findnet(ipcidr) + "/" + str(self.cip_cidr[i])

		    object.cdest_net.append(net)
		    ip=None
	    	    if self.cmask[i]=="255.255.255.252":
			parts=string.split(self.cip[i],'.')
			if len(parts)==4:
			    if ( (int(parts[3])-1) % 4) ==0:
		    	        byte4=int(parts[3]) + 1
			    else:		    
		    	        byte4=int(parts[3]) - 1
	            	    ipcidr=("%s.%s.%s.%s" % (parts[0], parts[1], parts[2], byte4))

		            #object.cdest_ip.append(ipcidr)
		            ip=ipcidr

		    object.cdest_ip.append(ip)	

	            #print " ** ** addroute() net=", object.cdest_net[-1], "ip=",object.cdest_ip[-1]
	        self.croutes.append(object)
	return