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

* Added comm url as property

* Moved values from storage() to properties table
* Added support for idle times to Windows & Linux OS Managers
* Fixed configurations objects, so if get() is invoked before DB is
accesible, returns default value and, later, will be executed "in fact"
This commit is contained in:
Adolfo Gómez García 2014-12-02 19:39:26 +01:00
parent d77a56f953
commit 8cf6815e8e
9 changed files with 45 additions and 46 deletions

View File

@ -141,6 +141,7 @@ class Actor(Handler):
maxIdle = None
if service.deployed_service.osmanager is not None:
maxIdle = service.deployed_service.osmanager.getInstance().maxIdle()
logger.debug('Max idle: {}'.format(maxIdle))
return Actor.result((service.uuid, service.unique_id, 0 if maxIdle is None else maxIdle))
raise RequestError('Invalid request')
@ -169,8 +170,7 @@ class Actor(Handler):
username = ''
if message == 'notifyComms':
service.comms_url = data
service.save()
service.setProperty('comms_url', data)
return Actor.result('ok')
# Preprocess some messages, common to all clients, such as "log"

View File

@ -33,6 +33,7 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext, ugettext_lazy as _
from django.conf import settings
from uds.models import OSManager
from uds.REST import NotFound, RequestError
@ -77,7 +78,7 @@ class OsManagers(ModelHandler):
raise RequestError(ugettext('Can\'t delete an OSManager with deployed services associated'))
def checkSave(self, item):
if item.deployedServices.count() > 0:
if item.deployedServices.count() > 0 and settings.DEBUG is False:
raise RequestError(ugettext('Can\'t modify an OSManager with deployed services associated'))
# Types related

View File

@ -45,6 +45,7 @@ CLUSTER_SECTION = 'Cluster'
# For save when initialized
saveLater = []
getLater = []
class Config(object):
@ -74,9 +75,13 @@ class Config(object):
def get(self, force=False):
# Ensures DB contains configuration values
# From Django 1.7, DB can only be accessed AFTER all apps are initialized, curious at least.. :)
if apps.ready is True and GlobalConfig.initDone is False:
logger.debug('Initializing configuration & updating db values')
GlobalConfig.initialize()
if apps.ready is True:
if GlobalConfig.initDone is False:
logger.debug('Initializing configuration & updating db values')
GlobalConfig.initialize()
else:
getLater.append(self)
return self._default
try:
if force or self._data is None:
@ -108,7 +113,7 @@ class Config(object):
logger.error('Value for {0}.{1} is invalid (integer expected)'.format(self._section, self._key))
try:
return int(self._default)
except:
except Exception:
logger.error('Default value for {0}.{1} is also invalid (integer expected)'.format(self._section, self._key))
return -1
@ -303,6 +308,12 @@ class GlobalConfig(object):
if type(v) is Config._Value:
v.get()
for c in getLater:
logger.debug('Get later: {}'.format(c))
c.get()
getLater[:] = []
for c, v in saveLater:
logger.debug('Saving delayed value: {}'.format(c))
c.set(v)

View File

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('uds', '0004_auto_20140916_1217'),
]
operations = [
migrations.AddField(
model_name='userservice',
name='comms_url',
field=models.CharField(default=None, max_length=256, null=True, blank=True),
preserve_default=True,
),
]

View File

