mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-11 05:17:55 +03:00
refactorization
This commit is contained in:
parent
1d7c57eb2f
commit
78372e593a
@ -173,16 +173,16 @@ def getServicesData(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Now generic user service
|
# Now generic user service
|
||||||
for svr in availServicePools:
|
for sPool in availServicePools:
|
||||||
# Skip pools that are part of meta pools
|
# Skip pools that are part of meta pools
|
||||||
if svr.owned_by_meta:
|
if sPool.owned_by_meta:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
use = str(svr.usage(typing.cast(typing.Any, svr).usage_count)) + '%'
|
use = str(sPool.usage(typing.cast(typing.Any, sPool).usage_count)) + '%'
|
||||||
|
|
||||||
trans = []
|
trans = []
|
||||||
for t in sorted(
|
for t in sorted(
|
||||||
svr.transports.all(), key=lambda x: x.priority
|
sPool.transports.all(), key=lambda x: x.priority
|
||||||
): # In memory sort, allows reuse prefetched and not too big array
|
): # In memory sort, allows reuse prefetched and not too big array
|
||||||
try:
|
try:
|
||||||
typeTrans = t.getType()
|
typeTrans = t.getType()
|
||||||
@ -194,9 +194,9 @@ def getServicesData(
|
|||||||
and t.validForOs(osName)
|
and t.validForOs(osName)
|
||||||
):
|
):
|
||||||
if typeTrans.ownLink:
|
if typeTrans.ownLink:
|
||||||
link = reverse('TransportOwnLink', args=('F' + svr.uuid, t.uuid))
|
link = reverse('TransportOwnLink', args=('F' + sPool.uuid, t.uuid))
|
||||||
else:
|
else:
|
||||||
link = html.udsAccessLink(request, 'F' + svr.uuid, t.uuid)
|
link = html.udsAccessLink(request, 'F' + sPool.uuid, t.uuid)
|
||||||
trans.append(
|
trans.append(
|
||||||
{'id': t.uuid, 'name': t.name, 'link': link, 'priority': t.priority}
|
{'id': t.uuid, 'name': t.name, 'link': link, 'priority': t.priority}
|
||||||
)
|
)
|
||||||
@ -205,65 +205,71 @@ def getServicesData(
|
|||||||
if not trans:
|
if not trans:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if svr.image:
|
if sPool.image:
|
||||||
imageId = svr.image.uuid
|
imageId = sPool.image.uuid
|
||||||
else:
|
else:
|
||||||
imageId = 'x'
|
imageId = 'x'
|
||||||
|
|
||||||
# Locate if user service has any already assigned user service for this. Use "pre cached" number of assignations in this pool to optimize
|
# Locate if user service has any already assigned user service for this. Use "pre cached" number of assignations in this pool to optimize
|
||||||
in_use = typing.cast(typing.Any, svr).number_in_use > 0
|
in_use = typing.cast(typing.Any, sPool).number_in_use > 0
|
||||||
# if svr.number_in_use: # Anotated value got from getDeployedServicesForGroups(...). If 0, no assignation for this user
|
# if svr.number_in_use: # Anotated value got from getDeployedServicesForGroups(...). If 0, no assignation for this user
|
||||||
# ads = userServiceManager().getExistingAssignationForUser(svr, request.user)
|
# ads = userServiceManager().getExistingAssignationForUser(svr, request.user)
|
||||||
# if ads:
|
# if ads:
|
||||||
# in_use = ads.in_use
|
# in_use = ads.in_use
|
||||||
|
|
||||||
group = (
|
group = (
|
||||||
svr.servicesPoolGroup.as_dict
|
sPool.servicesPoolGroup.as_dict
|
||||||
if svr.servicesPoolGroup
|
if sPool.servicesPoolGroup
|
||||||
else ServicePoolGroup.default().as_dict
|
else ServicePoolGroup.default().as_dict
|
||||||
)
|
)
|
||||||
|
|
||||||
# Only add toBeReplaced info in case we allow it. This will generate some "overload" on the services
|
# Only add toBeReplaced info in case we allow it. This will generate some "overload" on the services
|
||||||
toBeReplaced = (
|
toBeReplaced = (
|
||||||
svr.toBeReplaced(request.user)
|
sPool.toBeReplaced(request.user)
|
||||||
if typing.cast(typing.Any, svr).pubs_active > 0
|
if typing.cast(typing.Any, sPool).pubs_active > 0
|
||||||
and GlobalConfig.NOTIFY_REMOVAL_BY_PUB.getBool(False)
|
and GlobalConfig.NOTIFY_REMOVAL_BY_PUB.getBool(False)
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
# tbr = False
|
# tbr = False
|
||||||
if toBeReplaced:
|
if toBeReplaced:
|
||||||
toBeReplaced = formats.date_format(toBeReplaced, "SHORT_DATETIME_FORMAT")
|
toBeReplaced = formats.date_format(toBeReplaced, 'SHORT_DATETIME_FORMAT')
|
||||||
toBeReplacedTxt = ugettext(
|
toBeReplacedTxt = ugettext(
|
||||||
'This service is about to be replaced by a new version. Please, close the session before {} and save all your work to avoid loosing it.'
|
'This service is about to be replaced by a new version. Please, close the session before {} and save all your work to avoid loosing it.'
|
||||||
).format(toBeReplaced)
|
).format(toBeReplaced)
|
||||||
else:
|
else:
|
||||||
toBeReplacedTxt = ''
|
toBeReplacedTxt = ''
|
||||||
|
|
||||||
def datator(x):
|
# Calculate max deployed
|
||||||
return x.replace('{use}', use).replace('{total}', str(svr.max_srvs))
|
maxDeployed = str(sPool.max_srvs)
|
||||||
|
# if sPool.service.getType().usesCache is False:
|
||||||
|
# maxDeployed = sPool.service.getInstance().maxDeployed
|
||||||
|
|
||||||
|
def datator(x) -> str:
|
||||||
|
return x.replace('{use}', use).replace('{total}', maxDeployed)
|
||||||
|
|
||||||
|
|
||||||
services.append(
|
services.append(
|
||||||
{
|
{
|
||||||
'id': 'F' + svr.uuid,
|
'id': 'F' + sPool.uuid,
|
||||||
'name': datator(svr.name),
|
'name': datator(sPool.name),
|
||||||
'visual_name': datator(
|
'visual_name': datator(
|
||||||
svr.visual_name.replace('{use}', use).replace(
|
sPool.visual_name.replace('{use}', use).replace(
|
||||||
'{total}', str(svr.max_srvs)
|
'{total}', maxDeployed
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'description': svr.comments,
|
'description': sPool.comments,
|
||||||
'group': group,
|
'group': group,
|
||||||
'transports': trans,
|
'transports': trans,
|
||||||
'imageId': imageId,
|
'imageId': imageId,
|
||||||
'show_transports': svr.show_transports,
|
'show_transports': sPool.show_transports,
|
||||||
'allow_users_remove': svr.allow_users_remove,
|
'allow_users_remove': sPool.allow_users_remove,
|
||||||
'allow_users_reset': svr.allow_users_reset,
|
'allow_users_reset': sPool.allow_users_reset,
|
||||||
'maintenance': svr.isInMaintenance(),
|
'maintenance': sPool.isInMaintenance(),
|
||||||
'not_accesible': not svr.isAccessAllowed(now),
|
'not_accesible': not sPool.isAccessAllowed(now),
|
||||||
'in_use': in_use,
|
'in_use': in_use,
|
||||||
'to_be_replaced': toBeReplaced,
|
'to_be_replaced': toBeReplaced,
|
||||||
'to_be_replaced_text': toBeReplacedTxt,
|
'to_be_replaced_text': toBeReplacedTxt,
|
||||||
'custom_calendar_text': svr.calendar_message,
|
'custom_calendar_text': sPool.calendar_message,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user