Several minor fixes & aditions

This commit is contained in:
Adolfo Gómez García 2015-10-24 10:32:51 +02:00
parent aaf4b539d5
commit 6bc70ff4de
14 changed files with 78 additions and 44 deletions

View File

@ -212,6 +212,9 @@ class ServicesPools(ModelHandler):
except Exception:
raise RequestError(ugettext('This service requires an OS Manager'))
# If max < initial or cache_1 or cache_l2
fields['max_srvs'] = max((int(fields['initial_srvs']), int(fields['cache_l1_srvs']), int(fields['max_srvs'])))
imgId = fields['image_id']
fields['image_id'] = None
logger.debug('Image id: {}'.format(imgId))

View File

@ -143,10 +143,12 @@ class AssignedService(DetailHandler):
self.invalidItemException()
logger.debug('Deleting assigned service')
if service.state == State.USABLE:
if service.state in (State.USABLE, State.REMOVING):
service.remove()
elif service.state == State.PREPARING:
service.cancel()
elif service.state == State.REMOVABLE:
self.invalidItemException(_('Item already being removed'))
else:
self.invalidItemException(_('Item is not removable'))

View File

@ -52,7 +52,7 @@ import logging
logger = logging.getLogger(__name__)
__updated__ = '2015-04-28'
__updated__ = '2015-10-23'
# a few constants
@ -238,8 +238,9 @@ class BaseModelHandler(Handler):
'''
Raises a NotFound exception, with location info
'''
message = _('Item not found') if message is None else None
raise NotFound('{} {}: {}'.format(message, self.__class__, self._args))
message = _('Item not found') if message is None else message
raise NotFound(message)
# raise NotFound('{} {}: {}'.format(message, self.__class__, self._args))
def accessDenied(self, message=None):
raise AccessDenied(message or _('Access denied'))

View File

@ -46,6 +46,7 @@ import uds.xmlrpc # To make actor live
from django.db.backends.signals import connection_created
from django.dispatch import receiver
import math
import ssl
from django.apps import AppConfig
@ -55,7 +56,19 @@ import logging
logger = logging.getLogger(__name__)
__updated__ = '2015-06-09'
__updated__ = '2015-10-20'
# Default ssl context is unverified, as MOST servers that we will connect will be with self signed certificates...
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
class UDSAppConfig(AppConfig):

View File

@ -44,7 +44,7 @@ import threading
import time
import logging
__updated__ = '2015-10-16'
__updated__ = '2015-10-24'
logger = logging.getLogger(__name__)
@ -60,8 +60,8 @@ class DelayedTaskThread(threading.Thread):
def run(self):
try:
self._taskInstance.execute()
except Exception, e:
logger.debug("Exception in thread {0}: {1}".format(e.__class__, e))
except Exception as e:
logger.exception("Exception in thread {0}: {1}".format(e.__class__, e))
class DelayedTaskRunner(object):

View File

@ -51,7 +51,7 @@ import requests
import json
import logging
__updated__ = '2015-10-15'
__updated__ = '2015-10-24'
logger = logging.getLogger(__name__)
@ -69,7 +69,7 @@ class UserServiceOpChecker(DelayedTask):
'''
This method ensures that there will be only one delayedtask related to the userService indicated
'''
DelayedTaskRunner.runner().remove(USERSERVICE_TAG + str(userService.id))
DelayedTaskRunner.runner().remove(USERSERVICE_TAG + userService.uuid)
UserServiceOpChecker.checkAndUpdateState(userService, userServiceInstance, state)
@staticmethod
@ -139,9 +139,9 @@ class UserServiceOpChecker(DelayedTask):
@param pi: Instance of Publication manager for the object
'''
# Do not add task if already exists one that updates this service
if DelayedTaskRunner.runner().checkExists(USERSERVICE_TAG + str(userService.id)):
if DelayedTaskRunner.runner().checkExists(USERSERVICE_TAG + userService.uuid):
return
DelayedTaskRunner.runner().insert(UserServiceOpChecker(userService), ci.suggestedTime, USERSERVICE_TAG + str(userService.id))
DelayedTaskRunner.runner().insert(UserServiceOpChecker(userService), ci.suggestedTime, USERSERVICE_TAG + userService.uuid)
def run(self):
logger.debug('Checking user service finished {0}'.format(self._svrId))
@ -325,8 +325,9 @@ class UserServiceManager(object):
Removes a uService element
@return: the uService removed (marked for removal)
'''
uService = UserService.objects.get(id=uService.id)
logger.debug('Removing uService {0}'.format(uService))
uService.refresh_from_db()
# uService = UserService.objects.get(id=uService.id)
logger.debug('Removing uService {}'.format(uService))
if uService.isUsable() is False and State.isRemovable(uService.state) is False:
raise OperationException(_('Can\'t remove a non active element'))

