summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorHaiwei Xu <xu-haiwei@mxw.nes.nec.co.jp>2013-02-12 01:37:27 +0000
committerHaiwei Xu <xu-haiwei@mxw.nes.nec.co.jp>2013-02-13 10:32:48 +0000
commit2c1bb9efd9287381f16979899bf25022822bf95b (patch)
tree6b59fd6cd6382c5c20c93a322caf4d54aad669eb /nova/utils.py
parentd980805880c681881504e269e03130e4452630ab (diff)
downloadnova-2c1bb9efd9287381f16979899bf25022822bf95b.tar.gz
nova-2c1bb9efd9287381f16979899bf25022822bf95b.tar.xz
nova-2c1bb9efd9287381f16979899bf25022822bf95b.zip
Check the length of flavor name in "flavor-create"
Fixes bug 1102280 The length of flavor name is defined 255 charaters in database. But flavor name can be more than 255 characters when a flavor is created. This patch adds the length check of flavor name. Change-Id: If9db879e5f6340594b215b057a29d03c6fef1503
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 7ad810504..57f9433df 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -1341,3 +1341,25 @@ class ExceptionHelper(object):
except rpc_common.ClientException, e:
raise (e._exc_info[1], None, e._exc_info[2])
return wrapper
+
+
+def check_string_length(value, name, min_length=0, max_length=None):
+ """Check the length of specified string
+ :param value: the value of the string
+ :param name: the name of the string
+ :param min_length: the min_length of the string
+ :param max_length: the max_length of the string
+ """
+ if not isinstance(value, basestring):
+ msg = _("%s is not a string or unicode") % name
+ raise exception.InvalidInput(message=msg)
+
+ if len(value) < min_length:
+ msg = _("%(name)s has less than %(min_length)s "
+ "characters.") % locals()
+ raise exception.InvalidInput(message=msg)
+
+ if max_length and len(value) > max_length:
+ msg = _("%(name)s has more than %(max_length)s "
+ "characters.") % locals()
+ raise exception.InvalidInput(message=msg)