forked from shaba/openuds
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):
|
||||
res = []
|
||||
for line in field.splitlines():
|
||||
equalPos = line.find('=')
|
||||
if equalPos != -1:
|
||||
attr, pattern = (line[:equalPos], line[equalPos+1:])
|
||||
attr = attr.lower()
|
||||
# if pattern do not have groups, define one with full re
|
||||
if pattern.find('(') == -1:
|
||||
pattern = '(' + pattern + ')'
|
||||
val = attributes.get(attr, [])
|
||||
if type(val) is not list: # May we have a single value
|
||||
val = [val]
|
||||
|
||||
logger.debug('Pattern: {0}'.format(pattern))
|
||||
|
||||
for v in val:
|
||||
try:
|
||||
srch = re.search(pattern, v, re.IGNORECASE)
|
||||
logger.debug("Found against {0}: {1} ".format(v, srch))
|
||||
if srch is None:
|
||||
continue
|
||||
res.append(''.join(srch.groups()))
|
||||
except Exception as e:
|
||||
logger.warn('Invalid regular expression')
|
||||
logger.debug(e)
|
||||
break
|
||||
else:
|
||||
res += attributes.get(line, [])
|
||||
equalPos = line.find('=')
|
||||
if equalPos == -1:
|
||||
line = line + '=(.*)'
|
||||
equalPos = line.find('=')
|
||||
attr, pattern = (line[:equalPos], line[equalPos+1:])
|
||||
attr = attr.lower()
|
||||
# if pattern do not have groups, define one with full re
|
||||
if pattern.find('(') == -1:
|
||||
pattern = '(' + pattern + ')'
|
||||
val = attributes.get(attr, [])
|
||||
if type(val) is not list: # May we have a single value
|
||||
val = [val]
|
||||
|
||||
logger.debug('Pattern: {0}'.format(pattern))
|
||||
|
||||
for vv in val:
|
||||
try:
|
||||
v = vv.decode('utf-8')
|
||||
srch = re.search(pattern, v, re.IGNORECASE)
|
||||
logger.debug("Found against {0}: {1} ".format(v, srch))
|
||||
if srch is None:
|
||||
continue
|
||||
res.append(''.join(srch.groups()))
|
||||
except Exception as e:
|
||||
logger.warn('Invalid regular expression')
|
||||
logger.debug(e)
|
||||
break
|
||||
return res
|
||||
|
||||
def valuesDict(self):
|
||||
|
@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
@ -30,11 +29,13 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.db import transaction
|
||||
from uds.core.jobs.DelayedTask import DelayedTask
|
||||
from uds.core.jobs.DelayedTaskRunner import DelayedTaskRunner
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
from uds.core.services.Exceptions import PublishException
|
||||
from uds.models import DeployedServicePublication, getSqlDatetime, State
|
||||
import logging
|
||||
@ -43,6 +44,26 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
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):
|
||||
def __init__(self, publish):
|
||||
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
|
||||
Return True if it has to continue checking, False if finished
|
||||
'''
|
||||
prevState = dsp.state
|
||||
checkLater = False
|
||||
if State.isFinished(state):
|
||||
# Now we mark, if it exists, the previous usable publication as "Removable"
|
||||
if State.isPreparing(prevState):
|
||||
dsp.deployed_service.publications.filter(state=State.USABLE).update(state=State.REMOVABLE)
|
||||
dsp.setState(State.USABLE)
|
||||
dsp.deployed_service.markOldUserServicesAsRemovables(dsp)
|
||||
elif State.isRemoving(prevState):
|
||||
dsp.setState(State.REMOVED)
|
||||
else: # State is canceling
|
||||
dsp.setState(State.CANCELED)
|
||||
# Mark all previous publications deployed services as removables
|
||||
# and make this usable
|
||||
pi.finish()
|
||||
dsp.updateData(pi)
|
||||
elif State.isErrored(state):
|
||||
dsp.updateData(pi)
|
||||
dsp.state = State.ERROR
|
||||
else:
|
||||
checkLater = True # The task is running
|
||||
dsp.updateData(pi)
|
||||
|
||||
dsp.save()
|
||||
if checkLater:
|
||||
try:
|
||||
prevState = dsp.state
|
||||
checkLater = False
|
||||
if State.isFinished(state):
|
||||
# Now we mark, if it exists, the previous usable publication as "Removable"
|
||||
if State.isPreparing(prevState):
|
||||
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.deployed_service.markOldUserServicesAsRemovables(dsp)
|
||||
elif State.isRemoving(prevState):
|
||||
dsp.setState(State.REMOVED)
|
||||
else: # State is canceling
|
||||
dsp.setState(State.CANCELED)
|
||||
# Mark all previous publications deployed services as removables
|
||||
# and make this usable
|
||||
pi.finish()
|
||||
dsp.updateData(pi)
|
||||
elif State.isErrored(state):
|
||||
dsp.updateData(pi)
|
||||
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)
|
||||
|
||||
@staticmethod
|
||||
@ -132,7 +162,6 @@ class PublicationFinishChecker(DelayedTask):
|
||||
except Exception, e:
|
||||
logger.debug('Deployed service not found (erased from database) {0} : {1}'.format(e.__class__, e))
|
||||
|
||||
|
||||
class PublicationManager(object):
|
||||
_manager = None
|
||||
|
||||
|
@ -34,10 +34,10 @@ from __future__ import unicode_literals
|
||||
|
||||
from uds.core.managers.PublicationManager import PublicationManager
|
||||
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.util.State import State
|
||||
from uds.core.jobs.Job import Job
|
||||
from uds.core.jobs import Job
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
@ -47,14 +47,14 @@ logger = logging.getLogger(__name__)
|
||||
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
|
||||
friendly_name = 'Publications Info Cleaner'
|
||||
|
||||
now = getSqlDatetime()
|
||||
def __init__(self, environment):
|
||||
super(PublicationInfoItemsCleaner,self).__init__(environment)
|
||||
|
||||
def run(self):
|
||||
removeFrom = getSqlDatetime() - timedelta(seconds = GlobalConfig.KEEP_INFO_TIME.getInt(True))
|
||||
DeployedServicePublication.objects.filter(state__in=State.INFO_STATES, state_date__lt=removeFrom).delete()
|
||||
|
||||
|
||||
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
|
||||
friendly_name = 'Publication Cleaner'
|
||||
@ -70,11 +70,3 @@ class PublicationCleaner(Job):
|
||||
except PublishException: # Can say that it cant be removed right now
|
||||
logger.debug('Delaying removal')
|
||||
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
|
||||
try:
|
||||
state = self.service().getMachineState(self._vmid)
|
||||
if state == 'up' and state == 'suspended':
|
||||
if state in ('up', 'suspended'):
|
||||
self.service().stopMachine(self._vmid)
|
||||
except:
|
||||
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
|
||||
'''
|
||||
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.services import ServiceProvider
|
||||
from OVirtLinkedService import OVirtLinkedService
|
||||
|
@ -90,6 +90,7 @@ class OVirtPublication(Publication):
|
||||
try:
|
||||
self._templateId = self.service().makeTemplate(self._name, comments)
|
||||
except Exception as e:
|
||||
self._state = 'error'
|
||||
self._reason = str(e)
|
||||
return State.ERROR
|
||||
|
||||
@ -151,6 +152,7 @@ class OVirtPublication(Publication):
|
||||
try:
|
||||
self.service().removeTemplate(self._templateId)
|
||||
except Exception as e:
|
||||
self._state = 'error'
|
||||
self._reason = str(e)
|
||||
return State.ERROR
|
||||
|
||||
|
@ -51,8 +51,8 @@ class Client(object):
|
||||
'''
|
||||
global cached_api, cached_api_key
|
||||
aKey = self.__getKey('o-host')
|
||||
if cached_api_key == aKey:
|
||||
return cached_api
|
||||
#if cached_api_key == aKey:
|
||||
# return cached_api
|
||||
|
||||
if cached_api is not None:
|
||||
try:
|
||||
@ -374,8 +374,8 @@ class Client(object):
|
||||
display = params.Display(type_=displayType)
|
||||
|
||||
template = params.Template(name=name, vm=params.VM(id=vm.get_id(), disks=disks),
|
||||
cluster=params.Cluster(id=cluster.get_id()), description=comments,
|
||||
display=display)
|
||||
cluster=params.Cluster(id=cluster.get_id()), description=comments)
|
||||
#display=display)
|
||||
|
||||
return api.templates.add(template).get_id()
|
||||
|
||||
@ -442,7 +442,7 @@ class Client(object):
|
||||
|
||||
memoryPolicy = params.MemoryPolicy(guaranteed=guaranteedMB*1024*1024)
|
||||
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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user