Commit d3987543 by Kálmán Viktor

occi: basic error handling

parent 37f608b2
......@@ -5,6 +5,7 @@ from django.contrib.auth.models import User
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.formats import date_format
from django.utils.translation import ugettext_noop
from django_sshkey.models import UserKey
......@@ -13,6 +14,7 @@ from storage.models import Disk
from vm.models import Instance, InstanceTemplate, Lease, Interface
from vm.models.common import ARCHITECTURES
from vm.models.instance import ACCESS_METHODS, pwgen
from common.models import humanize_exception
logger = logging.getLogger(__name__)
......@@ -327,6 +329,10 @@ class Compute(Resource):
operation = "deploy"
else:
action = compute_action_to_operation.get(action_term)
if not method:
raise humanize_exception(ugettext_noop(
"Missing 'method' attribute."),
Exception())
operation = action.get(method)
getattr(self.instance, operation).async(user=user)
......
......@@ -7,6 +7,7 @@ from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View, DetailView
from common.models import HumanReadableException
from firewall.models import Vlan
from vm.models import Instance, InstanceTemplate, Interface
from storage.models import Disk
......@@ -36,8 +37,10 @@ logger = logging.getLogger(__name__)
class CSRFExemptMixin(object):
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(CSRFExemptMixin, self).dispatch(*args, **kwargs)
try:
return super(CSRFExemptMixin, self).dispatch(*args, **kwargs)
except HumanReadableException as e:
return HttpResponse(e.get_user_text(), status=400)
class OCCIPostDataAsListMixin(object):
......
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