1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-23 17:34:17 +03:00

Fixed service pools info

This commit is contained in:
Adolfo Gómez García 2023-11-06 16:57:50 +01:00
parent 8997d2fac0
commit 3451719675
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
6 changed files with 22 additions and 18 deletions

View File

@ -90,6 +90,9 @@ BOOL_TRUE_VALUES: typing.Final[typing.Set[typing.Union[bool, str, bytes, int]]]
TRUE_STR: typing.Final[str] = 'true'
FALSE_STR: typing.Final[str] = 'false'
# Constant to mark an "UNLIMITED" value
UNLIMITED: typing.Final[int] = -1
# Default length for Gui Text Fields
DEFAULT_TEXT_LENGTH: typing.Final[int] = 64

View File

@ -30,9 +30,10 @@
"""
Author: Adolfo Gómez, dkmaster at dkmon dot com
"""
from . import actor
from . import auth
from . import validation
from . import service
from . import validation
# Common exceptions inserted here
from .common import UDSException, BlockAccess

View File

@ -109,7 +109,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
"""
serviceInstance = service.getInstance()
# Early return, so no database count is needed
if serviceInstance.maxUserServices == services.Service.UNLIMITED:
if serviceInstance.maxUserServices == consts.UNLIMITED:
return False
if self.getExistingUserServices(service) >= (serviceInstance.maxUserServices or 1):
@ -604,7 +604,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
def notifyPreconnect(self, userService: UserService, info: types.connections.ConnectionData) -> None:
try:
comms.notifyPreconnect(userService, info)
except exceptions.NoActorComms: # If no comms url for userService, try with service
except exceptions.actor.NoActorComms: # If no comms url for userService, try with service
userService.deployed_service.service.notifyPreconnect(userService, info)
def checkUuid(self, userService: UserService) -> bool:
@ -918,7 +918,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
if meta.policy == types.pools.LoadBalancingPolicy.PRIORITY:
sortPools = [(p.priority, p.pool) for p in poolMembers]
elif meta.policy == types.pools.LoadBalancingPolicy.GREATER_PERCENT_FREE:
sortPools = [(p.pool.usage(), p.pool) for p in poolMembers]
sortPools = [(p.pool.usage()[0], p.pool) for p in poolMembers]
else:
sortPools = [
(

View File

@ -40,7 +40,7 @@ from uds.core.transports import protocols
from uds.core.util.state import State
from uds.core.util import log
from uds.core import types
from uds.core import types, consts
if typing.TYPE_CHECKING:
@ -93,9 +93,6 @@ class Service(Module):
"""
# : Constant for indicating that max elements this service can deploy is unlimited.
UNLIMITED: int = -1
# : Name of type, used at administration interface to identify this
# : service (i.e. Xen server, oVirt Server, ...)
# : This string will be translated when provided to admin interface
@ -125,7 +122,7 @@ class Service(Module):
# : Normally set to UNLIMITED. This attribute indicates if the service has some "limitation"
# : for providing deployed services to users. This attribute can be set here or
# : modified at instance level, core will access always to it using an instance object.
maxUserServices: int = UNLIMITED # : If the service provides more than 1 "provided service" (-1 = no limit, 0 = ???? (do not use it!!!), N = max number to deploy
maxUserServices: int = consts.UNLIMITED # : If the service provides more than 1 "provided service" (-1 = no limit, 0 = ???? (do not use it!!!), N = max number to deploy
# : If this item "has constains", on deployed service edition, defined keys will overwrite defined ones
# : That is, this Dicionary will OVERWRITE fields ON ServicePool (normally cache related ones) dictionary from a REST api save invocation!!
@ -271,10 +268,10 @@ class Service(Module):
try:
self.maxUserServices = getattr(self, 'maxServices').num()
except Exception:
self.maxUserServices = Service.UNLIMITED
self.maxUserServices = consts.UNLIMITED
if self.maxUserServices < 1:
self.maxUserServices = Service.UNLIMITED
self.maxUserServices = consts.UNLIMITED
# Keep untouched if maxServices is not present

View File

@ -38,7 +38,7 @@ from django.db import models
from django.db.models import QuerySet, signals
from django.utils.translation import gettext_noop as _
from uds.core import types
from uds.core import consts, types
from uds.core.util import log, states
from uds.core.util.calendar import CalendarChecker
@ -178,6 +178,7 @@ class MetaPool(UUIDModel, TaggingMixin): # type: ignore
)
.prefetch_related(
'service',
'service__provider',
)
)
@ -186,13 +187,14 @@ class MetaPool(UUIDModel, TaggingMixin): # type: ignore
for pool in query:
p, u, m = pool.usage(pool.usage_count) # type:ignore # Anotated field
usage_count += u
if max_count <= 0 or m <= 0:
max_count = -1
# If any of the pools has no max, then max is -1
if max_count == consts.UNLIMITED or m == consts.UNLIMITED:
max_count = consts.UNLIMITED
else:
max_count += m
if max_count <= 0:
return (0, usage_count, max_count)
if max_count == 0 or max_count == consts.UNLIMITED:
return (0, usage_count, consts.UNLIMITED)
return (usage_count * 100 // max_count, usage_count, max_count)

View File

@ -55,6 +55,7 @@ from .account import Account
from ..core.consts import NEVER
from ..core.util.model import getSqlDatetime
from uds.core import consts
# Not imported at runtime, just for type checking
@ -643,8 +644,8 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
if cachedValue == -1:
cachedValue = self.assignedUserServices().filter(state__in=states.userService.VALID_STATES).count()
if maxs <= 0:
return 0, cachedValue, maxs
if maxs == 0 or max == consts.UNLIMITED:
return 0, cachedValue, consts.UNLIMITED
return 100 * cachedValue // maxs, cachedValue, maxs