Esempio n. 1
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
Esempio n. 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
Esempio n. 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
Esempio n. 4
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