Fixing validation for volume size

This commit is contained in:
Michael Basnight 2012-05-31 11:03:32 -05:00
parent cab7ab623e
commit c4f0f697e7
2 changed files with 11 additions and 1 deletions

View File

@ -124,3 +124,9 @@ class TaskManagerError(ReddwarfError):
message = _("An error occurred communicating with the task manager: "
"%(original_message)s.")
class BadValue(ReddwarfError):
message = _("Value could not be converted: %(msg)s")

View File

@ -47,6 +47,7 @@ class BaseController(wsgi.Controller):
models.InvalidModelError,
exception.BadRequest,
exception.CannotResizeToSameSize,
exception.BadValue
],
webob.exc.HTTPNotFound: [
exception.NotFound,
@ -263,7 +264,10 @@ class InstanceController(BaseController):
if databases is None:
databases = []
if body['instance'].get('volume', None) is not None:
volume_size = body['instance']['volume']['size']
try:
volume_size = int(body['instance']['volume']['size'])
except ValueError as e:
raise exception.BadValue(msg=e)
else:
volume_size = None
instance = models.Instance.create(context, name, flavor_ref,