示例#1
0
	def addExcludedMac(self,macStr,comment=""):
		'''
		Add an MAC to the exclusion list	
		'''
		with MutexStore.getObjectLock(self.getLockIdentifier()):
			#Check is not already allocated
			if not  self.__isMacAvailable(macStr):
				raise Exception("Mac already allocated or marked as excluded")

			#then forbidd
			if not EthernetUtils.isMacInRange(macStr,self.startMac,self.endMac):
				raise Exception("Mac is not in range")

			newMac = MacSlot.excludedMacFactory(self,macStr,comment)
			self.macs.add(newMac)

			#if was nextSlot shift
			if self.nextAvailableMac == macStr:
				try:
                        		it= EthernetUtils.getMacIterator(self.nextAvailableMac,self.endMac)
					while True:
						mac = it.getNextMac()
						if self.__isMacAvailable(mac):
							break
					self.nextAvailableMac= mac
				except Exception as e:
					self.nextAvailableMac = None
			
			self.autoSave()
示例#2
0
	def allocateMac(self):
		'''
		Allocates an MAC address of the range	
		'''
		with MutexStore.getObjectLock(self.getLockIdentifier()):
			#Implements first fit algorithm
				
			if self.nextAvailableMac == None:
				raise Exception("Could not allocate any Mac")
		
			newMac = MacSlot.macFactory(self,self.nextAvailableMac)
			self.macs.add(newMac)
			
			#Try to find new slot
			try:
                        	it= EthernetUtils.getMacIterator(self.nextAvailableMac,self.endMac)
				while True:
					mac = it.getNextMac()
					if self.__isMacAvailable(mac):
						break
				self.nextAvailableMac = mac
			except Exception as e:
				self.nextAvailableMac = None
	
			self.autoSave()

			return newMac
示例#3
0
    def allocateMac(self):
        '''
		Allocates an MAC address of the range	
		'''
        with MutexStore.getObjectLock(self.getLockIdentifier()):
            #Implements first fit algorithm

            if self.nextAvailableMac == None:
                raise Exception("Could not allocate any Mac")

            newMac = MacSlot.macFactory(self, self.nextAvailableMac)
            self.macs.add(newMac)

            #Try to find new slot
            try:
                it = EthernetUtils.getMacIterator(self.nextAvailableMac,
                                                  self.endMac)
                while True:
                    mac = it.getNextMac()
                    if self.__isMacAvailable(mac):
                        break
                self.nextAvailableMac = mac
            except Exception as e:
                self.nextAvailableMac = None

            self.autoSave()

            return newMac
示例#4
0
	def removeExcludedMac(self,macObj):
		'''
		Deletes an Mac from the exclusion list	(but it does not destroy the object!!)
		'''	
		with MutexStore.getObjectLock(self.getLockIdentifier()):

			macStr = macObj.getMac()

			if (not self.macs.get(mac=macStr).isExcludedMac()):
				raise Exception("Cannot release Mac. Reason may be is unallocated or is not excluded Mac")
	
			self.macs.remove(macObj)

			#Determine new available Mac
			if not self.nextAvailableMac == None:
				if EthernetUtils.compareMacs(macStr,self.nextAvailableMac) > 0:
					#Do nothing
					pass
				else:	
					self.nextAvailableMac = macStr
			else:
				#No more gaps
				self.nextAvailableMac = macStr

	
			self.autoSave()
示例#5
0
    def releaseMac(self, macObj):
        '''
		Releases an MAC address of the range (but it does not destroy the object!!)	
		'''
        with MutexStore.getObjectLock(self.getLockIdentifier()):
            macStr = macObj.getMac()
            if not self.macs.filter(mac=macStr).count() > 0:
                raise Exception(
                    "Cannot release Mac %s. Reason may be is unallocated or is an excluded Mac",
                    macStr)

            self.macs.remove(macObj)

            #Determine new available Mac
            if not self.nextAvailableMac == None:
                if EthernetUtils.compareMacs(macStr,
                                             self.nextAvailableMac) > 0:
                    #Do nothing
                    pass
                else:
                    self.nextAvailableMac = macStr
            else:
                #No more gaps
                self.nextAvailableMac = macStr

            self.autoSave()
示例#6
0
文件: MacRange.py 项目: cargious/ocf
    def removeExcludedMac(self, macObj):
        '''
		Deletes an Mac from the exclusion list	(but it does not destroy the object!!)
		'''
        with MutexStore.getObjectLock(self.getLockIdentifier()):

            macStr = macObj.getMac()

            if (not self.macs.get(mac=macStr).isExcludedMac()):
                raise Exception(
                    "Cannot release Mac. Reason may be is unallocated or is not excluded Mac"
                )

            self.macs.remove(macObj)

            #Determine new available Mac
            if not self.nextAvailableMac == None:
                if EthernetUtils.compareMacs(macStr,
                                             self.nextAvailableMac) > 0:
                    #Do nothing
                    pass
                else:
                    self.nextAvailableMac = macStr
            else:
                #No more gaps
                self.nextAvailableMac = macStr

            self.autoSave()
示例#7
0
    def constructor(macRange, mac, excluded, comment="", save=True):
        self = MacSlot()

        #Check MAC
        if not mac == "":
            EthernetUtils.checkValidMac(mac)

        self.mac = mac
        self.isExcluded = excluded
        self.macRange = macRange
        self.comment = comment
        self.doSave = save

        if save:
            self.save()

        return self
