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

Added new way of counting "active" machines (taking into account the removable and removing services also)

This commit is contained in:
Adolfo Gómez García 2022-03-17 14:53:32 +01:00
parent 282495ce0f
commit 5836b33299
2 changed files with 11 additions and 3 deletions

View File

@ -38,6 +38,7 @@ from django.utils.translation import ugettext as _
from django.db.models import Q
from django.db import transaction
from uds.core.services.exceptions import OperationException
from uds.core.util.config import GlobalConfig
from uds.core.util.state import State
from uds.core.util import log
from uds.core.services.exceptions import (
@ -82,7 +83,11 @@ class UserServiceManager(metaclass=singleton.Singleton):
@staticmethod
def getStateFilter() -> Q:
return Q(state__in=[State.PREPARING, State.USABLE])
if GlobalConfig.MAX_SERVICES_COUNT_NEW.getBool() == False:
states = [State.PREPARING, State.USABLE]
else:
states = [State.PREPARING, State.USABLE, State.REMOVING, State.REMOVABLE]
return Q(state__in=states)
def __checkMaxDeployedReached(self, servicePool: ServicePool) -> None:
"""
@ -515,13 +520,11 @@ class UserServiceManager(metaclass=singleton.Singleton):
# Can't assign directly from L2 cache... so we check if we can create e new service in the limits requested
serviceType = servicePool.service.getType()
if serviceType.usesCache:
# inCacheL1 = ds.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L1_CACHE)).count()
inAssigned = (
servicePool.assignedUserServices()
.filter(UserServiceManager.getStateFilter())
.count()
)
# totalL1Assigned = inCacheL1 + inAssigned
if (
inAssigned >= servicePool.max_srvs
): # cacheUpdater will drop unnecesary L1 machines, so it's not neccesary to check against inCacheL1

View File

@ -414,6 +414,11 @@ class GlobalConfig:
'Notify on new publication', '0', type=Config.BOOLEAN_FIELD
)
# How "max services" is computed
MAX_SERVICES_COUNT_NEW: Config.Value = Config.section(GLOBAL_SECTION).value(
'New Max restriction', '0', type=Config.BOOLEAN_FIELD
)
# Allowed "trusted sources" for request
TRUSTED_SOURCES: Config.Value = Config.section(SECURITY_SECTION).value(
'Trusted Hosts', '*', type=Config.TEXT_FIELD