mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Merge of bug fixes done on trunk
This commit is contained in:
parent
7a3eccc5ba
commit
808dfa5aa0
@ -140,7 +140,9 @@ class RegexLdap(auths.Authenticator):
|
|||||||
res = []
|
res = []
|
||||||
for line in field.splitlines():
|
for line in field.splitlines():
|
||||||
equalPos = line.find('=')
|
equalPos = line.find('=')
|
||||||
if equalPos != -1:
|
if equalPos == -1:
|
||||||
|
line = line + '=(.*)'
|
||||||
|
equalPos = line.find('=')
|
||||||
attr, pattern = (line[:equalPos], line[equalPos+1:])
|
attr, pattern = (line[:equalPos], line[equalPos+1:])
|
||||||
attr = attr.lower()
|
attr = attr.lower()
|
||||||
# if pattern do not have groups, define one with full re
|
# if pattern do not have groups, define one with full re
|
||||||
@ -152,8 +154,9 @@ class RegexLdap(auths.Authenticator):
|
|||||||
|
|
||||||
logger.debug('Pattern: {0}'.format(pattern))
|
logger.debug('Pattern: {0}'.format(pattern))
|
||||||
|
|
||||||
for v in val:
|
for vv in val:
|
||||||
try:
|
try:
|
||||||
|
v = vv.decode('utf-8')
|
||||||
srch = re.search(pattern, v, re.IGNORECASE)
|
srch = re.search(pattern, v, re.IGNORECASE)
|
||||||
logger.debug("Found against {0}: {1} ".format(v, srch))
|
logger.debug("Found against {0}: {1} ".format(v, srch))
|
||||||
if srch is None:
|
if srch is None:
|
||||||
@ -163,8 +166,6 @@ class RegexLdap(auths.Authenticator):
|
|||||||
logger.warn('Invalid regular expression')
|
logger.warn('Invalid regular expression')
|
||||||
logger.debug(e)
|
logger.debug(e)
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
res += attributes.get(line, [])
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def valuesDict(self):
|
def valuesDict(self):
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright (c) 2012 Virtual Cable S.L.
|
# Copyright (c) 2012 Virtual Cable S.L.
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
@ -30,11 +29,13 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from uds.core.jobs.DelayedTask import DelayedTask
|
from uds.core.jobs.DelayedTask import DelayedTask
|
||||||
from uds.core.jobs.DelayedTaskRunner import DelayedTaskRunner
|
from uds.core.jobs.DelayedTaskRunner import DelayedTaskRunner
|
||||||
|
from uds.core.util.Config import GlobalConfig
|
||||||
from uds.core.services.Exceptions import PublishException
|
from uds.core.services.Exceptions import PublishException
|
||||||
from uds.models import DeployedServicePublication, getSqlDatetime, State
|
from uds.models import DeployedServicePublication, getSqlDatetime, State
|
||||||
import logging
|
import logging
|
||||||
@ -43,6 +44,26 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
PUBTAG = 'pm-'
|
PUBTAG = 'pm-'
|
||||||
|
|
||||||
|
class PublicationOldMachinesCleaner(DelayedTask):
|
||||||
|
def __init__(self, publicationId):
|
||||||
|
super(PublicationOldMachinesCleaner,self).__init__()
|
||||||
|
self._id = publicationId
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
dsp = DeployedServicePublication.objects.get(pk=self._id)
|
||||||
|
if (dsp.state!=State.REMOVABLE):
|
||||||
|
logger.info('Already removed')
|
||||||
|
|
||||||
|
now = getSqlDatetime()
|
||||||
|
activePub = dsp.deployed_service.activePublication()
|
||||||
|
dsp.deployed_service.userServices.filter(in_use=True).update(in_use=False, state_date=now)
|
||||||
|
dsp.deployed_service.markOldUserServicesAsRemovables(activePub)
|
||||||
|
except:
|
||||||
|
logger.info("Machine removal for {0} not executed because publication is already removed")
|
||||||
|
# Removed provider, no problem at all, no update is done
|
||||||
|
pass
|
||||||
|
|
||||||
class PublicationLauncher(DelayedTask):
|
class PublicationLauncher(DelayedTask):
|
||||||
def __init__(self, publish):
|
def __init__(self, publish):
|
||||||
super(PublicationLauncher,self).__init__()
|
super(PublicationLauncher,self).__init__()
|
||||||
@ -81,12 +102,18 @@ class PublicationFinishChecker(DelayedTask):
|
|||||||
Checks the value returned from invocation to publish or checkPublishingState, updating the dsp database object
|
Checks the value returned from invocation to publish or checkPublishingState, updating the dsp database object
|
||||||
Return True if it has to continue checking, False if finished
|
Return True if it has to continue checking, False if finished
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
prevState = dsp.state
|
prevState = dsp.state
|
||||||
checkLater = False
|
checkLater = False
|
||||||
if State.isFinished(state):
|
if State.isFinished(state):
|
||||||
# Now we mark, if it exists, the previous usable publication as "Removable"
|
# Now we mark, if it exists, the previous usable publication as "Removable"
|
||||||
if State.isPreparing(prevState):
|
if State.isPreparing(prevState):
|
||||||
dsp.deployed_service.publications.filter(state=State.USABLE).update(state=State.REMOVABLE)
|
for old in dsp.deployed_service.publications.filter(state=State.USABLE):
|
||||||
|
old.state=State.REMOVABLE
|
||||||
|
old.save()
|
||||||
|
pc = PublicationOldMachinesCleaner(old.id)
|
||||||
|
pc.register(GlobalConfig.SESSION_EXPIRE_TIME.getInt(True)*3600, 'pclean-'+str(old.id), True)
|
||||||
|
|
||||||
dsp.setState(State.USABLE)
|
dsp.setState(State.USABLE)
|
||||||
dsp.deployed_service.markOldUserServicesAsRemovables(dsp)
|
dsp.deployed_service.markOldUserServicesAsRemovables(dsp)
|
||||||
elif State.isRemoving(prevState):
|
elif State.isRemoving(prevState):
|
||||||
@ -107,6 +134,9 @@ class PublicationFinishChecker(DelayedTask):
|
|||||||
dsp.save()
|
dsp.save()
|
||||||
if checkLater:
|
if checkLater:
|
||||||
PublicationFinishChecker.checkLater(dsp, pi)
|
PublicationFinishChecker.checkLater(dsp, pi)
|
||||||
|
except:
|
||||||
|
logger.exception('At checkAndUpdate for publication')
|
||||||
|
PublicationFinishChecker.checkLater(dsp, pi)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def checkLater(dsp, pi):
|
def checkLater(dsp, pi):
|
||||||
@ -132,7 +162,6 @@ class PublicationFinishChecker(DelayedTask):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.debug('Deployed service not found (erased from database) {0} : {1}'.format(e.__class__, e))
|
logger.debug('Deployed service not found (erased from database) {0} : {1}'.format(e.__class__, e))
|
||||||
|
|
||||||
|
|
||||||
class PublicationManager(object):
|
class PublicationManager(object):
|
||||||
_manager = None
|
_manager = None
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from uds.core.managers.PublicationManager import PublicationManager
|
from uds.core.managers.PublicationManager import PublicationManager
|
||||||
from uds.core.util.Config import GlobalConfig
|
from uds.core.util.Config import GlobalConfig
|
||||||
from uds.models import DeployedServicePublication, DeployedService, getSqlDatetime
|
from uds.models import DeployedServicePublication, getSqlDatetime
|
||||||
from uds.core.services.Exceptions import PublishException
|
from uds.core.services.Exceptions import PublishException
|
||||||
from uds.core.util.State import State
|
from uds.core.util.State import State
|
||||||
from uds.core.jobs.Job import Job
|
from uds.core.jobs import Job
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ logger = logging.getLogger(__name__)
|
|||||||
class PublicationInfoItemsCleaner(Job):
|
class PublicationInfoItemsCleaner(Job):
|
||||||
frecuency = GlobalConfig.CLEANUP_CHECK.getInt() # Request run cache "info" cleaner every configured seconds. If config value is changed, it will be used at next reload
|
frecuency = GlobalConfig.CLEANUP_CHECK.getInt() # Request run cache "info" cleaner every configured seconds. If config value is changed, it will be used at next reload
|
||||||
friendly_name = 'Publications Info Cleaner'
|
friendly_name = 'Publications Info Cleaner'
|
||||||
|
now = getSqlDatetime()
|
||||||
def __init__(self, environment):
|
def __init__(self, environment):
|
||||||
super(PublicationInfoItemsCleaner,self).__init__(environment)
|
super(PublicationInfoItemsCleaner,self).__init__(environment)
|
||||||
|
|
||||||
@ -70,11 +70,3 @@ class PublicationCleaner(Job):
|
|||||||
except PublishException: # Can say that it cant be removed right now
|
except PublishException: # Can say that it cant be removed right now
|
||||||
logger.debug('Delaying removal')
|
logger.debug('Delaying removal')
|
||||||
pass
|
pass
|
||||||
# Now check too long "in use" services for all publications
|
|
||||||
now = getSqlDatetime()
|
|
||||||
removeFrom = now - timedelta(hours = GlobalConfig.SESSION_EXPIRE_TIME.getInt(True))
|
|
||||||
for dsp in removables.filter(state_date__lt=removeFrom):
|
|
||||||
activePub = dsp.deployed_service.activePublication()
|
|
||||||
dsp.deployed_service.userServices.filter(in_use=True).update(in_use=False, state_date=now)
|
|
||||||
dsp.deployed_service.markOldUserServicesAsRemovables(activePub)
|
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ class OVirtLinkedDeployment(UserDeployment):
|
|||||||
if self._vmid != '': # Powers off
|
if self._vmid != '': # Powers off
|
||||||
try:
|
try:
|
||||||
state = self.service().getMachineState(self._vmid)
|
state = self.service().getMachineState(self._vmid)
|
||||||
if state == 'up' and state == 'suspended':
|
if state in ('up', 'suspended'):
|
||||||
self.service().stopMachine(self._vmid)
|
self.service().stopMachine(self._vmid)
|
||||||
except:
|
except:
|
||||||
logger.debug('Can\t set machine state to stopped')
|
logger.debug('Can\t set machine state to stopped')
|
||||||
|
@ -32,8 +32,9 @@ Created on Jun 22, 2012
|
|||||||
|
|
||||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.utils.translation import ugettext_noop as _, ugettext
|
from django.utils.translation import ugettext_noop as _
|
||||||
from uds.core.util.State import State
|
from uds.core.util.State import State
|
||||||
from uds.core.services import ServiceProvider
|
from uds.core.services import ServiceProvider
|
||||||
from OVirtLinkedService import OVirtLinkedService
|
from OVirtLinkedService import OVirtLinkedService
|
||||||
|
@ -90,6 +90,7 @@ class OVirtPublication(Publication):
|
|||||||
try:
|
try:
|
||||||
self._templateId = self.service().makeTemplate(self._name, comments)
|
self._templateId = self.service().makeTemplate(self._name, comments)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
self._state = 'error'
|
||||||
self._reason = str(e)
|
self._reason = str(e)
|
||||||
return State.ERROR
|
return State.ERROR
|
||||||
|
|
||||||
@ -151,6 +152,7 @@ class OVirtPublication(Publication):
|
|||||||
try:
|
try:
|
||||||
self.service().removeTemplate(self._templateId)
|
self.service().removeTemplate(self._templateId)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
self._state = 'error'
|
||||||
self._reason = str(e)
|
self._reason = str(e)
|
||||||
return State.ERROR
|
return State.ERROR
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ class Client(object):
|
|||||||
'''
|
'''
|
||||||
global cached_api, cached_api_key
|
global cached_api, cached_api_key
|
||||||
aKey = self.__getKey('o-host')
|
aKey = self.__getKey('o-host')
|
||||||
if cached_api_key == aKey:
|
#if cached_api_key == aKey:
|
||||||
return cached_api
|
# return cached_api
|
||||||
|
|
||||||
if cached_api is not None:
|
if cached_api is not None:
|
||||||
try:
|
try:
|
||||||
@ -374,8 +374,8 @@ class Client(object):
|
|||||||
display = params.Display(type_=displayType)
|
display = params.Display(type_=displayType)
|
||||||
|
|
||||||
template = params.Template(name=name, vm=params.VM(id=vm.get_id(), disks=disks),
|
template = params.Template(name=name, vm=params.VM(id=vm.get_id(), disks=disks),
|
||||||
cluster=params.Cluster(id=cluster.get_id()), description=comments,
|
cluster=params.Cluster(id=cluster.get_id()), description=comments)
|
||||||
display=display)
|
#display=display)
|
||||||
|
|
||||||
return api.templates.add(template).get_id()
|
return api.templates.add(template).get_id()
|
||||||
|
|
||||||
@ -442,7 +442,7 @@ class Client(object):
|
|||||||
|
|
||||||
memoryPolicy = params.MemoryPolicy(guaranteed=guaranteedMB*1024*1024)
|
memoryPolicy = params.MemoryPolicy(guaranteed=guaranteedMB*1024*1024)
|
||||||
par = params.VM(name=name, cluster=cluster, template=template, description=comments,
|
par = params.VM(name=name, cluster=cluster, template=template, description=comments,
|
||||||
display=display, type_='desktop', memory=memoryMB*1024*1024, memory_policy=memoryPolicy)
|
type_='desktop', memory=memoryMB*1024*1024, memory_policy=memoryPolicy) # display=display,
|
||||||
|
|
||||||
return api.vms.add(par).get_id()
|
return api.vms.add(par).get_id()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user