diff --git a/server/.pydevproject b/server/.pydevproject index a7659a86..0f9f9433 100644 --- a/server/.pydevproject +++ b/server/.pydevproject @@ -8,4 +8,7 @@ DJANGO_SETTINGS_MODULE server.settings + + /${PROJECT_DIR_NAME}/src + diff --git a/server/src/uds/core/osmanagers/BaseOsManager.py b/server/src/uds/core/osmanagers/BaseOsManager.py index feee7bf8..6e248bbb 100644 --- a/server/src/uds/core/osmanagers/BaseOsManager.py +++ b/server/src/uds/core/osmanagers/BaseOsManager.py @@ -180,7 +180,7 @@ class OSManager(Module): def toReady(self, userService): userService.setProperty('loginsCounter', '0') - def loggedIn(self, userService, userName=None, save=True): + def loggedIn(self, userService, userName=None): """ This method: - Add log in event to stats @@ -215,7 +215,7 @@ class OSManager(Module): userService.setProperty('loginsCounter', six.text_type(counter)) - def loggedOut(self, userService, userName=None, save=True): + def loggedOut(self, userService, userName=None): """ This method: - Add log in event to stats diff --git a/server/src/uds/models/UserService.py b/server/src/uds/models/UserService.py index a857cf07..b62b27c4 100644 --- a/server/src/uds/models/UserService.py +++ b/server/src/uds/models/UserService.py @@ -37,7 +37,6 @@ from __future__ import unicode_literals from django.db import models from django.db.models import signals -from django.utils.encoding import python_2_unicode_compatible from uds.core.Environment import Environment from uds.core.util import log @@ -53,8 +52,6 @@ from uds.models.User import User from uds.models.Util import NEVER from uds.models.Util import getSqlDatetime -from uds.core.services import UserDeployment - import logging __updated__ = '2019-02-06' @@ -166,7 +163,7 @@ class UserService(UUIDModel): try: # We may have deleted publication... if self.publication is not None: publicationInstance = self.publication.getInstance() - except Exception as e: + except Exception: # The publication to witch this item points to, does not exists self.publication = None logger.exception("Got exception at getInstance of an userService {}".format(self)) @@ -255,7 +252,7 @@ class UserService(UUIDModel): """ self.src_ip = ip self.src_hostname = hostname - self.save() + self.save(update_fields=['src_ip', 'src_hostname']) def getConnectionSource(self): """ @@ -324,8 +321,6 @@ class UserService(UUIDModel): self.state = state self.save(update_fields=['state', 'state_date']) - self.save(update_fields=['state', 'state_date']) - def setOsState(self, state): """ Updates the os state (state of the os) of this object and, optionally, saves it @@ -339,6 +334,7 @@ class UserService(UUIDModel): if state != self.os_state: self.state_date = getSqlDatetime() self.os_state = state + self.save(update_fields=['os_state', 'state_date']) def assignToUser(self, user): """ @@ -422,7 +418,6 @@ class UserService(UUIDModel): Mark this user deployed service for removal """ self.setState(State.REMOVABLE) - self.save(update_fields=['state', 'state_date']) def release(self): """ diff --git a/server/src/uds/osmanagers/LinuxOsManager/LinuxOsManager.py b/server/src/uds/osmanagers/LinuxOsManager/LinuxOsManager.py index d48d2606..5b2ac726 100644 --- a/server/src/uds/osmanagers/LinuxOsManager/LinuxOsManager.py +++ b/server/src/uds/osmanagers/LinuxOsManager/LinuxOsManager.py @@ -173,12 +173,12 @@ class LinuxOsManager(osmanagers.OSManager): elif msg == "log": self.doLog(userService, data, log.ACTOR) elif msg == "login": - self.loggedIn(userService, data, False) + self.loggedIn(userService, data) ip, hostname = userService.getConnectionSource() deadLine = userService.deployed_service.getDeadline() ret = "{0}\t{1}\t{2}".format(ip, hostname, 0 if deadLine is None else deadLine) elif msg == "logout": - self.loggedOut(userService, data, False) + self.loggedOut(userService, data) doRemove = self.isRemovableOnLogout(userService) elif msg == "ip": # This ocurss on main loop inside machine, so userService is usable @@ -196,9 +196,7 @@ class LinuxOsManager(osmanagers.OSManager): if doRemove is True: userService.release() else: - if notifyReady is False: - userService.save() - else: + if notifyReady: UserServiceManager.manager().notifyReadyFromOsManager(userService, '') logger.debug('Returning {0}'.format(ret)) return ret diff --git a/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py b/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py index 2f8085b5..f1dffbba 100644 --- a/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py +++ b/server/src/uds/osmanagers/WindowsOsManager/WindowsOsManager.py @@ -8,10 +8,7 @@ """ @author: Adolfo Gómez, dkmaster at dkmon dot com """ -from __future__ import unicode_literals - from django.utils.translation import ugettext_noop as _, ugettext_lazy -from django.conf import settings from uds.core.services import types as serviceTypes from uds.core.ui.UserInterface import gui from uds.core import osmanagers @@ -19,9 +16,6 @@ from uds.core.managers.UserServiceManager import UserServiceManager from uds.core.util.State import State from uds.core.util import log from uds.models import TicketStore -from uds.REST.methods.actor import SECURE_OWNER - -import six import logging @@ -32,14 +26,14 @@ def scrambleMsg(data): """ Simple scrambler so password are not seen at source page """ - if isinstance(data, six.text_type): + if isinstance(data, str): data = data.encode('utf8') res = [] n = 0x32 for c in data[::-1]: res.append(chr(ord(c) ^ n)) n = (n + ord(c)) & 0xFF - return six.text_type(b''.join(res).encode('hex')) + return (b''.join(res).encode('hex')).decode('utf8') class WindowsOsManager(osmanagers.OSManager): @@ -187,7 +181,7 @@ class WindowsOsManager(osmanagers.OSManager): self.doLog(userService, data, log.ACTOR) elif msg == "logon" or msg == 'login': if '\\' not in data: - self.loggedIn(userService, data, False) + self.loggedIn(userService, data) userService.setInUse(True) # We get the userService logged hostname & ip and returns this ip, hostname = userService.getConnectionSource() @@ -197,7 +191,7 @@ class WindowsOsManager(osmanagers.OSManager): else: ret = "{0}\t{1}".format(ip, hostname) elif msg == "logoff" or msg == 'logout': - self.loggedOut(userService, data, False) + self.loggedOut(userService, data) doRemove = self.isRemovableOnLogout(userService) elif msg == "ip": # This ocurss on main loop inside machine, so userService is usable @@ -273,7 +267,7 @@ class WindowsOsManager(osmanagers.OSManager): """ Serializes the os manager data so we can store it in database """ - return '\t'.join(['v2', self._onLogout, six.text_type(self._idle)]).encode('utf8') + return '\t'.join(['v2', self._onLogout, str(self._idle)]).encode('utf8') def unmarshal(self, s): data = s.decode('utf8').split('\t') diff --git a/server/src/uds/services/OVirt/OVirtLinkedDeployment.py b/server/src/uds/services/OVirt/OVirtLinkedDeployment.py index 89d5e940..2c87a145 100644 --- a/server/src/uds/services/OVirt/OVirtLinkedDeployment.py +++ b/server/src/uds/services/OVirt/OVirtLinkedDeployment.py @@ -537,25 +537,6 @@ class OVirtLinkedDeployment(UserDeployment): return self.__executeQueue() - def userLoggedIn(self, user): - """ - This method must be available so os managers can invoke it whenever - an user get logged into a service. - - The user provided is just an string, that is provided by actor. - """ - # We store the value at storage, but never get used, just an example - pass - - def userLoggedOut(self, user): - """ - This method must be available so os managers can invoke it whenever - an user get logged out if a service. - - The user provided is just an string, that is provided by actor. - """ - pass - def reasonOfError(self): """ Returns the reason of the error. diff --git a/server/src/uds/services/OpenNebula/LiveDeployment.py b/server/src/uds/services/OpenNebula/LiveDeployment.py index 2fc113b6..779c712c 100644 --- a/server/src/uds/services/OpenNebula/LiveDeployment.py +++ b/server/src/uds/services/OpenNebula/LiveDeployment.py @@ -473,25 +473,6 @@ class LiveDeployment(UserDeployment): return self.__executeQueue() - def userLoggedIn(self, user): - """ - This method must be available so os managers can invoke it whenever - an user get logged into a service. - - The user provided is just an string, that is provided by actor. - """ - # We store the value at storage, but never get used, just an example - pass - - def userLoggedOut(self, user): - """ - This method must be available so os managers can invoke it whenever - an user get logged out if a service. - - The user provided is just an string, that is provided by actor. - """ - pass - def reasonOfError(self): """ Returns the reason of the error. diff --git a/server/src/uds/services/Xen/XenLinkedDeployment.py b/server/src/uds/services/Xen/XenLinkedDeployment.py index 45089786..0323dc77 100644 --- a/server/src/uds/services/Xen/XenLinkedDeployment.py +++ b/server/src/uds/services/Xen/XenLinkedDeployment.py @@ -529,25 +529,6 @@ class XenLinkedDeployment(UserDeployment): return self.__executeQueue() - def userLoggedIn(self, user): - """ - This method must be available so os managers can invoke it whenever - an user get logged into a service. - - The user provided is just an string, that is provided by actor. - """ - # We store the value at storage, but never get used, just an example - pass - - def userLoggedOut(self, user): - """ - This method must be available so os managers can invoke it whenever - an user get logged out if a service. - - The user provided is just an string, that is provided by actor. - """ - pass - def reasonOfError(self): """ Returns the reason of the error.