Implements _validate_uuid

Validates uuids with uuidutils.is_uuid_like
Reordered validation funtions alphabetically

Change-Id: I4c138d471c420ed520e6c881e07d36478119d12b
This commit is contained in:
Zhongyue Luo 2012-11-05 22:40:50 +08:00
parent e3244c285f
commit 3f7f526dec

View 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},