Right now, added de posibility to transfer a mac or name from an user service to an service.

This gives the posibility to to an user service to "reserve" (for now, indefinitely, but will add an "stamp" field to uniqueid database so we can clean up them from time to time) a mac or an name, so other deployed services do not uses them anymore.

One example of this is when a VM gets in error, and machine gets renamed. The mac is them reserved so no more machines clashes with this one reserved.
This commit is contained in:
Adolfo Gómez 2013-03-06 15:41:09 +00:00
parent 552e8b680b
commit 8eaec2c535
8 changed files with 44 additions and 1 deletions

View File

@ -198,6 +198,23 @@ class Service(Module):
'''
raise Exception('The class {0} has been marked as manually asignable but no requestServicesForAssignetion provided!!!'.format(self.__class__.__name__))
def macGenerator(self):
'''
Utility method to access provided macs generator (inside environment)
Returns the environment unique mac addresses generator
'''
return self.idGenerators('mac')
def nameGenerator(self):
'''
Utility method to access provided names generator (inside environment)
Returns the environment unique name generator
'''
return self.idGenerators('name')
def __str__(self):
'''
String method, mainly used for debugging purposes

View File

@ -80,6 +80,23 @@ class UniqueIDGenerator(object):
finally:
dbUniqueId.objects.unlock()
def transfer(self, seq, toUidGen):
try:
dbUniqueId.objects.lock()
obj = dbUniqueId.objects.get( owner=self._owner, seq=seq)
obj.owner = toUidGen._owner
obj.basename = toUidGen._baseName
obj.save()
return True
except:
logger.exception('EXCEPTION AT transfer')
return False
finally:
dbUniqueId.objects.unlock()
def free(self, seq):
try:
logger.debug('Freeing seq {0} from {1} ({2})'.format(seq, self._owner, self._baseName))

View File

@ -53,6 +53,9 @@ class UniqueMacGenerator(UniqueIDGenerator):
lastMac = self.__toInt(lastMac)
return self.__toMac(super(UniqueMacGenerator, self).get(firstMac, lastMac))
def transfer(self, mac, toUMgen):
super(UniqueMacGenerator, self).transfer( self.__toInt(mac), toUMgen )
def free(self, mac):
super(UniqueMacGenerator, self).free( self.__toInt(mac) )

View File

@ -50,6 +50,9 @@ class UniqueNameGenerator(UniqueIDGenerator):
maxVal = 10**length - 1
return self.__toName(super(UniqueNameGenerator, self).get(minVal, maxVal), length)
def transfer(self, baseName, name, toUNGen):
self.setBaseName(baseName)
super(UniqueNameGenerator, self).transfer(int(name[len(self._baseName):]), toUNGen)
def free(self, baseName, name):
self.setBaseName(baseName)

View File

@ -192,7 +192,10 @@ class Service(models.Model):
'''
Returns an environment valid for the record this object represents
'''
return Environment.getEnvForTableElement(self._meta.verbose_name, self.id)
from uds.core.util.UniqueMacGenerator import UniqueMacGenerator
from uds.core.util.UniqueNameGenerator import UniqueNameGenerator
return Environment.getEnvForTableElement(self._meta.verbose_name, self.id, {'mac' : UniqueMacGenerator, 'name' : UniqueNameGenerator })
def getInstance(self, values = None):
'''