summaryrefslogtreecommitdiff
path: root/nova/api/openstack/compute/plugins/v3/console_output.py
diff options
context:
space:
mode:
authorEiich Aikawa <aikawa@mxk.nes.nec.co.jp>2013-12-26 14:51:04 +0900
committerEiichi Aikawa <aikawa@mxk.nes.nec.co.jp>2014-01-14 14:26:39 +0900
commite0c95813235f25ab0baeec7ff00d83f59804b579 (patch)
tree5a799100bcc5556cec59f007ff8e0fa9e20e4710 /nova/api/openstack/compute/plugins/v3/console_output.py
parent3fa05e201be1d5210492190bb662c776859f1660 (diff)
downloadnova-e0c95813235f25ab0baeec7ff00d83f59804b579.tar.gz
API schema for v3 console_output API
By defining the API schema, it is possible to separate the validation code from the API method. The API method can be more simple. In addition, a response of API validation error can be consistent for the whole Nova API. Partially implements blueprint nova-api-validation-fw Change-Id: Id6330e2250448c54679df4f27af25c2614a871f0
Diffstat (limited to 'nova/api/openstack/compute/plugins/v3/console_output.py')
-rw-r--r--nova/api/openstack/compute/plugins/v3/console_output.py20
1 files changed, 4 insertions, 16 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/console_output.py b/nova/api/openstack/compute/plugins/v3/console_output.py
index 45fb68d0d5..0fee690d62 100644
--- a/nova/api/openstack/compute/plugins/v3/console_output.py
+++ b/nova/api/openstack/compute/plugins/v3/console_output.py
@@ -19,8 +19,10 @@
import re
import webob
+from nova.api.openstack.compute.schemas.v3 import console_output
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
+from nova.api import validation
from nova import compute
from nova import exception
from nova.openstack.common.gettextutils import _
@@ -36,6 +38,7 @@ class ConsoleOutputController(wsgi.Controller):
@extensions.expected_errors((400, 404, 409, 501))
@wsgi.action('get_console_output')
+ @validation.schema(console_output.get_console_output)
def get_console_output(self, req, id, body):
"""Get text console output."""
context = req.environ['nova.context']
@@ -46,22 +49,7 @@ class ConsoleOutputController(wsgi.Controller):
except exception.InstanceNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
- try:
- length = body['get_console_output'].get('length')
- except (TypeError, KeyError):
- raise webob.exc.HTTPBadRequest(_('get_console_output malformed '
- 'or missing from request body'))
-
- if length is not None:
- try:
- # NOTE(maurosr): cast length into a string before cast into an
- # integer to avoid thing like: int(2.5) which is 2 instead of
- # raise ValueError like it would when we try int("2.5"). This
- # can be removed once we have api validation landed.
- int(str(length))
- except ValueError:
- raise webob.exc.HTTPBadRequest(_('Length in request body must '
- 'be an integer value'))
+ length = body['get_console_output'].get('length')
try:
output = self.compute_api.get_console_output(context,