@@ -1,4 +1,9 @@
.\" -*- nroff -*-
+.de IQ
+. br
+. ns
+. IP "\\$1"
+..
.TH ovsdb\-idlc 1 "November 2009" "Open vSwitch" "Open vSwitch Manual"
.ds PN ovsdb\-idlc
.
@@ -45,6 +50,13 @@ These optional members may specify arbitrary code to include in the
generated \fB.c\fR or \fB.h\fR file, respectively, in each case just
after the \fB#include\fR directives in those files.
.
+.IP "\fB""\fBextensions\fR"" member of <table-schema>"
+.IQ "\fB""\fBextensions\fR"" member of <column-schema>"
+This member is optional. If specified, it is an object whose contents
+describes extensions to the OVSDB schema language, for the purpose of
+specifying interpretation by the IDL.
+No extensions are supported yet.
+.
.SS "Commands"
.IP "\fBannotate\fI schema annotations\fR"
Reads \fIschema\fR, which should be a file in JSON format (ordinarily
@@ -32,7 +32,7 @@ def _check_id(name, json):
class DbSchema(object):
"""Schema for an OVSDB database."""
- def __init__(self, name, version, tables):
+ def __init__(self, name, version, tables, allow_extensions=False):
self.name = name
self.version = version
self.tables = tables
@@ -64,7 +64,7 @@ class DbSchema(object):
return n_root
@staticmethod
- def from_json(json):
+ def from_json(json, allow_extensions=False):
parser = ovs.db.parser.Parser(json, "database schema")
name = parser.get("name", ['id'])
version = parser.get_optional("version", six.string_types)
@@ -80,7 +80,8 @@ class DbSchema(object):
tables = {}
for tableName, tableJson in six.iteritems(tablesJson):
_check_id(tableName, json)
- tables[tableName] = TableSchema.from_json(tableJson, tableName)
+ tables[tableName] = TableSchema.from_json(tableJson, tableName,
+ allow_extensions)
return DbSchema(name, version, tables)
@@ -146,7 +147,7 @@ class IdlSchema(DbSchema):
del subjson["idlHeader"]
subjson.pop("cDecls", None)
subjson.pop("hDecls", None)
- schema = DbSchema.from_json(subjson)
+ schema = DbSchema.from_json(subjson, allow_extensions=True)
return IdlSchema(schema.name, schema.version, schema.tables,
idlPrefix, idlHeader, cDecls, hDecls)
@@ -173,22 +174,27 @@ def column_set_from_json(json, columns):
class TableSchema(object):
def __init__(self, name, columns, mutable=True, max_rows=sys.maxsize,
- is_root=True, indexes=[]):
+ is_root=True, indexes=[], extensions={}):
self.name = name
self.columns = columns
self.mutable = mutable
self.max_rows = max_rows
self.is_root = is_root
self.indexes = indexes
+ self.extensions = extensions
@staticmethod
- def from_json(json, name):
+ def from_json(json, name, allow_extensions=False):
parser = ovs.db.parser.Parser(json, "table schema for table %s" % name)
columns_json = parser.get("columns", [dict])
mutable = parser.get_optional("mutable", [bool], True)
max_rows = parser.get_optional("maxRows", [int])
is_root = parser.get_optional("isRoot", [bool], False)
indexes_json = parser.get_optional("indexes", [list], [])
+ if allow_extensions:
+ extensions = parser.get_optional("extensions", [dict], {})
+ else:
+ extensions = {}
parser.finish()
if max_rows is None:
@@ -203,7 +209,8 @@ class TableSchema(object):
for column_name, column_json in six.iteritems(columns_json):
_check_id(column_name, json)
columns[column_name] = ColumnSchema.from_json(column_json,
- column_name)
+ column_name,
+ allow_extensions)
indexes = []
for index_json in indexes_json:
@@ -218,7 +225,8 @@ class TableSchema(object):
"not be indexed" % column.name, json)
indexes.append(index)
- return TableSchema(name, columns, mutable, max_rows, is_root, indexes)
+ return TableSchema(name, columns, mutable, max_rows, is_root, indexes,
+ extensions)
def to_json(self, default_is_root=False):
"""Returns this table schema serialized into JSON.
@@ -255,21 +263,26 @@ class TableSchema(object):
class ColumnSchema(object):
- def __init__(self, name, mutable, persistent, type_):
+ def __init__(self, name, mutable, persistent, type_, extensions={}):
self.name = name
self.mutable = mutable
self.persistent = persistent
self.type = type_
self.unique = False
+ self.extensions = extensions
@staticmethod
- def from_json(json, name):
+ def from_json(json, name, allow_extensions=False):
parser = ovs.db.parser.Parser(json, "schema for column %s" % name)
mutable = parser.get_optional("mutable", [bool], True)
ephemeral = parser.get_optional("ephemeral", [bool], False)
_types = list(six.string_types)
_types.extend([dict])
type_ = ovs.db.types.Type.from_json(parser.get("type", _types))
+ if allow_extensions:
+ extensions = parser.get_optional("extensions", [dict], {})
+ else:
+ extensions = {}
parser.finish()
if not mutable and (type_.key.is_weak_ref()
@@ -278,7 +291,7 @@ class ColumnSchema(object):
# rows are deleted, then the weak reference needs to change.
mutable = True
- return ColumnSchema(name, mutable, not ephemeral, type_)
+ return ColumnSchema(name, mutable, not ephemeral, type_, extensions)
def to_json(self):
json = {"type": self.type.to_json()}
@@ -286,4 +299,6 @@ class ColumnSchema(object):
json["mutable"] = False
if not self.persistent:
json["ephemeral"] = True
+ if self.extensions:
+ json["extensions"] = self.extensions
return json
An IDL schema is an OVSDB schema with some extra stuff in it. So far, all of the extras have been at the top level. This commit makes it possible for IDL schemas to have extra information at the table and column levels as long as it is in an "extensions" member. No extensions are actually supported yet. Signed-off-by: Ben Pfaff <blp@ovn.org> --- ovsdb/ovsdb-idlc.1 | 12 ++++++++++++ python/ovs/db/schema.py | 37 ++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 11 deletions(-)