Ejemplo n.º 1
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
Ejemplo n.º 2
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()
Ejemplo n.º 3
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