Merge pull request #92 from hub-cap/fix_validation

Fixing validation for volume size
This commit is contained in:
Michael Basnight 2012-06-01 10:51:03 -07:00
commit 6c3dec2237
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,