@ -10,7 +10,6 @@ def add_parent_uuids(apps, schema_editor):
'''
model = apps.get_model("uds", 'User')
for m in model.objects.all():
print m
parent = int(m.parent)
if parent != -1:
try:
@ -44,7 +43,7 @@ def remove_parent_uuids(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
('uds', '0005_userservice_comms_url'),
('uds', '0004_auto_20140916_1217'),
]
operations = [

View File

@ -35,7 +35,7 @@
from __future__ import unicode_literals
__updated__ = '2014-11-24'
__updated__ = '2014-12-02'
from django.db import models
from django.db.models import signals
@ -92,7 +92,7 @@ class UserService(UUIDModel):
# "Secret" url used to communicate (send message) to services
# if This is None, communication is not possible
# The communication is done using POST via REST & Json
comms_url = models.CharField(max_length=256, default=None, null=True, blank=True)
# comms_url = models.CharField(max_length=256, default=None, null=True, blank=True)
# objects = LockingManager() This model is on an innoDb table, so we do not need the locking manager anymore
@ -199,7 +199,8 @@ class UserService(UUIDModel):
name: Name of the value to store
value: Value of the value to store
'''
self.getEnvironment().storage().put(name, value)
# Store value as a property
self.setProperty(name, value)
def recoverValue(self, name):
'''
@ -211,7 +212,13 @@ class UserService(UUIDModel):
Returns:
Stored value, None if no value was stored
'''
return self.getEnvironment().storage().get(name)
val = self.getProperty(name)
# To transition between old stor at storage table and new properties table
# If value is found on property, use it, else, try to recover it from storage
if val is None:
val = self.getEnvironment().storage().get(name)
return val
def setConnectionSource(self, ip, hostname=''):
'''
@ -403,13 +410,10 @@ class UserService(UUIDModel):
res.append({'id': us.id, 'name': usi.getName(), 'transports': us.deployed_service.transports, 'service': us})
return res
def __str__(self):
return "User service {0}, cache_level {1}, user {2}, name {3}, state {4}:{5}".format(self.id, self.cache_level, self.user, self.friendly_name,
State.toString(self.state), State.toString(self.os_state))
def getProperty(self, propName, default=None):
try:
return self.properties.get(name=propName).value
val = self.properties.get(name=propName).value
return val if val is not '' else default # Empty string is null
except Exception:
return default
@ -418,6 +422,10 @@ class UserService(UUIDModel):
prop.value = propValue
prop.save()
def __str__(self):
return "User service {0}, cache_level {1}, user {2}, name {3}, state {4}:{5}".format(self.id, self.cache_level, self.user, self.friendly_name,
State.toString(self.state), State.toString(self.os_state))
@staticmethod
def beforeDelete(sender, **kwargs):
'''

View File

@ -63,7 +63,7 @@ class LinuxOsManager(osmanagers.OSManager):
defvalue='keep')
idle = gui.NumericField(label=_("Max.Idle time"), length=4, defvalue=-1, rdonly=False, order=11,
tooltip=_('Maximum idle time (in seconds) before session is automaticatlly closed to the user (<= 0 means no max idle time). Note that this value only applies to "removable" services'), required=True)
tooltip=_('Maximum idle time (in seconds) before session is automaticatlly closed to the user (<= 0 means no max idle time).'), required=True)
def __setProcessUnusedMachines(self):
self.processUnusedMachines = self._onLogout == 'remove'
@ -188,7 +188,7 @@ class LinuxOsManager(osmanagers.OSManager):
return State.RUNNING
def maxIdle(self):
if self._onLogout == 'remove' or self._idle <= 0:
if self._idle <= 0:
return None
return self._idle

View File

@ -56,7 +56,7 @@ class WindowsOsManager(osmanagers.OSManager):
)
idle = gui.NumericField(label=_("Max.Idle time"), length=4, defvalue=-1, rdonly=False, order=11,
tooltip=_('Maximum idle time (in seconds) before session is automaticatlly closed to the user (<= 0 means no max idle time). Note that this value only applies to "removable" services'), required=True)
tooltip=_('Maximum idle time (in seconds) before session is automaticatlly closed to the user (<= 0 means no max idle time).'), required=True)
@staticmethod
def validateLen(length):
@ -112,7 +112,7 @@ class WindowsOsManager(osmanagers.OSManager):
msg, level = data.split('\t')
log.doLog(service, int(level), msg, origin)
except:
except Exception:
log.doLog(service, log.ERROR, "do not understand {0}".format(data), origin)
def process(self, service, msg, data):
@ -195,7 +195,7 @@ class WindowsOsManager(osmanagers.OSManager):
return State.RUNNING
def maxIdle(self):
if self._onLogout == 'remove' or self._idle <= 0:
if self._idle <= 0:
return None
return self._idle

View File

@ -12,9 +12,9 @@
from django.utils.translation import ugettext_noop as _
from uds.core.osmanagers.OSManagersFactory import OSManagersFactory
from uds.core.managers.DownloadsManager import DownloadsManager
from WindowsOsManager import WindowsOsManager
from WinDomainOsManager import WinDomainOsManager
from WinRandomPassOsManager import WinRandomPassManager
from .WindowsOsManager import WindowsOsManager
from .WinDomainOsManager import WinDomainOsManager
from .WinRandomPassOsManager import WinRandomPassManager
import os.path
import sys