View File

@ -63,7 +63,7 @@ class Storage(object):
dbStorage.objects.create(owner=self._owner, key=key, data=data, attr1=attr1) # @UndefinedVariable
except Exception:
dbStorage.objects.filter(key=key).update(owner=self._owner, data=data, attr1=attr1) # @UndefinedVariable
logger.debug('Key saved')
# logger.debug('Key saved')
def put(self, skey, data):
return self.saveData(skey, data)
@ -127,24 +127,26 @@ class Storage(object):
dbStorage.objects.unlock() # @UndefinedVariable
def locateByAttr1(self, attr1):
res = []
if isinstance(attr1, (list, tuple)):
query = dbStorage.objects.filter(owner=self._owner, attr1_in=attr1) # @UndefinedVariable
else:
query = dbStorage.objects.filter(owner=self._owner, attr1=attr1) # @UndefinedVariable
for v in query:
res.append(v.data.decode(Storage.CODEC))
return res
yield v.data.decode(Storage.CODEC)
def filterPickle(self, attr1=None):
def filter(self, attr1):
if attr1 is None:
query = dbStorage.objects.filter(owner=self._owner) # @UndefinedVariable
else:
query = dbStorage.objects.filter(owner=self._owner, attr1=attr1) # @UndefinedVariable
for v in query: # @UndefinedVariable
yield (v.key, pickle.loads(v.data.decode(Storage.CODEC)), v.attr1)
yield (v.key, v.data.decode(Storage.CODEC), v.attr1)
def filterPickle(self, attr1=None):
for v in self.filter(attr1):
yield (v[0], pickle.loads(v[1]), v[2])
@staticmethod
def delete(owner=None):

View File

