Ejemplo n.º 1
0
    def addExcludedIp(self, ipStr, comment):
        '''
		Add an IP to the exclusion list	
		'''
        with MutexStore.getObjectLock(self.getLockIdentifier()):
            #Check is not already allocated
            if not self.__isIpAvailable(ipStr):
                raise Exception("Ip already allocated or marked as excluded")

            #then forbidd
            if not IP4Utils.isIpInRange(ipStr, self.startIp, self.endIp):
                raise Exception("Ip is not in range")
            newIp = Ip4Slot.excludedIpFactory(self, ipStr, comment)
            self.ips.add(newIp)

            #if was nextSlot shift
            if self.nextAvailableIp == ipStr:
                try:
                    it = IP4Utils.getIpIterator(self.nextAvailableIp,
                                                self.endIp, self.netMask)
                    while True:
                        ip = it.getNextIp()
                        if self.__isIpAvailable(ip):
                            break
                    self.nextAvailableIp = ip
                except Exception as e:
                    self.nextAvailableIp = None

            self.autoSave()
Ejemplo n.º 2
0
	def addExcludedIp(self,ipStr,comment):
		'''
		Add an IP to the exclusion list	
		'''
		with MutexStore.getObjectLock(self.getLockIdentifier()):
			#Check is not already allocated
			if not  self.__isIpAvailable(ipStr):
				raise Exception("Ip already allocated or marked as excluded")

			#then forbidd
			if not IP4Utils.isIpInRange(ipStr,self.startIp,self.endIp):
				raise Exception("Ip is not in range")
			newIp = Ip4Slot.excludedIpFactory(self,ipStr,comment)
			self.ips.add(newIp)

			#if was nextSlot shift
			if self.nextAvailableIp == ipStr:
				try:
                        		it= IP4Utils.getIpIterator(self.nextAvailableIp,self.endIp,self.netMask)
					while True:
						ip = it.getNextIp()
						if self.__isIpAvailable(ip):
							break
					self.nextAvailableIp = ip
				except Exception as e:
					self.nextAvailableIp = None
			
			self.autoSave()
Ejemplo n.º 3
0
    def allocateIp(self):
        '''
		Allocates an IP address of the range	
		'''
        with MutexStore.getObjectLock(self.getLockIdentifier()):
            #Implements first fit algorithm

            if self.nextAvailableIp == None:
                raise Exception("Could not allocate any IP")

            newIp = Ip4Slot.ipFactory(self, self.nextAvailableIp)
            self.ips.add(newIp)

            #Try to find new slot
            try:
                it = IP4Utils.getIpIterator(self.nextAvailableIp, self.endIp,
                                            self.netMask)
                while True:
                    ip = it.getNextIp()
                    if self.__isIpAvailable(ip):
                        break
                self.nextAvailableIp = ip
            except Exception as e:
                self.nextAvailableIp = None

            self.autoSave()
            return newIp
Ejemplo n.º 4
0
	def allocateIp(self):
		'''
		Allocates an IP address of the range	
		'''
		with MutexStore.getObjectLock(self.getLockIdentifier()):
			#Implements first fit algorithm
				
			if self.nextAvailableIp == None:
				raise Exception("Could not allocate any IP")
		
			newIp = Ip4Slot.ipFactory(self,self.nextAvailableIp)
			self.ips.add(newIp)
			
			#Try to find new slot
			try:
                        	it= IP4Utils.getIpIterator(self.nextAvailableIp,self.endIp,self.netMask)
				while True:
					ip = it.getNextIp()
					if self.__isIpAvailable(ip):
						break
				self.nextAvailableIp = ip
			except Exception as e:
				self.nextAvailableIp = None
	
			self.autoSave()
			return newIp