diff options
author | Ben Pfaff <blp@nicira.com> | 2011-09-21 10:43:03 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2011-09-23 14:23:16 -0700 |
commit | 8cdf0349740c3e1a73af9aa6209bb22be952cd37 (patch) | |
tree | 866331f253cf075ff4c5b5b83d510897a27dbb17 /ovsdb | |
parent | 7cba02e442012a7ae6cfdfe67f858a18057e5470 (diff) |
python: Implement write support in Python IDL for OVSDB.
Until now, the Python bindings for OVSDB have not supported writing to the
database. Instead, writes had to be done with "ovs-vsctl" subprocesses.
This commit adds write support and brings the Python bindings in line with
the C bindings.
This commit deletes the Python-specific IDL tests in favor of using the
same tests as the C version of the IDL, which now pass with both
implementations.
This commit updates the two users of the Python IDL to use the new write
support. I tested this updates only by writing unit tests for them,
which appear in upcoming commits.
Diffstat (limited to 'ovsdb')
-rw-r--r-- | ovsdb/automake.mk | 5 | ||||
-rwxr-xr-x | ovsdb/ovsdb-idlc.in | 21 |
2 files changed, 22 insertions, 4 deletions
diff --git a/ovsdb/automake.mk b/ovsdb/automake.mk index 39bc65fc..5d0b6d7a 100644 --- a/ovsdb/automake.mk +++ b/ovsdb/automake.mk @@ -67,7 +67,7 @@ EXTRA_DIST += \ ovsdb/ovsdb-idlc.in \ ovsdb/ovsdb-idlc.1 DISTCLEANFILES += ovsdb/ovsdb-idlc -SUFFIXES += .ovsidl +SUFFIXES += .ovsidl .ovsschema .py OVSDB_IDLC = $(run_python) $(srcdir)/ovsdb/ovsdb-idlc.in .ovsidl.c: $(OVSDB_IDLC) c-idl-source $< > $@.tmp @@ -75,6 +75,9 @@ OVSDB_IDLC = $(run_python) $(srcdir)/ovsdb/ovsdb-idlc.in .ovsidl.h: $(OVSDB_IDLC) c-idl-header $< > $@.tmp mv $@.tmp $@ +.ovsschema.py: + $(OVSDB_IDLC) python-module $< > $@.tmp + mv $@.tmp $@ EXTRA_DIST += $(OVSIDL_BUILT) BUILT_SOURCES += $(OVSIDL_BUILT) diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 3392c355..4e402888 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -548,6 +548,21 @@ void print " %s_columns_init();" % structName print "}" +def print_python_module(schema_file): + schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_file(schema_file)) + print """\ +# Generated automatically -- do not modify! -*- buffer-read-only: t -*- + +import ovs.db.schema +import ovs.json + +__schema_json = \"\"\" +%s +\"\"\" + +schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_string(__schema_json)) +""" % ovs.json.to_string(schema.to_json(), pretty=True) + def ovsdb_escape(string): def escape(match): c = match.group(0) @@ -569,8 +584,6 @@ def ovsdb_escape(string): return '\\x%02x' % ord(c) return re.sub(r'["\\\000-\037]', escape, string) - - def usage(): print """\ %(argv0)s: ovsdb schema compiler @@ -580,6 +593,7 @@ The following commands are supported: annotate SCHEMA ANNOTATIONS print SCHEMA combined with ANNOTATIONS c-idl-header IDL print C header file for IDL c-idl-source IDL print C source file for IDL implementation + python-module IDL print Python module for IDL nroff IDL print schema documentation in nroff format The following options are also available: @@ -618,7 +632,8 @@ if __name__ == "__main__": commands = {"annotate": (annotateSchema, 2), "c-idl-header": (printCIDLHeader, 1), - "c-idl-source": (printCIDLSource, 1)} + "c-idl-source": (printCIDLSource, 1), + "python-module": (print_python_module, 1)} if not args[0] in commands: sys.stderr.write("%s: unknown command \"%s\" " |