Signed-off-by: Stephen Finucane <step...@that.guru>
---
I was really hoping to provide a script that gave 'ovs-vsctl show'-like
output, but I wasn't able to figure out how to dump rows in the time I
allocated to this. Based on [1] (which should probably be merged in some
form) and [2], I suspect this involves some use of .run(), .wait() and
.change_seqno (and transactions in general) but I'm not sure. Input
welcome!

[1] 
https://patchwork.ozlabs.org/project/openvswitch/patch/1531140808-66648-1-git-send-email-cpp.code...@gmail.com/
[2] 
https://opendev.org/openstack/os-ken/src/branch/master/os_ken/lib/ovs/vsctl.py
---
 python/README.rst | 62 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/python/README.rst b/python/README.rst
index 6d289badb..aa6c81f37 100644
--- a/python/README.rst
+++ b/python/README.rst
@@ -54,6 +54,68 @@ this purpose:
 .. __: 
https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-extras
 
 
+Examples
+--------
+
+Show the schema
+~~~~~~~~~~~~~~~
+
+You need to generate a schema helper. If Open vSwitch is installed and running
+on your localhost, you can do this with a local file:
+
+.. code-block:: python
+
+    import ovs.db.idl
+    import ovs.dirs
+
+    remote = f'unix:{ovs.dirs.RUNDIR}/db.sock'
+    schema_path = f'{ovs.dirs.PKGDATADIR}/vswitch.ovsschema'
+    schema_helper = ovs.db.idl.SchemaHelper(schema_path)
+
+Alternatively, you can do this for a remote host via TCP:
+
+.. code-block:: python
+
+    import ovs.db.idl
+    import ovs.dirs
+    import ovs.jsonrpc
+
+    remote = 'tcp:127.0.0.1:6640'
+
+    error, stream = 
ovs.stream.Stream.open_block(ovs.stream.Stream.open(remote))
+    if error:
+        print(error)
+        sys.exit(1)
+
+    rpc = ovs.jsonrpc.Connection(stream)
+    request = ovs.jsonrpc.Message.create_request('get_schema', 
['Open_vSwitch'])
+    error, reply = rpc.transact_block(request)
+    rpc.close()
+    if error:
+        print(error)
+        sys.exit(1)
+
+    schema_json = reply.result
+
+    schema_helper = ovs.db.idl.SchemaHelper(None, schema_json)
+
+.. note::
+
+    The above assumes the default port (``6640``) is used and exposed.
+
+Once done, you can create an instance of ``ovs.db.idl.IDL`` and use this to
+iterate over the instance:
+
+.. code-block:: python
+
+    idl = ovs.db.idl.Idl(remote, schema_helper)
+
+    for table in idl.tables.values():
+        print(f'- {table.name}')
+        for column in table.columns.values():
+            print(f'\t- {column.name}')
+
+
 Documentation
 -------------
 
-- 
2.49.0

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to