Refactoring manager filenames & some fixes for python 3.7 conversion

This commit is contained in:
Adolfo Gómez García 2019-08-16 11:26:48 +02:00
parent 9a9eee9d5e
commit beb09115c2
10 changed files with 33 additions and 41 deletions

View File

@ -209,11 +209,11 @@ class Actor(Handler):
logger.debug('Setting comms url to %s', data) logger.debug('Setting comms url to %s', data)
service.setCommsUrl(data) service.setCommsUrl(data)
return Actor.result('ok') return Actor.result('ok')
elif message == 'ssoAvailable': if message == 'ssoAvailable':
logger.debug('Setting that SSO is available') logger.debug('Setting that SSO is available')
service.setProperty('sso_available', 1) service.setProperty('sso_available', 1)
return Actor.result('ok') return Actor.result('ok')
elif message == 'version': if message == 'version':
version = self._params.get('version', 'unknown') version = self._params.get('version', 'unknown')
logger.debug('Got notified version %s', version) logger.debug('Got notified version %s', version)
service.setProperty('actor_version', version) service.setProperty('actor_version', version)
@ -237,8 +237,7 @@ class Actor(Handler):
service.release() # Release for removal service.release() # Release for removal
return 'ok' return 'ok'
raise Exception('Unknown message {} for an user service without os manager'.format(message)) raise Exception('Unknown message {} for an user service without os manager'.format(message))
else: res = osmanager.process(service, message, data, options={'scramble': False})
res = osmanager.process(service, message, data, options={'scramble': False})
except Exception as e: except Exception as e:
logger.exception("Exception processing from OS Manager") logger.exception("Exception processing from OS Manager")
return Actor.result(six.text_type(e), ERR_OSMANAGER_ERROR) return Actor.result(six.text_type(e), ERR_OSMANAGER_ERROR)

View File

@ -37,10 +37,10 @@ import typing
# Imports for type checking only (not on runtime), we have later to get rid of false "redefined outer names" for pylint # Imports for type checking only (not on runtime), we have later to get rid of false "redefined outer names" for pylint
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from .crypto import CryptoManager from .crypto import CryptoManager
from .TaskManager import TaskManager from .task import TaskManager
from .downloads import DownloadsManager from .downloads import DownloadsManager
from .log import LogManager from .log import LogManager
from .StatsManager import StatsManager from .stats import StatsManager
from .UserServiceManager import UserServiceManager from .UserServiceManager import UserServiceManager
from .publication import PublicationManager from .publication import PublicationManager
@ -50,7 +50,7 @@ def cryptoManager() -> 'CryptoManager':
def taskManager() -> typing.Type['TaskManager']: def taskManager() -> typing.Type['TaskManager']:
from .TaskManager import TaskManager # pylint: disable=redefined-outer-name from .task import TaskManager # pylint: disable=redefined-outer-name
return TaskManager return TaskManager
@ -65,7 +65,7 @@ def logManager() -> 'LogManager':
def statsManager() -> 'StatsManager': def statsManager() -> 'StatsManager':
from .StatsManager import StatsManager # pylint: disable=redefined-outer-name from .stats import StatsManager # pylint: disable=redefined-outer-name
return StatsManager.manager() return StatsManager.manager()

View File

@ -131,13 +131,6 @@ class OSManager(Module):
""" """
return None return None
def maxSession(self) -> typing.Optional[int]:
"""
If os manager requests "max session duration", this methos will return a value distinct of None so actors will get informed on Connection
@return Must return None (default if not override), or a "max session duration" in seconds
"""
return None
@classmethod @classmethod
def transformsUserOrPasswordForService(cls: typing.Type['OSManager']) -> bool: def transformsUserOrPasswordForService(cls: typing.Type['OSManager']) -> bool:
""" """

View File

@ -44,7 +44,7 @@ def initialize():
import pkgutil import pkgutil
import sys import sys
from uds.core import jobs from uds.core import jobs
from uds.core.managers.TaskManager import TaskManager from uds.core.managers import taskManager
# Dinamycally import children of this package. # Dinamycally import children of this package.
pkgpath = os.path.dirname(sys.modules[__name__].__file__) pkgpath = os.path.dirname(sys.modules[__name__].__file__)
@ -59,4 +59,4 @@ def initialize():
# Limit to autoregister just workers jobs inside this module # Limit to autoregister just workers jobs inside this module
if cls.__module__[0:16] == 'uds.core.workers': if cls.__module__[0:16] == 'uds.core.workers':
logger.debug('Added worker %s to list', cls.__module__) logger.debug('Added worker %s to list', cls.__module__)
TaskManager.registerJob(cls) taskManager().registerJob(cls)

View File

@ -40,7 +40,7 @@ import time
from django.core.management.base import BaseCommand # , CommandError from django.core.management.base import BaseCommand # , CommandError
from django.conf import settings from django.conf import settings
from uds.core.managers.TaskManager import TaskManager from uds.core.managers import taskManager
from uds.core.util.Config import GlobalConfig from uds.core.util.Config import GlobalConfig
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -137,7 +137,7 @@ class Command(BaseCommand):
open(getPidFile(), 'w+').write('{}\n'.format(pid)) open(getPidFile(), 'w+').write('{}\n'.format(pid))
manager = TaskManager() manager = taskManager()()
manager.run() manager.run()
if start is False and stop is False: if start is False and stop is False:

View File