@ -60,7 +60,7 @@ class UniqueIDGenerator(object):
'''
# First look for a name in the range defined
stamp = getSqlDatetime(True)
logger.debug(UniqueId)
# logger.debug(UniqueId)
try:
UniqueId.objects.lock() # @UndefinedVariable
flt = self.__filter(rangeStart, rangeEnd)
@ -74,7 +74,7 @@ class UniqueIDGenerator(object):
seq = last.seq + 1
except Exception: # If there is no assigned at database
seq = rangeStart
logger.debug('Found seq {0}'.format(seq))
# logger.debug('Found seq {0}'.format(seq))
if seq > rangeEnd:
return -1 # No ids free in range
UniqueId.objects.create(owner=self._owner, basename=self._baseName, seq=seq, assigned=True, stamp=stamp) # @UndefinedVariable

View File

@ -78,4 +78,7 @@ class UserServiceRemover(Job):
removables = UserService.objects.filter(state=State.REMOVABLE, state_date__lt=removeFrom,
deployed_service__service__provider__maintenance_mode=False)[0:UserServiceRemover.removeAtOnce]
for us in removables:
UserServiceManager.manager().remove(us)
try:
UserServiceManager.manager().remove(us)
except Exception:
logger.exception('Exception invoking remove user service {}'.format(us))

View File

@ -155,6 +155,7 @@ gui.providers.link = (event) ->
permission: api.permissions.MANAGEMENT
text: maintenanceText('fa-ambulance', gettext("Maintenance"))
css: "disabled"
disabled: true
click: (vals, value, btn, tbl, refreshFnc) ->
if vals.length > 1

View File

@ -199,7 +199,7 @@ gui.servicesPools.link = (event) ->
doNotLoadData: true
icon: 'cached'
container: "cache-placeholder_tbl"
rowSelect: "single"
rowSelect: "multi"
deferRender: true
doNotLoadData: true
buttons: [
@ -442,6 +442,7 @@ gui.servicesPools.link = (event) ->
{
text: gettext("Cancel")
css: "disabled"
disabled: true
click: (val, value, btn, tbl, refreshFnc) ->
gui.promptModal gettext("Publish"), gettext("Cancel publication"),
onYes: ->
@ -453,11 +454,14 @@ gui.servicesPools.link = (event) ->
return
select: (val, value, btn, tbl, refreshFnc) ->
unless val
$(btn).removeClass("btn3d-warning").addClass "disabled"
select: (vals, self, btn, tbl, refreshFnc) ->
unless vals.length == 1
$(btn).addClass "disabled"
$(btn).prop('disabled', true)
return
val = vals[0]
if val.state == 'K'
$(btn).empty().append(gettext("Force Cancel"))
else
@ -465,12 +469,12 @@ gui.servicesPools.link = (event) ->
# Waiting for publication, Preparing or running
gui.doLog "State: ", val.state
$(btn).removeClass("disabled").addClass "btn3d-warning" if [
"P"
"W"
"L"
"K"
].indexOf(val.state) != -1
if ["P", "W", "L", "K"].indexOf(val.state) != -1
$(btn).removeClass("disabled")
$(btn).prop('disabled', false)
else
$(btn).addClass("disabled")
$(btn).prop('disabled', true)
return
}

View File

@ -381,6 +381,7 @@
type: "text"
content: value.text
css: css
disabled: value.disabled? and value.disabled is true
if value.click
btn.fnClick = () ->
@ -473,8 +474,17 @@
for btn in btns
$div = $('div.'+tbId)
if btn.type == 'text'
gui.doLog "Button: ", btn
btnId = gui.genRamdonId('btn')
$div.append('<button id="' + btnId + '" class="' + btn.css + '">' + btn.content + '</button>')
btnHtml = '<button id="' + btnId + '" class="' + btn.css + '"'
if btn.disabled? and btn.disabled is true
btnHtml += ' disabled'
btnHtml += '>' + btn.content + '</button>'
gui.doLog "Button2: ", btnHtml
$div.append btnHtml
$btn = $('#'+btnId)
$btn.on 'click', btn.fnClick

View File

@ -431,7 +431,7 @@
deletedFnc = (name, errorMsg) ->
count -= 1
if errorMsg?
msgs.push '<span class="text-danger">' + gettext("Error deleting") + " <b>" + name + "</b>: " + errorMsg + '</span>'
msgs.push gettext("Error deleting") + " <b>" + name + '</b>: <span class="text-danger">' + errorMsg + '</span>'
else
msgs.push gettext("Successfully deleted") + " <b>" + name + "</b>"
@ -449,12 +449,12 @@
gui.tools.blockUI()
for value in values
((value) ->
name = value.name or value.friendly_name
parent.rest.del value.id, (->
name = value.name or value.friendly_name
deletedFnc name
return
), (jqXHR, textStatus, errorThrown) -> # fail on put
deletedFnc name, jqXHR.responseText)(value)
), (jqXHR, textStatus, errorThrown) -> # fail on delete
deletedFnc(name, jqXHR.responseText))(value)
return
return

View File

@ -50,17 +50,11 @@
{{# ifequals value.type 3 }}
<input type="checkbox" data-on-text="{% endverbatim %}{% trans 'Yes' %}{% verbatim %}" data-off-text="{% endverbatim %}{% trans 'No' %}{% verbatim %}" class="config-ctrl" {{# ifequals value.value 1 }} checked{{/ ifequals }} data-section="{{ cfg_section }}" data-key="{{ cfg_key }}">
{{ else }}
{{# ifequals value.type 2 }}
<div>
<input type="numeric" class="form-control config-ctrl" data-section="{{ ../../../../../key }}" data-key="{{ key }}" value="{{ value.value }}">
</div>
{{ else }}
<div>
<input type="{{# ifequals value.type 2 }}numeric{{ else }}text{{/ ifequals}}" class="form-control config-ctrl" data-section="{{ cfg_section }}" data-key="{{ cfg_key }}" value="{{ value.value }}">
</div>
{{/ ifequals }}
{{/ ifequals }}
{{/ ifequals }}
{{/ if }}
</div>
</div>