diff --git a/server/src/uds/core/services/BaseService.py b/server/src/uds/core/services/BaseService.py index ebbc59ee..2bc1fb8c 100644 --- a/server/src/uds/core/services/BaseService.py +++ b/server/src/uds/core/services/BaseService.py @@ -197,6 +197,23 @@ class Service(Module): returned are not repeated... :-) ''' 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): ''' diff --git a/server/src/uds/core/util/UniqueIDGenerator.py b/server/src/uds/core/util/UniqueIDGenerator.py index 10bcbf42..2e2fa4fc 100644 --- a/server/src/uds/core/util/UniqueIDGenerator.py +++ b/server/src/uds/core/util/UniqueIDGenerator.py @@ -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)) diff --git a/server/src/uds/core/util/UniqueMacGenerator.py b/server/src/uds/core/util/UniqueMacGenerator.py index 4f97bfb7..a85b5a53 100644 --- a/server/src/uds/core/util/UniqueMacGenerator.py +++ b/server/src/uds/core/util/UniqueMacGenerator.py @@ -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) ) diff --git a/server/src/uds/core/util/UniqueNameGenerator.py b/server/src/uds/core/util/UniqueNameGenerator.py index ec9ab20c..83927836 100644 --- a/server/src/uds/core/util/UniqueNameGenerator.py +++ b/server/src/uds/core/util/UniqueNameGenerator.py @@ -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) diff --git a/server/src/uds/locale/de/LC_MESSAGES/django.mo b/server/src/uds/locale/de/LC_MESSAGES/django.mo index 8defd3c5..1e47de18 100644 Binary files a/server/src/uds/locale/de/LC_MESSAGES/django.mo and b/server/src/uds/locale/de/LC_MESSAGES/django.mo differ diff --git a/server/src/uds/locale/es/LC_MESSAGES/django.mo b/server/src/uds/locale/es/LC_MESSAGES/django.mo index f0162f3c..9e223051 100644 Binary files a/server/src/uds/locale/es/LC_MESSAGES/django.mo and b/server/src/uds/locale/es/LC_MESSAGES/django.mo differ diff --git a/server/src/uds/locale/fr/LC_MESSAGES/django.mo b/server/src/uds/locale/fr/LC_MESSAGES/django.mo index a3fedf30..b4e5bdba 100644 Binary files a/server/src/uds/locale/fr/LC_MESSAGES/django.mo and b/server/src/uds/locale/fr/LC_MESSAGES/django.mo differ diff --git a/server/src/uds/models.py b/server/src/uds/models.py index bd063dc4..fa102391 100644 --- a/server/src/uds/models.py +++ b/server/src/uds/models.py @@ -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): '''