def computerRegister(self, computerName, macAddress, imagingData=False, waitToBeInventoried=False): """ Method to register a new computer. if imagingData is set, we know that the method is called from a MMC agent ! @raise TypeError: if computerName or MACAddress are malformed @return: a deferred object resulting to True if registration was successful, else False. @rtype: bool """ def onSuccess(result): if type(result) != list and len(result) != 2: self.logger.error( 'Imaging: Registering client %s (%s) failed: %s' % (computerName, macAddress, str(result))) ret = False elif not result[0]: self.logger.error( 'Imaging: Registering client %s (%s) failed: %s' % (computerName, macAddress, result[1])) ret = False else: uuid = result[1] self.logger.info('Imaging: Client %s (%s) registered as %s' % (computerName, macAddress, uuid)) self.myUUIDCache.set(uuid, macAddress, hostname, domain, entity) ret = self.computerPrepareImagingDirectory( uuid, { 'mac': macAddress, 'hostname': hostname }) return ret try: # check MAC Addr is conform if not isMACAddress(macAddress): raise TypeError('Malformed MAC address: %s' % macAddress) # check computer name is conform if not len(computerName): raise TypeError('Malformed computer name: %s' % computerName) profile, entity_path, hostname, domain = splitComputerPath( computerName) entity_path = entity_path.split('/') entity = entity_path.pop() except TypeError, ex: self.logger.error('Imaging: Won\'t register %s as %s : %s' % (macAddress, computerName, ex)) return maybeDeferred(lambda x: x, False)
def test_computerPathValid(self): self.assertEqual(splitComputerPath('hostname'), ('', '', 'hostname', '')) self.assertEqual(splitComputerPath(u'123456'), ('', '', '123456', '')) self.assertEqual(splitComputerPath('hostname.domain-example.net'), ('', '', 'hostname', 'domain-example.net')) self.assertEqual(splitComputerPath('profile:hostname'), ('profile', '', 'hostname', '')) self.assertEqual(splitComputerPath('profile:/hostname'), ('profile', '', 'hostname', '')) self.assertEqual(splitComputerPath('/root/sub1/sub2/hostname'), ('', '/root/sub1/sub2', 'hostname', '')) self.assertEqual(splitComputerPath('profile:/root/sub1/sub2/hostname'), ('profile', '/root/sub1/sub2', 'hostname', '')) self.assertRaises(TypeError, splitComputerPath, 'profile:root/sub1/sub2/hostname') self.assertRaises(TypeError, splitComputerPath, 'profile:')
def computerRegister(self, computerName, macAddress, imagingData = False, waitToBeInventoried=False): """ Method to register a new computer. if imagingData is set, we know that the method is called from a MMC agent ! @raise TypeError: if computerName or MACAddress are malformed @return: a deferred object resulting to True if registration was successful, else False. @rtype: bool """ def onSuccess(result): if type(result) != list and len(result) != 2: self.logger.error('Imaging: Registering client %s (%s) failed: %s' % (computerName, macAddress, str(result))) ret = False elif not result[0]: self.logger.error('Imaging: Registering client %s (%s) failed: %s' % (computerName, macAddress, result[1])) ret = False else: uuid = result[1] self.logger.info('Imaging: Client %s (%s) registered as %s' % (computerName, macAddress, uuid)) self.myUUIDCache.set(uuid, macAddress, hostname, domain, entity) ret = self.computerPrepareImagingDirectory(uuid, {'mac': macAddress, 'hostname': hostname}) return ret try: # check MAC Addr is conform if not isMACAddress(macAddress): raise TypeError('Malformed MAC address: %s' % macAddress) # check computer name is conform if not len(computerName): raise TypeError('Malformed computer name: %s' % computerName) profile, entity_path, hostname, domain = splitComputerPath(computerName) entity_path = entity_path.split('/') entity = entity_path.pop() except TypeError, ex: self.logger.error('Imaging: Won\'t register %s as %s : %s' % (macAddress, computerName, ex)) return maybeDeferred(lambda x: x, False)