[ovs-dev] [PATCH] [python] Allow custom transaction ops to be added

Terry Wilson twilson at redhat.com
Wed Oct 13 22:40:23 UTC 2021


It can be useful to be able to send raw transaction operations
through the Idl's connection. For example, to clean up MAC_Binding
entries for floating IPs without having to monitor the MAC_Binding
table which can be quite large.

Signed-off-by: Terry Wilson <twilson at redhat.com>
---
 python/ovs/db/idl.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index ecae5e143..b2fd30775 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -1405,6 +1405,8 @@ class Transaction(object):
 
         self._inserted_rows = {}  # Map from UUID to _InsertedRow
 
+        self._operations = []
+
     def add_comment(self, comment):
         """Appends 'comment' to the comments that will be passed to the OVSDB
         server when this transaction is committed.  (The comment will be
@@ -1535,7 +1537,7 @@ class Transaction(object):
                                    "rows": [rows]})
 
         # Add updates.
-        any_updates = False
+        any_updates = bool(self._operations)
         for row in self._txn_rows.values():
             if row._changes is None:
                 if row._table.is_root:
@@ -1670,6 +1672,7 @@ class Transaction(object):
         if self.dry_run:
             operations.append({"op": "abort"})
 
+        operations += self._operations
         if not any_updates:
             self._status = Transaction.UNCHANGED
         else:
@@ -1684,6 +1687,19 @@ class Transaction(object):
         self.__disassemble()
         return self._status
 
+    def add_op(self, op):
+        """Add a raw OVSDB operation to the transaction
+
+        This can be useful for re-using the existing Idl connection to take
+        actions that are difficult or expensive to do with the Idl itself. e.g.
+        deleting a bunch of rows on the server that you don't want to store
+        in memory.
+
+        :param op: An "op" for an OVSDB "transact" request (rfc 7047 Sec 5.2)
+        :type op:   dict
+        """
+        self._operations.append(op)
+
     def commit_block(self):
         """Attempts to commit this transaction, blocking until the commit
         either succeeds or fails.  Returns the final commit status, which may
-- 
2.31.1



More information about the dev mailing list