mirror of
https://github.com/openvswitch/ovs
synced 2025-10-29 15:28:56 +00:00
ovs.db.schema: Factor common checks for identifiers into new function.
Suggested-by: Reid Price <reid@nicira.com>
This commit is contained in:
@@ -19,6 +19,12 @@ from ovs.db import error
|
|||||||
import ovs.db.parser
|
import ovs.db.parser
|
||||||
from ovs.db import types
|
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):
|
class DbSchema(object):
|
||||||
"""Schema for an OVSDB database."""
|
"""Schema for an OVSDB database."""
|
||||||
|
|
||||||
@@ -70,11 +76,7 @@ class DbSchema(object):
|
|||||||
|
|
||||||
tables = {}
|
tables = {}
|
||||||
for tableName, tableJson in tablesJson.iteritems():
|
for tableName, tableJson in tablesJson.iteritems():
|
||||||
if tableName.startswith('_'):
|
_check_id(tableName, json)
|
||||||
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)
|
|
||||||
tables[tableName] = TableSchema.from_json(tableJson, tableName)
|
tables[tableName] = TableSchema.from_json(tableJson, tableName)
|
||||||
|
|
||||||
return DbSchema(name, version, tables)
|
return DbSchema(name, version, tables)
|
||||||
@@ -182,11 +184,7 @@ class TableSchema(object):
|
|||||||
|
|
||||||
columns = {}
|
columns = {}
|
||||||
for column_name, column_json in columns_json.iteritems():
|
for column_name, column_json in columns_json.iteritems():
|
||||||
if column_name.startswith('_'):
|
_check_id(column_name, json)
|
||||||
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)
|
|
||||||
columns[column_name] = ColumnSchema.from_json(column_json,
|
columns[column_name] = ColumnSchema.from_json(column_json,
|
||||||
column_name)
|
column_name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user