diff --git a/server/src/uds/core/services/generics/dynamic/service.py b/server/src/uds/core/services/generics/dynamic/service.py index 976405644..4b8948f46 100644 --- a/server/src/uds/core/services/generics/dynamic/service.py +++ b/server/src/uds/core/services/generics/dynamic/service.py @@ -111,7 +111,7 @@ class DynamicService(services.Service, abc.ABC): # pylint: disable=too-many-pub return name # overridable - def find_duplicated_machines(self, name: str, mac: str) -> collections.abc.Iterable[str]: + def find_duplicates(self, name: str, mac: str) -> collections.abc.Iterable[str]: """ Checks if a machine with the same name or mac exists Returns the list with the vmids of the duplicated machines @@ -126,10 +126,10 @@ class DynamicService(services.Service, abc.ABC): # pylint: disable=too-many-pub Note: Maybe we can only check name or mac, or both, depending on the service """ - raise NotImplementedError('find_duplicated_machines must be implemented if remove_duplicates is used!') + raise NotImplementedError(f'{self.__class__}: find_duplicates must be implemented if remove_duplicates is used!') @typing.final - def perform_find_duplicated_machines(self, name: str, mac: str) -> collections.abc.Iterable[str]: + def perform_find_duplicates(self, name: str, mac: str) -> collections.abc.Iterable[str]: """ Checks if a machine with the same name or mac exists Returns the list with the vmids of the duplicated machines @@ -145,7 +145,7 @@ class DynamicService(services.Service, abc.ABC): # pylint: disable=too-many-pub Maybe we can only check name or mac, or both, depending on the service """ if self.has_field('remove_duplicates') and self.remove_duplicates.value: - return self.find_duplicated_machines(name, mac) + return self.find_duplicates(name, mac) # Not removing duplicates, so no duplicates return [] diff --git a/server/src/uds/core/services/generics/dynamic/userservice.py b/server/src/uds/core/services/generics/dynamic/userservice.py index 4d80a9ca0..3da87f2ea 100644 --- a/server/src/uds/core/services/generics/dynamic/userservice.py +++ b/server/src/uds/core/services/generics/dynamic/userservice.py @@ -516,7 +516,7 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable def remove_duplicated_names(self) -> None: name = self.get_vmname() try: - for vmid in self.service().perform_find_duplicated_machines(name, self.get_unique_id()): + for vmid in self.service().perform_find_duplicates(name, self.get_unique_id()): userservice = self.db_obj() log.log( userservice.service_pool, diff --git a/server/src/uds/core/ui/user_interface.py b/server/src/uds/core/ui/user_interface.py index 0d96c7797..b4b4443f7 100644 --- a/server/src/uds/core/ui/user_interface.py +++ b/server/src/uds/core/ui/user_interface.py @@ -43,8 +43,8 @@ import time import typing import collections.abc import abc -from django.conf import settings +from django.conf import settings from django.utils.translation import gettext from uds.core import consts, exceptions, types @@ -1498,7 +1498,7 @@ class UserInterface(metaclass=UserInterfaceType): fld.value = values[fld_name] else: logger.warning('Field %s.%s not found in values data, ', self.__class__.__name__, fld_name) - if settings.DEBUG: + if getattr(settings, 'DEBUG', False): for caller in itertools.islice(inspect.stack(), 1, 8): logger.warning(' %s:%s:%s', caller.filename, caller.lineno, caller.function) diff --git a/server/src/uds/services/Xen/service.py b/server/src/uds/services/Xen/service.py index 327525999..221518c95 100644 --- a/server/src/uds/services/Xen/service.py +++ b/server/src/uds/services/Xen/service.py @@ -30,6 +30,7 @@ Author: Adolfo Gómez, dkmaster at dkmon dot com """ import logging +import collections.abc import typing from django.utils.translation import gettext_noop as _ @@ -223,6 +224,29 @@ class XenLinkedService(DynamicService): # pylint: disable=too-many-public-metho Xen Seems to allow all kind of names """ return name + + def find_duplicates(self, name: str, mac: str) -> collections.abc.Iterable[str]: + """ + Checks if a machine with the same name or mac exists + Returns the list with the vmids of the duplicated machines + + Args: + name: Name of the machine + mac: Mac of the machine + + Returns: + List of duplicated machines + + Note: + Maybe we can only check name or mac, or both, depending on the service + """ + with self.provider().get_connection() as api: + vms = api.list_vms() + return [ + vm.opaque_ref + for vm in vms + if vm.name == name + ] # Only check for name, mac is harder to get, so by now, we only check for name def start_deploy_of_template(self, name: str, comments: str) -> str: """