@ -8,16 +8,22 @@
""" """
@author: Adolfo Gómez, dkmaster at dkmon dot com @author: Adolfo Gómez, dkmaster at dkmon dot com
""" """
import logging
import typing
from django.utils.translation import ugettext_noop as _, ugettext_lazy from django.utils.translation import ugettext_noop as _, ugettext_lazy
from uds.core.services import types as serviceTypes from uds.core.services import types as serviceTypes
from uds.core.ui import gui from uds.core.ui import gui
from uds.core import osmanagers from uds.core import osmanagers
from uds.core.managers.UserServiceManager import UserServiceManager from uds.core.managers import userServiceManager
from uds.core.util.State import State from uds.core.util.State import State
from uds.core.util import log from uds.core.util import log
from uds.models import TicketStore from uds.models import TicketStore
import logging # Not imported in runtime, just for type checking
if typing.TYPE_CHECKING:
from uds.models import UserService
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -148,7 +154,7 @@ class WindowsOsManager(osmanagers.OSManager):
def readyReceived(self, userService, data): def readyReceived(self, userService, data):
pass pass
def process(self, userService, msg, data, options=None): def process(self, userService: 'UserService', msg, data, options=None):
""" """
We understand this messages: We understand this messages:
* msg = info, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class) (old method) * msg = info, data = None. Get information about name of machine (or domain, in derived WinDomainOsManager class) (old method)
@ -186,11 +192,11 @@ class WindowsOsManager(osmanagers.OSManager):
# We get the userService logged hostname & ip and returns this # We get the userService logged hostname & ip and returns this
ip, hostname = userService.getConnectionSource() ip, hostname = userService.getConnectionSource()
deadLine = userService.deployed_service.getDeadline() deadLine = userService.deployed_service.getDeadline()
if userService.getProperty('actor_version', '0.0.0') >= '2.0.0': if typing.cast(str, userService.getProperty('actor_version', '0.0.0')) >= '2.0.0':
ret = "{0}\t{1}\t{2}".format(ip, hostname, 0 if deadLine is None else deadLine) ret = "{0}\t{1}\t{2}".format(ip, hostname, 0 if deadLine is None else deadLine)
else: else:
ret = "{0}\t{1}".format(ip, hostname) ret = "{0}\t{1}".format(ip, hostname)
elif msg == "logoff" or msg == 'logout': elif msg in ('logoff', 'logout'):
self.loggedOut(userService, data) self.loggedOut(userService, data)
doRemove = self.isRemovableOnLogout(userService) doRemove = self.isRemovableOnLogout(userService)
elif msg == "ip": elif msg == "ip":
@ -214,7 +220,7 @@ class WindowsOsManager(osmanagers.OSManager):
userService.save(update_fields=['in_use', 'in_use_date', 'os_state', 'state', 'data']) userService.save(update_fields=['in_use', 'in_use_date', 'os_state', 'state', 'data'])
else: else:
logger.debug('Notifying ready') logger.debug('Notifying ready')
UserServiceManager.manager().notifyReadyFromOsManager(userService, '') userServiceManager().notifyReadyFromOsManager(userService, '')
logger.debug('Returning {} to {} message'.format(ret, msg)) logger.debug('Returning {} to {} message'.format(ret, msg))
if options is not None and options.get('scramble', True) is False: if options is not None and options.get('scramble', True) is False:
return ret return ret

View File

@ -34,29 +34,19 @@
# pylint: disable=maybe-no-member # pylint: disable=maybe-no-member
import types import types
import xmlrpc.client import xmlrpc.client
import logging
from uds.core.util import xml2dict from uds.core.util import xml2dict
from . import storage from . import storage
from . import template from . import template
from . import vm from . import vm
# Import submodules
from .common import *
__updated__ = '2017-03-28' # Import submodules
from .common import VmState, ImageState, sanitizeName
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
module = sys.modules[__name__]
VmState = types.ModuleType('VmState')
ImageState = types.ModuleType('ImageState')
for i in enumerate(['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', 'FAILED', 'POWEROFF', 'UNDEPLOYED']):
setattr(VmState, i[1], i[0])
for i in enumerate(['INIT', 'READY', 'USED', 'DISABLED', 'LOCKED', 'ERROR', 'CLONE', 'DELETE', 'USED_PERS', 'LOCKED_USED', 'LOCKED_USED_PERS']):
setattr(ImageState, i[1], i[0])
# Decorator # Decorator
def ensureConnected(fnc): def ensureConnected(fnc):
@ -83,7 +73,7 @@ def asList(element):
# noinspection PyShadowingNames # noinspection PyShadowingNames
class OpenNebulaClient(object): class OpenNebulaClient:
def __init__(self, username, password, endpoint): def __init__(self, username, password, endpoint):
self.username = username self.username = username
self.password = password self.password = password

View File

@ -31,7 +31,7 @@
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com .. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
""" """
import sys # import sys
import types import types
import re import re
@ -39,12 +39,16 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
module = sys.modules[__name__] # module = sys.modules[__name__]
VmState = types.ModuleType('VmState') VmState = types.ModuleType('VmState')
ImageState = types.ModuleType('ImageState')
for i in enumerate(['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', 'FAILED', 'POWEROFF', 'UNDEPLOYED', 'UNKNOWN']): for i in enumerate(['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', 'FAILED', 'POWEROFF', 'UNDEPLOYED', 'UNKNOWN']):
setattr(VmState, i[1], i[0]) setattr(VmState, i[1], i[0])
for i in enumerate(['INIT', 'READY', 'USED', 'DISABLED', 'LOCKED', 'ERROR', 'CLONE', 'DELETE', 'USED_PERS', 'LOCKED_USED', 'LOCKED_USED_PERS']):
setattr(ImageState, i[1], i[0])
def sanitizeName(name): def sanitizeName(name):
""" """