mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-03 01:17:56 +03:00
some minor refactoring on duplicate on DynamicService
This commit is contained in:
parent
e90193ce2a
commit
17027e50f4
@ -111,7 +111,7 @@ class DynamicService(services.Service, abc.ABC): # pylint: disable=too-many-pub
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
# overridable
|
# 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
|
Checks if a machine with the same name or mac exists
|
||||||
Returns the list with the vmids of the duplicated machines
|
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:
|
Note:
|
||||||
Maybe we can only check name or mac, or both, depending on the service
|
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
|
@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
|
Checks if a machine with the same name or mac exists
|
||||||
Returns the list with the vmids of the duplicated machines
|
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
|
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:
|
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
|
# Not removing duplicates, so no duplicates
|
||||||
return []
|
return []
|
||||||
|
@ -516,7 +516,7 @@ class DynamicUserService(services.UserService, autoserializable.AutoSerializable
|
|||||||
def remove_duplicated_names(self) -> None:
|
def remove_duplicated_names(self) -> None:
|
||||||
name = self.get_vmname()
|
name = self.get_vmname()
|
||||||
try:
|
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()
|
userservice = self.db_obj()
|
||||||
log.log(
|
log.log(
|
||||||
userservice.service_pool,
|
userservice.service_pool,
|
||||||
|
@ -43,8 +43,8 @@ import time
|
|||||||
import typing
|
import typing
|
||||||
import collections.abc
|
import collections.abc
|
||||||
import abc
|
import abc
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext
|
from django.utils.translation import gettext
|
||||||
|
|
||||||
from uds.core import consts, exceptions, types
|
from uds.core import consts, exceptions, types
|
||||||
@ -1498,7 +1498,7 @@ class UserInterface(metaclass=UserInterfaceType):
|
|||||||
fld.value = values[fld_name]
|
fld.value = values[fld_name]
|
||||||
else:
|
else:
|
||||||
logger.warning('Field %s.%s not found in values data, ', self.__class__.__name__, fld_name)
|
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):
|
for caller in itertools.islice(inspect.stack(), 1, 8):
|
||||||
logger.warning(' %s:%s:%s', caller.filename, caller.lineno, caller.function)
|
logger.warning(' %s:%s:%s', caller.filename, caller.lineno, caller.function)
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import collections.abc
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from django.utils.translation import gettext_noop as _
|
from django.utils.translation import gettext_noop as _
|
||||||
@ -224,6 +225,29 @@ class XenLinkedService(DynamicService): # pylint: disable=too-many-public-metho
|
|||||||
"""
|
"""
|
||||||
return name
|
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:
|
def start_deploy_of_template(self, name: str, comments: str) -> str:
|
||||||
"""
|
"""
|
||||||
Invokes makeTemplate from parent provider, completing params
|
Invokes makeTemplate from parent provider, completing params
|
||||||
|
Loading…
Reference in New Issue
Block a user