summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-02-13 19:50:03 +0000
committerGerrit Code Review <review@openstack.org>2013-02-13 19:50:03 +0000
commit787e334a105c47bb387dc51c8798b4ac8e1d7bc0 (patch)
tree4790e1037c69a189be5cc48af8c5dfc28b5a324b /nova/utils.py
parent07e0c2421adf14d01389f5d6692ac2e18b8b7134 (diff)
parent2c1bb9efd9287381f16979899bf25022822bf95b (diff)
downloadnova-787e334a105c47bb387dc51c8798b4ac8e1d7bc0.tar.gz
nova-787e334a105c47bb387dc51c8798b4ac8e1d7bc0.tar.xz
nova-787e334a105c47bb387dc51c8798b4ac8e1d7bc0.zip
Merge "Check the length of flavor name in "flavor-create""
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)