diff --git a/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/__init__.py b/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/__init__.py index ed487b9..3678a21 100644 --- a/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/__init__.py +++ b/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/__init__.py @@ -50,7 +50,7 @@ from univention.management.console.modules import Base, UMC_OptionTypeError, UMC from univention.management.console.modules.decorators import simple_response, sanitize, multi_response from univention.management.console.modules.sanitizers import ( LDAPSearchSanitizer, EmailSanitizer, ChoicesSanitizer, - ListSanitizer, StringSanitizer, DictSanitizer + ListSanitizer, StringSanitizer, DictSanitizer, BooleanSanitizer ) from univention.management.console.modules.mixins import ProgressMixin from univention.management.console.log import MODULE @@ -644,6 +644,10 @@ class Instance(Base, ProgressMixin): result = module.get_default_values(property_name) self.finished(request.id, result) + @sanitize( + networkDN=StringSanitizer(required=True), + increaseCounter=BooleanSanitizer(default=False) + ) def network(self, request): """Returns the next IP configuration based on the given network object @@ -653,12 +657,11 @@ class Instance(Base, ProgressMixin): return: {} """ - self.required_options(request, 'networkDN') module = self._get_module('networks/network') obj = module.get(request.options['networkDN']) if not obj: - raise UMC_OptionTypeError('Could not find network object') + raise ObjectDoesNotExists(request.options['networkDN']) try: obj.refreshNextIp() except udm_errors.nextFreeIp: @@ -667,7 +670,7 @@ class Instance(Base, ProgressMixin): result = {'ip': obj['nextIp'], 'dnsEntryZoneForward': obj['dnsEntryZoneForward'], 'dhcpEntryZone': obj['dhcpEntryZone'], 'dnsEntryZoneReverse': obj['dnsEntryZoneReverse']} self.finished(request.id, result) - if request.options.get('increaseCounter', False) == True: + if request.options['increaseCounter']: # increase the next free IP address obj.stepIp() obj.modify() diff --git a/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py b/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py index 0b50de2..182750d 100644 --- a/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py +++ b/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py @@ -266,19 +266,20 @@ class SuperordinateDoesNotExists(ObjectDoesNotExists): yield _('Superordinate %s could not be found.') % (self.ldap_dn,) yield _('It possibly has been deleted or moved. Please update your search results and open the object again.') + class NoIpLeft(UMCError): - def __init__(self, networkDN): - self.networkName = (udm.uldap.explodeDn(networkDN)[0]).split('=')[1] + def __init__(self, ldap_dn): + try: + self.network_name = udm.uldap.explodeDn(ldap_dn, True)[0] + except IndexError: + self.network_name = ldap_dn super(NoIpLeft, self).__init__() def _error_msg(self): - - yield _('Failed to automatically assign an IP address.') - yield _('All IP addresses in the specified network "%s" are already in use.') % (self.networkName,) - yield _('Please specify a different network or make sure that free IP addresses are available.') - - + yield _('Failed to automatically assign an IP address.') + yield _('All IP addresses in the specified network "%s" are already in use.') % (self.network_name,) + yield _('Please specify a different network or make sure that free IP addresses are available.') class UDM_Error(Exception):