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

refactoring & fixes

This commit is contained in:
Adolfo Gómez García 2017-02-27 09:41:32 +01:00
parent 240be81f26
commit 70dc779fc4
19 changed files with 32 additions and 24 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
*_enterprise.*
.settings/
.ipynb_checkpoints
.idea/
# Debian buildings
*.debhelper*

View File

@ -1,4 +1,6 @@
import sys
reload(sys)
import six
six.reload_module(sys)
sys.setdefaultencoding('utf-8') # @UndefinedVariable

View File

@ -35,6 +35,7 @@ from __future__ import unicode_literals
from uds.core.services.BaseServiceProvider import ServiceProvider
from uds.core.util.Config import GlobalConfig
import six
import logging
__updated__ = '2016-02-26'
@ -85,7 +86,7 @@ class ClusteredServiceProvider(ServiceProvider):
maxCpuLoad = GlobalConfig.CLUSTER_MIGRATE_CPULOAD.getInt(True)
minFreeMemPercent = GlobalConfig.CLUSTER_MIGRATE_MEMORYLOAD.getInt(True)
for nodeName, nodeStats in nodesStats.iteritems():
for nodeName, nodeStats in six.iteritems(nodesStats):
if nodeStats['freeMemory'] is None or nodeStats['totalMemory'] is None or nodeStats['cpuLoad'] is None:
continue
freeMemPercent = (nodeStats['freeMemory'] * 100) / nodeStats['totalMemory']
@ -123,7 +124,7 @@ class ClusteredServiceProvider(ServiceProvider):
maxCpuLoad = GlobalConfig.CLUSTER_ELEGIBLE_CPULOAD.getInt(True)
minFreeMemPercent = GlobalConfig.CLUSTER_ELEGIBLE_MEMORYLOAD.getInt(True)
for nodeName, nodeStats in nodesStats.iteritems():
for nodeName, nodeStats in six.iteritems(nodesStats):
if nodeStats['freeMemory'] is None or nodeStats['totalMemory'] is None or nodeStats['cpuLoad'] is None:
continue
freeMemPercent = (nodeStats['freeMemory'] * 100) / nodeStats['totalMemory']
@ -144,7 +145,7 @@ class ClusteredServiceProvider(ServiceProvider):
def getClusterBestNodeForDeploy(self):
nodesStats = self.clusterStats()
nodes = [name for name in nodesStats.iterkeys()]
nodes = [name for name in six.iteritems(nodesStats)]
def getNodeStatsKey(name):
ns = nodesStats[name]

View File

@ -71,9 +71,9 @@ class FileStorage(Storage):
self.cache._cache.flush_all() # On start, ensures that cache is empty to avoid surprises
# noinspection PyArgumentList
Storage.__init__(self, *args, **kwargs)
def get_valid_name(self, name):
return name.replace('\\', os.path.sep)

View File

@ -165,9 +165,9 @@ class ClusterMigrationTask(DelayedTask):
logger.debug("uService instance class: {0}".format(ci.__class__))
state = ci.checkState()
ClusterMigrationTask.checkAndUpdateState(uService, ci, state)
except UserService.DoesNotExist, e:
except UserService.DoesNotExist as e:
logger.error('User service not found (erased from database?) {0} : {1}'.format(e.__class__, e))
except Exception, e:
except Exception as e:
# Exception caught, mark service as errored
logger.exception("Error {0}, {1} :".format(e.__class__, e))
if uService is not None:

View File

@ -225,8 +225,8 @@ class WindowsOsManager(osmanagers.OSManager):
'password': password,
'domain': domain
}
ticket = TicketStore.create(creds, validator=None, validity=300, owner=SECURE_OWNER, secure=True)
return (ticket, '')
ticket = TicketStore.create(creds, validator=None, validity=300) # , owner=SECURE_OWNER, secure=True)
return ticket, ''
else:
return osmanagers.OSManager.processUserPassword(self, service, username, password)

View File

@ -39,4 +39,7 @@ __updated__ = '2015-06-21'
class ListReport(reports.Report):
def generate(self):
raise NotImplementedError('ListReport generate invoked and not implemented')
group = _('Lists') # So we can make submenus with reports

View File

@ -68,7 +68,6 @@ class NXPassword(object):
for i in range(len(p)):
sPass += '{}:'.format(ord(p[i]) + i + 1)
print sPass
return sPass
@staticmethod

View File

@ -200,6 +200,6 @@ class NXTransport(Transport):
}.get(os['OS'])
if os is None:
return super(NXTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/direct.py'.format(os)).format(r=r)

View File

@ -236,7 +236,7 @@ class TSNXTransport(Transport):
}.get(os['OS'])
if os is None:
return super(TSNXTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/tunnel.py'.format(os)).format(
r=r,

View File

@ -145,6 +145,6 @@ class RDPTransport(BaseRDPTransport):
}.get(m.os)
if os is None:
return super(RDPTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m)

View File

@ -179,6 +179,6 @@ class TRDPTransport(BaseRDPTransport):
}.get(m.os)
if os is None:
return super(TRDPTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m)

View File

@ -83,6 +83,6 @@ class SPICETransport(BaseSpiceTransport):
}.get(os.OS)
if os is None:
return super(SPICETransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m)

View File

@ -108,6 +108,6 @@ class TSPICETransport(BaseSpiceTransport):
}.get(os.OS)
if os is None:
return super(TSPICETransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m)

View File

@ -140,6 +140,6 @@ class TX2GOTransport(BaseX2GOTransport):
}.get(m.os)
if os is None:
return super(BaseX2GOTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m)

View File

@ -38,6 +38,7 @@ from uds.core.util import tools
from .BaseX2GOTransport import BaseX2GOTransport
from . import x2gofile
import six
import logging
__updated__ = '2017-01-30'
@ -113,6 +114,6 @@ class X2GOTransport(BaseX2GOTransport):
}.get(m.os)
if os is None:
return super(X2GOTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m)

View File

@ -29,7 +29,7 @@ def updateAuthorizedKeys(user, pubKey):
sshFolder = '{}/.ssh'.format(home)
if not os.path.exists(sshFolder):
try:
os.makedirs(sshFolder, 0700)
os.makedirs(sshFolder, 0o0700)
os.chown(sshFolder, uid, -1)
except OSError as e:
if e.errno != errno.EEXIST:
@ -53,7 +53,7 @@ def updateAuthorizedKeys(user, pubKey):
# Ensure access is correct
os.chown(authorizedKeys, uid, -1)
os.chmod(authorizedKeys, 0600)
os.chmod(authorizedKeys, 0o0600)
# Done

View File

@ -33,7 +33,7 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.template import RequestContext
from django.http import HttpResponseRedirect
@ -148,4 +148,4 @@ def error(request, idError):
if code != 0:
errStr += ' (code {0:04X})'.format(code)
return render_to_response(theme.template('error.html'), {'errorString': errStr}, context_instance=RequestContext(request))
return render(request, theme.template('error.html'), {'errorString': errStr})

View File

@ -75,7 +75,7 @@ def index(request):
:param request: http request
'''
if request.session.get('ticket') == '1':
return webLogout()
return webLogout(request)
# Session data
os = request.os
@ -222,7 +222,8 @@ def index(request):
logger.debug('Groups: {}'.format(groups))
response = render(request,
response = render(
request,
theme.template('index.html'),
{
'groups': groups,