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
@ -139,32 +139,33 @@ class RegexLdap(auths.Authenticator):
|
|||||||
def __processField(self, field, attributes):
|
def __processField(self, field, attributes):
|
||||||
res = []
|
res = []
|
||||||
for line in field.splitlines():
|
for line in field.splitlines():
|
||||||
equalPos = line.find('=')
|
equalPos = line.find('=')
|
||||||
if equalPos != -1:
|
if equalPos == -1:
|
||||||
attr, pattern = (line[:equalPos], line[equalPos+1:])
|
line = line + '=(.*)'
|
||||||
attr = attr.lower()
|
equalPos = line.find('=')
|
||||||
# if pattern do not have groups, define one with full re
|
attr, pattern = (line[:equalPos], line[equalPos+1:])
|
||||||
if pattern.find('(') == -1:
|
attr = attr.lower()
|
||||||
pattern = '(' + pattern + ')'
|
# if pattern do not have groups, define one with full re
|
||||||
val = attributes.get(attr, [])
|
if pattern.find('(') == -1:
|
||||||
if type(val) is not list: # May we have a single value
|
pattern = '(' + pattern + ')'
|
||||||
val = [val]
|
val = attributes.get(attr, [])
|
||||||
|
if type(val) is not list: # May we have a single value
|
||||||
logger.debug('Pattern: {0}'.format(pattern))
|
val = [val]
|
||||||
|
|
||||||
for v in val:
|
logger.debug('Pattern: {0}'.format(pattern))
|
||||||
try:
|
|
||||||
srch = re.search(pattern, v, re.IGNORECASE)
|
for vv in val:
|
||||||
logger.debug("Found against {0}: {1} ".format(v, srch))
|
try:
|
||||||
if srch is None:
|
v = vv.decode('utf-8')
|
||||||
continue
|
srch = re.search(pattern, v, re.IGNORECASE)
|
||||||
res.append(''.join(srch.groups()))
|
logger.debug("Found against {0}: {1} ".format(v, srch))
|
||||||
except Exception as e:
|
if srch is None:
|
||||||
logger.warn('Invalid regular expression')
|
continue
|
||||||
logger.debug(e)
|
res.append(''.join(srch.groups()))
|
||||||
break
|
except Exception as e:
|
||||||
else:
|
logger.warn('Invalid regular expression')
|
||||||
res += attributes.get(line, [])
|
logger.debug(e)
|
||||||
|
break
|
||||||
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,31 +102,40 @@ 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
|
||||||
'''
|
'''
|
||||||
prevState = dsp.state
|
try:
|
||||||
checkLater = False
|
prevState = dsp.state
|
||||||
if State.isFinished(state):
|
checkLater = False
|
||||||
# Now we mark, if it exists, the previous usable publication as "Removable"
|
if State.isFinished(state):
|
||||||
if State.isPreparing(prevState):
|
# Now we mark, if it exists, the previous usable publication as "Removable"
|
||||||
dsp.deployed_service.publications.filter(state=State.USABLE).update(state=State.REMOVABLE)
|
if State.isPreparing(prevState):
|
||||||
dsp.setState(State.USABLE)
|
for old in dsp.deployed_service.publications.filter(state=State.USABLE):
|
||||||
dsp.deployed_service.markOldUserServicesAsRemovables(dsp)
|
old.state=State.REMOVABLE
|
||||||
elif State.isRemoving(prevState):
|
old.save()
|
||||||
dsp.setState(State.REMOVED)
|
pc = PublicationOldMachinesCleaner(old.id)
|
||||||
else: # State is canceling
|
pc.register(GlobalConfig.SESSION_EXPIRE_TIME.getInt(True)*3600, 'pclean-'+str(old.id), True)
|
||||||
dsp.setState(State.CANCELED)
|
|
||||||
# Mark all previous publications deployed services as removables
|
dsp.setState(State.USABLE)
|
||||||
# and make this usable
|
dsp.deployed_service.markOldUserServicesAsRemovables(dsp)
|
||||||
pi.finish()
|
elif State.isRemoving(prevState):
|
||||||
dsp.updateData(pi)
|
dsp.setState(State.REMOVED)
|
||||||
elif State.isErrored(state):
|
else: # State is canceling
|
||||||
dsp.updateData(pi)
|
dsp.setState(State.CANCELED)
|
||||||
dsp.state = State.ERROR
|
# Mark all previous publications deployed services as removables
|
||||||
else:
|
# and make this usable
|
||||||
checkLater = True # The task is running
|
pi.finish()
|
||||||
dsp.updateData(pi)
|
dsp.updateData(pi)
|
||||||
|
elif State.isErrored(state):
|
||||||
dsp.save()
|
dsp.updateData(pi)
|
||||||
if checkLater:
|
dsp.state = State.ERROR
|
||||||
|
else:
|
||||||
|
checkLater = True # The task is running
|
||||||
|
dsp.updateData(pi)
|
||||||
|
|
||||||
|
dsp.save()
|
||||||
|
if checkLater:
|
||||||
|
PublicationFinishChecker.checkLater(dsp, pi)
|
||||||
|
except:
|
||||||
|
logger.exception('At checkAndUpdate for publication')
|
||||||
PublicationFinishChecker.checkLater(dsp, pi)
|
PublicationFinishChecker.checkLater(dsp, pi)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -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,14 +47,14 @@ 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)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
removeFrom = getSqlDatetime() - timedelta(seconds = GlobalConfig.KEEP_INFO_TIME.getInt(True))
|
removeFrom = getSqlDatetime() - timedelta(seconds = GlobalConfig.KEEP_INFO_TIME.getInt(True))
|
||||||
DeployedServicePublication.objects.filter(state__in=State.INFO_STATES, state_date__lt=removeFrom).delete()
|
DeployedServicePublication.objects.filter(state__in=State.INFO_STATES, state_date__lt=removeFrom).delete()
|
||||||
|
|
||||||
class PublicationCleaner(Job):
|
class PublicationCleaner(Job):
|
||||||
frecuency = GlobalConfig.REMOVAL_CHECK.getInt() # Request run publication "removal" every configued seconds. If config value is changed, it will be used at next reload
|
frecuency = GlobalConfig.REMOVAL_CHECK.getInt() # Request run publication "removal" every configued seconds. If config value is changed, it will be used at next reload
|
||||||
friendly_name = 'Publication Cleaner'
|
friendly_name = 'Publication Cleaner'
|
||||||
@ -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