summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-08-23 09:55:14 -0700
committerBen Pfaff <blp@nicira.com>2011-08-24 11:57:43 -0700
commit693e5dc7484b15c159cb9f644d28dc759db01b7c (patch)
treed5f28e56bd310e2dbef5d1fe1c38376597b2dc1b
parentc29e06be0e224f1c2392e892016bd6b80749611d (diff)
downloadopenvswitch-693e5dc7484b15c159cb9f644d28dc759db01b7c.tar.gz
ovs.db.schema: Factor common checks for identifiers into new function.
Suggested-by: Reid Price <reid@nicira.com>
-rw-r--r--python/ovs/db/schema.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py
index 2d053a045..29fe986a2 100644
--- a/python/ovs/db/schema.py
+++ b/python/ovs/db/schema.py
@@ -19,6 +19,12 @@ from ovs.db import error
import ovs.db.parser
from ovs.db import types
+def _check_id(name, json):
+ if name.startswith('_'):
+ raise error.Error('names beginning with "_" are reserved', json)
+ elif not ovs.db.parser.is_identifier(name):
+ raise error.Error("name must be a valid id", json)
+
class DbSchema(object):
"""Schema for an OVSDB database."""
@@ -70,11 +76,7 @@ class DbSchema(object):
tables = {}
for tableName, tableJson in tablesJson.iteritems():
- if tableName.startswith('_'):
- raise error.Error('names beginning with "_" are reserved',
- json)
- elif not ovs.db.parser.is_identifier(tableName):
- raise error.Error("name must be a valid id", json)
+ _check_id(tableName, json)
tables[tableName] = TableSchema.from_json(tableJson, tableName)
return DbSchema(name, version, tables)
@@ -182,11 +184,7 @@ class TableSchema(object):
columns = {}
for column_name, column_json in columns_json.iteritems():
- if column_name.startswith('_'):
- raise error.Error('names beginning with "_" are reserved',
- json)
- elif not ovs.db.parser.is_identifier(column_name):
- raise error.Error("name must be a valid id", json)
+ _check_id(column_name, json)
columns[column_name] = ColumnSchema.from_json(column_json,
column_name)