コード例 #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
ファイル: NetworkInterface.py プロジェクト: HalasNet/felix
	def constructor(name,macStr,macObj,switchID,port,ip4Obj,isMgmt=False,isBridge=False,save=True):
		self = NetworkInterface()	
		try:
			self.name = name;

			if macObj == None:
				self.mac = MacSlot.macFactory(None,macStr)	
			else:
				if not isinstance(macObj,MacSlot):
					raise Exception("Cannot construct NetworkInterface with a non MacSlot object as parameter")
				self.mac = macObj
			self.isMgmt = isMgmt

			'''Connectivity'''
			if isBridge:
				self.isBridge = isBridge
				self.switchID = switchID 
				self.port = port
			if not ip4Obj == None:
				if not isinstance(ip4Obj,Ip4Slot):
						raise Exception("Cannot construct NetworkInterface with a non Ip4Slot object as parameter")
				else:		
					self.save()
					self.ip4s.add(ip4Obj)			

			self.doSave = save
			if save:
				self.save()
		except Exception as e:
			print e
#			self.delete()
			raise e

		return self
コード例 #4
0
ファイル: MacRange.py プロジェクト: HalasNet/felix
	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()
コード例 #5
0
ファイル: MacRange.py プロジェクト: HalasNet/felix
	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
コード例 #6
0
    def constructor(name,
                    macStr,
                    macObj,
                    switchID,
                    port,
                    ip4Obj,
                    isMgmt=False,
                    isBridge=False,
                    save=True):
        self = NetworkInterface()
        try:
            self.name = name

            if macObj == None:
                self.mac = MacSlot.macFactory(None, macStr)
            else:
                if not isinstance(macObj, MacSlot):
                    raise Exception(
                        "Cannot construct NetworkInterface with a non MacSlot object as parameter"
                    )
                self.mac = macObj
            self.isMgmt = isMgmt
            '''Connectivity'''
            if isBridge:
                self.isBridge = isBridge
                self.switchID = switchID
                self.port = port
            if not ip4Obj == None:
                if not isinstance(ip4Obj, Ip4Slot):
                    raise Exception(
                        "Cannot construct NetworkInterface with a non Ip4Slot object as parameter"
                    )
                else:
                    self.save()
                    self.ip4s.add(ip4Obj)

            self.doSave = save
            if save:
                self.save()
        except Exception as e:
            print e
            #			self.delete()
            raise e

        return self