1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-11 05:17:55 +03:00

* Increased field size for service pools name, shot name

* Added replacement for "macros" so it does not count as too long text fields
* Added support for random access list on MultiIp Phisical Machines
This commit is contained in:
Adolfo Gómez García 2023-10-23 16:33:45 +02:00
parent 30efde68fe
commit b072d1d95b
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
7 changed files with 83 additions and 29 deletions

View File

@ -148,9 +148,18 @@ class MetaPools(ModelHandler):
# Gui related
def getGui(self, type_: str) -> typing.List[typing.Any]:
localGUI = self.addDefaultFields([], ['name', 'short_name', 'comments', 'tags'])
localGUI = self.addDefaultFields([], ['name', 'comments', 'tags'])
for field in [
{
'name': 'short_name',
'type': 'text',
'label': _('Short name'),
'tooltip': _('Short name for user service visualization'),
'required': False,
'length': 32,
'order': 0 - 95,
},
{
'name': 'policy',
'choices': [

View File

@ -278,9 +278,18 @@ class ServicesPools(ModelHandler):
if Service.objects.count() < 1:
raise ResponseError(gettext('Create at least a service before creating a new service pool'))
g = self.addDefaultFields([], ['name', 'short_name', 'comments', 'tags'])
g = self.addDefaultFields([], ['name', 'comments', 'tags'])
for f in [
{
'name': 'short_name',
'type': 'text',
'label': _('Short name'),
'tooltip': _('Short name for user service visualization'),
'required': False,
'length': 64,
'order': 0 - 95,
},
{
'name': 'service_id',
'choices': [gui.choiceItem('', '')]
@ -457,6 +466,18 @@ class ServicesPools(ModelHandler):
# pylint: disable=too-many-statements
def beforeSave(self, fields: typing.Dict[str, typing.Any]) -> None:
# logger.debug(self._params)
def macro_fld_len(x) -> int:
w = x
for i in ('{use}', '{total}', '{usec}', '{left}'):
w = w.replace(i, 'xx')
return len(w)
if macro_fld_len(fields['name']) > 128:
raise RequestError(gettext('Name too long'))
if macro_fld_len(fields['short_name']) > 32:
raise RequestError(gettext('Short name too long'))
try:
try:
service = Service.objects.get(uuid=processUuid(fields['service_id']))

View File

@ -177,19 +177,6 @@ class BaseModelHandler(Handler):
'order': 0 - 100,
},
)
if 'short_name' in flds:
self.addField(
gui,
{
'name': 'short_name',
'type': 'text',
'label': _('Short name'),
'tooltip': _('Short name for user service visualization'),
'required': False,
'length': 32,
'order': 0 - 95,
},
)
if 'comments' in flds:
self.addField(
gui,

View File

@ -300,5 +300,24 @@ class Migration(migrations.Migration):
model_name="ticketstore",
name="validator",
),
migrations.AlterField(
model_name="servicepool",
name="name",
field=models.CharField(default="", max_length=192),
),
migrations.AlterField(
model_name="servicepool",
name="short_name",
field=models.CharField(default="", max_length=96),
),
migrations.AlterField(
model_name="metapool",
name="name",
field=models.CharField(default="", max_length=192),
),
migrations.AlterField(
model_name="metapool",
name="short_name",
field=models.CharField(default="", max_length=96),
),
]

View File

@ -64,8 +64,8 @@ class MetaPool(UUIDModel, TaggingMixin): # type: ignore
A meta pool is a pool that has pool members
"""
name = models.CharField(max_length=128, default='')
short_name = models.CharField(max_length=32, default='')
name = models.CharField(max_length=192, default='') # Give enouth space for "macros"
short_name = models.CharField(max_length=96, default='') # Give enouth space for "macros"
comments = models.CharField(max_length=256, default='')
visible = models.BooleanField(default=True)
image = models.ForeignKey(

View File

@ -78,8 +78,8 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
A deployed service is the Service produced element that is assigned finally to an user (i.e. a Virtual Machine, etc..)
"""
name = models.CharField(max_length=128, default='')
short_name = models.CharField(max_length=32, default='')
name = models.CharField(max_length=192, default='') # Give enouth space for "macros"
short_name = models.CharField(max_length=96, default='') # Give enouth space for "macros"
comments = models.CharField(max_length=256, default='')
service = models.ForeignKey(
Service,

View File

@ -31,12 +31,12 @@
Author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import logging
import pickle # nosec # Pickle use is controled by app, never by non admin user input
import pickle
import random # nosec # Pickle use is controled by app, never by non admin user input
import typing
from django.db import transaction
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext, gettext_lazy as _
from uds.core import exceptions, services, types
from uds.core.ui import gui
@ -112,6 +112,13 @@ class IPMachinesService(IPServiceBase):
order=4,
tab=types.ui.Tab.ADVANCED,
)
useRandomIp = gui.CheckBoxField(
label=_('Use random IP'),
tooltip=_('If checked, UDS will use a random IP from the list of servers.'),
default=False,
order=5,
tab=types.ui.Tab.ADVANCED,
)
# Description of service
typeName = _('Static Multiple IP')
@ -135,6 +142,7 @@ class IPMachinesService(IPServiceBase):
_skipTimeOnFailure: int = 0
_maxSessionForMachine: int = 0
_lockByExternalAccess: bool = False
_useRandomIp: bool = False
def initialize(self, values: 'Module.ValuesType') -> None:
if values is None:
@ -168,6 +176,7 @@ class IPMachinesService(IPServiceBase):
self._skipTimeOnFailure = self.skipTimeOnFailure.num()
self._maxSessionForMachine = self.maxSessionForMachine.num()
self._lockByExternalAccess = self.lockByExternalAccess.isTrue()
self._useRandomIp = self.useRandomIp.isTrue()
def getToken(self):
return self._token or None
@ -181,18 +190,20 @@ class IPMachinesService(IPServiceBase):
'skipTimeOnFailure': str(self._skipTimeOnFailure),
'maxSessionForMachine': str(self._maxSessionForMachine),
'lockByExternalAccess': gui.fromBool(self._lockByExternalAccess),
'useRandomIp': gui.fromBool(self._useRandomIp),
}
def marshal(self) -> bytes:
self.storage.saveData('ips', pickle.dumps(self._ips))
return b'\0'.join(
[
b'v6',
b'v7',
self._token.encode(),
str(self._port).encode(),
str(self._skipTimeOnFailure).encode(),
str(self._maxSessionForMachine).encode(),
gui.fromBool(self._lockByExternalAccess).encode(),
gui.fromBool(self._useRandomIp).encode(),
]
)
@ -208,14 +219,16 @@ class IPMachinesService(IPServiceBase):
self._ips = []
if values[0] != b'v1':
self._token = values[1].decode()
if values[0] in (b'v3', b'v4', b'v5', b'v6'):
if values[0] in (b'v3', b'v4', b'v5', b'v6', b'v7'):
self._port = int(values[2].decode())
if values[0] in (b'v4', b'v5', b'v6'):
if values[0] in (b'v4', b'v5', b'v6', b'v7'):
self._skipTimeOnFailure = int(values[3].decode())
if values[0] in (b'v5', b'v6'):
if values[0] in (b'v5', b'v6', b'v7'):
self._maxSessionForMachine = int(values[4].decode())
if values[0] in (b'v6',):
if values[0] in (b'v6', b'v7'):
self._lockByExternalAccess = gui.toBool(values[5].decode())
if values[0] in (b'v7',):
self._useRandomIp = gui.toBool(values[6].decode())
# Sets maximum services for this
self.maxUserServices = len(self._ips)
@ -243,7 +256,12 @@ class IPMachinesService(IPServiceBase):
try:
now = getSqlStampInSeconds()
for ip in self._ips:
# Reorder ips, so we do not always get the same one if requested
allIps = self._ips[:]
if self._useRandomIp:
random.shuffle(allIps)
for ip in allIps:
theIP = IPServiceBase.getIp(ip)
theMAC = IPServiceBase.getMac(ip)
locked = self.storage.getPickle(theIP)