示例#8
0
文件: MacSlot.py 项目: HalasNet/felix
	def constructor(macRange,mac,excluded,comment="",save=True):
		self = MacSlot()

		#Check MAC
		if not mac == "":
			EthernetUtils.checkValidMac(mac)

		self.mac = mac
		self.isExcluded = excluded 
		self.macRange = macRange
		self.comment = comment
		self.doSave = save

		if save:
			self.save()
		
		return self
示例#9
0
	def constructor(name,startMac,endMac,isGlobal=True,save=True):
		self = MacRange()
		try:
			#Default constructor
			EthernetUtils.checkValidMac(startMac)
			EthernetUtils.checkValidMac(endMac)
			
			self.startMac = startMac.upper()
			self.endMac = endMac.upper()
			
			self.name = name
			self.isGlobal= isGlobal
			
			#Create an iterator
			it= EthernetUtils.getMacIterator(self.startMac,self.endMac)
			self.nextAvailableMac = it.getNextMac()
			
			#Number of Slots
			try:
				self.numberOfSlots = EthernetUtils.getNumberOfSlotsInRange(startMac,endMac)		
			except Exception as e:	
				print "Exception doing slot calculation"+str(e)	
				self.numberOfSlots = -1		
		
			self.doSave = save
			if save:
				self.save()
		except Exception as e:
			print e
			raise e
		return self
示例#10
0
    def constructor(name, startMac, endMac, isGlobal=True, save=True):
        self = MacRange()
        try:
            #Default constructor
            EthernetUtils.checkValidMac(startMac)
            EthernetUtils.checkValidMac(endMac)

            self.startMac = startMac.upper()
            self.endMac = endMac.upper()

            self.name = name
            self.isGlobal = isGlobal

            #Create an iterator
            it = EthernetUtils.getMacIterator(self.startMac, self.endMac)
            self.nextAvailableMac = it.getNextMac()

            #Number of Slots
            try:
                self.numberOfSlots = EthernetUtils.getNumberOfSlotsInRange(
                    startMac, endMac)
            except Exception as e:
                print "Exception doing slot calculation" + str(e)
                self.numberOfSlots = -1

            self.doSave = save
            if save:
                self.save()
        except Exception as e:
            print e
            raise e
        return self
示例#11
0
    def rebasePointer(self):
        '''Used when pointer has lost track mostly due to bug #'''
        with MutexStore.getObjectLock(self.getLockIdentifier()):
            print "Rebasing pointer of range: " + str(self.id)
            print "Current pointer point to: " + self.nextAvailableMac
            try:
                it = EthernetUtils.getMacIterator(self.startMac, self.endMac)
                while True:
                    mac = it.getNextMac()
                    if self.__isMacAvailable(mac):
                        break
                self.nextAvailableMac = mac
            except Exception as e:
                self.nextAvailableMac = None

            print "Pointer will be rebased to: " + self.nextAvailableMac
            self.save()
示例#12
0
	def rebasePointer(self):
		'''Used when pointer has lost track mostly due to bug #'''
		with MutexStore.getObjectLock(self.getLockIdentifier()):
			print "Rebasing pointer of range: "+str(self.id)
			print "Current pointer point to: "+self.nextAvailableMac
			try:
                    		it= EthernetUtils.getMacIterator(self.startMac,self.endMac)
				while True:
					mac = it.getNextMac()
					if self.__isMacAvailable(mac):
						break
				self.nextAvailableMac= mac
			except Exception as e:
				self.nextAvailableMac = None
			
			print "Pointer will be rebased to: "+self.nextAvailableMac
			self.save()
示例#13
0
	def releaseMac(self,macObj):
		'''
		Releases an MAC address of the range (but it does not destroy the object!!)	
		'''
		with MutexStore.getObjectLock(self.getLockIdentifier()):
			macStr = macObj.getMac()
			if not self.macs.filter(mac=macStr).count() > 0:
				raise Exception("Cannot release Mac %s. Reason may be is unallocated or is an excluded Mac",macStr)
					
			self.macs.remove(macObj)
				
			#Determine new available Mac
			if not self.nextAvailableMac == None:
				if EthernetUtils.compareMacs(macStr,self.nextAvailableMac) > 0:
					#Do nothing
					pass
				else:	
					self.nextAvailableMac = macStr
			else:
				#No more gaps
				self.nextAvailableMac = macStr

			self.autoSave()
示例#14
0
        def __setEndMac(self, value):
		EthernetUtils.checkValidMac(value)
                self.endMac = value.upper()
		self.autoSave()
示例#15
0
 def __setEndMac(self, value):
     EthernetUtils.checkValidMac(value)
     self.endMac = value.upper()
     self.autoSave()
示例#16
0
 def __setStartMac(self, value):
     EthernetUtils.checkValidMac(value)
     MAC4Utils.checkValidMac(value)
     self.startMac = value.upper()
     self.autoSave()
示例#17
0
        def __setStartMac(self, value):
		EthernetUtils.checkValidMac(value)
		MAC4Utils.checkValidMac(value) 
                self.startMac = value.upper()
		self.autoSave()