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
    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()
    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
Beispiel #4
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
Beispiel #5
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()
Beispiel #6
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
    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()
Beispiel #8
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()