mirror of
https://github.com/dkmstr/openuds.git
synced 2025-03-12 04:58:34 +03:00
updating max.... names to better ones
This commit is contained in:
parent
7cdc11219c
commit
d2c466c542
@ -195,7 +195,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
"""
|
||||
Creates a new assigned deployed service for the current publication (if any) of service pool and user indicated
|
||||
"""
|
||||
# First, honor max_preparing_services
|
||||
# First, honor concurrent_creation_limit
|
||||
if self.can_grow_service_pool(service_pool) is False:
|
||||
# Cannot create new
|
||||
operationsLogger.info(
|
||||
@ -539,7 +539,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
service_instance = service_pool.service.get_instance()
|
||||
if (
|
||||
service_instance.is_avaliable()
|
||||
and removing >= service_instance.parent().get_max_removing_services()
|
||||
and removing >= service_instance.parent().get_concurrent_removal_limit()
|
||||
and service_instance.parent().get_ignore_limits() is False
|
||||
):
|
||||
return False
|
||||
@ -554,7 +554,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
)
|
||||
serviceInstance = service_pool.service.get_instance()
|
||||
if self.maximum_user_services_reached(service_pool.service) or (
|
||||
preparingForProvider >= serviceInstance.parent().get_max_preparing_services()
|
||||
preparingForProvider >= serviceInstance.parent().get_concurrent_creation_limit()
|
||||
and serviceInstance.parent().get_ignore_limits() is False
|
||||
):
|
||||
return False
|
||||
|
@ -43,6 +43,7 @@ class Serializable:
|
||||
- Initialize the object with default values
|
||||
- Read values from seralized data
|
||||
"""
|
||||
|
||||
_flag_for_remarshal: bool
|
||||
|
||||
# Note:
|
||||
@ -68,7 +69,7 @@ class Serializable:
|
||||
# This is an struct, and will be pickled by default
|
||||
|
||||
if hasattr(self, 'data') and hasattr(getattr(self, 'data'), '__dict__'):
|
||||
return pickle.dumps(getattr(self, 'data'), protocol=pickle.HIGHEST_PROTOCOL) # type: ignore
|
||||
return pickle.dumps(getattr(self, 'data'), protocol=pickle.HIGHEST_PROTOCOL) # type: ignore
|
||||
|
||||
raise NotImplementedError('You must override the marshal method or provide a data member')
|
||||
|
||||
@ -113,11 +114,19 @@ class Serializable:
|
||||
def flag_for_remarshalling(self, value: bool = True) -> None:
|
||||
"""
|
||||
Flags this object for remarshalling
|
||||
|
||||
Args:
|
||||
value: True if this object needs remarshalling, False if not
|
||||
|
||||
Note:
|
||||
This is not mandatory, meaning this that even if flagged, the object
|
||||
will not be remarshalled if not appropriate (basically, it's remarshalled on
|
||||
get_instance unserialize method call)
|
||||
"""
|
||||
self._flag_for_remarshal = value
|
||||
|
||||
def needs_remarshal(self) -> bool:
|
||||
|
||||
def needs_remarshalling(self) -> bool:
|
||||
"""
|
||||
Returns true if this object needs remarshalling
|
||||
"""
|
||||
return self._flag_for_remarshal
|
||||
return self._flag_for_remarshal
|
||||
|
@ -113,13 +113,13 @@ class ServiceProvider(module.Module):
|
||||
# : Default is return the GlobalConfig value of GlobalConfig.MAX_PREPARING_SERVICES
|
||||
# : Note: this variable can be either a fixed value (integer, string) or a Gui text field (with a .value property)
|
||||
# : Note: This cannot be renamed with out a "migration", because it's used at database
|
||||
max_preparing_services: typing.Optional[typing.Union[int, gui.NumericField]] = None
|
||||
concurrent_creation_limit: typing.Optional[typing.Union[int, gui.NumericField]] = None
|
||||
|
||||
# : This defines the maximum number of concurrent services that should be in state "removing" for this provider
|
||||
# : Default is return the GlobalConfig value of GlobalConfig.MAX_REMOVING_SERVICES
|
||||
# : Note: this variable can be either a fixed value (integer, string) or a Gui text field (with a .value property)
|
||||
# : Note: This cannot be renamed with out a "migration", because it's used at database
|
||||
max_removing_services: typing.Optional[typing.Union[int, gui.NumericField]] = None
|
||||
concurrent_removal_limit: typing.Optional[typing.Union[int, gui.NumericField]] = None
|
||||
|
||||
# : This defines if the limits (max.. vars) should be taken into accout or simply ignored
|
||||
# : Default is return the GlobalConfig value of GlobalConfig.IGNORE_LIMITS
|
||||
@ -192,10 +192,10 @@ class ServiceProvider(module.Module):
|
||||
self._db_obj = Provider.objects.get(uuid=self._uuid)
|
||||
return self._db_obj
|
||||
|
||||
def get_max_preparing_services(self) -> int:
|
||||
val = self.max_preparing_services
|
||||
def get_concurrent_creation_limit(self) -> int:
|
||||
val = self.concurrent_creation_limit
|
||||
if val is None:
|
||||
val = self.max_preparing_services = consts.system.DEFAULT_MAX_PREPARING_SERVICES
|
||||
val = self.concurrent_creation_limit = consts.system.DEFAULT_MAX_PREPARING_SERVICES
|
||||
|
||||
if isinstance(val, gui.NumericField):
|
||||
ret_val = val.as_int()
|
||||
@ -203,10 +203,10 @@ class ServiceProvider(module.Module):
|
||||
ret_val = val
|
||||
return max(ret_val, 1) # Ensure that is at least 1
|
||||
|
||||
def get_max_removing_services(self) -> int:
|
||||
val = self.max_removing_services
|
||||
def get_concurrent_removal_limit(self) -> int:
|
||||
val = self.concurrent_removal_limit
|
||||
if val is None:
|
||||
val = self.max_removing_services = 15
|
||||
val = self.concurrent_removal_limit = 15
|
||||
|
||||
if isinstance(val, gui.NumericField):
|
||||
ret_val = val.as_int()
|
||||
|
@ -251,7 +251,7 @@ def lenname_field(
|
||||
|
||||
|
||||
# Max preparing services field
|
||||
def max_preparing_services_field(
|
||||
def concurrent_creation_limit_field(
|
||||
order: int = 50, tab: typing.Optional[types.ui.Tab] = None
|
||||
) -> ui.gui.NumericField:
|
||||
# Advanced tab
|
||||
@ -269,7 +269,7 @@ def max_preparing_services_field(
|
||||
)
|
||||
|
||||
|
||||
def max_removing_services_field(
|
||||
def concurrent_removal_limit_field(
|
||||
order: int = 51, tab: 'types.ui.Tab|str|None' = None
|
||||
) -> ui.gui.NumericField:
|
||||
return ui.gui.NumericField(
|
||||
|
@ -71,9 +71,7 @@ class ManagedObjectModel(UUIDModel):
|
||||
"""
|
||||
return Environment.get_environment_for_table(self._meta.verbose_name, self.id) # type: ignore # pylint: disable=no-member
|
||||
|
||||
def deserialize(
|
||||
self, obj: Module, values: typing.Optional[collections.abc.Mapping[str, str]]
|
||||
):
|
||||
def deserialize(self, obj: Module, values: typing.Optional[collections.abc.Mapping[str, str]]):
|
||||
"""
|
||||
Conditionally deserializes obj if not initialized via user interface and data holds something
|
||||
"""
|
||||
@ -81,18 +79,16 @@ class ManagedObjectModel(UUIDModel):
|
||||
# data contains something
|
||||
if not values and self.data:
|
||||
obj.deserialize(self.data)
|
||||
|
||||
if obj.needs_remarshal():
|
||||
# Re-serialize to db
|
||||
self.data = obj.serialize()
|
||||
self.save(update_fields=['data'])
|
||||
obj.flag_for_remarshalling(False)
|
||||
|
||||
if obj.needs_remarshalling():
|
||||
# Re-serialize to db
|
||||
self.data = obj.serialize()
|
||||
self.save(update_fields=['data'])
|
||||
obj.flag_for_remarshalling(False)
|
||||
|
||||
self._cached_instance = None # Ensures returns correct value on get_instance
|
||||
|
||||
def get_instance(
|
||||
self, values: typing.Optional[dict[str, str]] = None
|
||||
) -> Module:
|
||||
def get_instance(self, values: typing.Optional[dict[str, str]] = None) -> Module:
|
||||
"""
|
||||
Instantiates the object this record contains.
|
||||
|
||||
@ -125,9 +121,7 @@ class ManagedObjectModel(UUIDModel):
|
||||
Returns the type of self (as python type)
|
||||
Must be overriden!!!
|
||||
"""
|
||||
raise NotImplementedError(
|
||||
f'get_type has not been implemented for {self.__class__.__name__}'
|
||||
)
|
||||
raise NotImplementedError(f'get_type has not been implemented for {self.__class__.__name__}')
|
||||
|
||||
def is_type(self, type_: str) -> bool:
|
||||
"""
|
||||
|
@ -131,7 +131,7 @@ class OVirtProvider(
|
||||
required=True,
|
||||
)
|
||||
|
||||
max_preparing_services = gui.NumericField(
|
||||
concurrent_creation_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Creation concurrency'),
|
||||
default=10,
|
||||
@ -143,7 +143,7 @@ class OVirtProvider(
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
old_field_name='maxPreparingServices',
|
||||
)
|
||||
max_removing_services = gui.NumericField(
|
||||
concurrent_removal_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Removal concurrency'),
|
||||
default=5,
|
||||
|
@ -141,7 +141,7 @@ class OGProvider(ServiceProvider):
|
||||
tab=types.ui.Tab.PARAMETERS,
|
||||
)
|
||||
|
||||
max_preparing_services = gui.NumericField(
|
||||
concurrent_creation_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Creation concurrency'),
|
||||
default=10,
|
||||
@ -153,7 +153,7 @@ class OGProvider(ServiceProvider):
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
old_field_name='maxPreparingServices',
|
||||
)
|
||||
max_removing_services = gui.NumericField(
|
||||
concurrent_removal_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Removal concurrency'),
|
||||
default=8,
|
||||
|
@ -113,7 +113,7 @@ class OpenNebulaProvider(ServiceProvider): # pylint: disable=too-many-public-me
|
||||
required=True,
|
||||
)
|
||||
|
||||
max_preparing_services = gui.NumericField(
|
||||
concurrent_creation_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Creation concurrency'),
|
||||
default=10,
|
||||
@ -125,7 +125,7 @@ class OpenNebulaProvider(ServiceProvider): # pylint: disable=too-many-public-me
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
old_field_name='maxPreparingServices',
|
||||
)
|
||||
max_removing_services = gui.NumericField(
|
||||
concurrent_removal_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Removal concurrency'),
|
||||
default=5,
|
||||
|
@ -143,7 +143,7 @@ class OpenStackProvider(ServiceProvider):
|
||||
required=True,
|
||||
)
|
||||
|
||||
max_preparing_services = gui.NumericField(
|
||||
concurrent_creation_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Creation concurrency'),
|
||||
default=10,
|
||||
@ -155,7 +155,7 @@ class OpenStackProvider(ServiceProvider):
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
old_field_name='maxPreparingServices',
|
||||
)
|
||||
max_removing_services = gui.NumericField(
|
||||
concurrent_removal_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Removal concurrency'),
|
||||
default=5,
|
||||
|
@ -159,7 +159,7 @@ class ProviderLegacy(ServiceProvider):
|
||||
required=True,
|
||||
)
|
||||
|
||||
max_preparing_services = gui.NumericField(
|
||||
concurrent_creation_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Creation concurrency'),
|
||||
default=10,
|
||||
@ -171,7 +171,7 @@ class ProviderLegacy(ServiceProvider):
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
old_field_name='maxPreparingServices',
|
||||
)
|
||||
max_removing_services = gui.NumericField(
|
||||
concurrent_removal_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Removal concurrency'),
|
||||
default=5,
|
||||
|
@ -92,8 +92,8 @@ class ProxmoxProvider(services.ServiceProvider): # pylint: disable=too-many-pub
|
||||
required=True,
|
||||
)
|
||||
|
||||
max_preparing_services = fields.max_preparing_services_field()
|
||||
max_removing_services = fields.max_removing_services_field()
|
||||
concurrent_creation_limit = fields.concurrent_creation_limit_field()
|
||||
concurrent_removal_limit = fields.concurrent_removal_limit_field()
|
||||
timeout = fields.timeout_field()
|
||||
|
||||
start_vmid = gui.NumericField(
|
||||
|
@ -73,10 +73,10 @@ class TestProvider(services.ServiceProvider):
|
||||
icon_file = 'provider.png'
|
||||
|
||||
# Max preparing concurrent services
|
||||
max_preparing_services = 1000 # a lot, this in fact will not make anything
|
||||
concurrent_creation_limit = 1000 # a lot, this in fact will not make anything
|
||||
|
||||
# Mas removing concurrent services
|
||||
max_removing_services = 1000 # a lot, this in fact will not make anything
|
||||
concurrent_removal_limit = 1000 # a lot, this in fact will not make anything
|
||||
|
||||
# Simple data for testing pourposes
|
||||
@dataclasses.dataclass
|
||||
|
@ -122,7 +122,7 @@ class XenProvider(ServiceProvider): # pylint: disable=too-many-public-methods
|
||||
required=True,
|
||||
)
|
||||
|
||||
max_preparing_services = gui.NumericField(
|
||||
concurrent_creation_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Creation concurrency'),
|
||||
default=10,
|
||||
@ -134,7 +134,7 @@ class XenProvider(ServiceProvider): # pylint: disable=too-many-public-methods
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
old_field_name='maxPreparingServices',
|
||||
)
|
||||
max_removing_services = gui.NumericField(
|
||||
concurrent_removal_limit = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Removal concurrency'),
|
||||
default=5,
|
||||
|
@ -102,6 +102,6 @@
|
||||
</svg>
|
||||
</div>
|
||||
</uds-root>
|
||||
<script src="/uds/res/admin/runtime.js?stamp=1706063307" type="module"></script><script src="/uds/res/admin/polyfills.js?stamp=1706063307" type="module"></script><script src="/uds/res/admin/main.js?stamp=1706063307" type="module"></script></body>
|
||||
<script src="/uds/res/admin/runtime.js?stamp=1706127911" type="module"></script><script src="/uds/res/admin/polyfills.js?stamp=1706127911" type="module"></script><script src="/uds/res/admin/main.js?stamp=1706127911" type="module"></script></body>
|
||||
|
||||
</html>
|
||||
|
@ -54,8 +54,8 @@ class ServiceCacheUpdaterTest(UDSTestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
# Default values for max
|
||||
TestProvider.max_preparing_services = 1000
|
||||
TestProvider.max_removing_services = 1000
|
||||
TestProvider.concurrent_creation_limit = 1000
|
||||
TestProvider.concurrent_removal_limit = 1000
|
||||
TestServiceCache.max_user_services = 1000
|
||||
TestServiceNoCache.max_user_services = 1000
|
||||
|
||||
@ -141,7 +141,7 @@ class ServiceCacheUpdaterTest(UDSTestCase):
|
||||
)
|
||||
|
||||
def test_provider_preparing_limits(self) -> None:
|
||||
TestProvider.max_preparing_services = 10
|
||||
TestProvider.concurrent_creation_limit = 10
|
||||
self.setCache(initial=100, cache=10, max=50)
|
||||
|
||||
# Try to "overcreate" cache elements but provider limits it to 10
|
||||
@ -151,11 +151,11 @@ class ServiceCacheUpdaterTest(UDSTestCase):
|
||||
self.servicePool.userServices.all().delete()
|
||||
|
||||
# Now, set provider limit to 0. Minumum aceptable is 1, so 1 will be created
|
||||
TestProvider.max_preparing_services = 0
|
||||
TestProvider.concurrent_creation_limit = 0
|
||||
self.assertEqual(self.runCacheUpdater(self.servicePool.cache_l1_srvs + 10), 1)
|
||||
|
||||
def test_provider_removing_limits(self) -> None:
|
||||
TestProvider.max_removing_services = 10
|
||||
TestProvider.concurrent_removal_limit = 10
|
||||
self.setCache(initial=0, cache=50, max=50)
|
||||
|
||||
# Try to "overcreate" cache elements but provider limits it to 10
|
||||
@ -164,7 +164,7 @@ class ServiceCacheUpdaterTest(UDSTestCase):
|
||||
# Now set cache to a lower value
|
||||
self.setCache(cache=10)
|
||||
|
||||
# Execute updater, must remove 10 elements (max_removing_services)
|
||||
# Execute updater, must remove 10 elements (concurrent_removal_limit)
|
||||
self.assertEqual(self.runCacheUpdater(10), 40)
|
||||
|
||||
def test_service_max_deployed(self) -> None:
|
||||
|
@ -52,8 +52,8 @@ PROVIDER_FIELDS_DATA: typing.Final[dict[str, typing.Any]] = {
|
||||
'port': 8666,
|
||||
'username': 'proxmox_username',
|
||||
'password': 'proxmox_passwd',
|
||||
'max_preparing_services': 31,
|
||||
'max_removing_services': 32,
|
||||
'concurrent_creation_limit': 31,
|
||||
'concurrent_removal_limit': 32,
|
||||
'timeout': 9999,
|
||||
'start_vmid': 99999,
|
||||
'macs_range': '52:54:01:02:03:04-52:54:05:06:07:08',
|
||||
|
Loading…
x
Reference in New Issue
Block a user