]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Implements _validate_uuid
authorZhongyue Luo <zhongyue.nah@intel.com>
Mon, 5 Nov 2012 14:40:50 +0000 (22:40 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Mon, 5 Nov 2012 14:51:26 +0000 (22:51 +0800)
Validates uuids with uuidutils.is_uuid_like
Reordered validation funtions alphabetically

Change-Id: I4c138d471c420ed520e6c881e07d36478119d12b

quantum/api/v2/attributes.py

index 306df78ca6607a9c41d3dafe1f650ce1fb78c2f8..c6784084ca11e3a6780e78217837060120edd752 100644 (file)
@@ -22,6 +22,8 @@ import re
 
 from quantum.common import exceptions as q_exc
 from quantum.openstack.common import log as logging
+from quantum.openstack.common import uuidutils
+
 
 LOG = logging.getLogger(__name__)
 
@@ -111,6 +113,15 @@ def _validate_regex(data, valid_values=None):
         return msg
 
 
+def _validate_uuid(data, valid_values=None):
+    if uuidutils.is_uuid_like(data):
+        return
+    else:
+        msg = _("%s is not a valid UUID") % data
+        LOG.debug("validate_uuid: %s", msg)
+        return msg
+
+
 def convert_to_boolean(data):
     try:
         i = int(data)
@@ -170,13 +181,14 @@ MAC_PATTERN = "^%s[aceACE02468](:%s{2}){5}$" % (HEX_ELEM, HEX_ELEM)
 
 # Dictionary that maintains a list of validation functions
 validators = {'type:boolean': _validate_boolean,
-              'type:values': _validate_values,
-              'type:range': _validate_range,
-              'type:mac_address': _validate_mac_address,
               'type:ip_address': _validate_ip_address,
               'type:ip_address_or_none': _validate_ip_address_or_none,
+              'type:mac_address': _validate_mac_address,
+              'type:range': _validate_range,
+              'type:regex': _validate_regex,
               'type:subnet': _validate_subnet,
-              'type:regex': _validate_regex}
+              'type:uuid': _validate_uuid,
+              'type:values': _validate_values}
 
 # Note: a default of ATTR_NOT_SPECIFIED indicates that an
 # attribute is not required, but will be generated by the plugin
@@ -204,7 +216,7 @@ validators = {'type:boolean': _validate_boolean,
 RESOURCE_ATTRIBUTE_MAP = {
     'networks': {
         'id': {'allow_post': False, 'allow_put': False,
-               'validate': {'type:regex': UUID_PATTERN},
+               'validate': {'type:uuid': None},
                'is_visible': True},
         'name': {'allow_post': True, 'allow_put': True,
                  'default': '', 'is_visible': True},
@@ -232,13 +244,13 @@ RESOURCE_ATTRIBUTE_MAP = {
     },
     'ports': {
         'id': {'allow_post': False, 'allow_put': False,
-               'validate': {'type:regex': UUID_PATTERN},
+               'validate': {'type:uuid': None},
                'is_visible': True},
         'name': {'allow_post': True, 'allow_put': True, 'default': '',
                  'is_visible': True},
         'network_id': {'allow_post': True, 'allow_put': False,
                        'required_by_policy': True,
-                       'validate': {'type:regex': UUID_PATTERN},
+                       'validate': {'type:uuid': None},
                        'is_visible': True},
         'admin_state_up': {'allow_post': True, 'allow_put': True,
                            'default': True,
@@ -269,7 +281,7 @@ RESOURCE_ATTRIBUTE_MAP = {
     },
     'subnets': {
         'id': {'allow_post': False, 'allow_put': False,
-               'validate': {'type:regex': UUID_PATTERN},
+               'validate': {'type:uuid': None},
                'is_visible': True},
         'name': {'allow_post': True, 'allow_put': True, 'default': '',
                  'is_visible': True},
@@ -279,7 +291,7 @@ RESOURCE_ATTRIBUTE_MAP = {
                        'is_visible': True},
         'network_id': {'allow_post': True, 'allow_put': False,
                        'required_by_policy': True,
-                       'validate': {'type:regex': UUID_PATTERN},
+                       'validate': {'type:uuid': None},
                        'is_visible': True},
         'cidr': {'allow_post': True, 'allow_put': False,
                  'validate': {'type:subnet': None},