Commit aaa3e50b by Bach Dániel

Merge branch 'issue-272' into 'master'

Make some errors human readable
parents c766e690 7cd242ed
...@@ -488,7 +488,7 @@ class HumanReadableException(HumanReadableObject, Exception): ...@@ -488,7 +488,7 @@ class HumanReadableException(HumanReadableObject, Exception):
"Level should be the name of an attribute of django." "Level should be the name of an attribute of django."
"contrib.messages (and it should be callable with " "contrib.messages (and it should be callable with "
"(request, message)). Like 'error', 'warning'.") "(request, message)). Like 'error', 'warning'.")
else: elif not hasattr(self, "level"):
self.level = "error" self.level = "error"
def send_message(self, request, level=None): def send_message(self, request, level=None):
......
...@@ -18,26 +18,37 @@ ...@@ -18,26 +18,37 @@
from logging import getLogger from logging import getLogger
from django.db.models import Sum from django.db.models import Sum
from django.utils.translation import ugettext_noop
from common.models import HumanReadableException
logger = getLogger(__name__) logger = getLogger(__name__)
class NotEnoughMemoryException(Exception): class SchedulerError(HumanReadableException):
admin_message = None
def __init__(self, message=None): def __init__(self, params=None, level=None, **kwargs):
if message is None: kwargs.update(params or {})
message = "No node has enough memory to accomodate the guest." super(SchedulerError, self).__init__(
level, self.message, self.admin_message or self.message,
kwargs)
Exception.__init__(self, message)
class NotEnoughMemoryException(SchedulerError):
message = ugettext_noop(
"The resources required for launching the virtual machine are not "
"available currently. Please try again later.")
class TraitsUnsatisfiableException(Exception): admin_message = ugettext_noop(
"The required free memory for launching the virtual machine is not "
"available on any usable node currently. Please try again later.")
def __init__(self, message=None):
if message is None:
message = "No node can satisfy all required traits of the guest."
Exception.__init__(self, message) class TraitsUnsatisfiableException(SchedulerError):
message = ugettext_noop(
"No node can satisfy the required traits of the "
"new vitual machine currently.")
def select_node(instance, nodes): def select_node(instance, nodes):
......
...@@ -620,6 +620,17 @@ class ShutdownOperation(InstanceOperation): ...@@ -620,6 +620,17 @@ class ShutdownOperation(InstanceOperation):
self.instance.yield_node() self.instance.yield_node()
self.instance.yield_vnc_port() self.instance.yield_vnc_port()
def on_abort(self, activity, error):
if isinstance(error, TimeLimitExceeded):
activity.result = humanize_exception(ugettext_noop(
"The virtual machine did not switch off in the provided time "
"limit. Most of the time this is caused by incorrect ACPI "
"settings. You can also try to power off the machine from the "
"operating system manually."), error)
activity.resultant_state = None
else:
super(ShutdownOperation, self).on_abort(activity, error)
register_operation(ShutdownOperation) register_operation(ShutdownOperation)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment